diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-02-02 02:13:40 +0100 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-02-02 02:13:40 +0100 |
commit | e9752056b6eb824b85854e20dadac31c197cd235 (patch) | |
tree | f60f7ba21b8bdfcfadb7f504679a9b13daa343e0 /config/common/mpv/scripts/mpv-cut/utils | |
parent | ca0cec60dacc4e8c6f8f37e0605b72bac54c9ea6 (diff) | |
parent | 541d9fa7014c5c197f7c8a09fa159ac84bd9a6a8 (diff) |
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'config/common/mpv/scripts/mpv-cut/utils')
-rw-r--r-- | config/common/mpv/scripts/mpv-cut/utils | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/config/common/mpv/scripts/mpv-cut/utils b/config/common/mpv/scripts/mpv-cut/utils new file mode 100644 index 0000000..b64ca8e --- /dev/null +++ b/config/common/mpv/scripts/mpv-cut/utils @@ -0,0 +1,44 @@ +#! /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() { + local prefix="$1" + shift + ffmpeg -f concat -safe 0 -i <(printf 'file %q\n' "$PWD"/"$prefix"*) "$@" +} + +make_cuts() { + local list="$1" + local vid="${list%.*}" + local ext="${vid##*.}" + local vid_noext="${vid%.*}" + local start_ts_hms + local end_ts_hms + 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")" + echo "$channel_name" "$start_ts" "$end_ts" + ffmpeg -nostdin -ss "$start_ts" -to "$end_ts" -i "$vid" "$@" "CUT_${channel_name}_${vid_noext}_${start_ts_hms}_${end_ts_hms}.${ext}" + done < "$list" +} + +_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" +} |