-
Notifications
You must be signed in to change notification settings - Fork 1
/
swift-encoder.sh
129 lines (110 loc) · 3.6 KB
/
swift-encoder.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
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
#!/bin/sh
###########################################################
# swift-encoder #
# #
# A fire-and-forget shell script that encodes #
# multiple video files with ffmpeg. #
# #
# Github: https://github.com/DonutDeflector/swift-encoder #
###########################################################
###########################################################
# Available Optimizations #
# #
# Anime - Adds some specific encoding options. #
# Normal - Adds no additional encoding options. #
###########################################################
##############################
# Settings
# Video Codec
# (libx264 or libx265)
# default: libx265
videocodec=libx265
# Rate Factor
# (0-51 | Lower Number = Higher Quality)
# default: 21
ratefactor=21
# Preset
# (ultrafast, superfast, veryfast, fast, medium, slow, slower, veryslow)
# default: medium
preset=medium
# Pixel Format (chroma sampling and bit depth)
# (yuv420p [8bit], yuv420p10le [10bit])
# Default: yu4v420p10le
pixelformat=yuv420p10le
# Audio Codec
# (ac3, eac3, wmav1, wmav2, libmp3lame, libfdk_aac, aac, libvorbis, vorbis, libopus)
# default: libopus
audiocodec=libopus
# Constant/Variable Bitrate
# (b:a for CBR | q:a for VBR)
# Default: b:a
audioencoding=b:a
# Audio Bitrate
# CBR (8k, 16k, 24k, 32k, 40k, 48k, 64k, 80k, 96k, 112k, 128k, 160k, 192k, 224k, 256k, or 320k)
# VBR (0-9 | Lower Number = Higher Quality)
# default: 192k
audiobitrate=192k # Very important to remember the 'k' for CBR
# Audio Channels
# default: 2
audiochannels=2
# Input Format
# (mp4, mkv, avi, etc.)
# default: mp4
inputformat=mkv
# Output Format
# (mp4, mkv, avi, etc.)
# default: mkv
outputformat=mkv
# Completed Files Folder
# (Ex: Completed | quality21/completed)
# default: completed
cmpltd_fls_fldr=completed
#########################
# Core Functionality
# (Better off not touching unless you know what you are doing)
if [ "$1" = "anime" ] && [ "$videocodec" = "libx264" ] ; then
for f in "$2"/*."$inputformat"; do
ffmpeg -i "$f" \
-c:v "$videocodec" \
-crf "$ratefactor" \
-preset "$preset" \
-tune animation \
-c:a "$audiocodec" \
-"$audioencoding" "$audiobitrate" \
-ac "$audiochannels" \
-pix_fmt "$pixelformat" \
-map 0 \
-c:s copy \
"${f%."$inputformat"}[se]."$outputformat""; done
elif [ "$1" = "anime" ] && [ "$videocodec" = "libx265" ] ; then
for f in "$2"/*."$inputformat"; do
ffmpeg -i "$f" \
-c:v "$videocodec" \
-crf "$ratefactor" \
-preset "$preset" \
-x265-params allow-non-conformance:ref=8:bframes=8:rd=6:me=star:b-adapt=2:qg-size=64:rc-lookahead=40:scenecut=45:weightb=1:psy-rd=2.0 \
-c:a "$audiocodec" \
-"$audioencoding" "$audiobitrate" \
-ac "$audiochannels" \
-pix_fmt "$pixelformat" \
-map 0 \
-c:s copy \
"${f%."$inputformat"}[se]."$outputformat""; done
else
for f in "$2"/*."$inputformat"; do
ffmpeg -i "$f" \
-c:v "$videocodec" \
-crf "$ratefactor" \
-preset "$preset" \
-c:a "$audiocodec" \
-"$audioencoding" "$audiobitrate" \
-ac "$audiochannels" \
-pix_fmt "$pixelformat" \
-map 0 \
-c:s copy \
"${f%."$inputformat"}[se]."$outputformat""; done
fi
# Palace of Immigration
# This is where we move the files
mkdir "$2""$cmpltd_fls_fldr"/ # create folder
mv "$2"*"[se]"."$outputformat" "$2""$cmpltd_fls_fldr"/ # move the completed encodes