如何叠加多个视频文件并使用ffmpeg合并所有音频?


1

我在网格中叠加2到5个视频文件,我想合并每个视频的所有音频。这是我的代码,结合3个视频文件。我认为它有效,但我得到了一个我不喜欢的警告。

C:\ffmpeg.exe -i C:\Wildlife2.mp4 -i C:\Wildlife3.mp4 -i C:\Wildlife4.mp4 -qscale:v 5  -filter_complex "[0:v]setpts=PTS-STARTPTS,pad=iw:1.5*ih[a]; [1:v]setpts=PTS-STARTPTS,scale=-1:ih/2[b]; [2:v]setpts=PTS-STARTPTS,scale=-1:ih/2[c]; [a][b]overlay=0:h*2[x]; [x][c]overlay=w:h*2; [0:a][1:a][2:a] amerge=inputs=3" grid(3)_2015-08-14.avi

这是输出。

ffmpeg version N-71544-g82d9c4e Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
 --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --ena
ble-decklink --enable-zlib
  libavutil      54. 23.100 / 54. 23.100
  libavcodec     56. 35.100 / 56. 35.100
  libavformat    56. 30.100 / 56. 30.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 14.100 /  5. 14.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Admin\Desktop\Wildlife2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2015-04-20 03:01:47
  Duration: 00:00:04.04, start: 0.000000, bitrate: 2103 kb/s
    Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D)
, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1908 kb/s, 29.97 fps, 29.97 tbr, 29970 t
bn, 29.97 tbc (default)
    Metadata:
      creation_time   : 2015-04-20 03:01:47
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 189 kb/s (default)
    Metadata:
      creation_time   : 2015-04-20 03:01:47
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Admin\Desktop\Wildlife3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2015-04-20 03:03:38
  Duration: 00:00:04.04, start: 0.000000, bitrate: 1835 kb/s
    Stream #1:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D)
, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1642 kb/s, 29.97 fps, 29.97 tbr, 29970 t
bn, 29.97 tbc (default)
    Metadata:
      creation_time   : 2015-04-20 03:03:38
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 187 kb/s (default)
    Metadata:
      creation_time   : 2015-04-20 03:03:38
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Admin\Desktop\Wildlife4.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2015-04-20 03:05:05
  Duration: 00:00:04.00, start: 0.000000, bitrate: 2172 kb/s
    Stream #2:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D)
, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1977 kb/s, 29.97 fps, 29.97 tbr, 29970 t
bn, 29.97 tbc (default)
    Metadata:
      creation_time   : 2015-04-20 03:05:05
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 188 kb/s (default)
    Metadata:
      creation_time   : 2015-04-20 03:05:05
[Parsed_amerge_8 @ 0000000004dac960] No channel layout for input 1
[Parsed_amerge_8 @ 0000000004dac960] Input channel layouts overlap: output layou
t will be determined by the number of distinct input channels
Output #0, avi, to 'grid(3)_2015-08-14.avi':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    ISFT            : Lavf56.30.100
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x1080 [SAR 1:1 D
AR 32:27], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc56.35.100 mpeg4
    Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo
, s16p (default)
    Metadata:
      encoder         : Lavc56.35.100 libmp3lame
Stream mapping:
  Stream #0:0 (mpeg4) -> setpts
  Stream #0:1 (aac) -> amerge:in0
  Stream #1:0 (mpeg4) -> setpts
  Stream #1:1 (aac) -> amerge:in1
  Stream #2:0 (mpeg4) -> setpts
  Stream #2:1 (aac) -> amerge:in2
  overlay -> Stream #0:0 (mpeg4)
  amerge -> Stream #0:1 (libmp3lame)
Press [q] to stop, [?] for help
frame=   23 fps=0.0 q=5.0 size=     876kB time=00:00:00.76 bitrate=9351.3kbits/s
frame=   46 fps= 46 q=5.0 size=    1927kB time=00:00:01.53 bitrate=10282.5kbits/
frame=   65 fps= 43 q=5.0 size=    2816kB time=00:00:02.16 bitrate=10635.2kbits/
frame=   89 fps= 44 q=5.0 size=    3736kB time=00:00:02.96 bitrate=10306.3kbits/
frame=  114 fps= 45 q=5.0 size=    4272kB time=00:00:03.80 bitrate=9200.7kbits/s
frame=  121 fps= 45 q=5.0 Lsize=    4494kB time=00:00:04.03 bitrate=9118.7kbits/
s
video:4416kB audio:62kB subtitle:0kB other streams:0kB global headers:0kB muxing
 overhead: 0.368438%

这是上面的警告。

[Parsed_amerge_8 @ 0000000004dac960] No channel layout for input 1
[Parsed_amerge_8 @ 0000000004dac960] Input channel layouts overlap: output layout will be determined by the number of distinct input channels

你能帮我纠正我的代码来合并三个音频流吗?

Answers:


0

我找不到使用过滤器amgerge或pan做到这一点的方法,但amix确实有效。我在下面将这个命令的新部分变为粗体。

C:\ ffmpeg.exe -i C:\ Wildlife2.mp4 -i C:\ Wildlife3.mp4 -i C:\ Wildlife4.mp4 -qscale:v 5 -filter_complex“[0:v] setpts = PTS-STARTPTS,pad = iw:1.5 * ih [a]; [1:v] setpts = PTS-STARTPTS,scale = -1:ih / 2 [b]; [2:v] setpts = PTS-STARTPTS,scale = -1:ih / 2 [c]; [a] [b] overlay = 0:h * 2 [x]; [x] [c] overlay = w:h * 2; amix = inputs = 3:duration = longest:dropout_transition = 1 [aa],[aa] volume = 2 [ab]“-map [ab] 网格(3)_2015-08-14.avi

这将自动将来自所有3个视频的音频组合成单声道。如果有更多视频,我可以增加输入数量以匹配或减少它,如果我不想要所有的音频通道。如果我想选择某些频道,那么我可以像下面那样指定它们,括号中的第一个数字是视频输入,第二个数字是音频频道的1。

[0:1] [1:1] [2:1] amix = inputs = 3:duration = longest:dropout_transition = 1 [aa],[aa] volume = 2 [ab]“-map [ab]

我还包括 体积= 2 增加音量,因为amix降低音量低于单个视频输入。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.