2

I have been looking for a way to use ffmpeg to downscale some MPEG-4 (Base Media / Version 2) video files recorded with a variable frame rate, adding fade in/out effects at the head and tail of each clip.

Based on the answer provided here, I've been using the following command line to add a 2 second fade/out effect on to my clips:

ffmpeg -i VID_1.mp4 -sseof -2 -copyts -i VID_1.mp4 -lavfi "[1]fade=out:s=0:d=2[tail];[0][tail]overlay,fade=in:s=0:d=2[overlay]; anullsrc,atrim=0:4[audiotail];[0][audiotail]acrossfade=d=2,afade=d=2[audio];[overlay]scale=640:-1[video]" -map "[video]" -map "[audio]" -vsync 2 -sws_flags gauss -c:v libx264 -crf 18 -preset slow -shortest -report -hide_banner VID_1_out.mp4

My questions:

  1. I seem to get a lot of the following error lines in the report

cur_dts is invalid (this is harmless if it occurs once at the start per stream)

Is it normal?

  1. In the resulting output video clip, the fade-in comes out less than 2 seconds (about 1 second), and there appears no fade out, just a black-out for the last four seconds. Where is my command line wrong?

  2. The duration of the original clip is 24s640ms, the output file is longer by 2s022ms. Why additional 22 ms?

If I drop the -vsync 2 option, the output clip frame rate becomes exactly the same as that of the source video file. This, however doesn't deal away with the above issues.

5
  • 1
    Share your file.
    – Gyan
    Commented Feb 4, 2018 at 5:11
  • link - the original video clip; link - the log file created by ffmpeg; link - the ffmpeg version used
    – USIKPA
    Commented Feb 4, 2018 at 20:57
  • Can't download video file - file access error.
    – Gyan
    Commented Feb 6, 2018 at 13:56
  • There is no password set, so all of the three files should be readily available for download. The link to the video file is filebin.ca/3qaIGfKJdhBs/VID_1.zip
    – USIKPA
    Commented Feb 9, 2018 at 14:11
  • Or this link sendspace.com/file/h47mib
    – USIKPA
    Commented Feb 9, 2018 at 15:55

1 Answer 1

1

This works here

ffmpeg -i VID_1.mp4 -sseof -2 -copyts -i VID_1.mp4 -lavfi "[1]fade=out:s=1:d=2[tail];[0][tail]overlay,fade=in:s=0:d=2,scale=640:-2[video];anullsrc,atrim=0:2.1[audiotail];[0][audiotail]acrossfade=d=2,afade=d=2[audio]" -map "[video]" -map "[audio]" -vsync 2 -sws_flags gauss -c:v libx264 -crf 18 -preset slow -shortest -report VID_1_out.mp4

With some videos, usually those with variable FPS, the fade filter only works with start frame as non-zero. Also, the anullsrc needs to be only slightly greater than the crossfade duration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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