-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcut
executable file
·105 lines (90 loc) · 3.21 KB
/
fcut
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/sh
#
# fcut
usage() {
base=$(basename $0)
cat >&2 << EOF
Usage:
$base
$base requires mpv open in a ipc socket, ab-loop points set and exist locally.
EOF
[ "$#" -eq 0 ] || exit "$1"
}
cutfile() {
path="${1%%|*}"
pointA="${1#*|}" pointA="${pointA%|*}" pointB="${1##*|}"
fileExt="${path#*.}" fileName="${path%%.*}"
case "$path" in
*youtu*|watch*) usage 1 ;;
esac
[ -z "$pointB" ] && eof="true"
case "$operation" in
# preform lossy transcode to x264
vidcord)
case "$eof" in
true)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" \
-max_muxing_queue_size 1024 \
-sws_flags lanczos -vf "scale=-1:720" \
-c:v libx264 -crf 25 -preset fast \
-c:a copy -map 0 -f mp4 "$fileName-$pointA-$pointB.mp4"
;;
*)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" -to "$pointB" \
-max_muxing_queue_size 1024 \
-sws_flags lanczos -vf "scale=-1:720" \
-c:v libx264 -crf 25 -preset fast \
-c:a copy -map 0 -f mp4 "$fileName-$pointA-$pointB.mp4"
;;
esac
;;
# preform lossless transcode to dnxhd
precise)
case "$eof" in
true)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" \
-c:v dnxhd -profile:v dnxhr_hq \
-pix_fmt yuv422p -c:a pcm_s16le -map 0 -f mov \
"$fileName-$pointA-$pointB.mov"
;;
*)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" -to "$pointB" \
-c:v dnxhd -profile:v dnxhr_hq \
-pix_fmt yuv422p -c:a pcm_s16le -map 0 -f mov \
"$fileName-$pointA-$pointB.mov"
;;
esac
;;
# cuts to keyframe desyncing audio
*)
case "$eof" in
true)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" -c copy -map 0 \
"$fileName-$pointA.$fileExt"
;;
*)
ffmpeg -hide_banner -loglevel error -i "$path" \
-ss "$pointA" -to "$pointB" -c copy -map 0 \
"$fileName-$pointA-$pointB.$fileExt"
;;
esac
;;
esac
}
main() {
SOCKET="/tmp/vidsocket"
mpvc -S "$SOCKET" > /dev/null
[ $? -eq 3 ] && usage 1
case "$1" in
-p|--precise|precise) operation="precise" ;;
-v|--vidcord|vidcord) operation="vidcord" ;;
-d|--default|default|*) operation="default" ;;
esac
cutfile "$(mpvc -S "$SOCKET" -f "%path%|%ab-loop-a%|%ab-loop-b%")"
}
main "$@"