Created
August 16, 2023 08:01
-
-
Save ookiineko/58a570c09ff3f843a24e63b0b278a68d to your computer and use it in GitHub Desktop.
Batch downscale video to 1080p (using AMD hwaccel and hwenc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
OIFS="$IFS" | |
IFS=$'\n' | |
for __vidfile in $(ls -1 *.mp4); do | |
if echo "$__vidfile" | grep _1080p; then | |
echo 'skip converted file: ' "$__vidfile" | |
continue | |
fi | |
echo -ne 'trying to process: \t' | |
echo "$__vidfile" file | |
__bitrate=$(ffprobe -v quiet -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "$__vidfile") | |
if [ -z "$__bitrate" -o ! "$__bitrate" -gt 0 ]; then | |
echo cannot process "$__vidfile", failed to get the bitrate | |
fi | |
echo "bitrate is: $__bitrate" time to encode | |
__outfile="${__vidfile%.mp4}_1080p.mp4" | |
ffmpeg -hwaccel d3d11va -i "$__vidfile" -vf scale=1920x1080 -c:v h264_amf -b:v "$__bitrate" "$__outfile" | |
if [ ! -f "$__outfile" ]; then | |
echo cannot process "$__vidfile", ffmpeg failed | |
else | |
echo success, nuke old file | |
rm -f "$__vidfile" | |
fi | |
done | |
IFS="$OIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment