-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.zsh
59 lines (54 loc) · 1.95 KB
/
video.zsh
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
ffp(){
ffprobe -print_format json -show_format -show_streams -show_chapters -show_private_data "$@" | jq '.streams'
}
yb(){
local url="$1"
shift 1
yt-dlp --cookies-from-browser firefox "$url" "$@"
}
hevc(){
local filename=$1:t:r
ffmpeg -i $1 -c:v hevc_videotoolbox -b:v 2M $filename.mp4
# ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 2M -hwaccel videotoolbox output.mp4
}
atv(){
# Apple 1080p60 4K HEVC Surround.
# also make sure it works with quicklook
# $2 accepts quality - 1080p60, 1080p30, 720p60, 720p30, 480p30, 360p30, 240p30, 144p30
local quality=${2:-"1080p30"}
fname=$1:t:r
input=$1
local output_dir=$HANDBRAKE_OUTPUT_DIR
# if HANDBRAKE_OUTPUT_DIR is not set, use current directory
if [[ -z $HANDBRAKE_OUTPUT_DIR ]]; then
output_dir=$(pwd)
fi
echo output_dir "$output_dir"
handbrake --input "$input" -o "$output_dir/$fname-$quality.mp4" \
--preset "Apple $quality Surround" \
--all-subtitles --all-audio --optimize \
&& trash "$input";
# ensure format will play in macos quicklook using handbrake
# ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 2M -hwaccel videotoolbox output.mp4
# ffmpeg -i "${1%.*}.mp4" -c copy -movflags faststart "${1%.*}.mp4"
}
atvs(){
# apply profile 'Apple 1080p60 HEVC Surround' to all files in current directory
local quality=${2:-"1080p30"}
for f in *;
# ignore if $f is a directory
# fi
# get file extension
# local ext=${f##*.}
# before applying profile, check if file is already Apple-optimized
if [[ $(mediainfo --Inform="Video;%Format%" "$f") != "HEVC" ]]; then
if [[ -d $f ]]; then
echo "it's a directory"
else
atv "$f" "$quality"
fi
else
echo " - $f is already optimized"
atv "$f" "$quality"
fi
}