Declaration of VAR

and some other stuff

Screen recording with FFmpeg

2017-04-24 11:10:38 +0200

2017-04-24 11:10:38 +0200 | Comments

Instead of filming your desktop’s screen with a smartphone, you should record it “directly” from the system. Needless to say, quality of the video will be much better that way.

I’ll show you how to do it with FFmpeg on Windows.

I got most of the information from this article, customized it a bit and also performed several experiments with different settings.

First, you need to install FFmpeg build for Window and then a recording device - usually FFmpeg works with files, but for screen recording you need to provide a screen device, which will be the source for FFmpeg to record. From several possible options for Windows I picked this one.

Now, there are lots of possible quality settings for recording. But in general it’s all about the ballance between the nice picture and the file-size. Here are my experiments with different settings.

Default encoding settings, default FPS (30)

Nothing is specified, FFmpeg uses whatever default settings it has.

ffmpeg -f dshow -i video="screen-capture-recorder" output-no-codec.mp4

CRF specified, default FPS (30)

Now we add the codec and specify the CRF parameter that controls the quality.

ffmpeg -f dshow -i video="screen-capture-recorder" -vcodec libx264 -crf 18 output.mp4

Default encoding settings, FPS 20

When you record a screen, 30 FPS is actually too much, because it’s not a movie, you don’t need the video to be that smooth. So we can limit the framerate to 20 (or even lower). And first let’s leave the encoding settings as defaults again.

ffmpeg -f dshow -i video="screen-capture-recorder" -r 20 output.mp4

CRF specified, FPS 20

And now with 20 FPS limit, but also with codec and CRF specified.

ffmpeg -f dshow -i video="screen-capture-recorder" -r 20 -vcodec libx264 -crf 18 output.mp4

Finally, let’s see the results.

With each experiment I performed a one-minute-long screen-capture and I used different formats and containers (FLV, MP4, MKV) with different encoding and FPS settings.

Here’s a table with results (sorted by the file-size):

Output fileSize, MBCRFFPSMediaInfo report

So, long story short: use AVC format, MP4 container, 20 FPS (or lower) and default encoding settings:

ffmpeg -f dshow -i video="screen-capture-recorder" -r 20 output.mp4

My knowledge about video-encoding is close to nothing, so probably I’m wrong, but from these results I assume that FLV doesn’t use any encoding when not specified (that’s why it gets the biggest files (with the worst video quality an the same time)), and MP4/MKV always applies encoding (even when it wasn’t specified).

…But why default-encoded MKV with 20 FPS is bigger than default-encoded MKV with 30 FPS - I have no idea. And also why the smallest file is a result of default encoding without specifying the CRF :)

If you need to go smaller, if you want to get the smallest file-size possible, then you need to operate with bitrate and profiles directly, do not rely on CRF only. This parameter, as I presume, is just an easy-way option for encoding-dummies like me.