Install
ffmpeg in apt reposity of Ubuntu 20.04 is 4.2, which is not the lastest version.
Download its lastest version on its static build page.
And extract binary (ffmpeg
and ffprobe
) to ~/.local/bin.
Add fade-in and fade-out
Add fade-in and fade-out for each clip:
ffprobe part1.flv # get "Duration: 00:01:00.29" , and "30.30 fps" (30 frames/sec)
ffmpeg -i self-intro-part1.flv -vf 'fade=in:135:10,fade=out:1930:10' c1.flv
ffmpeg -i self-intro-part2.flv -vf 'fade=in:15:10,fade=out:730:10' c2.flv
ffmpeg -i self-intro-part3.flv -vf 'fade=in:195:10,fade=out:1290:10' c3.flv
ffmpeg -i self-intro-part4.flv -vf 'fade=in:105:15,fade=out:1720:10' c4.flv
ffmpeg -i self-intro-part5.flv -vf 'fade=in:75:10,fade=out:780:10' c5.flv
fade-in & out 用来擦除视频开头结尾无用的片段很好用。
fade=in:
和 fade=out:
后面两个数字是视频的帧数,需要根据剪切的时间点乘以每秒帧数估算,
然后再根据实际效果调整。
所以需要用 ffprobe
命令确定待处理视频的长度和每秒帧数。
Cut video
Cut video input.flv from 00:00:05 to 00:01:04 and output to output.flv:
ffmpeg -ss 00:00:05 -i input.flv -to 00:01:00 -c copy output.flv
Here -ss
means start, -to
means duration,
-c
means codec (-c copy
means keep the codec of the input video).
ffmpeg -ss 00:00:04 -i c1.flv -to 00:01:01 cc1.flv
ffmpeg -i c2.flv -to 00:00:25 cc2.flv
ffmpeg -ss 00:00:06 -i c3.flv -to 00:00:37.5 cc3.flv
ffmpeg -ss 00:00:02.8 -i c4.flv -to 00:00:55 cc4.flv
ffmpeg -ss 00:00:02 -i c5.flv -to 00:00:24 cc5.flv
Merge clips
Merge 5 flv files to 'final.flv':
cat << EOF > merge.txt
file 'cc1.flv'
file 'cc2.flv'
file 'cc3.flv'
file 'cc4.flv'
file 'cc5.flv'
EOF
ffmpeg -f concat -i merge.txt -c copy final.flv
Notes
Concat 2 images with transition:
ffmpeg-4.3.1-amd64-static/ffmpeg -loop 1 -t 5 -i part1.png -loop 1 -t 5 -i part5.png -filter_complex "[0][1]xfade=transition=fade:duration=1:offset=4.5,format=yuv420p" output.mp4
Failed attempts:
ffmpeg -i 0.mp4 -i 1.mp4 -filter_complex "gltransition=duration=4:offset=1.5" out.mp4
ffmpeg -i part1.flv -i part2.flv -filter_complex "[0][1]xfade=transition=fade:offset=59.5:duration=1,format=yuv420p" m12.flv
ffmpeg -i part1.flv -vf "fade=type=in:duration=1:start_time=0,fade=type=out:duration=1:start_time=59" -c:a copy p1.flv