从不同来源捕获音频和视频,如何同步?

时间:2017-02-16 09:31:11

标签: ffmpeg avfoundation

这是我的代码:

Lapaki:~ Lapaki$ /Users/Lapaki/Desktop/ffmpeg -f avfoundation -video_size 960x540 -pixel_format uyvy422 -framerate ntsc -thread_queue_size 8B -i "XI:none" -f avfoundation -thread_queue_size 8B -i "none:XI" -vf 'crop=iw-240:ih:120:0' -af 'asetpts=PTS+.58735/TB' -pix_fmt yuv420p -aspect 4:3 -s 720x480 -q:v 3 -maxrate 5000k -bufsize 2000k -acodec ac3 -ac 2 -ab 256k -ar 48000 -f dvd /Users/Lapaki/Desktop/FF\ Test/`date +%F`\ `date +%H_%M_%S`.mpg
ffmpeg version 3.2.3-tessus Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-version3 --disable-ffplay --disable-indev=qtkit --disable-indev=x11grab_xcb
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, avfoundation, from 'XI:none':
  Duration: N/A, start: 648413.295900, bitrate: N/A
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 960x540, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Input #1, avfoundation, from 'none:XI':
  Duration: N/A, start: 648413.884042, bitrate: 3072 kb/s
    Stream #1:0: Audio: pcm_f32le, 48000 Hz, stereo, flt, 3072 kb/s
Output #0, dvd, to '/Users/Lapaki/Desktop/FF Test/2017-02-16 04_16_33.mpg':
  Metadata:
    encoder         : Lavf57.56.101
    Stream #0:0: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 200 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc57.64.101 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 5000000/0/200000 buffer size: 2000000 vbv_delay: -1
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
    Metadata:
      encoder         : Lavc57.64.101 ac3
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native))
  Stream #1:0 -> #0:1 (pcm_f32le (native) -> ac3 (native))
Press [q] to stop, [?] for help
[swscaler @ 0x7f8e0c8ab400] Warning: data is not aligned! This can lead to a speedloss
frame=   33 fps=0.0 q=3.0 size=     266kB time=00:00:01.06 bitrate=2051.9kbits/sframe=   49 fps= 48 q=3.0 size=     444kB time=00:00:01.54 bitrate=2358.8kbits/sframe=   64 fps= 42 q=3.0 size=     652kB time=00:00:02.08 bitrate=2560.5kbits/sframe=   79 fps= 39 q=3.0 size=     838kB time=00:00:02.59 bitrate=2642.4kbits/sframe=   94 fps= 37 q=3.0 size=    1022kB time=00:00:03.07 bitrate=2720.0kbits/sframe=  109 fps= 36 q=3.0 size=    1208kB time=00:00:03.59 bitrate=2756.5kbits/sframe=  124 fps= 35 q=3.0 size=    1406kB time=00:00:04.07 bitrate=2830.0kbits/sframe=  127 fps= 35 q=3.0 Lsize=    1474kB time=00:00:04.19 bitrate=2876.4kbits/s dup=12 drop=0 speed=1.15x    
video:1310kB audio:113kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.604597%

Input #0的开头是648413.295900,Input #1的开头是648413.884042。

我已经能够通过减去两个值(我假设是壁钟值)来保持音频和视频非常接近同步,并使用asetpts audio filter来延迟录制的mpeg-的音频流2个文件的数量。

我希望能够完全做到这一点,并且每次开始新捕获时该值都会略有变化。更不用说了,我希望能够在不同的机器上可靠地做到这一点,我认为这个值很可能是不同的,因此如果可能的话,使用计算而不是固定数字显然是最好的选择。

有没有办法从输入#1的挂钟开始时间中减去输入#0的挂钟开始时间?我想在asetpts过滤器中执行此操作,而不是手动查找先前运行的差异,每次都会略有不同......

我在想像-af asetpts=PTS-([1:0]RTCSTART-[0:0]RTCSTART)/TB之类的东西可能有用,但我不知道如何格式化它。

提前致谢!

0 个答案:

没有答案