I figured out that you don't need to use a full fledge video editor to apply some basic transition effects to video and audio.
Using ffmpeg, you can apply basic fade in and fade out to video using the fade filter. For audio, the afade filter can be used to achieve a similar effect.
ffmpeg -i video.mp4 -vf "fade=t=in:st=0:d=3" -c:a copy out.mp4
This will start the video with a black screen and fade in to full view over 3 seconds.
ffmpeg -i video.mp4 -vf "fade=t=out:st=10:d=5" -c:a copy out.mp4
This will make the video start fading to black over 5 seconds at the 10 second mark.
ffmpeg -i music.mp3 -af "afade=t=in:st=0:d=5" out.mp3
The audio file will start at a low volume and fade in to full over 5 seconds.
ffmpeg -i music.mp3 -af "afade=t=out:st=5:d=5" out.mp3
The audio file will start fading to zero volume over 5 seconds starting at the 5 second mark.
ffmpeg -i video.mp4 -vf "fade=t=in:st=0:d=10,fade=t=out:st=10:d=5" -c:a copy out.mp4
You can apply both fade in and out effects at the same time, to avoid having to re-encode twice.
Enjoy
Discussion (6)
Can you also combine the video & audio fade at the same time?
Sure, just use the afade filter in your filtergraph with the same start and end times as your fade filters.
Check out the documentation for the afade filter if you get confused - ffmpeg.org/ffmpeg-filters.html#afa...
Got it, thanks! I made this bash function to make things easier for myself:
Very nice! Your bash-fu is much stronger than mine 😉
hi, is there a way to change the color from black to white while fading in/out a video?
oh, I just figure it out, like below
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=3:color=white" -c:a copy out.mp4