-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils
57 lines (49 loc) · 1.43 KB
/
utils
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
#! /usr/bin/env bash
mcc() {
local list=( *.list )
if [[ ${#list[@]} -ne 1 ]]; then
echo "Number of .list files in cwd must be exactly 1, exiting."
return 1
fi
make_cuts "$list" "$@"
concat CUT -c copy "CONCAT_${list%.*}"
}
concat() {
if [[ $# -eq 0 ]]; then
echo "You must provide a prefix"
return
fi
local prefix="$1"
shift
ffmpeg -y -f concat -safe 0 -i <(printf 'file %q\n' "$PWD"/"$prefix"*) "$@"
}
make_cuts() {
if [[ $1 != *".list" ]]; then
echo "You must supply a single .list file as argument"
return
fi
local list="$1"
local vid="${list%.*}"
local ext="${vid##*.}"
local vid_noext="${vid%.*}"
local start_ts_hms
local end_ts_hms
local ffmpeg_cmd=("ffmpeg" "-y" "-i" "$vid")
shift
while IFS=: read -r channel_name start_ts end_ts || [[ -n "$channel_name" ]]; do
if [[ -z "$end_ts" ]]; then continue; fi
start_ts_hms="$(_mpv_cut_to_hms "$start_ts")"
end_ts_hms="$(_mpv_cut_to_hms "$end_ts")"
ffmpeg_cmd+=("-ss" "$start_ts" "-to" "$end_ts" "$@" "CUT_${channel_name}_${vid_noext}_${start_ts_hms}_${end_ts_hms}.${ext}")
done < "$list"
"${ffmpeg_cmd[@]}"
}
_mpv_cut_to_hms() {
local total_seconds="$1"
local hours=$(( ${total_seconds%.*} / 3600 ))
local minutes=$(( (${total_seconds%.*} % 3600) / 60 ))
local seconds=$(( ${total_seconds%.*} % 60 ))
local ms
ms=$(printf "%.0f" "$(echo "($total_seconds - ${total_seconds%.*}) * 1000" | bc)")
printf "%02d-%02d-%02d-%03d\n" $hours $minutes $seconds "$ms"
}