-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjoin-insv
More file actions
executable file
·139 lines (110 loc) · 3.02 KB
/
Copy pathjoin-insv
File metadata and controls
executable file
·139 lines (110 loc) · 3.02 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
#
# Join 360-degree INSV files into a single MP4
#
set -euo pipefail
#######################################################
# Self test
#######################################################
err() {
echo -e "$*" >&2
exit 1
}
self_test() {
# check if MediaSDKTest is available
command -v MediaSDKTest >/dev/null || \
err "Error: MediaSDKTest is not available"
# check if ffmpeg is available
command -v ffmpeg >/dev/null || \
err "Error: ffmpeg is not available"
# check if exiftool is available
command -v exiftool >/dev/null || \
err "Error: exiftool is not available"
# check if bc is available
command -v bc >/dev/null || \
err "Error: bc is not available"
# check if exiftool version is 12.40 or later
exiftool_ver="$(exiftool -ver | cut -d. -f1,2)"
if [ "$(echo "${exiftool_ver} >= 12.40" | bc)" -eq 0 ]; then
err "Error: exiftool version 12.40 or later is required"
fi
}
join_insv() {
if [ "$#" -lt 3 ]; then
echo "Usage: ${FUNCNAME[0]} is_57k outfile infile1 [infile2 ...]"
exit 1
fi
self_test
local is_57k=$1
local outfile="$2"
shift 2
local tmpfile="${outfile}"_tmp_.mp4
local file_list
file_list="$(mktemp --suffix="_list.txt" --tmpdir="$(pwd)")"
rm -rf "${file_list}" "${tmpfile}"
if ${is_57k}; then
if [ $(( $# % 2 )) -ne 0 ]; then
err "Error: 5.7K mode requires even number of files"
fi
while [ $# -gt 0 ]; do
local left_eye="$1"
local right_eye="$2"
shift 2
MediaSDKTest -inputs "$left_eye" "$right_eye" -output "${left_eye}.mp4" \
-enable_directionlock -enable_flowstate -enable_denoise
echo "file ${left_eye}.mp4" >> "${file_list}"
done
else
for v in "$@"; do
MediaSDKTest -inputs "$v" -output "${v}.mp4" \
-enable_directionlock -enable_flowstate -enable_denoise
echo "file ${v}.mp4" >> "${file_list}"
done
fi
ffmpeg -safe 0 \
-f concat \
-i "${file_list}" \
-vcodec copy \
-acodec copy \
-f mp4 "$tmpfile"
exiftool -XMP-GSpherical:Spherical="true" \
-XMP-GSpherical:Stitched="true" \
-XMP-GSpherical:ProjectionType="equirectangular" \
-XMP-GSpherical:StereoMode="mono" \
-api largefilesupport=1 \
"$tmpfile" \
-o "$outfile"
}
usage() {
>&2 cat << EOF
Usage: ${0}
[ -H | --is_57k ]
[ -o | --output outfile ]
[ -h | --help ]
<infile> [infiles]
EOF
}
############################
# CLI entrypoint
############################
cli() {
local is_57k=false
local outfile=''
args=$(getopt -a -o Ho:h --long is_57k,output:,help -- "$@")
eval set -- "${args}"
while :
do
case "$1" in
-H | --is_57k) is_57k=true ; shift ;;
-h | --help) usage ; exit 0 ;;
-o | --output) outfile="$2" ; shift 2 ;;
--) shift; break ;;
*) >&2 echo "Unsupported optoin: $1"
usage ; exit 1 ;;
esac
done
[ -z "$outfile" ] && err "Error: [-o | --output] outfile is missing"
[[ $# -eq 0 ]] && { usage; exit 1; }
join_insv ${is_57k} "$outfile" "$@"
}
cli "$@"