Capture Windows screen with ffmpeg

2020-05-11 09:47发布

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?

7条回答
等我变得足够好
2楼-- · 2020-05-11 10:26

This will help for capturing the working screen on windows :

ffmpeg -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 c:/video_comapre2.mp4

查看更多
Summer. ? 凉城
3楼-- · 2020-05-11 10:30

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"
查看更多
虎瘦雄心在
4楼-- · 2020-05-11 10:30

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
查看更多
何必那么认真
5楼-- · 2020-05-11 10:40

*this code is tried successfully on windows XP Sp3 and ffmpeg (last version 28/12/2012 for windows) -ffmpeg.exe must be copied in c:\windows\system32 directory for being accessed from anywhere from your PC) ScreenCapture can be downloaded for free (google). Install it (msi file). Its registered automatically from the (ScreenCapture.ax file). It's sent with an IscrenCapture.h file also.

-capture screen video and audio (adjust the device audio you have-mine is RealTek AC97 Audio) I cannot install params of UscreenCapture in registry (tried even on IscrenCapture.h file ).It always provide the full scren capture only. There is an error in registry location,in parameters types (dwords are specified by the author but reg_binary is installed)... then i used the crop() ffmpeg function to capture any region on the screen.the command line is :

xwidth, xheight are the width & height of the region want to capture. xleft, xtop the coord of the top left point of the rectangle capture.

ffmpeg -f dshow -i video="UScreenCapture":audio="Realtek AC97 Audio" -vf crop=xwidth:xheight:xleft:xtop c:\output.flv

to capture video only can use

ffmpeg -f dshow -i video="UScreenCapture" -vf  crop=xwidth:xheight:xleft:xtop c:\output.flv

NB: x11grab dont work on windows (it's specifically for Linux/X11) can use wscript.shell to code the line command silently. i used the format video output as flv because i have the best rendering and small capacity.I dont success with mp4.

you can know your media devices with ffmpeg:

ffmpeg -list_devices true -f dshow -i dummy

-you can record any sound from your pc with this command line (adapt the device you have):

ffmpeg -f dshow -i audio="Realtek AC97 Audio" -acodec libmp3lame "c:\out.mp3"
查看更多
Anthone
6楼-- · 2020-05-11 10:40

http://nerdlogger.com/2011/11/03/stream-your-windows-desktop-using-ffmpeg/

explains how to do it.

basically, install uscreencapture dshow filter, then ffmpeg -f dshow -i video="UScreenCapture" out.mp4

查看更多
在下西门庆
7楼-- · 2020-05-11 10:50

Use the built-in GDI screengrabber (no install needed) like this :

ffmpeg -f gdigrab -framerate 10 -i desktop [output]

This will capture ALL your displays as one big contiguous display.

If you want to limit to a region, and show the area being grabbed:

ffmpeg -f gdigrab -framerate ntsc -offset_x 10 -offset_y 20 -video_size 640x480 \
-show_region 1 -i desktop [output]

To grab the contents of the window named "Calculator":

ffmpeg -f gdigrab -framerate 25 -i title=Calculator [output]

I found that framerate 10 suits screen capture well (you can change it).

I have encoded to both files and streaming outputs and it works quite well.

查看更多
登录 后发表回答