Capture Windows screen with ffmpeg

Viewed 112700

The ffmpeg is cross-platform and very powerful software to handle video/audio or to stream it. On Linux ffmpeg can capture X11 screen with a command below:

ffmpeg -f x11grab -r 25 -s cif -i :0.0 out.mpeg

But is it possible to grab Windows Desktop with ffmpeg?

8 Answers

ffmpeg windows static version 4.2.2, screen recording with audio

to check your microphone

ffmpeg -list_devices true -f dshow -i dummy

next copy your audio="YOUR MICROPHONE OR STEREO MIX", mine is "Microphone (Realtek High Definition Audio)".

ffmpeg -rtbufsize 1500M -f dshow -i audio="Microphone (Realtek High Definition Audio)" -f -y -rtbufsize 100M -f gdigrab -t 00:00:30 -framerate 30 -probesize 10M -draw_mouse 1 -i desktop -c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -pix_fmt yuv420p "d:\ffmpeg_testing.mp4"

This can be done without using x11grab/xcbgrab/gdigrab with help of the below commands in linux .

To record a video,

 ffmpeg -f x11grab  -s 1366x768 -i :0.0 -r 25 -vcodec libx264  output.mkv

To record a frame,

./ffmpeg -f fbdev -framerate 1 -i /dev/fb1 -frames:v 1 screenshot3.jpeg

I would like to add the command I use to capture the screen:

ffmpeg.exe -y ^
-vsync vfr ^
-f gdigrab ^
-indexmem 300M ^
-rtbufsize 1G ^
-probesize 7M ^
-max_probe_packets 50k ^
-draw_mouse 0 ^
-video_size 1280x720 ^
-offset_y 152 ^
-framerate 24 ^
-c:v bmp ^
-strict strict ^
-thread_queue_size 50k ^
-r 24 ^
-i desktop ^
-f dshow ^
-channel_layout stereo ^
-thread_queue_size 50k ^
-strict strict ^
-i "audio=Stereo-mix (Realtek High Definition Audio)" ^
-map 0:v ^
-max_muxing_queue_size 50k ^
-f mp4 ^
-movflags +faststart ^
-max_interleave_delta 0 ^
-c:v libx264 ^
-r 24 ^
-preset fast ^
-tune film ^
-strict strict ^
-crf 25 ^
-pix_fmt yuv422p ^
-map 1:a ^
-max_muxing_queue_size 50k ^
-max_interleave_delta 0 ^
-c:a aac ^
-strict strict ^
-ac 2 ^
screencapture.mp4

The value of probesize appears to have much influence on the audio/video synchronisation. Raising the value by a few megabytes may cause A/V out of sync. Change by 1M or 500k, e.g. to 7500k, at a time. If you leave out the probesize option, ffmpeg will, by default, set the probesize to 5M.

max_interleave_delta option prevents ffmpeg forcing output. If ffmpeg forces output, a message will appear in your log, e.g.: [mp4 @ 00000199f7512040] Delay between the first packet and last packet in the muxing queue is 10007271 > 10000000: forcing output

If ffmpeg takes to much processor time, try changing the -preset option (ultrafast, superfast, veryfast, faster, fast, medium (default), slow, slower, veryslow), larger -crf (constant rate factor), e.g. 32 or lower framerate (-framerate and -r options on several places in the command).

Related