Post

Recording video on Linux

#1
I saw Josh's dev log on how he could finally record his linux version of LT but wanted to finteune it for more quality. I'm going to ask here, how exactly did you do that? Last week coincidentally I was looking into this. And it took me a bit of time to figure out the right way to get the thing to record like I wanted it to, but I really like using ffmpeg to do this, generally gave me a much better experience than anything I ever used on windows, from fraps to OBS. This is the command I personally use, naturally set up as an alias in bashrc so I don't have to remember it.

Code: Select all

ffmpeg -f alsa -ac 2 -i plughw:0,0 -async 1 -f x11grab -s 1920x1080 -i :0.0 -c:a libmp3lame -b:a 384k -c:v libx264 -b:v 4000k -r 30 -preset faster output.mkv
It took me a bit of research to find the right combination of arguments for me, but ffmpeg recordings default to libx264 (which is very nice quality vs compression, wouldn't have it any other way! which is why I specify it in my arguments to make doubly sure) and I am using mp3 for compressed audio. the "-r 30" is saying 30fps and "-s 1920x1080" is something anyone can guess (resolution) and then there is "b:a" and "b:v" which set the bitrate. This is what I personally like to use when recording (but I don't need to meet any sort of quality standards, I'm mostly not recording games)

The tricky part for me was getting the sound and video to sync, it might actually be better to use a different program (audacity is a good choice) to record sound and then merge the files. To get it working I specifically needed to add the command "-async 1" and I needed to specify framerate at the output (-r 30) not at the input (this was in my older configuration located after the 1920x1080 setting) and finally, at any preset slower than "faster" my audio can break during recording (otherwise I would use the default medium). The alternative would be to figure this out or use pulseaudio. I'm lazy so I went for the easiest route by using a faster preset.

You can see a list of the available presets here i'm using "faster", but I hear even a low end 12" laptop can record on the ultrafast preset. (so just add "-preset ultrafast" if thats what you need) what a faster preset does is just lower the compression rate.

This yields truly nice quality video(x264 is known as one of the highest quality codecs) at very good compression and for me it worked out pretty well to record games too, you can always increase the FPS of the video too if needed but I haven't experimented with that (30 or more specifically 23/24 fps is usually what videos run at.) Just seeing if I can help :thumbup: sadly I don't have a mic, and would record voice separate from the video itself, but it can't be that hard to tell it to record mic. If it's hard to figure out though, you can just cheat and download teamspeak 3 and use that to record your voice through the mic while you're recording the video (that is actually what I do 8-) just make sure not to use voice activation detection when recording. For best quality I use the CELT Mono codec in teamspeak at maximum quality) (or you could use audacity for better quality control)

The alternative to the h264 codec would be VP8, here they are compared. Of course you can also look into h265 and vp9, the next gen codecs essentially. h265 might actually be available for ffmpeg already (i'll have to check) question is if youtube can decode it. (Edit: I actually tried, but failed to record anything with hevc, all i managed to get were either a black screen or errors)

I recommend recording first in lossless for maximum quality and performance together during the recording

Code: Select all

ffmpeg -f alsa -ac 2 -i plughw:0,0 -async 1 -f x11grab -s 1920x1080 -i :0.0 -c:a flac -c:v libx264 -r 60 -preset ultrafast -qp 0 output.mkv
(if 60FPS is what you want)
then encode it again with the veryslow preset, like so

Code: Select all

ffmpeg -i output.mkv c:a flac -b:a 384k c:v libx264 -b:v 8000k -preset veryslow compressed.mkv
'

To get the most out of the codec's compression capabilities. (Encoding veryslow takes a long time, probably longer than the video itself)

What I think (but don't truly know) "-qp 0" does is set it to record losslessly, that is it records at the same bitrate as source (when I used it I had 28000k bitrate and a 2 minute file at 400mbs (seems lossless to me judging by that size)). If you don't want that enormous filesize, just set a bitrate on the original capture with "-b:v" but remember to erase the "-qp 0" setting.

More on recommended specs here. Note that I read somewhere Mkv is the best format for uploading to youtube (not mp4 like that page suggests)

Bitrates in video generally affect how smooth it is overall (8000 should be very very smooth) although I don't know how exactly it works for audio. This setting also has an enormous impact on the filesize.

If you want to deinterlace, go here.

Hint: You can set an alias for encoding by ending the command with "-i" instead of starting with it
Hint 2: You can set the naming of the output files in the alias to be bound to date and time so you won't have to overwrite everytime you run the command
Please tell me you saw this Josh! :roll: it was a lot of work to get this right.
This is where the cat is from and yes you should definitely watch that.

Online Now

Users browsing this forum: No registered users and 23 guests

cron