forked from trahay/bbb-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrop_video.sh
executable file
·77 lines (60 loc) · 1.77 KB
/
crop_video.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
usage()
{
cat << EOF
usage: $0 [options] input_file output_file
OPTIONS:
-? Show this message
-s startup_duration Remove the first startup_duration seconds of the video
-e stop_duration Cut the video after stop_duration (from the start of the input video)
-m Only show the main screen (ie. remove the webcam)
EOF
}
startup_duration=11 # duration of firefox startup (that will be cut out of the video)
stop_duration=0
main_screen_only=n
while getopts 's:e:m' OPTION; do
case $OPTION in
s)
startup_duration=$OPTARG
;;
e)
stop_duration=$OPTARG
;;
m)
main_screen_only=y
;;
?) usage
exit 2
;;
esac
done
# remove the options from the command line
shift $(($OPTIND - 1))
if [ $# -lt 2 ]; then
usage
exit 2
fi
input=$1
output=$2
video_size=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $input )
height=$(echo $video_size |awk -Fx '{print $2}')
width=$(echo $video_size |awk -Fx '{print $1}')
if [ "$stop_duration" -gt 0 ]; then
duration=$(echo "$stop_duration - $startup_duration"|bc)
DURATION_OPTION="-t $duration"
fi
echo "height=$height, width=$width"
upper_window=144 # height of the upper part of the firefox window
lower_window=56 # height of the lower part of the firefox window
#out_w is the width of the output rectangle
out_w=$width
if [ "$main_screen_only" = "y" ]; then
out_w=720
fi
#out_h is the height of the output rectangle
out_h=$(echo "$height - $upper_window - $lower_window"|bc)
#x and y specify the top left corner of the output rectangle
x=0
y=$upper_window
ffmpeg -y -ss $startup_duration -i "$input" -filter:v "crop=$out_w:$out_h:$x:$y" $DURATION_OPTION "$output"