-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Describe what you are trying to accomplish and why in non technical terms
One of the first options I set was for my preview quality to be very_high as I generally scrub the timeline of my important cameras daily. One thing that has always bugged me is that at the hour breaks when a new preview segment mp4 is loaded, the first several preview frames of the new hour are a garbled mess. I'd like to improve that.
Describe the solution you'd like
I have a solution I've been testing, which is to set the -qmax ffmpeg parameter when generating the preview segments.
-qmax sets a quantization ceiling, preventing the encoder from aggressively and excessively compressing frames, which is especially important for the preview I-Frame at the start of the segment. The encoder will still try to hit the target bitrate, but with -qmax set will refuse to compress frames beyond the quantization ceiling, which is especially impactful for the starting I-Frame. This does have the downside of temporarily exceeding the target bitrate, due to the fact that the initial I-Frame cannot "fit" in the target bitrate without excessive quantization (compression).
Describe alternatives you've considered
I also did some testing with the -maxrate, -bufsize and -rc_init_occupancy parameters to try and give the encoder a bitrate buffer budget, however since all of the webp frames we are encoding are significantly larger than the target bitrate this had the unfortunate side effect of the buffer being filled by the early frames, quickly exceeding the target bitrate, and then using excessive compression to get the average bitrate back down to the target bitrate. Moving the problem from the start of the preview segment, to later once the buffer budget was full.
Additional context
If this is something that would be considered, I'd be happy to do some further testing at each of the preview quality presets to try and come up with an appropriate -qmax setting for each preset and then put together a PR. This would be a small change, with a large benefit imo.
Currently I have my qmax set at 20, quality profile set to very_high and have seamless scrubbing between hours. Comparing clips at the same time of day from the same cameras before and after my change I'm seeing a 100KB-200KB increase in hourly preview segment file sizes (~4.5MB-4.6MB vs ~4.4MB during the day) for most segments, but many are actually smaller, likely just due to less activity and therefore less frames.
I think this could be tweaked to get us closer to the target bitrate while still making the initial frames "acceptable".
My expectation would be that other quality profiles would need a higher qmax value to keep us closer to their target bitrates. However, I'm not sure if that would definitely be the case due to the webp frames being lower quality to start with. Additional testing would be needed, which I'm happy to do.