My goal is to take clips that last over 40 seconds and overlay them on a background, then trim the total time once the clips and background fade out. It works great, except the seeking goes up to 24 seconds even when I specify 21.

ffmpeg -y -framerate 60 -loop 1 -ss 0 -t 21 -i ~/Desktop/FP2.tiff -ss 0 -t 21 -i ~/Desktop/fp.mov -lavfi \
"[0]fade=t=in:st=0:d=1,fade=t=out:st=20:d=1,trim=end=21[bg]; \
[1:v]setpts=(PTS-STARTPTS)+1/TB,fifo,fade=t=in:st=1:d=2,fade=t=out:st=15:d=2[fade]; \
[bg][fade]overlay=10:(main_h-overlay_h)/2:format=rgb[v1]; \
[1:v]setpts=(PTS-STARTPTS)+3/TB,fifo,fade=in:0:120,fade=t=out:st=18:d=2[v2]; \
[v1][v2]overlay=460:(main_h-overlay_h)/2:format=rgb[video]; \
[1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2[a1]; \
[1:a]adelay=3000|3000,stereotools=mutel=1,afade=t=in:st=3:d=2,afade=t=out:st=18:d=2[a2]; \
[a1][a2]amix=inputs=2[audio]" \
-map [video] -map [audio] -c:v ffv1 -level 3 -c:a pcm_s16be ~/Desktop/filtergraph.nut

You can see this in ffplay; the background will fade completely by the 21 second mark, but the video itself ends at 24 seconds. How do I get them to match exactly? I'm aware I can use -ss and -t after the inputs, but that method can be slow if you intend to use a start point past 0.

  • I'm aware I can use -ss and -t after the inputs -> you can keep your current command and just add -t 21 after the inputs. – Gyan Nov 14 '16 at 17:20

You are feeding 21 seconds of audio from the video file and then applying adelay=3000|3000, hence 24 seconds. Add atrim=end=21 at the end to both your audio filterchains.


Add shortest=1 to both your overlays.

  • I still get the 24 seconds when I try that, even if I lower the seconds for atrim below 21. – HDL Nov 15 '16 at 1:03
  • Works here. Where have you placed the atrim? – Gyan Nov 15 '16 at 2:07
  • [1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2,atrim=end=21[a1]; \ – HDL Nov 15 '16 at 12:27
  • Adding shortest worked and now the video properly ends after the background fades. ffprobe and ffplay still report the duration as 20.98 instead of 21 (final encoded frame says 21 flat), but for all intents this gives the expected result. Thanks for the help! – HDL Nov 15 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.