[FFmpeg-user] xfade + acrossfade usage - keeping A/V in sync

Rob Hallam robert at roberthallam.com
Tue Jun 16 18:34:16 EEST 2020


Hi all,

tl;dr: with the same duration, should xfade and
acrossfade produce synched output?

I'd like to join three videos together, which have
audio and video streams of virtually the same
length. I thought I'd give the xfade [0] filter a
try as it looked useful. To fade the audio as
well I used acrossfade [1].

However, the output has audio-video desync,
which gets worse with each join- it is more
noticeable after the second transition.

Should I expect synchronised output if I use
the same duration for both xfade and acrossfade
(with overlap)?

I don't often use a complex filtergraph, and though
this one isn't terribly complex as filtergraphs go, I
would appreciate pointers if there is a better
approach.

Command and output are appended [2].

As a side note, is there a way to generate audio
from ffmpeg for the purposes of testing
synchronisation? I searched and had a quick look
at 'audio sources', but didn't see anything obvious.
It would make creating an MWE easier.

Thanks in advance,
Rob


[0]: https://ffmpeg.org/ffmpeg-filters.html#xfade &
 https://trac.ffmpeg.org/wiki/Xfade

[1]: https://ffmpeg.org/ffmpeg-filters.html#acrossfade

[2]: Full command and output:

TR1=764.3    # input 0 duration - 1 second
TR2=1250.498    # input 0 + input 1 duration - 1 second

$ ffmpeg -i 2020-03-18\ 19-22-03.mkv -i 2020-03-18\ 20-02-07.mkv -i
 2020-03-18\ 20-11-25.mkv -filter_complex
"[0][1]xfade=transition=dissolve:duration=2:offset=$TR1,format=yuv420p[x1]
;[x1][2]xfade=transition=dissolve:duration=2:offset=$TR2,format=yuv420p[x2];[0][1]acrossfade=d=2:o=1:c1=tri:c2=tri[a
x1];[ax1][2]acrossfade=d=2:o=1:c1=tri:c2=tri[ax2]" -map "[x2]" -map "[ax2]"
-c:v libx264 -crf 18 -c:a aac 2020-03-18
\ 19-22-03-jx.mkv
ffmpeg version N-98238-g276dfa9d91 Copyright (c) 2000-2020 the FFmpeg
developers
  built with gcc 10.1.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static
--disable-stripping --enable-avisynth --enable-fontconfig --enable-gmp
--enable-gnutls --enable-gpl --enable-ladspa --enable-libaom
--enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm
--enable-libfreetype --enable-libfribidi --enable-libgsm
--enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug
--enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb
--enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr
--enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora
--enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis
--enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec
--enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 92.100 / 58. 92.100
  libavformat    58. 46.101 / 58. 46.101
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, matroska,webm, from '2020-03-18 19-22-03.mkv':
  Metadata:
    ENCODER         : Lavf58.29.100
  Duration: 00:12:45.88, start: 0.000000, bitrate: 16786 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 60
fps, 60 tbr, 1k tbn, 120 tbc (default)
    Metadata:
      DURATION        : 00:12:45.884000000
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp (default)
    Metadata:
      title           : Track1
      DURATION        : 00:12:45.794000000
Input #1, matroska,webm, from '2020-03-18 20-02-07.mkv':
  Metadata:
    ENCODER         : Lavf58.29.100
  Duration: 00:08:07.12, start: 0.000000, bitrate: 20933 kb/s
    Stream #1:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 60
fps, 60 tbr, 1k tbn, 120 tbc (default)
    Metadata:
      DURATION        : 00:08:07.117000000
    Stream #1:1: Audio: aac (LC), 44100 Hz, stereo, fltp (default)
    Metadata:
      title           : Track1
      DURATION        : 00:08:07.062000000
Input #2, matroska,webm, from '2020-03-18 20-11-25.mkv':
  Metadata:
    ENCODER         : Lavf58.29.100
  Duration: 00:06:49.10, start: 0.000000, bitrate: 20261 kb/s
    Stream #2:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 60
fps, 60 tbr, 1k tbn, 120 tbc (default)
    Metadata:
      DURATION        : 00:06:49.100000000
    Stream #2:1: Audio: aac (LC), 44100 Hz, stereo, fltp (default)
    Metadata:
      title           : Track1
      DURATION        : 00:06:49.066000000
Stream mapping:
  Stream #0:0 (h264) -> xfade:main
  Stream #0:1 (aac) -> acrossfade:crossfade0
  Stream #1:0 (h264) -> xfade:xfade
  Stream #1:1 (aac) -> acrossfade:crossfade1
  Stream #2:0 (h264) -> xfade:xfade
  Stream #2:1 (aac) -> acrossfade:crossfade1
  format -> Stream #0:0 (libx264)
  acrossfade -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0x55813c4e0000] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55813c4e0000] profile High, level 4.2, 4:2:0, 8-bit
[libx264 @ 0x55813c4e0000] 264 - core 159 r2999 296494a - H.264/MPEG-4 AVC
codec - Copyleft 2003-2020 - 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=18
lookahead_threads=3 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=18.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to '2020-03-18 19-22-03-jx.mkv':
  Metadata:
    encoder         : Lavf58.46.101
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248),
yuv420p(progressive), 1920x1080, q=-1--1, 60 fps, 1k tbn, 60 tbc (default)
    Metadata:
      encoder         : Lavc58.92.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) ([255][0][0][0] / 0x00FF), 44100 Hz,
stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc58.92.100 aac
frame=99573 fps= 34 q=-1.0 Lsize= 3922244kB time=00:27:39.55
bitrate=19361.3kbits/s speed=0.575x
video:3895726kB audio:25261kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.032044%
[libx264 @ 0x55813c4e0000] frame I:758   Avg QP:17.84  size:216791
[libx264 @ 0x55813c4e0000] frame P:44230 Avg QP:20.56  size: 64647
[libx264 @ 0x55813c4e0000] frame B:54585 Avg QP:22.98  size: 17689
[libx264 @ 0x55813c4e0000] consecutive B-frames: 13.2% 39.1%  6.4% 41.3%
[libx264 @ 0x55813c4e0000] mb I  I16..4:  6.9% 55.0% 38.0%
[libx264 @ 0x55813c4e0000] mb P  I16..4:  1.4% 12.0%  4.3%  P16..4: 39.1%
10.6%  5.6%  0.0%  0.0%    skip:27.1%
[libx264 @ 0x55813c4e0000] mb B  I16..4:  0.3%  2.4%  0.8%  B16..8: 25.7%
 2.4%  0.6%  direct: 4.1%  skip:63.8%  L0:37.0% L1:47.9% BI:15.1%
[libx264 @ 0x55813c4e0000] 8x8 transform intra:67.2% inter:49.9%
[libx264 @ 0x55813c4e0000] coded y,uvDC,uvAC intra: 70.4% 40.7% 8.4% inter:
18.0% 7.3% 0.1%
[libx264 @ 0x55813c4e0000] i16 v,h,dc,p: 33% 30% 15% 22%
[libx264 @ 0x55813c4e0000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 17% 19%  6%
 7%  7%  8%  6%  8%
[libx264 @ 0x55813c4e0000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 18% 13%  8%
 8%  8%  8%  7%  8%
[libx264 @ 0x55813c4e0000] i8c dc,h,v,p: 60% 19% 17%  3%
[libx264 @ 0x55813c4e0000] Weighted P-Frames: Y:3.0% UV:1.0%
[libx264 @ 0x55813c4e0000] ref P L0: 73.5% 15.8%  9.4%  1.3%  0.0%
[libx264 @ 0x55813c4e0000] ref B L0: 93.3%  6.2%  0.6%
[libx264 @ 0x55813c4e0000] ref B L1: 99.3%  0.7%
[libx264 @ 0x55813c4e0000] kb/s:19229.80
[aac @ 0x55813c0017c0] Qavg: 2556.838


More information about the ffmpeg-user mailing list