In my previous posts, I covered how to combine two mp4 streams (one audio and one video) together and how to download a m3u8 file.
The next installment is how to transcode your mp4 file into a smaller h265 format.
As before, ffmpeg is the answer to all your problems (and likely will be the cause of several more… but that is a story for another post.)
As a reminder, if you don’t already have ffmpeg, installation is quite simple (assuming a debian based os)
sudo apt update
sudo apt install ffmpeg
After the install process it is as simple as using the following command:
ffmpeg -i infile.mp4 -c:v libx265 -c:a copy -x265-params crf=28 outfile.mp4
where crf is the “constant rate factor” that controls the quality (and size) of the end result. The bigger the number, the smaller the file (and less the quality). If 0 is lossless (and huge) and 51 is small (but really bad). I have found the high 20’s to result in a good medium between high quality and small files, but the best way to find your sweet spot is through trying a few runs at different quality for your use case.