FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
scripts/ffavencode at master · Ferk/scripts · GitHub
Ferk
/
scripts
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
11
Code
Issues
1
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
scripts
/
ffavencode
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
245 lines (216 loc) · 7.49 KB
Breadcrumbs
scripts
/
ffavencode
Copy path
File metadata and controls
executable file
·
245 lines (216 loc) · 7.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!
/bin/bash
#
----
#
Wrapper for ffmpeg to convert videos into AV Media family of codecs.
#
#
The wrapper will accept the video files as parameters, if the video
#
is not already in an AV codec, it will convert it, using a set of
#
sane default presets (which can be tweaked via environment variables
#
`VCODER` `VOPTS` `AOPTS` `XOPTS`), and then display the difference in
#
size of the new fiel vs the old.. if the new file is bigger, it'll be
#
renamed for further analysis, considering the compression unsuccessful.
#
#
You can also set the env variable `successful_command` to set a command
#
to be run on the original file after it has been successfully processed
#
(for example set it to 'rm -v' to delete each original file automatically)
#
----
i=
"
$@
"
VCODER=libsvtav1
#
VCODER=av1_amf
ACODER=libopus
VOPTS=
${VOPTS
:-
'
-preset 6 -crf 35
'
}
#
AOPTS='-b:a 96K -af "channelmap=channel_layout=5.1"'
#
AOPTS='-b:a 96K -af aformat=channel_layouts="7.1|6.1|5.1|stereo|mono"'
#
AOPTS='-b:a 96K -af aformat=channel_layouts="mono|stereo|5.1|6.1|7.1"'
#
AOPTS='-b:a 96K -ac 2 -lfe_mix_level 1' # Downmixing to 2.1
AOPTS=
${AOPTS
:-
'
-b:a 96K
'
}
XOPTS=
'
-map_metadata 0
'
XOPTS=
$XOPTS
'
-hide_banner -loglevel warning -stats
'
${EXTRA_OPTS}
#
###########################
#
#### VFILTER #####
#
Set a filter:v parameter
#
#
Examples:
#
#
VFILTER="crop=408:720:436:0" ffavencode "16:9-vertical-720-video.mp4"
#
VFILTER="crop=612:1080:654:0" ffavencode "16:9-vertical-1080-video.mp4"
#
VFILTER="scale=-1:720" ffavencode "1080-video.mp4"
#
VFILTER="scale=-1:540" ffavencode "720-video.mp4"
#
VFILTER="pp=hb/vb/dr/fq|8" ffavencode "cartoon-poorly-encoded.avi"
#
if
[
$VFILTER
]
then
VOPTS=
"
$VOPTS
-filter:v:0
$VFILTER
"
fi
#
##########################
#
#### File processing #####
processFile
() {
case
$1
in
*
mp3|
*
wav)
processMusic
"
$1
"
"
$2
"
;;
*
)
processMovie
"
$1
"
"
$2
"
;;
esac
}
processMovie
() {
file=
$1
out=
$2
printf
'
\033[33m ----------\n
'
echo
"
- FILE:
\"
$out
\"
"
echo
"
- VIDEO CODEC:
$VCODER
OPTS:
$VOPTS
"
echo
"
- AUDIO CODEC:
$ACODER
OPTS:
$AOPTS
"
printf
'
\033[36m **********\n * Single PASS *\n
'
echo
'
ffmpeg -i "
'
$file
'
"
'
$XOPTS
'
-map 0 -c copy -c:v:0
'
$VCODER
'
'
$VOPTS
'
-c:a
'
$ACODER
'
'
${AFORMAT
:
+-af
$AFORMAT
}
'
'
$AOPTS
'
-c:s copy -copy_unknown "
'
$out
'
"
'
ffmpeg -nostdin -i
"
$file
"
$XOPTS
-c copy -c:v:0
$VCODER
$VOPTS
-c:a
$ACODER
$AOPTS
${AFORMAT
:
+-af
$AFORMAT
}
-c:s copy -copy_unknown
"
$out
"
}
processMovie2pass
() {
file=
$1
out=
$2
printf
'
\033[33m ----------\n
'
echo
"
- FILE:
\"
$out
\"
"
echo
"
- VIDEO CODEC:
$VCODER
OPTS:
$VOPTS
"
echo
"
- AUDIO CODEC:
$ACODER
OPTS:
$AOPTS
"
printf
'
\033[36m **********\n * PASS 1 *\n
'
if
ffmpeg -nostdin -i
"
$file
"
$XOPTS
-c:v
$VCODER
$VOPTS
-pass 1 -passlogfile
"
${out
/
.mkv
/
}
"
-an -f null -c:s copy -ignore_unknown /dev/null
2>&1
then
printf
'
\033[35m **********\n * PASS 2 *\n
'
if
[
"
$audio_codec_name
"
!=
"
opus
"
]
then
if
[
"
${channels
#
5.1}
"
!=
"
$audio_hannel_layout
"
]
then
AFORMAT=
"
aformat=channel_layouts=5.1
"
fi
fi
echo
'
ffmpeg -i "
'
$file
'
"
'
$XOPTS
'
-map 0 -c copy -c:v:0
'
$VCODER
'
'
$VOPTS
'
-pass 2 -passlogfile "
'
${out
/
.mkv
/
}
'
" -c:a
'
$ACODER
'
'
${AFORMAT
:
+-af
$AFORMAT
}
'
'
$AOPTS
'
-c:s copy -copy_unknown "
'
$out
'
"
'
ffmpeg -nostdin -i
"
$file
"
$XOPTS
-map 0 -c copy -c:v:0
$VCODER
$VOPTS
-pass 2 -passlogfile
"
${out
/
.mkv
/
}
"
-c:a
$ACODER
$AOPTS
${AFORMAT
:
+-af
$AFORMAT
}
-c:s copy -copy_unknown
"
$out
"
else
return
$?
fi
}
processMusic
() {
file=
$1
name=
${1
%
.
*
}
out=
${name}
.opus
printf
'
\033[33m ----------\n
'
echo
"
- FILE:
\"
$out
\"
"
echo
"
- AUDIO CODEC:
$ACODER
\t OPTS:
$AOPTS
"
printf
'
\033[36m **********\n
'
ffmpeg -i
"
$file
"
$XOPTS
-c copy -c:a
$ACODER
$AOPTS
${AFORMAT
:
+-af
$AFORMAT
}
-c:s copy -copy_unknown
"
$out
"
}
validateFile
() {
file=
$1
name=
${1
#*
.}
name=
${name
#*
.}
ext=
${1
#
$name
}
codec=
$(
getVideoCodec
"
$file
"
)
eval
"
$(
getVideoProperties
"
$file
"
)
"
printf
"
\033[35m\n * File:
$file
\n * Video Codec:
${video_codec_name}
\n
"
if
[
"
$ext
"
=
"
av1opus.mkv
"
]
then
echo
"
File name already matches av1opus pattern, skipping...
"
return
1
else
case
"
$codec
"
in
*
av1)
#
echo "Codec is already AV1, skipping..."
return
1
;;
esac
fi
duration=
$(
getDuration
"
$file
"
)
eval
$(
getAudioProperties
"
$file
"
)
printf
"
* Resolution:
${video_width}
x
${video_height}
\n * Audio Codec:
$audio_codec_name
\n * Audio Channels:
$audio_channel_layout
\n * Duration:
$duration
\n
"
}
getVideoCodec
() {
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1
"
$1
"
}
getAudioCodec
() {
ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1
"
$1
"
}
getResolution
() {
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0
"
$1
"
}
getDuration
() {
ffprobe -i
"
$1
"
-v quiet -show_entries format=duration -hide_banner -of default=noprint_wrappers=1:nokey=1 -sexagesimal
|
sed
'
s/0*$//
'
}
getChannels
() {
ffprobe -v error -select_streams a:0 -show_entries stream=channel_layout -of csv=s=x:p=0
"
$1
"
}
getAudioProperties
() {
ffprobe -i
"
$1
"
-v quiet -select_streams a:0 -show_entries stream=codec_name,channel_layout -of default=noprint_wrappers=1
|
sed
'
s/^/audio_/;s/\([()]\)/\\\1/g
'
}
getVideoProperties
() {
ffprobe -i
"
$1
"
-v quiet -select_streams v:0 -show_entries stream=codec_name,width,height,duration -of default=noprint_wrappers=1
|
sed
'
s/^/video_/;s/\([()]\)/\\\1/g
'
}
getOutFilename
() {
f=
${1
%
.
*
}
#
filename without extension
case
"
$f
"
in
*
.
\[
*
.
*
\]
)
echo
"
$f
"
|
sed
'
s/\(\[[^[]*\)\.[^[\.]*\]$/\1\.av1].mkv/
'
;;
*
\ \[
*
\
*
\]
*
)
echo
"
$f
"
|
sed
'
s/\(\[[^[]*\) [^[ ]*\]$/\1 av1].mkv/
'
;;
*
)
echo
"
$f
[
${video_height}
p av1].mkv
"
;;
esac
}
#
###########################
#
#### Handle arguments #####
for
file
in
"
$@
"
do
if
!
[
-f
"
$file
"
]
then
echo
"
file not found:
$file
"
elif
!
validateFile
"
$file
"
then
echo
"
Skipping file:
$file
"
else
out=
"
$(
getOutFilename
"
$file
"
)
"
if
[
-f
"
$out
"
]
then
echo
"
Output file exists, skipping
$file
"
continue
fi
if
processFile
"
$file
"
"
$out
"
then
printf
'
\033[32m ----------\n
'
du -h
"
$file
"
"
$out
"
oldbytes=
$(
stat -c %s
"
$file
"
)
newbytes=
$(
stat -c %s
"
$out
"
)
kbdiff=
$((
(newbytes
-
oldbytes)
/
1024
))
if
[
$newbytes
-gt
$oldbytes
]
then
printf
"
COMPLETED!! \033[31m; BUT NEW FILE IS BIGGER!! :(
$kbdiff
KB\n
"
echo
"
Please check manually in case there's an issue! further processing for it will be interrupted
"
mv -v
"
${out}
"
"
${out
%
.mkv}
.[BIGGER].mkv
"
continue
#
stop further processing, skip the success_command
elif
[ -1024
-lt
$kbdiff
]
then
echo
"
SUCCESS!! ...size diff:
$kbdiff
KB (less than 1MB!)
"
else
echo
"
SUCCESS!! ...size diff:
$((
(kbdiff)
/
1024
))
MB
"
fi
rm -f
"
${out
/
.mkv
/
}
"
-
*
.log
#
Remove ffmpeg pass 1 log
#
Copy over subtitles and metadata
f=
${file
%
.
*
}
#
filename without extension
for
s
in
"
${f}
"
*
.{nfo,bif,srt,ass,sub,smi,vtt}
do
test
-f
"
$s
"
||
continue
ext=
${s
#
${f
/
[
/
\\
[}
}
new=
${out
%
.
*
}
$ext
cp -nv
"
$s
"
"
$new
"
done
[
"
$success_command
"
]
&&
$success_command
"
$file
"
else
printf
"
\033[31m\n////////////////////////\n ERROR RESPONSE CODE:
$?
\n
"
if
test
-e
"
$out
"
then
echo
"
The result might have been defective, moving it over with .error extension, please check it
"
mv -v
"
$out
"
"
$out
.error
"
fi
fi
printf
'
\033[0m
'
fi
done
Back
|
FazBrowse Home
|
New Git URL