使用 FFmpeg 对带有音频的视频进行淡入淡出会导致音频不同步

使用 FFmpeg 对带有音频的视频进行淡入淡出会导致音频不同步

我想淡入淡出两个带音频的视频,第一个视频,,first.mkv时长 (20 秒),第二个视频,,second.mkv时长未知。由于我希望过渡从第一个视频的 19 秒开始,时长为 1 秒,我尝试使用以下命令,使用xfade视频过滤器和acrossfade音频过滤器。

ffmpeg -i first.mkv -i second.mkv -filter_complex "[0:v][1:v]xfade=transition=fade:duration=1:offset=19[v];[0:a][1:a]acrossfade=duration=1[a]" -map "[v]" -map "[a]" output.mkv

但是,在输出视频的第二部分(即 20 秒后),音频和视频不同步。音频超前,视频延迟。

为什么会发生这种情况?如何解决?谢谢。

更新:这是完整的日志。

  Metadata:
    MINOR_VERSION   : 0
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    ENCODER         : Lavf58.47.100
  Duration: 00:00:20.02, start: 0.000000, bitrate: 4101 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      HANDLER_NAME    : ISO Media file produced by Google Inc.
      ENCODER         : Lavc58.93.100 libx264
      DURATION        : 00:00:20.020000000
    Stream #0:1(eng): Audio: vorbis, 48000 Hz, stereo, fltp (default)
    Metadata:
      ENCODER         : Lavc58.93.100 libvorbis
      DURATION        : 00:00:20.000000000
Input #1, matroska,webm, from 'second.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    ENCODER         : Lavf58.47.100
  Duration: 00:05:55.46, start: -0.007000, bitrate: 4221 kb/s
    Stream #1:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 1k tbn, 120 tbc (default)
    Metadata:
      HANDLER_NAME    : ISO Media file produced by Google Inc.
      DURATION        : 00:05:55.434000000
    Stream #1:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:05:55.461000000
Stream mapping:
  Stream #0:0 (h264) -> xfade:main
  Stream #0:1 (vorbis) -> acrossfade:crossfade0
  Stream #1:0 (h264) -> xfade:xfade
  Stream #1:1 (opus) -> acrossfade:crossfade1
  xfade -> Stream #0:0 (libx264)
  acrossfade -> Stream #0:1 (libvorbis)
Press [q] to stop, [?] for help
[libx264 @ 0x55c214e9e940] using SAR=1/1
[libx264 @ 0x55c214e9e940] using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2
[libx264 @ 0x55c214e9e940] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x55c214e9e940] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 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=23 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
Output #0, matroska, to 'output.mkv':
  Metadata:
    MINOR_VERSION   : 0
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    encoder         : Lavf58.47.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 23.98 fps, 1k tbn, 23.98 tbc (default)
    Metadata:
      encoder         : Lavc58.93.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, stereo, fltp (default)
    Metadata:
      encoder         : Lavc58.93.100 libvorbis
frame=  720 fps= 15 q=-1.0 Lsize=   15257kB time=00:00:29.99 bitrate=4166.4kbits/s dup=0 drop=359 speed=0.642x    
video:14914kB audio:320kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: 0.151794%
[libx264 @ 0x55c214e9e940] frame I:11    Avg QP:18.59  size: 97377
[libx264 @ 0x55c214e9e940] frame P:266   Avg QP:22.33  size: 37075
[libx264 @ 0x55c214e9e940] frame B:443   Avg QP:25.85  size:  9792
[libx264 @ 0x55c214e9e940] consecutive B-frames:  6.4% 29.2% 16.7% 47.8%
[libx264 @ 0x55c214e9e940] mb I  I16..4: 45.1%  0.0% 54.9%
[libx264 @ 0x55c214e9e940] mb P  I16..4: 15.4%  0.0% 10.9%  P16..4: 36.3%  9.8%  3.1%  0.0%  0.0%    skip:24.5%
[libx264 @ 0x55c214e9e940] mb B  I16..4:  1.3%  0.0%  1.4%  B16..8: 35.2%  2.8%  0.4%  direct: 0.9%  skip:57.9%  L0:41.3% L1:55.1% BI: 3.5%
[libx264 @ 0x55c214e9e940] coded y,u,v intra: 34.8% 22.0% 13.1% inter: 5.9% 2.5% 1.3%
[libx264 @ 0x55c214e9e940] i16 v,h,dc,p: 39% 22% 13% 26%
[libx264 @ 0x55c214e9e940] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 19% 17%  6%  7%  7%  6%  6%  4%
[libx264 @ 0x55c214e9e940] Weighted P-Frames: Y:2.3% UV:2.3%
[libx264 @ 0x55c214e9e940] ref P L0: 64.7% 16.1% 13.7%  5.4%  0.0%
[libx264 @ 0x55c214e9e940] ref B L0: 89.8%  8.9%  1.4%
[libx264 @ 0x55c214e9e940] ref B L1: 98.2%  1.8%
[libx264 @ 0x55c214e9e940] kb/s:4068.15```

相关内容