As an inspiration for this, look into Two-Pass encoding
pory@lemmy.world 23 hours ago
One thing I’d like to see from an app like this is “force the video into an arbitrary file size limit” with a list of priorities to do so defined by the user. Say I’ve got a video I want to send over Discord (10mb limit) but I’m not intending for the vid to be fullscreened by the recipient so scaling it down to like 480x480 would be fine.
LiveLM@lemmy.zip 22 hours ago
obelisk_complex@piefed.ca 20 hours ago
Fun fact - HISTV actually has two-pass encoding! Though, with enough system RAM you can actually look ahead far enough that you can get the benefits of two-pass in just a single pass. I have a bit about this in the README.md:
Precision mode
One checkbox for the best quality the app can produce. It picks the smartest encoding strategy based on how much RAM your system has:
Your RAM What it does 16GB or more Looks 250 frames ahead to plan bitrate (single pass) 8-16GB Looks 120 frames ahead to plan bitrate (single pass) Under 8GB Scans the whole file first, then encodes (two passes) Two-pass only happens when precision mode is on AND the system has less than 8GB RAM AND the file would be CRF-encoded. Reason being, Precision Mode normally uses CRF with extended lookahead (120-250 frames depending on RAM). Lookahead buffers live in memory. On low-RAM systems that buffer would be too large, so the app falls back to two-pass instead and stores the analysis run in a tempfile on disk. To break down each one:
- Pass 1: Runs ffmpeg with -pass 1 writing to a null output. ffmpeg analyses the entire file and writes a statistics log (the passlog file) describing the complexity of every scene. No actual video is produced - this pass is pure analysis.
- Pass 2: Runs ffmpeg with -pass 2 using the statistics from pass 1. The encoder now knows what’s coming and can distribute bits intelligently across the whole file - spending more on complex scenes, less on simple ones - without needing a large lookahead buffer in RAM. After both passes complete, the passlog temp files are cleaned up.
I went with this architecture to mitigate the biggest problem with two-pass encoding, when there’s enough system RAM to store the lookahead frames: the speed. The quality of single-pass with a 250-frame lookahead is equal to two-pass; 120-frame lookahead is just as fast, and still close enough in quality that it doesn’t really make a difference.
LiveLM@lemmy.zip 16 hours ago
Damn, I had no clue about this single-pass look ahead, all this time I’ve been doing two-pass for nothing 😵💫
Thanks!
obelisk_complex@piefed.ca 20 hours ago
You know what? I think I can figure out a way to estimate final file size and display it to the user. It’ll only work if “Precision Mode” is off though - that uses “CRF” or “Constant Rate Factor” which basically tells the encoder “be efficient, but make the file as big as it needs to be to look good”. As a result there’s no way to tell how big the file will end up being - the encoder makes the decision on the fly.
With “Precision Mode” off, HISTV has two gears: