Saturday, January 28, 2012

Getting screen recording to sort of work on ubuntu latest

I'm writing this down for you as much as me. I recently had gtk-record get in a serious fight with mencoder and ffmpeg. FFmpeg never parsed swscaler properly for me. So my initial response was to use mencoder to reindex the file then use the great ffmpeg tool to do all the transcoding. Recently, something got borked during an upgrade and now the frame-rate gets messed up during mencoder reindexing, so the video component plays in fast-forward.

My solution was to take ALL of the transcoding I could out of the hands of automated tools and do it manually. So the flow looks something like this:

Record with ffmpeg x11grab
Record audio separately with sound recorder(not the best tool, but it works. I probably would have had better results if I had just used alsa as a capture device)
Generate silence with sox if required.
Join audio files and transcode with sox as required.
Combine streams with ffmpeg.
Re-encode once there is no cross codec witchery. <== I could have done this better by fixing the resolution at capture and using alsa as my audio capture device...
Finished.

So recording with x11grab:
I have a multimonitor system and I only record on monitor three so my ffmpeg line looks something like -
ffmpeg -f x11grab -s 1600*900 -sameq -r 25 -i :0.0+3200,0 test.mp4

Using soundrecorder is pretty obvious.

Silence with sox that gets along with soundrecorder was accomplished like so -
sox -n -c 2 -r 44100 silence.mp3 trim 0.0 25
25 being number of seconds 44100 being the expected bitrate of soundrecord and set to 2 channel.

Joining being accomplished by sox -
sox partc1.mp3 silence.mp3 partc2.mp3 full.mp3

AAC transcoding being accomplished like so -
ffmpeg -i full.mp3 -acodec aac -ab 128 full.aac

Combining of streams being accomplished like so -
ffmpeg -i test.mp4 -map 0:0 -vcodec copy -i full.aac -map 1:0 intermediate.mp4

Correcting resolution could have been accomplished in the last step, but I did it separately -
ffmpeg -i intermediate.mp4 -vf scale=1280:720 -sameq final.mp4

And now we have a procedure that works and doesn't crash or complain. I used to use kdenlive, but it has gotten more instead of less buggy for me. When you can't get a tool to work properly, I go to manual steps.

So, there you go... It works, preserves a decent amount of quality, and bypasses a lot of the transcoding hell that generates issues.