Saturday 3 May 2014

Capturing video in Ubuntu 14.04

(Disclamer: never captured video before, must be missing a whole lot of things and optimizations).

The following line will capture 1920x1080 screen at 30 frames per second and is suitable for taking video game footage.

avconv -f x11grab -r 30 -s hd1080 -i :0.0 -f pulse -name 'screencap -> system audio' -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -map 0 -map 1  -codec:v libx264 -pre:v lossless_ultrafast -codec:a libmp3lame -threads auto -y captured.avi

If audio & video are out of sync, chances are you have run into yet another bug in Ubuntu.

http://askubuntu.com/questions/336747/audio-and-video-auto-of-sync-when-streaming
https://github.com/MaartenBaert/ssr/issues/16

To fix that, set the 2 following values in  /etc/pulse/daemon.conf:
does storing
default-sample-rate = 44100
alternate-sample-rate = 44100
To get window geometry if you're capturing a window, you can use xwininfo and then change the resolution (-s WxH) and offset (-i :0.0+x_off,y_off) accordingly.

Expect that 1 minute of stream will hog roughly 1GB with these settings for 1080p.

When the capture is done, compress & (optionally)cut:
avconv -i captured.avi -ss FROM_TIME -t LENGTH -vcodec libx264 -pre:v veryslow -acodec libmp3lame result.avi

So why is GNU/Linux not a popular platform for gaming and streaming? Anyone?

Update as of August 22, 2014 (still needs some polish):

The following line allows for real-time capture AND encoding. The line gives a 50 MB/min output and looks like a full replacement to the old one.
avconv -f x11grab -s hd1080 -i :0.0 -f pulse -name 'screencap -> system audio' -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -map 0 -map 1  -codec:v libx264 -pre:v ultrafast -codec:a libmp3lame -af asyncts -threads auto -y captured.mkv

add -filter:v scale=960:-1 (or whatever size you prefer) to record downscaled video. Reduces video size and some CPU power (obviously) at the cost of lower resolution.

Seems like the -r parameter specified earlier may actually cause audio/video desync when the encoder cannot keep up with the input. If there is still desync, try loading the game and THEN starting the capture (still don't know what's causing this).

Update as of May 05, 2015:

OBS now natively supports Linux. The up-to-date version that I tried was a bit buggy, but it was still a great improvement over what I had been dealing with before. One small caveat is that it needs ffmpeg instead of avconv, and those two hate each other with passion. It IS possible to install ffmpeg locally in your home directory (without removing avconv) and make OBS use it from there, though you'll probably need to compile ffmpeg and OBS manually to do that (which is fairly straightforward regardless, I must add).

No comments:

Post a Comment