combine video files by ffmpeg

Suppose you have a chain of video files, such as 1.mp4, 2.mp4, 3.mp4 and etc. They should be one video file but were cut into small video fragments.

You can use ffmpeg tool to combine them. And for convenience, I wrote a shell script to do these stuff.

concat=""
count=10
for i in`seq count` do
    if [ \${i} -eq \${number} ];then
        concat = \${concat}"/Users/Desktop/us/Nico/2/tmp/${i}.mpg"
    else
        concat = \${concat}"/Users/Desktop/us/Nico/2/tmp/${i}.mpg|"
    fi
    ffmpeg -i ~/\${i}.mp4 -f mpeg -r 29.97 ~/tmp/\${i}.mpg
done
ffmpeg -i concat:\${concat} -vcodec copy -acodec copy ~/tmp.mpg
ffmpeg -i ~/tmp.mpg -strict -2 -vcodec h264 -acodec aac ~/combined.mp4
rm ~/tmp.mpg
rm -rf ~/tmp
echo "Done!"

Leave a Reply

Your email address will not be published. Required fields are marked *

19 − seven =