Krysti.Engineer Official Chat
You are viewing an inferior version of the site because your browser does not support WebP. Do upgrade to something like Chrome or Firefox. Loading websites like this causes them to require a fallback set of images and they are almost always lower quality and larger in size.

Use Low Bitrate Video For HTML 5 Video & Save Bandwidth

This script will help you produce low bitrate video that should play on any device using the HTML 5 video player.
2022-07-26T:00:00:00+00:00 July 26 2022 00:00:00

#!/bin/bash
CWD=`pwd`
X264_OPTS="mixed-refs=0:weightb=0:8x8dct=0:psy-rd=1|0.2:ref=3:bframes=3:b-adapt=1:merange=16:subme=7:me=hex:partitions=most:trellis=1:weightp=2:b-pyramid=normal"
WIDTH=640 # Max video width (4:3 aspect ratio 640x480 is the aim here)
VKBPS=450 # Max Video Bitrate (kbps)
AKBPS=128 # Max Audio Bitrate (kbps)
# we are expecting files to be put into your current working directory's "enc/" directory
ENC_OUT="enc"
mkdir -p $CWD/$ENC_OUT
for file in $CWD/*; do
	if test -f $file; then
		if ! test -f $ENC_OUT/$(basename "$file"); then
			HandBrakeCLI -i $(basename "$file") -f mp4 -o $ENC_OUT/$(basename "$file") -e x264 -x $X264_OPTS -b $VKBPS -2 -T -E ffac3 -w $WIDTH -B $AKBPS --custom-anamorphic --keep-display-aspect -5 -9  --modulus 16
		fi
    fi
done

Save this script somewhere in your $PATH and make the file is executable (chmod a+x) and you can open terminal, change to the directory with all your videos and run the script. This will create a "enc/" directory in your current working directory which it will place all your encoded videos. You will need to install 'handbrake-cli' from your package manager prior to running this program.

<video preload="metadata" onloadstart="this.volume=0.5" controls="" poster="https://url.to/default_image.jpg">
	<source src="https://url.to/your_video.mp4" type="video/mp4"> 
	Your browser does not support the video tag.
</video>

Now you just load it up in a basic HTML 5 player like so. I do recommend that higher resolution videos be available for download, and these videos are your direct streaming from the website's player. In this example it is shown how to handle default volume.

Contact Krysti

@itskrystibitch Twitter Photo
GitHub:
IRC:
Direct.Me:
Ko-fi:
Photos:
E-Mail / Notify of errors:
coder [@] krysti.engineer
Please be patient contacting me, I don't really check much of social media or anything. If you use the IRC be sure to stick around because that's how IRC works, silly. :P