Log in New API Help About

video2png.sh

1.4 KB of Bash
Created 1 month, 1 week ago — expires in 325 days
https://dpaste.com/HFTKAPM5V
COPY TO CLIPBOARD SOFT WRAP RAW TEXT DUPLICATE DIFF
#!/bin/env bash
# usage: script.sh <input> <hres> <yres> <fps divisor> <aspect> <audio bitrate> [<output>]
# example: script.sh input.mkv 320 240 24/1.001 16/9 48 [output.mkv]
if [ ! "$1" ]; then echo Specify an input.; exit; fi
if [ ! -e "$1" ]; then echo \"$1\" doesn\'t exist.; exit; fi
if [ "$7" ]; then output="${2%.*}.png"; else output="${1%.*}.png"; fi
if [ -e "$output" ]; then echo Output exists, specify another name.; exit; fi
input="$1"
hres="$2"
vres="$3"
fps="$4"
aspect="$5"
abitrate="$6"
length=$(ffprobe -v quiet -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input")
vbitrate=$(bc <<< "((3920*8)/${length})-${abitrate}")

function pass {
 ffmpeg -i "$input" -map 0:v:0 -map 0:a:0? -map 0:s:0? -pix_fmt yuv420p10 -c:v libx265 -vf scale=${hres}:${vres},fps=$fps -aspect $aspect -b:v ${vbitrate}k -preset slow -x265-params no-slow-firstpass=1:pass=$1:keyint=7200:min-keyint=48:scenecut=70 -c:a libopus -b:a ${abitrate}k -f matroska -y "$2"
}

pass 1 /dev/null
pass 2 "${output%.*}-encoded.mkv"
size=$(bc <<< "sqrt($(stat -c%s "${output%.*}-encoded.mkv")/8)+0.5/1")
cat "${output%.*}-encoded.mkv" /dev/zero - | ffmpeg -f rawvideo -s ${size}:${size} -pix_fmt rgba64be -i - -vframes 1 "$output"
rm x265_2pass.log x265_2pass.log.cutree
#rm "${output%.*}-encoded.mkv"

echo Playback with\:
echo ffmpeg -i \"$output\" -f rawvideo - \| mpv -

Share: