skip to Main Content

I’m having trouble using xfade together with acrossfade.

I have two videos t1.mp4 and t2.mp4 of same fps, resolution and so on. Both videos are 15 seconds long.

Now I want a one-second fade transition in between.

Without acrossfade,

ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "xfade=transition=fade:duration=1:offset=14,format=yuv420p" output.mp4

after checking all the frames, the transition looks good. There are some overlapped frames with fading effect.
Please see below two consecutive frames.
fading11fading12

But the second part of the result has no audio, that’s why I decide to use acrossfade.

ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "xfade=transition=fade:duration=1:offset=14,format=yuv420p;acrossfade=d=1" output.mp4

Now it seems the transition effect is incomplete, there are less overlapped frames with fading effect, and the transition is sharp. Please see below two consecutive frames, same frame nubmer as above.
fading21fading22

What am I missing here please?

 ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "xfade=transition=fade:duration=1:offset=14,format=yuv420p;acrossfade=d=1" output.mp4
ffmpeg version 4.3.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
  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 't1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:15.02, start: 0.000000, bitrate: 2447 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 2315 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 't2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:15.02, start: 0.000000, bitrate: 1643 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 1509 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
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
  format -> Stream #0:0 (libx264)
  acrossfade -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0x5963dc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5963dc0] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0x5963dc0] 264 - core 161 r3018 db0d417 - 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=34 lookahead_threads=5 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
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      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), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc58.91.100 aac
frame=  726 fps= 69 q=-1.0 Lsize=    7114kB time=00:00:29.00 bitrate=2009.4kbits/s dup=1 drop=0 speed=2.76x    
video:6633kB audio:456kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.351093%
[libx264 @ 0x5963dc0] frame I:8     Avg QP:16.38  size: 96958
[libx264 @ 0x5963dc0] frame P:319   Avg QP:19.49  size: 14630
[libx264 @ 0x5963dc0] frame B:399   Avg QP:23.99  size:  3379
[libx264 @ 0x5963dc0] consecutive B-frames:  4.5% 63.6%  8.7% 23.1%
[libx264 @ 0x5963dc0] mb I  I16..4: 16.4% 61.0% 22.6%
[libx264 @ 0x5963dc0] mb P  I16..4:  3.5%  9.8%  0.7%  P16..4: 26.6%  4.9%  1.9%  0.0%  0.0%    skip:52.5%
[libx264 @ 0x5963dc0] mb B  I16..4:  0.3%  0.6%  0.2%  B16..8: 13.8%  0.9%  0.1%  direct: 0.9%  skip:83.1%  L0:44.1% L1:52.3% BI: 3.6%
[libx264 @ 0x5963dc0] 8x8 transform intra:67.2% inter:81.6%
[libx264 @ 0x5963dc0] coded y,uvDC,uvAC intra: 26.3% 38.2% 8.9% inter: 3.2% 5.8% 0.1%
[libx264 @ 0x5963dc0] i16 v,h,dc,p: 43% 25% 15% 17%
[libx264 @ 0x5963dc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 17% 37%  2%  2%  2%  2%  3%  2%
[libx264 @ 0x5963dc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 19% 14%  6%  7%  7%  6%  6%  5%
[libx264 @ 0x5963dc0] i8c dc,h,v,p: 60% 19% 18%  3%
[libx264 @ 0x5963dc0] Weighted P-Frames: Y:0.9% UV:0.9%
[libx264 @ 0x5963dc0] ref P L0: 69.4%  7.6% 17.5%  5.5%  0.0%
[libx264 @ 0x5963dc0] ref B L0: 85.1% 12.9%  2.1%
[libx264 @ 0x5963dc0] ref B L1: 99.0%  1.0%
[libx264 @ 0x5963dc0] kb/s:1870.80
[aac @ 0x58bb580] Qavg: 174.733

2

Answers


  1. Chosen as BEST ANSWER

    fixed by separating the video and audio track.

    ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "[0:v][1:v]xfade=transition=fadeblack:duration=1.000:offset=8.960,format=yuv420p[video];[0:a][1:a]acrossfade=d=1.000:c1=tri:c2=tri[audio]" -map [video] -map [audio] -movflags +faststart output.mp4
    

  2. There is an open bug report for a similar issue that I’ve stumbled upon, in which separating video and audio does not solve the problem.

    Here, the only reliable workaround was to process the audio completely separately from the video, in another ffmpeg command, and later merge it via stream-copying, e.g.:

    ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "[0:v][1:v]xfade=transition=fadeblack:duration=1.000:offset=8.960,format=yuv420p[video]" -an video.mp4
    ffmpeg -i t1.mp4 -i t2.mp4 -filter_complex "[0:a][1:a]acrossfade=d=1.000:c1=tri:c2=tri[audio]" -vn audio.m4a
    ffmpeg -i video.mp4 -i audio.m4a -c copy -movflags +faststart output.mp4
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search