Search Results
6/21/2025, 1:10:56 AM
Please excuse the shitty AI slop
Why doesn't this work correctly when trying to target specific bitrate to achieve certain file size?
I'm not sure what's going wrong.
vp8_scale() {
scale=${3:-1}
iw=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$1")
ih=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "$1")
ow=$(echo "$iw * $scale" | bc | awk '{print int($1+0.5)}')
oh=$(echo "$ih * $scale" | bc | awk '{print int($1+0.5)}')
ow=$(( (ow / 2) * 2 ))
oh=$(( (oh / 2) * 2 ))
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1")
base_bitrate_kbps=$(echo "scale=0; 0.95 * (2^25) / 1000 / $duration" | bc -l | awk '{print int($1+0.5)}')
orig_pixels=$((iw * ih))
out_pixels=$((ow * oh))
pixel_ratio_inv=$(echo "$orig_pixels / $out_pixels" | bc -l)
adjusted_bitrate_kbps=$(echo "$base_bitrate_kbps * $pixel_ratio_inv" | bc -l | awk '{print int($1+0.5)}')
max_bitrate_kbps=$(echo "scale=0; 0.95 * (2^25) / 1000 / $duration" | bc -l | awk '{print int($1+0.5)}')
[ "$adjusted_bitrate_kbps" -gt "$max_bitrate_kbps" ] && adjusted_bitrate_kbps=$max_bitrate_kbps
echo " Input resolution: ${iw}x${ih}"
echo " Output resolution: ${ow}x${oh}"
echo " Target bitrate: ${adjusted_bitrate_kbps}k"
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -vaapi_device /dev/dri/renderD128 \
-i "$1" \
-vf "format=nv12,hwupload,scale_vaapi=w=${ow}:h=${oh}" \
-c:v vp8_vaapi \
-b:v "${adjusted_bitrate_kbps}k" \
-g 300 \
-quality 1 \
-an \
"$2.webm"
}
Why doesn't this work correctly when trying to target specific bitrate to achieve certain file size?
I'm not sure what's going wrong.
vp8_scale() {
scale=${3:-1}
iw=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$1")
ih=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "$1")
ow=$(echo "$iw * $scale" | bc | awk '{print int($1+0.5)}')
oh=$(echo "$ih * $scale" | bc | awk '{print int($1+0.5)}')
ow=$(( (ow / 2) * 2 ))
oh=$(( (oh / 2) * 2 ))
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1")
base_bitrate_kbps=$(echo "scale=0; 0.95 * (2^25) / 1000 / $duration" | bc -l | awk '{print int($1+0.5)}')
orig_pixels=$((iw * ih))
out_pixels=$((ow * oh))
pixel_ratio_inv=$(echo "$orig_pixels / $out_pixels" | bc -l)
adjusted_bitrate_kbps=$(echo "$base_bitrate_kbps * $pixel_ratio_inv" | bc -l | awk '{print int($1+0.5)}')
max_bitrate_kbps=$(echo "scale=0; 0.95 * (2^25) / 1000 / $duration" | bc -l | awk '{print int($1+0.5)}')
[ "$adjusted_bitrate_kbps" -gt "$max_bitrate_kbps" ] && adjusted_bitrate_kbps=$max_bitrate_kbps
echo " Input resolution: ${iw}x${ih}"
echo " Output resolution: ${ow}x${oh}"
echo " Target bitrate: ${adjusted_bitrate_kbps}k"
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -vaapi_device /dev/dri/renderD128 \
-i "$1" \
-vf "format=nv12,hwupload,scale_vaapi=w=${ow}:h=${oh}" \
-c:v vp8_vaapi \
-b:v "${adjusted_bitrate_kbps}k" \
-g 300 \
-quality 1 \
-an \
"$2.webm"
}
Page 1