<p>This works here</p>

<pre><code>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
</code></pre>

<p>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.</p>

CC BY-SA 3.0
2018-02-13T05:27:13.927Z
2018-02-13T05:27:13.927Z
Gyan
<p>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.</p>

<p>Based on the answer provided <a href="https://video.stackexchange.com/questions/19867/how-to-fade-in-out-a-video-audio-clip-with-unknown-duration?newreg=4c241e6d6ff2416aa3f53df8a038b8ed">here</a>, I've been using the following command line to add a 2 second fade/out effect on to my clips:</p>

<pre><code>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
</code></pre>

<p>My questions:</p>

<ol>
<li>I seem to get a lot of the following error lines in the report</li>
</ol>

<p><code>cur_dts is invalid (this is harmless if it occurs once at the start per stream)</code></p>

<p>Is it normal?</p>

<ol start="2">
<li><p>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?</p></li>
<li><p>The duration of the original clip is 24s640ms, the output file is longer by 2s022ms. Why additional 22 ms? </p></li>
</ol>

<p>If I drop the <code>-vsync 2</code> 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. </p>

CC BY-SA 3.0
2018-02-04T05:11:20.853Z
Share your file.
Gyan
CC BY-SA 3.0
2018-02-04T20:57:37.810Z
[link](https://turl.ca/mmez) - the original video clip; [link](https://turl.ca/vxduny) - the log file created by ffmpeg; [link](https://turl.ca/ojqc) - the ffmpeg version used
USIKPA
CC BY-SA 3.0
2018-02-06T13:56:39.620Z
Can't download video file - file access error.
Gyan
CC BY-SA 3.0
2018-02-09T14:11:57.727Z
There is no password set, so all of the three files should be readily available for download. The link to the video file is https://filebin.ca/3qaIGfKJdhBs/VID_1.zip
USIKPA
CC BY-SA 3.0
2018-02-09T15:55:25.533Z
Or this link https://www.sendspace.com/file/h47mib
USIKPA
<ffmpeg><framerate><filter><scale>
How to use ffmpeg to fade in/out a veriable frame rate video clip with unknown duration
USIKPA
# How to use ffmpeg to fade in/out a veriable frame rate video clip with unknown duration

(Asked by: username_0 on 2018-02-03)

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:

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?

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?
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.

**Tags:** ffmpeg, framerate, filter, scale

> **Comments:**
> **username_1**: Share your file.  
> **username_0**: [link](https://turl.ca/mmez) - the original video clip; [link](https://turl.ca/vxduny) - the log file created by ffmpeg; [link](https://turl.ca/ojqc) - the ffmpeg version used  
> **username_1**: Can't download video file - file access error.  
> **username_0**: There is no password set, so all of the three files should be readily available for download. The link to the video file is https://filebin.ca/3qaIGfKJdhBs/VID_1.zip  
> **username_0**: Or this link https://www.sendspace.com/file/h47mib  

---

## 1 answers

### Answer by username_1 on 2018-02-13. Score: 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.


---

