Skip to content

Instantly share code, notes, and snippets.

@raminious
Created July 30, 2015 15:27
Show Gist options
  • Save raminious/9fcf2e134dc048cbc18a to your computer and use it in GitHub Desktop.
Save raminious/9fcf2e134dc048cbc18a to your computer and use it in GitHub Desktop.
rm -rf $3
START=$(($(date +%s)*1000))
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:v copy -c:a libfdk_aac -bsf h264_mp4toannexb -f mpegts $1.ts
# convert prefix to ts
ffmpeg $SILENT -i tmp-$2 -map 0 -c:v copy -c:a libfdk_aac -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
#ffmpeg -i tmp-$2 -i $1 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" $3
rm -rf $1.ts
rm -rf $2.ts
rm -rf tmp-$2
END=$(($(date +%s)*1000))
#echo `expr $END - $START`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment