美文网首页
FFmpeg采集设备(2)

FFmpeg采集设备(2)

作者: Goning | 来源:发表于2019-03-25 10:06 被阅读0次

    FFmpeg中OS X设备操作


    在FFmpeg中采集OS X系统的输入输出设备,常规方式采用的是OS X的avfoundation设备进行采集。

    ffmpeg -h demuxer=avfoundation
    
    Demuxer avfoundation [AVFoundation input device]:
    AVFoundation input device AVOptions:
      -list_devices      <int>        .D....... list available devices (from 0 to 1) (default false)
         true                         .D....... 
         false                        .D....... 
      -video_device_index <int>        .D....... select video device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
      -audio_device_index <int>        .D....... select audio device by index for devices with same name (starts at 0) (from -1 to INT_MAX) (default -1)
      -pixel_format      <pix_fmt>    .D....... set pixel format (default yuv420p)
      -framerate         <video_rate> .D....... set frame rate (default "ntsc")
      -video_size        <image_size> .D....... set video size
      -capture_cursor    <int>        .D....... capture the screen cursor (from 0 to 1) (default 0)
      -capture_mouse_clicks <int>        .D....... capture the screen mouse clicks (from 0 to 1) (default 0)
    

    1、OS X下查看设备列表
    ffmpeg -devices
    
    Devices:
     D. = Demuxing supported
     .E = Muxing supported
     --
     D  avfoundation    AVFoundation input device
     D  lavfi           Libavfilter virtual input device
      E sdl,sdl2        SDL2 output device
    

    如上信息,分为两大部分:

    • 解封装或封装的支持情况
    • 设备列表

    2、OS X下设备采集

    枚举avfoundation支持的输入设备:

    ffmpeg -f avfoundation -list_devices true -i ""
    
    [AVFoundation input device @ 0x7fea535022c0] AVFoundation video devices:
    [AVFoundation input device @ 0x7fea535022c0] [0] FaceTime 高清摄像头(内建)
    [AVFoundation input device @ 0x7fea535022c0] [1] Capture screen 0
    [AVFoundation input device @ 0x7fea535022c0] AVFoundation audio devices:
    [AVFoundation input device @ 0x7fea535022c0] [0] Built-in Microphone
    

    视频输入设备:

    • [0] FaceTime 高清摄像头(内建)
    • [1] Capture screen 0
      音频输入设备:
    • [0] Built-in Microphone

    avfoundation除了枚举了物理摄像头(FaceTime 高清摄像头)之外,还包括了1个虚拟设备,即Capture screen 0设备代表了OS X桌面。

    (1)采集内置摄像头

    ffmpeg -f avfoundation -i "FaceTime 高清摄像头(内建)" out.mp4
    
    Input #0, avfoundation, from 'FaceTime 高清摄像头(内建)':
      Duration: N/A, start: 33714.868500, bitrate: N/A
        Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 12 tbr, 1000k tbn, 1000k tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
    Press [q] to stop, [?] for help
    [libx264 @ 0x7fb10b87c600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
    [libx264 @ 0x7fb10b87c600] profile High 4:2:2, level 3.1, 4:2:2 8-bit
    [libx264 @ 0x7fb10b87c600] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=12 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 'out.mp4':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv422p, 1280x720, q=-1--1, 12 fps, 12288 tbn, 12 tbc
        Metadata:
          encoder         : Lavc58.35.100 libx264
        Side data:
          cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    frame=   11 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   18 fps= 16 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   24 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   31 fps= 14 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   37 fps= 13 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   44 fps= 13 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=
    frame=   51 fps= 13 q=26.0 size=       0kB time=-00:00:00.16 bitrate=N/A speed=N
    frame=   58 fps= 13 q=26.0 size=       0kB time=00:00:00.41 bitrate=   0.9kbits/
    frame=   65 fps= 13 q=26.0 size=       0kB time=00:00:01.00 bitrate=   0.4kbits/
    frame=   71 fps= 13 q=26.0 size=       0kB time=00:00:01.50 bitrate=   0.3kbits/frame
    frame=   78 fps= 13 q=26.0 size=       0kB time=00:00:02.08 bitrate=   0.2kbits/
    frame=   84 fps= 13 q=26.0 size=     256kB time=00:00:02.58 bitrate= 811.9kbits/
    frame=   90 fps= 13 q=26.0 size=     256kB time=00:00:03.08 bitrate= 680.3kbits/
    frame=   97 fps= 13 q=26.0 size=     512kB time=00:00:03.66 bitrate=1144.0kbits/
    frame=  103 fps= 12 q=26.0 size=     512kB time=00:00:04.16 bitrate=1006.7kbits/
    frame=  110 fps= 12 q=26.0 size=     768kB time=00:00:04.75 bitrate=1324.6kbits/
    frame=  113 fps=9.6 q=-1.0 Lsize=    1950kB time=00:00:09.16 bitrate=1742.6kbits/s speed=0.778x    
    video:1948kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.110501%
    

    (2)采集OS X桌面

    ffmpeg -f avfoundation -i "Capture screen 0" -r:v 30 out1.mp4
    
    Input #0, avfoundation, from 'Capture screen 0':
      Duration: N/A, start: 34246.268167, bitrate: N/A
        Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 2560x1600, 1000k tbr, 1000k tbn, 1000k tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
    Press [q] to stop, [?] for help
    [libx264 @ 0x7fea3f2b7400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
    [libx264 @ 0x7fea3f2b7400] profile High 4:2:2, level 5.0, 4:2:2 8-bit
    [libx264 @ 0x7fea3f2b7400] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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 'out1.mp4':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv422p, 2560x1600, q=-1--1, 30 fps, 15360 tbn, 30 tbc
        Metadata:
          encoder         : Lavc58.35.100 libx264
        Side data:
          cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    frame=   17 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0
    frame=   33 fps= 32 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0
    frame=   55 fps= 30 q=29.0 size=     256kB time=00:00:00.06 bitrate=31432.2kbits/
    frame=   81 fps= 30 q=29.0 size=     256kB time=00:00:00.93 bitrate=2247.2kbits/s
    frame=   98 fps= 30 q=29.0 size=     256kB time=00:00:01.50 bitrate=1398.3kbits/s
    frame=  114 fps= 30 q=29.0 size=     256kB time=00:00:02.03 bitrate=1031.5kbits/s
    frame=  130 fps= 30 q=29.0 size=     256kB time=00:00:02.56 bitrate= 817.2kbits/s
    frame=  148 fps= 30 q=29.0 size=     256kB time=00:00:03.16 bitrate= 662.4kbits/s
    frame=  148 fps= 21 q=-1.0 Lsize=     422kB time=00:00:04.83 bitrate= 714.5kbits/
    s dup=95 drop=0 speed=0.691x    
    video:419kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.606895%
    

    参数Capture screen 0指定了桌面0为输入设备,与x11grab的方式类似,我们还可以录制鼠标,在OS X上通过capture_cursor来指定:

    ffmpeg -f avfoundation -capture_cursor 1 -i "Capture screen 0" -r:v 30 out2.mp4
    

    (3)采集麦克风

    ffmpeg -f avfoundation -i "0:0" out.aac
    

    通过参数“0:0”分别指定第0个视频设备与第0个音频设备,输出信息如下:

    Input #0, avfoundation, from '0:0':
      Duration: N/A, start: 35022.728322, bitrate: N/A
        Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 1280x720, 23.92 tbr, 1000k tbn, 1000k tbc
        Stream #0:1: Audio: pcm_f32le, 44100 Hz, stereo, flt, 2822 kb/s
    Stream mapping:
      Stream #0:1 -> #0:0 (pcm_f32le (native) -> aac (native))
    Press [q] to stop, [?] for help
    Output #0, adts, to 'out.aac':
      Metadata:
        encoder         : Lavf58.20.100
        Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
        Metadata:
          encoder         : Lavc58.35.100 aac
    size=      71kB time=00:00:04.50 bitrate= 129.6kbits/s speed=1.05x    
    video:0kB audio:70kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.896118%
    

    如上信息所示,采集的数据包含了视频rawvideo数据和音频pcm_f32le数据,但是编码输出只有AAC的编码的数据。
    除了以上方法,还可以使用设备索引参数指定设备采集:

    ffmpeg -f avfoundation -video_deivce_index 0 -i ":0" out.aac
    ffmpeg -f avfoundation -video_deivce_index 0 -audio_device_index 0 out.aac
    

    相关文章

      网友评论

          本文标题:FFmpeg采集设备(2)

          本文链接:https://www.haomeiwen.com/subject/kketvqtx.html