diff options
Diffstat (limited to 'video/ffconcat')
| -rwxr-xr-x | video/ffconcat | 30 | 
1 files changed, 30 insertions, 0 deletions
diff --git a/video/ffconcat b/video/ffconcat new file mode 100755 index 0000000..34e6550 --- /dev/null +++ b/video/ffconcat @@ -0,0 +1,30 @@ +#!/bin/sh + +trap cleanup EXIT + +ccf=/tmp/concatfile. +cleanup() { rm ${ccf}*; } +concat() { +	outfile="output$i.mkv" +	concatfile=$(mktemp ${ccf}XXXXXX) +	dir="$(pwd)" +	for video in $vidfiles; do +		echo "file '$dir/$video'" >> $concatfile +	done +	cat $concatfile | sort > ${concatfile}_ # Sort concatfile so videos are ordered correctly +	ffmpeg -v error -f concat -safe 0 -i ${concatfile}_ -c copy $outfile +} + +for video in "$@"; do +	codechash=$(ffprobe -v quiet -show_format -show_streams "$video" | \grep 'width\|height\|codec' | md5sum | cut -d' ' -f1) +	[ -z "$prevhash" ] && prevhash=$codechash +	if [ $prevhash = $codechash ]; then +		vidfiles="$video${vidfiles:+ }$vidfiles" +	else +		[ -z "$i" ] && i=0 +		concat +		vidfiles="" +		i=$((i+1)) +	fi +done +concat  | 
