合并视频后丢失第二个视频的音频

时间:2021-05-25 23:40:40

标签: ffmpeg

我正在尝试添加 xfade 过滤器并且该命令正在运行,但输出视频中缺少第二个视频的音频。

命令是 -

ffmpeg -i 1.mp4 -i 1.mp4  -filter_complex "[0:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];
[v0][v1]xfade=transition=pixelize:duration=1:offset=7,format=yuv420p" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus -deadline good -cpu-used 8 output.webm

完整日志如下-

ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc - 
-disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid -- 
enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable- 
libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype 
--enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb -- 
enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-
sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:09.12, start: 0.000000, bitrate: 702 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 474x360, 568 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:08.75, start: 0.000000, bitrate: 2546 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360, 2416 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 (h264) -> scale (graph 0)
  Stream #1:0 (h264) -> scale (graph 0)
  format (graph 0) -> Stream #0:0 (libvpx-vp9)
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> opus (libopus))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x561afcf3a280] v1.7.0
Output #0, webm, to 'output.webm':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 480x360 [SAR 1:1 DAR 4:3], q=-1--1, 30 fps, 1k tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc58.91.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(und): Audio: opus (libopus), 48000 Hz, stereo, flt, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 libopus
frame=   87 fps=0.0 q=0.0 size=       1kB time=00:00:03.19 bitrate=   2.1kbits/sframe=  157 fps=156 q=0.0 size=     171kB time=00:00:05.51 bitrate= 254.3kbits/sframe=  227 fps=150 q=0.0 size=     171kB time=00:00:07.85 bitrate= 178.5kbits/sframe=  265 fps=131 q=0.0 size=     171kB time=00:00:08.31 bitrate= 168.7kbits/sframe=  303 fps=120 q=0.0 size=     256kB time=00:00:09.30 bitrate= 225.5kbits/sframe=  341 fps=113 q=0.0 size=     256kB time=00:00:10.56 bitrate= 198.4kbits/sframe=  379 fps=107 q=0.0 size=     256kB time=00:00:11.83 bitrate= 177.2kbits/sframe=  416 fps=103 q=0.0 size=     256kB time=00:00:13.06 bitrate= 160.5kbits/sframe=  454 fps=100 q=0.0 size=     256kB time=00:00:14.33 bitrate= 146.3kbits/sframe=  472 fps= 93 q=0.0 Lsize=    1168kB time=00:00:15.73 bitrate= 608.2kbits/s speed=3.09x    
video:1036kB audio:125kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.629681%

使用没有音频的在线网址时出现此错误- 收到此错误-

    ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-cuda --enable-cuda-sdk --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libnpp --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://player.vimeo.com/external/183300180.sd.mp4?s=8d9b1561f39df586af49fe5ab105f57f5873854b&profile_id=164':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-09-19T12:39:02.000000Z
  Duration: 00:00:10.00, start: 0.000000, bitrate: 489 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt470bg/smpte170m/bt470bg), 640x360 [SAR 1:1 DAR 16:9], 486 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2016-09-19T12:39:02.000000Z
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://player.vimeo.com/external/166335878.sd.mp4?s=828bf6e8594fab383d7ee6bac40d3f247cc40af9&profile_id=164':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-05-12T09:34:11.000000Z
  Duration: 00:00:10.01, start: 0.000000, bitrate: 479 kb/s
    Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt470bg/smpte170m/bt470bg), 474x360 [SAR 1:1 DAR 79:60], 345 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2016-05-12T09:34:11.000000Z
      handler_name    : L-SMASH Video Handler
      encoder         : AVC Coding
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-05-12T09:34:11.000000Z
      handler_name    : L-SMASH Audio Handler
Stream specifier ':a' in filtergraph description [0:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=8,format=yuv420p;[0:a][1:a]acrossfade=d=0 matches no streams.

1 个答案:

答案 0 :(得分:0)

您没有告诉 ffmpeg 如何处理音频,因此它只是从第一个输入中选择音频(请参阅 stream selection)。

因为您使用的是 xfade,所以您可能想要使用 acrossfade,如 Merging multiple video files with ffmpeg and xfade filter 所示:

ffmpeg -i 1.mp4 -i 1.mp4 -filter_complex "[0:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=480:360:force_original_aspect_ratio=decrease,pad=480:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=7,format=yuv420p;[0:a][1:a]acrossfade=d=1" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus -deadline good -cpu-used 8 output.webm

对于没有音频的输入,一种方法是添加 adelay 过滤器:

ffmpeg -i noaudio -i input1 -filter_complex "[0:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v0];[1:v]scale=614:360:force_original_aspect_ratio=decrease,pad=614:360:-1:-1,setsar=1,fps=30,format=yuv420p[v1];[v0][v1]xfade=transition=pixelize:duration=1:offset=8,format=yuv420p;[1:a]adelay=8s:all=1" output

其他方法包括使用 anullsrc + concat 或 apad(如果 noaudio 不是第一个输入)。