encode things

This commit is contained in:
2024-04-17 17:44:21 -05:00
parent c73469a0d9
commit f5e2b55c41
6 changed files with 69 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ COMMON_DEP_NAMES="autoconf automake cmake libtool pkg-config bc texinfo \
APT_DEP_NAMES="build-essential git-core g++-12 libass-dev libfreetype6-dev \ APT_DEP_NAMES="build-essential git-core g++-12 libass-dev libfreetype6-dev \
libsdl2-dev libva-dev libvdpau-dev gcc-12 libvorbis-dev libxcb1-dev \ libsdl2-dev libva-dev libvdpau-dev gcc-12 libvorbis-dev libxcb1-dev \
libxcb-shm0-dev libxcb-xfixes0-dev zlib1g-dev libssl-dev ninja-build \ libxcb-shm0-dev libxcb-xfixes0-dev zlib1g-dev libssl-dev ninja-build \
gobjc++ python3-pip mawk" gobjc++ python3-pip mawk mediainfo mkvpropedit"
PACMAN_DEP_NAMES="base-devel ninja python-pip" PACMAN_DEP_NAMES="base-devel ninja python-pip"

View File

@@ -3,34 +3,77 @@
# this is simply my recommended encoding method. # this is simply my recommended encoding method.
# do not take this as a holy grail. # do not take this as a holy grail.
encode() { usage() {
FILENAME="$1" echo "unrecognized arguments, please retry"
OUTPUT_NAME="" echo "encode -i input_file [-p] output_file"
# allow optional output filename echo -e "\t-p print the command instead of executing [optional]"
if [[ -n "$2" ]]; return 0
then }
OUTPUT_NAME="$2"
else
OUTPUT_NAME="${HOME}/av1_${FILENAME}"
fi
echo ffmpeg -i \""$FILENAME"\" -map 0 \ encode() {
-af '"aformat=channel_layouts=7.1|5.1|stereo|mono"' -c:a libopus $(get_bitrate_audio "$FILENAME") \ echo ffmpeg -i \""$INPUT"\" -map 0 \
-c:s copy -c:v libsvtav1 -pix_fmt yuv420p10le -crf 20 -preset 3 -g 240 \ -af '"aformat=channel_layouts=7.1|5.1|stereo|mono"' -c:a libopus $(get_bitrate_audio "$INPUT") \
-c:s copy -c:V libsvtav1 -pix_fmt yuv420p10le -crf 25 -preset 3 -g 240 \
-svtav1-params \"tune=0:enable-overlays=1:scd=1:enable-hdr=1:fast-decode=1:enable-variance-boost=1\" \ -svtav1-params \"tune=0:enable-overlays=1:scd=1:enable-hdr=1:fast-decode=1:enable-variance-boost=1\" \
\""$OUTPUT_NAME"\" \""$OUTPUT"\" > /tmp/encode.sh
if [[ "$PRINT_OUT" == "true" ]];
then
cat /tmp/encode.sh
else
bash /tmp/encode.sh
fi
}
unmap_streams(){
INPUT="$1"
num_video_streams=$(ffprobe -v error -select_streams v -show_entries stream=index -of csv=p=0 "$INPUT" | wc -l)
for ((i = 0; i < num_video_streams; i++)); do
ffprobe -v error -select_streams "v:$i" -of default=noprint_wrappers=1:nokey=1 "$INPUT"
ffprobe -select_streams "v:0" -of default=noprint_wrappers=1:nokey=1 'first_20_DN.mkv'
ffprobe -v error -select_streams v -show_entries stream=index:stream_tags=type -of csv=p=0 'first_20_DN.mkv'
done
echo "$num_video_streams"
} }
get_bitrate_audio() { get_bitrate_audio() {
FILENAME="$1"
bitrate_cmd="" bitrate_cmd=""
num_streams=$(ffprobe -v error -select_streams a -show_entries stream=index -of csv=p=0 "$FILENAME" | wc -l) num_audio_streams=$(ffprobe -v error -select_streams a -show_entries stream=index -of csv=p=0 "$INPUT" | wc -l)
for ((i = 0; i < num_streams; i++)); do for ((i = 0; i < num_audio_streams; i++)); do
num_channels=$(ffprobe -v error -select_streams "a:$i" -show_entries stream=channels -of default=noprint_wrappers=1:nokey=1 "$FILENAME") num_channels=$(ffprobe -v error -select_streams "a:$i" -show_entries stream=channels -of default=noprint_wrappers=1:nokey=1 "$INPUT")
bitrate=$((num_channels * 64)) bitrate=$((num_channels * 64))
bitrate_cmd+="-b:a:$i ${bitrate}k " bitrate_cmd+="-b:a:$i ${bitrate}k "
done done
echo "$bitrate_cmd" echo "$bitrate_cmd"
} }
encode "$@" # between only 1-4 arguments
test "$#" -eq 0 && usage && exit 1
test "$#" -gt 4 && usage && exit 1
while getopts "i:p" flag; do
case "${flag}" in
i)
INPUT="${OPTARG}"
;;
p)
PRINT_OUT="true"
;;
*)
usage
exit 1
;;
esac
done
# allow optional output filename
if [[ "$PRINT_OUT" == "true" && "$#" -eq 4 ]];
then
OUTPUT="${@: -1}"
else
OUTPUT="${HOME}/av1_${INPUT}"
fi
encode
# encode "$@"
# unmap_streams "$@"

View File

@@ -0,0 +1,3 @@
#!/bin/bash
sudo rm /usr/local/bin/encode