FFmpeg 3.3.4 avfoundation 使用命令行仅记录 macOS Sierra 上屏幕的特定部分 [英] FFmpeg 3.3.4 avfoundation to record only a specific section of the screen on macOS Sierra using the command line
问题描述
我通过命令行使用 FFmpeg 3.3.4 版(通过 brew 安装)在我的 macOS Sierra (10.12.6) 上进行一些自动化测试期间记录我的桌面.
I'm using FFmpeg version 3.3.4 (installed via brew) through the command line to record my desktop during some automated tests on my macOS Sierra (10.12.6).
我只想记录屏幕的特定部分,但不幸的是,我无法在文档中找到合适的选项来实现我的目标.
I would like to record only a specific section of the screen but, unfortunately, I'm not able to find the proper options in the documentation to reach my goal.
根据avfoundation的FFmpeg文档,这是我的命令使用:
According to the FFmpeg documentation for avfoundation, this is the command I use:
ffmpeg
-f avfoundation // avfoundation
-pix_fmt uyvy422 // pixel format
-i 1 // input: desktop
-r 30 // framerate for output
[PATH]/test.mp4 // filename
当我运行这个命令时,我有以下输出:
When I run this command I have the following output:
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.37)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --enable-openssl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.3.0/include/openjpeg-2.3 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
[avfoundation @ 0x7fb7d4005800] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, avfoundation, from '1':
Duration: N/A, start: 7263.782833, bitrate: N/A
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1920x1080, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x7fb7d4028400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fb7d4028400] profile High 4:2:2, level 4.0, 4:2:2 8-bit
[libx264 @ 0x7fb7d4028400] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '[PATH]/test.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv422p, 1920x1080, q=-1--1, 30 fps, 15360 tbn, 30 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 83 fps= 28 q=-1.0 Lsize= 525kB time=00:00:02.66 bitrate=1612.6kbits/s dup=1 drop=0 speed=0.889x
我尝试使用 -video_size
选项来设置视频帧大小,但它不起作用.
I tried to use the -video_size
option to set the video frame size, but it doesn't work.
推荐答案
首先你需要找到与你的屏幕对应的AVFoundation设备的名称:
First you need to find the name of the AVFoundation device that corresponds to your screen:
ffmpeg -hide_banner -f avfoundation -list_devices true -i ""
[AVFoundation input device @ 0x7fc1cd40ec60] AVFoundation video devices:
[AVFoundation input device @ 0x7fc1cd40ec60] [0] HD Pro Webcam C920
[AVFoundation input device @ 0x7fc1cd40ec60] [1] FaceTime HD Camera (Built-in)
[AVFoundation input device @ 0x7fc1cd40ec60] [2] Capture screen 0
[AVFoundation input device @ 0x7fc1cd40ec60] AVFoundation audio devices:
[AVFoundation input device @ 0x7fc1cd40ec60] [0] HD Pro Webcam C920
[AVFoundation input device @ 0x7fc1cd40ec60] [1] Built-in Microphone
所以我的屏幕是设备 [2]
因为我连接了两个摄像头,它们是设备 [0]
和 [1]
.
So my screen is device [2]
because I have two cameras attached and they are devices [0]
and [1]
.
然后,当您使用 Mac 时,您可能希望使用 QuickTime 来查看视频,因此您需要确保制作的视频兼容 - 这意味着使用 -pix_fmtyuv420p
.
Then, as you are on a Mac, you will probably want to use QuickTime to view videos, so you need to ensure you make videos that are compatible - that means using -pix_fmt yuv420p
.
ffmpeg -f avfoundation -i "2:0" -vf "crop=1024:768:400:800" -pix_fmt yuv420p -y -r 10 out.mov
1024x768 是视频的宽度和高度,400:800 是我想要录制的屏幕左上角的偏移量.
The 1024x768 are the width and height of the video, and the 400:800 are the offset from top-left of screen that I want to record from.
这篇关于FFmpeg 3.3.4 avfoundation 使用命令行仅记录 macOS Sierra 上屏幕的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!