-
Notifications
You must be signed in to change notification settings - Fork 0
/
video-combiner.sh
executable file
·65 lines (44 loc) · 1.77 KB
/
video-combiner.sh
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
#!/bin/bash
# Automatically combine multipart videos
# https://github.com/tofran/video-combiner
# usage:
# $ video-combiner.sh video1.avi video2.avi video3.avi
MAX_SECONDS_BETWEEN_PARTS=5
OUTPUT_FILE_EXTENSION=".avi"
OUTPUT_DATE_FORMAT="%Y-%m-%d_%H-%M_%Z"
TOUCH_DATE_FORMAT="%Y%m%d%H%M.%S"
set -e
generate_video () {
local start_timstamp=$1; shift;
local files=( $@ )
if [ ${#files[@]} -ne 0 ]; then
output_file=$(date --date="@${start_timstamp}" +"${OUTPUT_DATE_FORMAT}")${OUTPUT_FILE_EXTENSION}
touch_date=$(date --date="@${start_timstamp}" +"${TOUCH_DATE_FORMAT}")
echo "${output_file} will be created from ${files[@]}"
read -p "Press enter to contune..."
mencoder -oac copy -ovc copy ${files[@]} -o ${output_file}
touch -camt ${touch_date} ${output_file}
fi
}
files=( $@ )
end_timestamps=( $(stat -c "%Y" ${files[@]}) )
previous_end_timestamp=0
current_video_files=()
current_output=""
for i in "${!files[@]}"; do
file=${files[i]}
end_timestamp=${end_timestamps[i]}
lenght=$(ffprobe -loglevel panic -show_format ${file} | sed -n '/duration/s/.*=//p' | sed "s/\..*//")
start_timstamp=$(( ${end_timestamp} - ${lenght} ))
interval=$(( ${start_timstamp} - ${previous_end_timestamp} ))
# echo "-> ${file} (timestamp: ${start_timstamp}; lenght: ${lenght}; interval: ${interval})"
if [ "${interval}" -gt "${MAX_SECONDS_BETWEEN_PARTS}" ]; then
generate_video "${current_video_start_timstamp}" "${current_video_files[@]}"
current_video_start_timstamp=${start_timstamp}
current_video_files=($file)
else
current_video_files+=($file)
fi
previous_end_timestamp=${end_timestamp}
done
generate_video "${current_video_start_timstamp}" "${current_video_files[@]}"