View difference between Paste ID: sBztjw44 and n8Jk3DjS
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
function cropdetect ()
3
{
4
	FFOUT=/tmp/ffout
5
	CROP="1"
6
	TOTAL_LOOPS="10"
7
8
	A=0
9
	while [ "$A" -lt "$TOTAL_LOOPS" ] ; do
10
	A="$(( $A + 1 ))"
11
	SKIP_SECS="$(( 120 * $A ))"
12
13
	ffmpeg -ss $SKIP_SECS -i "$@" -vframes 20 -an -sn -vf \
14
	cropdetect=30:2 -y /tmp/crop.mp4 2>$FFOUT
15
	CROP[$A]=$(grep -m 1 crop= $FFOUT |awk -F "=" '{print $2}')
16
17
	done
18
	
19
20
	B=0
21
	while [ "$B" -lt "$TOTAL_LOOPS" ] ; do
22
	B="$(( $B + 1 ))"
23
24
	C=0
25
	while [ "$C" -lt "$TOTAL_LOOPS" ] ; do
26
	C="$(( $C + 1 ))"
27
  
28
	if [ "${CROP[$B]}" == "${CROP[$C]}" ] ; then
29
		COUNT_CROP[$B]="$(( ${COUNT_CROP[$B]} + 1 ))"
30
	fi
31
	done  
32
	done
33
34
	HIGHEST_COUNT=0
35
36
	D=0
37
	while [ "$D" -lt "$TOTAL_LOOPS" ] ; do
38
	D="$(( $D + 1 ))"
39
40
	if [ "${COUNT_CROP[$D]}" -gt "$HIGHEST_COUNT" ] ; then
41
		HIGHEST_COUNT="${COUNT_CROP[$D]}"
42
		GREATEST="$D"
43
	fi
44
	done
45
	rm /tmp/crop.mp4
46
	CROP="${CROP[$GREATEST]}"
47
	CROP=$(echo $CROP|awk -F ":" '{print $1-4":"$2-4":"$3+2":"$4+2}')
48
	echo $CROP
49
	rm $FFOUT
50
}
51
cropdetect "$@"
52
exit 0