ffmpeg使用命令行视频采集录制

时间:2021-7-2 作者:qvyue

ffmpeg使用命令行视频采集录制

电脑为mac系统

ffmpeg使用命令行视频采集录制
image-20210517174110404
ffmpeg -devices -hide_banner
Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
 D  avfoundation    AVFoundation input device
 D  lavfi           Libavfilter virtual input device
  E sdl,sdl2        SDL2 output device
 D  x11grab         X11 screen capture, using XCB
  • D. = Demuxing supported(支持视频/音频封装)
  • E = Muxing supported(支持解封装视频/音频)

avfoundation支持的设备

ffmpeg -f avfoundation -list_devices true -i ''
[AVFoundation indev @ 0x7f97d2708b80] AVFoundation video devices:
[AVFoundation indev @ 0x7f97d2708b80] [0] FaceTime高清摄像头(内建)
[AVFoundation indev @ 0x7f97d2708b80] [1] Capture screen 0
[AVFoundation indev @ 0x7f97d2708b80] [2] Capture screen 1
[AVFoundation indev @ 0x7f97d2708b80] [3] Capture screen 2
[AVFoundation indev @ 0x7f97d2708b80] AVFoundation audio devices:
[AVFoundation indev @ 0x7f97d2708b80] [0] Built-in Microphone
ffmpeg使用命令行视频采集录制
image-20210517174828309

0号设备就是Mac自带的摄像头。

avfoundation支持的参数

ffmpeg -h demuxer=avfoundation -hide_banner

输出结果

Demuxer avfoundation [AVFoundation input device]:
AVFoundation indev AVOptions:
  -list_devices          .D........ list available devices (default false)
  -video_device_index         .D........ select video device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
  -audio_device_index         .D........ select audio device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
  -pixel_format          .D........ set pixel format (default yuv420p)
  -framerate         
  • -video_size:分辨率
  • -pixel_format:像素格式

    • 默认是yuv420p
  • -framerate:帧率(每秒采集多少帧画面)

    • 默认是ntsc,也就是30000/1001,约等于29.970030
  • -list_devices:true表示列出avfoundation支持的所有设备
ffmpeg -f avfoundation  -video_device_index 0 -i "" -hide_banner
[avfoundation @ 0x7f8c3780bc00] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7f8c3780bc00] Supported pixel formats:
[avfoundation @ 0x7f8c3780bc00]   uyvy422
[avfoundation @ 0x7f8c3780bc00]   yuyv422
[avfoundation @ 0x7f8c3780bc00]   nv12
[avfoundation @ 0x7f8c3780bc00]   0rgb
[avfoundation @ 0x7f8c3780bc00]   bgr0
[avfoundation @ 0x7f8c3780bc00] Overriding selected pixel format to use uyvy422 instead.
Input #0, avfoundation, from '':
  Duration: N/A, start: 32990.458967, bitrate: N/A
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 30 tbr, 1000k tbn, 1000k tbc
At least one output file must be specified

录制

ffmpeg -f avfoundation -i 0 out.yuv -hide_banner

输出

[avfoundation @ 0x7f830a012e00] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7f830a012e00] Supported pixel formats:
[avfoundation @ 0x7f830a012e00]   uyvy422
[avfoundation @ 0x7f830a012e00]   yuyv422
[avfoundation @ 0x7f830a012e00]   nv12
[avfoundation @ 0x7f830a012e00]   0rgb
[avfoundation @ 0x7f830a012e00]   bgr0
[avfoundation @ 0x7f830a012e00] Overriding selected pixel format to use uyvy422 instead.
Input #0, avfoundation, from '0':
  Duration: N/A, start: 31535.985400, bitrate: N/A
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 15 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help

修改参数 -pixel_format:像素格式

ffmpeg -f avfoundation -pixel_format uyvy422 -i 0 out.yuv -hide_banner
Input #0, avfoundation, from '0':
  Duration: N/A, start: 33830.098033, bitrate: N/A
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 25 tbr, 1000k tbn, 1000k tbc
File 'out.yuv' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, rawvideo, to 'out.yuv':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, q=2-31, 368640 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.91.100 rawvideo

添加-framerate试试

ffmpeg -f avfoundation  -video_size 640x480 -framerate 30 -pixel_format yuyv422 -i 0  out.yuv -hide_banner
[avfoundation @ 0x7fb6a9817600] Selected framerate (30.000000) is not supported by the device.
[avfoundation @ 0x7fb6a9817600] Supported modes:
[avfoundation @ 0x7fb6a9817600]   160x120@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   160x120@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   160x120@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   160x120@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   176x144@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   176x144@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   176x144@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   176x144@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   320x240@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   320x240@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   320x240@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   320x240@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   352x288@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   352x288@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   352x288@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   352x288@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   480x360@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   480x360@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   480x360@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   480x360@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   640x480@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   640x480@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   640x480@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   960x544@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   960x544@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   960x544@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   960x544@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   1024x576@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   1024x576@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   1024x576@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   1024x576@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   960x720@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   960x720@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   960x720@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   960x720@[14.999993 14.999993]fps
[avfoundation @ 0x7fb6a9817600]   1280x720@[29.970000 29.970000]fps
[avfoundation @ 0x7fb6a9817600]   1280x720@[25.000000 25.000000]fps
[avfoundation @ 0x7fb6a9817600]   1280x720@[23.999981 23.999981]fps
[avfoundation @ 0x7fb6a9817600]   1280x720@[14.999993 14.999993]fps
0: Input/output error
ffmpeg -f avfoundation  -video_size 640x480 -framerate 29.970000 -pixel_format yuyv422 -i 0  out.yuv -hide_banner
Input #0, avfoundation, from '0':
  Duration: N/A, start: 33899.406533, bitrate: N/A
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 25 tbr, 1000k tbn, 1000k tbc
File 'out.yuv' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, rawvideo, to 'out.yuv':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, q=2-31, 122880 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.91.100 rawvideo
frame=  110 fps= 47 q=-0.0 Lsize=   66000kB time=00:00:04.40 bitrate=122880.0kbits/s dup=42 drop=0 speed=1.89x
ffmpeg使用命令行视频采集录制
image-20210517183353547
播放录制好的YUV。
ffplay -video_size 640x480 -pixel_format yuyv422 -framerate 25 out.yuv
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。