3

I had initially used VLC to record the screen of computer using the following script:

/Applications/VLC.app/Contents/MacOS/VLC -I rc screen:// --sout-keep --screen-fps=7.0 --screen-index=0 --sout #transcode{vcodec=h264,vb=1500,width=1280,height=720,acodec=mp3,ab=128,channels=2,samplerate=44100}:file{dst=/Users/shashi/temp/vlctesting4.mp4,no-overwrite}

The audio codec parameters are redundant because I am only recording the screen. However, with these video parameters, I get a decent recording of the screen without a noticeable cpu usage as well as relatively low file size.

Now I have to achieve the same but using FFmpeg instead of VLC. I thought that should be possible because both use the same underlying library. However, no matter how much I try, FFmpeg recording takes more CPU and the resulting file takes up much more space than what VLC achieves.

A sample FFmpeg command I tried:

ffmpeg -hide_banner  -f avfoundation -i "2:none" -r 10 -vf "scale=-1:720,setsar=sar=10/9"  -c:v h264_videotoolbox -b:v 1250K -keyint_min 20 -bf 5 testing_ffmpeg.mp4

Both are using the h264 encoding but how is VLC more efficient by such a degree? In fact VLC does not even seem to use the HW acceleration for encoding.. ? But a 1 minute recording from VLC is around 1 MB with decent quality but to get similar quality from FFmpeg, the file size is around 7 MB...

2
  • Yes. The VLC is most certainly using the HW accelerated compressor. For ffmpeg, you'll need to find the correct command line options to force the use of a compressor which supports hardware. Jul 9, 2021 at 17:51
  • What codec does VLC say it is using?
    – rogerdpack
    Dec 3, 2022 at 0:27

1 Answer 1

2

Okay, I found the one option that will show you whether there is hardware support:

ffmpeg -codecs | less

Then search for your format, it looks like you'd type:

/h264<enter>

In my case, it shows me that I have nvenc as one of the sub-options:

DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_crystalhd h264_v4l2m2m h264_vdpau h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc h264_omx h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )

Reading from the nvidia/ffmpeg page, if ffmpeg is compiled with hardware acceleration, it should auto-pickup the available hardware encoder. However, hardware may not always encode with the same level of quality so it may be preferable to use software anyway. If you need realtime, though, you definitely want the hardware when available.

Next you need the following option:

... -hwaccel auto ...

The default, as I mentioned in my comment, is none.

For more info you may want to look at the manual page:

man ffmpeg

and search for hardware or hw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.