This script will encode a video file into a png image that may be shared on the Internet. This is very cool indeed, this allows a good-quality video to be shared in a relatively small image.
#!/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 |
The image below was encoded with this command.
./my.sh zombiekill.mp4 320 240 24/1.001 16/9 48 zonby.mp4 |
Sample PNG image with the video encoded within.
Use this command to play this image back.
┌──[jason@192.168.1.2]─[~/Pictures] └──╼ ╼ $ ffmpeg -i 320.png -f rawvideo - | mpv - |
This is quite a revolutionary technique for encoding a video file, and it works.