Created
July 30, 2015 10:28
-
-
Save raminious/de84575a7a5aca255c4d to your computer and use it in GitHub Desktop.
Concat two mp4 video files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# How to use | |
# ./concat main_video.mp4 prefix_video.mp4 output.mp4 | |
# | |
# | |
rm -rf $3 | |
SILENT="-loglevel panic" | |
SILENT="" | |
# get video size | |
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $1) | |
size=${streams_stream_0_width}:${streams_stream_0_height} | |
# get video fps | |
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=r_frame_rate $1) | |
fps=${streams_stream_0_r_frame_rate} | |
#fps=$(($fps)) | |
# 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 | |
#concat | |
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