-
Notifications
You must be signed in to change notification settings - Fork 4
/
ffmpeg-fuji-to-mp4
executable file
·91 lines (74 loc) · 2 KB
/
ffmpeg-fuji-to-mp4
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
#!/bin/bash
set -euo pipefail
run() {
echo >&2 "+ $*"
"$@"
}
vcodec=
opts=()
while [ $# -gt 0 ] && [[ $1 == -* ]]; do
case "$1" in
-h|--help)
usage
exit
;;
--crf)
opts+=(-crf "$2")
shift
;;
--preset)
opts+=(-preset "$2")
shift
;;
-s|--size)
opts+=(-s "$2")
shift
;;
--vcodec)
vcodec="$2"
shift
;;
*)
usage
echo >&2 "Unknown option $1"
exit 1
;;
esac
shift
done
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
cat >&2 <<EOM
usage: $(basename "$0") [OPTIONS] INPUT.MOV [OUTPUT.mp4]
Convert Fuji .mov quicktime video to .mp4 container, which makes native
playback possible on Android.
Under the hood, this will keep the video codec as-is (expected to be H264),
while encoding the audio as AAC (expected to be PCM originally).
It will also remove the timecode track, which can cause compatibility issues.
Options:
-h,--help Display this message
--crf NUM Set video quality rate factor (see -crf 22)
-s,--size SIZE Resize video to SIZE (e.g. 1920x1080)
--preset PRESET Set video encoding preset (e.g. slow/medium/fast)
--vcodec CODEC Set video codec (e.g. libx264/libx265)
Convert a whole directory, one at a time (ffmpeg messes up tty if parallel):
parallel -j 1 $(basename "$0") -- *.MOV
EOM
exit 1
fi
input="$1"
if [ $# -ge 2 ]; then
output="$2"
else
output="$(dirname "$input")/${input%.???}.mp4"
fi
if [ -z "$vcodec" ]; then
if [ "${#opts[@]}" -eq 0 ]; then
# if no transcoding options, then copy input without transcoding
vcodec=copy
else
# otherwise default to libx265
vcodec=libx265
fi
fi
run ffmpeg -i "$input" "${opts[@]}" -map_metadata 0 -c:v "$vcodec" -c:a aac -write_tmcd 0 -- "$output"
echo "Successfully wrote $output"