-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipper
executable file
·42 lines (38 loc) · 1.36 KB
/
clipper
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
#!/usr/bin/env bash
function print_usage
{
echo "Overlays video2 onto video1 as an inset. Optionally, user can clip portions of the overlayed video using ; and '"
echo "Usage: clipper <path_to_video1> <path_to_video2>"
}
function has_audio
{
if [[ "$1" != "" ]]
then
result=$(ffprobe -i "$1" -show_streams -select_streams a -loglevel error)
if [[ "$result" != "" ]]
then
true
return
fi
fi
false
}
if [[ "$1" == "" || "$2" == "" || ! -f "$1" || ! -f "$2" ]]; then
print_usage
else
if has_audio "$1" && has_audio "$2"
then
mix_audio="; [aid1][aid2]amerge=inputs=2,pan=stereo|c0<c0+c2|c1<c1+c3[ao]"
fi
fname=$(basename "$1")
fname=${fname%.*}
mpv --script="./mark.lua" --lavfi-complex="[vid2]scale=iw/3:ih/3 [pip]; [vid1][pip] overlay=main_w-overlay_w-10:10 [vo]${mix_audio}" "$1" --external-file="$2"
if [ -f endpoints.txt ]
then
while IFS=',' read start_ts stop_ts
do
ffmpeg -y -i "$1" -i "$2" -filter_complex "[0:v] trim=${start_ts}:${stop_ts}, setpts=PTS-STARTPTS, scale=iw/2:ih/2 [clip1]; [1:v] trim=${start_ts}:${stop_ts}, setpts=PTS-STARTPTS, scale=iw/2:ih/2 [clip2]; [clip1][clip2] hstack [vout]" -map "[vout]" "${fname}_${start_ts%.*}_${stop_ts%.*}.avi" </dev/null
done<endpoints.txt
rm endpoints.txt
fi
fi