-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpegcut.sh
105 lines (103 loc) · 3.05 KB
/
ffmpegcut.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
/bin/date >>segmenter.log
function segment (){
while true; do
echo "Would you like to cut out a segment ?"
echo -e "1) Yes\n2) No\n3) Quit"
read CHOICE
if [ "$CHOICE" == "3" ]; then
exit
elif [ "$CHOICE" == "2" ]; then
clear
break
elif [ "$CHOICE" == "1" ]; then
clear
((segments++))
echo "What time does segment $segments start ?"
read SEGMENTSTART
clear
SEGSTART=$(bc <<< $SEGMENTSTART)
echo -e "Segment $segments start set to $SEGSTART\n"
echo "What time does segment $segments end ?"
read SEGMENTEND
clear
SEGEND=$(bc <<< $SEGMENTEND)
echo -e "Segment $segments end set to $SEGEND\n"
break
else
clear
echo -e "Bad option"
segment "$segments"
fi
done
if [ "$CHOICE" == "1" ]; then
echo "Cutting file $file video segment $segments starting at $SEGSTART and ending at $SEGEND"
ffmpeg -ss $SEGSTART -to $SEGEND -i "$file" -map 0:0 -map 0:1 -c:a copy -c:v copy "$filename-part$segments.$extension" >> segmenter.log 2>&1
clear
echo -e "Cut file $filename-part$segments.$extension starting at $SEGSTART and ending at $SEGEND\n"
segment "$segments"
fi
}
file="$1"
filename="${file%.*}"
extension="${file##*.}"
clear
segments=0
segment "$segments"
clear
if (("$segments"==1)); then
mv "$filename-part1."$extension "$filename-segmented.$extension"
elif (("$segments">1)); then
echo "Would you like to join the segments into one file ?"
OPTIONS="Yes No Quit"
select opt in $OPTIONS; do
clear
if [ "$opt" == "Quit" ]; then
exit
elif [ "$opt" == "Yes" ]; then
clear
echo "Joining segments"
ffmpeg -f concat -safe 0 -i <(for f in "$filename-part"*$extension; do echo "file '$(pwd)/$f'"; done) -c:a copy -c:v copy "$filename-segmented.$extension" >> segmenter.log 2>&1
clear
echo "Would you like to delete the part files ?"
select opt in $OPTIONS; do
clear
if [ "$opt" == "Quit" ]; then
exit
elif [ "$opt" == "Yes" ]; then
for f in "$filename-part"*$extension; do rm "$f"; done
break
elif [ "$opt" == "No" ]; then
break
else
clear
echo -e "Bad option\n"
fi
done
break
clear
elif [ "$opt" == "No" ]; then
exit
else
clear
echo -e "Bad option\n"
fi
done
fi
echo "Would you like to replace the original file with the result of your changes ?"
OPTIONS="Yes No Quit"
select opt in $OPTIONS; do
clear
if [ "$opt" == "Quit" ]; then
exit
elif [ "$opt" == "Yes" ]; then
rm "$file"
mv "$filename-segmented.$extension" "$file"
break
elif [ "$opt" == "No" ]; then
break
else
clear
echo -e "Bad option\n"
fi
done