-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathts
executable file
·58 lines (50 loc) · 863 Bytes
/
ts
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
#!/bin/bash -e
usage() {
cat <<EOF
Cut video into intermediary ts files
Synopsis:
$(basename $0) INPUT_FILE [even number of timestamps]
EOF
exit 1
}
if [[ $# -lt 3 ]]
then
usage
fi
if [[ !$(($#%2)) -eq 1 ]]
then
echo "Uneven number of timestamps."
exit 1
fi
input="$1"
output="${1%.*}"
fragment=1
join=()
shift
while [[ $# -ne 0 ]]
do
from="$1"
to="$2"
join+=("$output.$fragment.ts")
shift
shift
ffmpeg \
-fflags +genpts+igndts \
-ss "$from" \
-i "$input" \
-ss "$from" \
-to "$to" \
-copyts \
-c:v libx264 \
-preset ultrafast \
-c:a copy \
"$output.$fragment.ts"
((fragment++))
done
if [[ ${#join[@]} -eq 1 ]]
then
mv "${join[@]}" "$output.ts"
ffplay -loop 0 "$output.ts"
else
cc1 "${join[@]}" "$output.ts"
fi