使用 ffmpeg 捕获 Windows 屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6766333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Capture Windows screen with ffmpeg
提问by kamae
The ffmpegis 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的是跨平台的,非常强大的软件来处理视频/音频或流呢。在 Linux 上,ffmpeg 可以使用以下命令捕获 X11 屏幕:
ffmpeg -f x11grab -r 25 -s cif -i :0.0 out.mpeg
But is it possible to grab Windows Desktop with ffmpeg?
但是是否可以使用 ffmpeg 抓取 Windows 桌面?
回答by frustrated
Use the built-in GDI screengrabber(no install needed) like this :
使用内置的 GDI 屏幕抓取器(无需安装),如下所示:
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":
获取名为“Calculator”的窗口的内容:
ffmpeg -f gdigrab -framerate 25 -i title=Calculator [output]
I found that framerate 10 suits screen capture well (you can change it).
我发现帧率 10 非常适合屏幕捕获(您可以更改它)。
I have encoded to both files and streaming outputs and it works quite well.
我已经对文件和流输出进行了编码,并且效果很好。
回答by M. D. P
This will help for capturing the working screen on windows :
这将有助于在 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
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_fm0 p yuv4 /video_comapre2.mp4
回答by Ybenam
*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.
*此代码已在 Windows XP Sp3 和 ffmpeg(Windows 最新版本 28/12/2012)上成功尝试 -ffmpeg.exe 必须复制到 c:\windows\system32 目录中,以便从您的 PC 上的任何位置访问) ScreenCapture 可以免费下载(谷歌)。安装它(msi 文件)。它从(ScreenCapture.ax 文件)自动注册。它也与 IscrenCapture.h 文件一起发送。
-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 :
-捕获屏幕视频和音频(调整您拥有的设备音频 - 我的是 RealTek AC97 音频)我无法在注册表中安装 UscreenCapture 的参数(即使在 IscrenCapture.h 文件上也尝试过)。它始终仅提供完整的屏幕捕获。注册表位置有错误,参数类型有错误(dwords 由作者指定,但安装了 reg_binary)...然后我使用了crop() ffmpeg 函数来捕获屏幕上的任何区域。命令行是:
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.
xwidth
,xheight
是要捕获的区域的宽度和高度。
xleft
,xtop
矩形捕获左上点的坐标。
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.
注意:x11grab 在 Windows 上不起作用(它专门用于 Linux/X11)可以使用 wscript.shell 以静默方式对 line 命令进行编码。我使用格式视频输出作为 flv,因为我有最好的渲染和小容量。我没有成功使用 mp4。
you can know your media devices with ffmpeg:
您可以使用 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"
回答by somejerk
http://nerdlogger.com/2011/11/03/stream-your-windows-desktop-using-ffmpeg/
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
基本上,安装 uscreencapture dshow 过滤器,然后 ffmpeg -f dshow -i video="UScreenCapture" out.mp4
回答by Andreas Kl?ckner
A patch to implement this was sent to the ffmpeg mailing lista while back. This would have implemented gdigrab
to work just like x11grab
.
不久前,一个实现此功能的补丁已发送到ffmpeg 邮件列表。这会gdigrab
像x11grab
.
Also, the ffmpeg codec pagesays "VfW" (Video for Windows? aka DirectShow?) capture is supported.
此外,ffmpeg 编解码器页面显示支持“VfW”(Windows 视频?又名 DirectShow?)捕获。
回答by Sourcephy
ffmpeg windows static version 4.2.2, screen recording with audio
ffmpeg windows 静态版本 4.2.2,带音频的屏幕录制
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)".
接下来复制您的音频=“您的麦克风或立体声混音”,我的是“麦克风(Realtek 高清晰度音频)”。
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"
回答by Atita Halemani
This can be done without using x11grab/xcbgrab/gdigrab
with help of the below commands in linux
.
这可以在不使用x11grab/xcbgrab/gdigrab
以下命令的帮助下完成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