user30663: 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...

user30687: 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.

30663: <p>I had initially used VLC to record the screen of computer using the following script:</p>
<pre><code>/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}
</code></pre>
<p>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.</p>
<p>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.</p>
<p>A sample FFmpeg command I tried:</p>
<pre><code>ffmpeg -hide_banner  -f avfoundation -i &quot;2:none&quot; -r 10 -vf &quot;scale=-1:720,setsar=sar=10/9&quot;  -c:v h264_videotoolbox -b:v 1250K -keyint_min 20 -bf 5 testing_ffmpeg.mp4
</code></pre>
<p>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...</p>
 30687: <p>Okay, I found the one option that will show you whether there is hardware support:</p>
<pre><code>ffmpeg -codecs | less
</code></pre>
<p>Then search for your format, it looks like you'd type:</p>
<pre><code>/h264&lt;enter&gt;
</code></pre>
<p>In my case, it shows me that I have <code>nvenc</code> as one of the sub-options:</p>
<blockquote>
<p>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 )</p>
</blockquote>
<p>Reading from the <a href="https://developer.nvidia.com/ffmpeg" rel="nofollow noreferrer">nvidia/ffmpeg</a> 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.</p>
<p>Next you need the following option:</p>
<pre><code>... -hwaccel auto ...
</code></pre>
<p>The default, as I mentioned in my comment, is <code>none</code>.</p>
<p>For more info you may want to look at the manual page:</p>
<pre><code>man ffmpeg
</code></pre>
<p>and search for <code>hardware</code> or <code>hw</code>.</p>
