我有两个输入源,每个都是视频+音频。我使用拍手声和叠加的音频频率来确定第一个输入领先 x=1.555s。我想创建一个由第一和第二个输入的同步视频和音频组成的输出。
为了试验,我忽略了偏移量,并尝试了以下基于以下代码的不同变体类似帖子。我可以判断音频来自第一个来源,因为图像和声音是同步的。
显然,我误解了代码的作用。有人能解释一下并提出建议来实现既定目标吗?
$ ffmpeg -i ipad.MOV -i laptop.webm -vcodec copy -acodec copy muxed.MP4
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
WARNING: library configuration mismatch
avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ipad.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2019-05-06T19:22:15.000000Z
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPad mini 4
com.apple.quicktime.software: 12.1
com.apple.quicktime.creationdate: 2019-05-06T15:22:15-0400
Duration: 00:00:15.19, start: 0.000000, bitrate: 8385 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 8279 kb/s, 30.02 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 90
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 93 kb/s (default)
Metadata:
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
Input #1, matroska,webm, from 'laptop.webm':
Metadata:
encoder : GStreamer matroskamux version 1.14.1
creation_time : 2019-05-06T19:22:16.000000Z
Duration: 00:00:15.90, start: 0.000000, bitrate: 1106 kb/s
Stream #1:0(eng): Video: vp8, yuv420p(progressive), 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Metadata:
title : Video
Stream #1:1(eng): Audio: vorbis, 44100 Hz, mono, fltp (default)
Metadata:
title : Audio
Output #0, mp4, to 'muxed.MP4':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
com.apple.quicktime.creationdate: 2019-05-06T15:22:15-0400
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPad mini 4
com.apple.quicktime.software: 12.1
encoder : Lavf57.83.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, q=2-31, 8279 kb/s, 30.02 fps, 30 tbr, 19200 tbn, 600 tbc (default)
Metadata:
rotate : 90
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 93 kb/s (default)
Metadata:
creation_time : 2019-05-06T19:22:15.000000Z
handler_name : Core Media Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 456 fps=0.0 q=-1.0 Lsize= 15539kB time=00:00:15.18 bitrate=8382.5kbits/s speed=32.6x
video:15350kB audio:175kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.091235%
其他变体:
$ ffmpeg -i ipad.MOV -i laptop.webm -c:v copy -c:a copy muxed.MP4
答案1
FFmpeg 可以-map
选择明确指定哪些流用于输出。如果没有-map
,ffmpeg 有一个自动流选择算法,它可能不会选择您想要的流。
用于-map
挑选输出流:
ffmpeg -i ipad.MOV -itsoffset 1.555 -i laptop.webm -map 0:v -map 1:a -c copy muxed.MP4
看http://ffmpeg.org/ffmpeg.html#Stream-selection
将第二次输入延迟itsoffset
1.555 秒。请注意,您的播放器必须支持 MP4 中的编辑列表才能实现延迟。大多数现代播放器都支持。