While ffmpeg is recording, I want it to create a smaller and lower quality video

1.2k Views Asked by At

Currently I am using this...

ffmpeg -video_size 1920x1080 -framerate 1 -f x11grab -i :0.0+0,0 -f pulse -ac 2 -i default -t 00:00:10 Output.mkv

While ffmpeg is recording a video, I want it to significantly reduce both the size and quality compared to the ffmpeg command above.

In case you are curious, I am recording brief quality assurance videos to ensure a simple little web scraper I wrote in Python is scraping data properly (specifically, that it is clicking on a particular button, at a particular time, on a particular web page). My Python script triggers the command above to start recording my screen a few seconds before my Python script is supposed to click on that button.

Of course, to verify a button on a web page had been clicked on, low quality video resolution would normally suffice.

2

There are 2 best solutions below

2
On BEST ANSWER

For libx264/libx265 the most important option to reduce both the size and quality is -crf. This option controls quality. A value of 51 provides the worst quality. If it's too terrible then use a lower number.

ffmpeg -video_size 1920x1080 -framerate 1 -f x11grab -i :0.0+0,0 -f pulse -channels 2 -i default -t 00:00:10 -c:v libx264 -crf 51 -c:a libopus Output.mkv

See FFmpeg Wiki: H.264.

1
On

For significantly reduce both the size and quality of Output.mkv you can use the next ffmpeg configuration:

crop: iw-(cut width in pixels):ih-(cut heigth in pixels)

scale: to set the ratio and resolution (example 1700x800)

crf: to set quality, where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless

bitrate value: -b:v value -minrate value and -maxrate max value (example -b:v 4000K -minrate 2000K -maxrate 6000K)

preset: in theory slow is best quality/size, and you can probe ultrafast superfast veryfast faster fast medium – default preset slow slower veryslow

Cut a part of video, changue the resolution, changue crf, and bitrate, first only video, then you can add audio in other work, dont mix, repeat, is very important, encoding/decoding audio and video separate, then you can mix all, but first the video like in this example

ffmpeg -i  Output.mkv   -map 0:v  -vf  crop=iw-150:ih-85,scale=ih*16/9:ih,scale=1072:732,setsar=1   -c:v libx264 -crf 17  -b:v 4000K -maxrate  6000K -bufsize 4M   -movflags -faststart  -preset veryfast -dn video-new.mkv