@@ -13,6 +13,8 @@ target_audio_bitrate=96 # 128kbps target audio bitrate
13
13
audio_only=0
14
14
crop=0
15
15
cropvalue=" crop=iw:ih:(in_w-out_w)/2:(in_h-out_h)/2"
16
+ cropdetect_params_bb=" 20:16:0"
17
+ cropdetect_params_wb=" 3:16:0"
16
18
verbose=" --no-warnings"
17
19
ffmpeg_enable=1
18
20
ffmpeg_loglevel=" -loglevel quiet -stats"
@@ -89,24 +91,34 @@ file_no_ext=$(find .tmp -type f | cut -d "/" -f 2 | cut -d "." -f 1)
89
91
90
92
if [[ " $crop " = " 1" ]]
91
93
then
92
- echo -e " [FFmpeg] ${YELLOW} Auto-cropping enabled.${ENDCOL} "
94
+ echo " [FFmpeg] Auto-cropping enabled."
95
+
96
+ baseres=$( ffmpeg -i " .tmp/$file " -t 1 -vf " cropdetect=0:0:0" -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
97
+
93
98
# Detect black bars
94
- cropvalue_bb_initial=$( ffmpeg -i " .tmp/$file " -t 1 -vf " cropdetect=20:2:0 " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
95
- cropvalue_bb_seek=$( ffmpeg -ss 5 -i " .tmp/$file " -t 1 -vf " cropdetect=20:2:0 " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
99
+ cropvalue_bb_initial=$( ffmpeg -ss 1 - i " .tmp/$file " -t 1 -vf " cropdetect=${cropdetect_params_bb} " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
100
+ cropvalue_bb_seek=$( ffmpeg -ss 6 -i " .tmp/$file " -t 1 -vf " cropdetect=${cropdetect_params_bb} " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
96
101
97
102
# Detect white bars
98
- cropvalue_wb_initial=$( ffmpeg -i " .tmp/$file " -t 1 -vf " lutrgb=r=negval:g=negval:b=negval, cropdetect=20:2:0 " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
99
- cropvalue_wb_seek=$( ffmpeg -ss 5 -i " .tmp/$file " -t 1 -vf " lutrgb=r=negval:g=negval:b=negval, cropdetect=20:2:0 " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
103
+ cropvalue_wb_initial=$( ffmpeg -ss 1 - i " .tmp/$file " -t 1 -vf " lutrgb=r=negval:g=negval:b=negval, cropdetect=${cropdetect_params_wb} " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
104
+ cropvalue_wb_seek=$( ffmpeg -ss 6 -i " .tmp/$file " -t 1 -vf " lutrgb=r=negval:g=negval:b=negval, cropdetect=${cropdetect_params_wb} " -f null - 2>&1 | awk ' /crop/ { print $NF }' | tail -1)
100
105
101
- # If the calculated crop-value is identical from the start of the video and 5 seconds in, apply crop value.
106
+ # If calculated crop-value is identical value both from the start and 6 seconds in, and the values are different from base resolution
102
107
if [[ " $cropvalue_bb_initial " = " $cropvalue_bb_seek " ]]
103
108
then
104
- cropvalue=$cropvalue_bb_seek
105
- fi
106
-
107
- if [[ " $cropvalue_wb_initial " = " $cropvalue_wb_seek " ]]
108
- then
109
- cropvalue=$cropvalue_wb_seek
109
+ if [[ " $cropvalue_bb_initial " != " $baseres " ]]
110
+ then
111
+ cropvalue=$cropvalue_bb_initial
112
+ fi
113
+
114
+ # If the inverted crop-value detection is not base resolution, apply crop based on white borders instead.
115
+ if [[ " $cropvalue_wb_initial " = " $cropvalue_wb_seek " ]]
116
+ then
117
+ if [[ " $cropvalue_wb_initial " != " $baseres " ]]
118
+ then
119
+ cropvalue=$cropvalue_wb_initial
120
+ fi
121
+ fi
110
122
fi
111
123
fi
112
124
@@ -159,6 +171,7 @@ if [[ "$ffmpeg_enable" = "1" ]]
159
171
then
160
172
echo " [FFmpeg] Converting video..."
161
173
ffmpeg $ffmpeg_loglevel -i " .tmp/$file " $postprocessor_args_str " $file_no_ext .mp4" && rm " .tmp/$file " && rm -rf .tmp
174
+ echo -e " [FFmpeg] File saved as: '${YELLOW} $file_no_ext .mp4${ENDCOL} '"
162
175
fi
163
176
164
177
# Print debug info if verbose is enabled
173
186
echo -e " ${YELLOW} Total bitrate (bits):${ENDCOL} $total_bitrate "
174
187
echo -e " ${YELLOW} Video bitrate (bits):${ENDCOL} $video_bitrate "
175
188
echo -e " ${YELLOW} Audio bitrate (bits):${ENDCOL} $audio_bitrate "
189
+ echo -e " ${YELLOW} Base resolution:${ENDCOL} $baseres "
176
190
echo -e " ${YELLOW} Cropvalue black bars initial:${ENDCOL} $cropvalue_bb_initial "
177
191
echo -e " ${YELLOW} Cropvalue black bars seek:${ENDCOL} $cropvalue_bb_seek "
178
192
echo -e " ${YELLOW} Cropvalue white bars initial:${ENDCOL} $cropvalue_wb_initial "
0 commit comments