ffmpeg 将音频添加到视频文件时长问题

ffmpeg 将音频添加到视频文件时长问题

我正在使用以下 ffmpeg 命令在现有视频文件中添加背景音乐 mp3 文件

ffmpeg \
-i ./output/output.mp4 \
-i ./output/audio-loop.mp3 \
-filter_complex \
"[0:a]apad[main]; \
 [1:a]volume=-31dB,apad[A]; \
[main][A]amerge[out]" \
-c:v libx264 -c:a aac -map 0:v -map "[out]" \
-ac 2 -shortest -y ./output/new_output.mp4

除视频文件持续时间外,上述命令一切正常。

该文件的时长output.mp4为1分30秒。

运行上述命令时,new_output.mp4文件持续时间与原始文件不一样,1:27 seconds但原始文件持续时间为1:30秒。

audio-loop.mp3文件时长为3:16 seconds

请帮忙

Complete Logs

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.29)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/4.3.1_9 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  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
  libavresample   4.  0.  0 /  4.  0.  0
  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 './output/output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:01:29.84, start: 0.000000, bitrate: 564 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 479 kb/s, 30 fps, 30 tbr, 12k tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 24000 Hz, mono, fltp, 93 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mp3, from './output/audio-loop.mp3':
  Duration: 00:03:16.26, start: 0.025057, bitrate: 192 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 192 kb/s
    Metadata:
      encoder         : LAME3.97 
    Side data:
      replaygain: track gain - -5.700000, track peak - unknown, album gain - unknown, album peak - unknown, 
Stream mapping:
  Stream #0:1 (aac) -> apad (graph 0)
  Stream #1:0 (mp3float) -> volume (graph 0)
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  amerge (graph 0) -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0x14300d800] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x14300d800] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x14300d800] 264 - core 161 r3043 59c0609 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=12 lookahead_threads=2 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
[Parsed_amerge_3 @ 0x140f17dd0] No channel layout for input 1
Output #0, mp4, to './output/new_output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1280x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.91.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 24000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc58.91.100 aac
frame= 2611 fps=532 q=-1.0 Lsize=    2002kB time=00:01:27.04 bitrate= 188.4kbits/s speed=17.7x    
video:567kB audio:1366kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.577758%
[libx264 @ 0x14300d800] frame I:11    Avg QP:18.32  size: 23236
[libx264 @ 0x14300d800] frame P:683   Avg QP:23.17  size:   282
[libx264 @ 0x14300d800] frame B:1917  Avg QP:33.29  size:    68
[libx264 @ 0x14300d800] consecutive B-frames:  1.2%  2.7%  0.2% 95.9%
[libx264 @ 0x14300d800] mb I  I16..4:  7.9% 81.2% 10.9%
[libx264 @ 0x14300d800] mb P  I16..4:  0.0%  0.1%  0.0%  P16..4:  0.3%  0.0%  0.1%  0.0%  0.0%    skip:99.5%
[libx264 @ 0x14300d800] mb B  I16..4:  0.0%  0.1%  0.0%  B16..8:  0.5%  0.0%  0.0%  direct: 0.0%  skip:99.4%  L0:45.4% L1:54.1% BI: 0.5%
[libx264 @ 0x14300d800] 8x8 transform intra:83.3% inter:33.5%
[libx264 @ 0x14300d800] coded y,uvDC,uvAC intra: 6.7% 6.0% 5.8% inter: 0.1% 0.0% 0.0%
[libx264 @ 0x14300d800] i16 v,h,dc,p: 74% 22%  3%  0%
[libx264 @ 0x14300d800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 68%  4% 27%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x14300d800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 47% 22%  9%  2%  3%  6%  5%  3%  3%
[libx264 @ 0x14300d800] i8c dc,h,v,p: 88%  8%  3%  0%
[libx264 @ 0x14300d800] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x14300d800] ref P L0: 72.1% 24.6%  2.2%  1.1%
[libx264 @ 0x14300d800] ref B L0: 72.3% 26.8%  0.9%
[libx264 @ 0x14300d800] ref B L1: 99.1%  0.9%
[libx264 @ 0x14300d800] kb/s:53.27
[aac @ 0x143010800] Qavg: 964.117

相关内容