summaryrefslogtreecommitdiff
path: root/video/ffconcat
blob: 34e65502e5e8fdc92578a26f218d710c3df80be0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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