[FFMPEG/Libav] Game capture in Linux

I'm having a problem where if I'm recording at 60fps and a game drops below 60fps the video will speed up to a point where I'm running above 60fps. I'm assuming this is because FFMPEG isn't using variable frame rate. I want to know if it's possible to record with variable frame rate in FFMPEG.

So far I have been using 

avconv -f pulse -ac 2 -ar 44100 -i default -f x11grab -r 60 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 22 -threads 0 video.mkv

and it does record audio once I set it to record the monitor of the analog audio in pavucontrol though the audio is very quiet and sounds weird. The audio is also very out of sync.

Trial and error;

ffmpeg -v 1 -r 30 -f x11grab -s 1920x1080 -i :0.0 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 video.mkv

I got the video part working fine but the audio freaks out now.

use the new OBS rebuild, lol

Well I really don't know how to do this. I've tried flac, mp3, and vorbis in mkv and mp4 and the audio is choppy in all of them.

After a bit more testing I can easily record audio by itself but when I record audio and video together the audio gets all choppy.

Never used ffmpeg, but this worked for me:

Change the built in audio profile to "analog stereo output" instead of "- duplex" in pavucontrol > config. Your audio may crackle the first 10 seconds after you start recording but it wont appear on the video.

Add the -async 1 flag to sync the audio when the recording starts.

ffmpeg -f alsa -i default -v 1 -r 30 -f x11grab -s 1920x1080 -i :0.0 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 -async 1  video.mkv

Thanks I'll try that when I'm back at my desktop. I've already set the audio from the -duplex thing to the 7.1 profile since my on-board audio is 7.1.

Here's a link to my latest try: https://dl.dropboxusercontent.com/u/74532228/video.mkv

You can see the script I'm using in the lower left. The video is fine but the audio is choppy. That's what I'm trying to fix.

Have you tried:

-Change "pulse" to "default"

-Remove the "-ac 2" command?

-Change sound profile to stereo instead of 7.1? (-ac 2 = 2 channels)

-You're also out of sync

Using "default" and stereo there is only a little bit of sound and what there is is choppy.

Did some reading on ffmpeg last night, apparently -async is way outdated and doesn't work, besides it's probably on the wrong spot in the command I suggested anyway. Also found that -r messes the frame timestamping and may cause sync issues, so it's worth trying recording without any fps locks.

So I decided to give it another shot first thing in the morning, and indeed the audio wasn't in sync, guess I just happened to get lucky when trying with -async yeasterday. But I noticed that the audio was constantly about 1 second too late and that the gap didn't change, so adding -itsoffset 1 for the video to delay it with 1 second (hence the 1) fixed the issue. Here's 2 short samples, both with and without the offset modifier.

 

Not in sync:

ffmpeg -f alsa -ac 2 -i default -f x11grab -s hd1080 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -threads 0 video.mp4

http://youtu.be/elAxHSBYw4k

 

Better with with -itsoffset 1

ffmpeg -f alsa -ac 2 -i default -f x11grab -s hd1080 -itsoffset 1 -i :0.0 -acodec mp3 -vcodec libx264 -preset ultrafast -threads 0 video1.mp4

http://youtu.be/vG3Rcgj3__Y

 

So the delay doesn't in- or decrease and can be fixed like that. This is a bummer, there's a lot of people having the same issues with ffmpeg (when you google “ffmpeg”, “ffmpeg out of sync” comes out on top lol), so if anyone has any workarounds I want to know them aswell.

How about removing "-acodec flac" entirely? It's gonna warn about acc being experimental but you can force it.

I removed -r and -async and I'm getting little to no audio :/

Add "-report" to enable logging and record a short snip with audio playback, then post the log file. Or rather attach, it gets very long very quick.

Unrecognized option 'report'.

Probs in the wrong place, place it in front of "video.mkv"

Still not working :/

Wait hold on, I took a closer look at your shell script, what's up with avconv? Doesn't "ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec flac -vcodec libx264 -preset ultrafast -crf 30 -threards 0 -async 1 video.mkv" in the terminal work?