Skip to content

Instantly share code, notes, and snippets.

Created July 30, 2015 10:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Concat two mp4 video files
# How to use
# ./concat main_video.mp4 prefix_video.mp4 output.mp4
rm -rf $3
SILENT="-loglevel panic"
# get video size
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $1)
# get video fps
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=r_frame_rate $1)
# adjust prefix fps and resolution to original video fps and size
ffmpeg $SILENT -r $fps -i $2 -vf scale=$size -acodec copy tmp-$2
#ffmpeg -f lavfi -i aevalsrc=0 -r $fps -i $2 -vf scale=$size -shortest -c:a aac -strict experimental -flags global_header tmp-$2
# convert original video to ts
ffmpeg $SILENT -i $1 -map 0 -c copy -bsf h264_mp4toannexb -f mpegts $1.ts
# convert prefix to ts
ffmpeg $SILENT -i tmp-$2 -map 0 -c copy -bsf h264_mp4toannexb -f mpegts $2.ts
ffmpeg $SILENT -i "concat:$2.ts|$1.ts" -c copy -bsf:a aac_adtstoasc $3
#ffmpeg $SILENT -i "concat:$2.ts|$1.ts" -c:v copy -c:a copy -map 0:0 -bsf:a aac_adtstoasc $3
rm -rf $1.ts
rm -rf $2.ts
rm -rf tmp-$2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment