paulpacifico / shutter-encoder

A professional video compression tool accessible to all, mostly based on FFmpeg.
https://www.shutterencoder.com
GNU General Public License v3.0
984 stars 60 forks source link

Improve video bitrate calculation #186

Open endmarsfr opened 6 months ago

endmarsfr commented 6 months ago

Hi,

As I understand it, FunctionUtils.setVideoBitrate() calculates video bitrate values for auto, good, and best settings.

Good is calculated by auto value x 2 and best is auto value x 4.

If I consider auto calculation, I understand that auto video bitrate is calculated like this: outputHeight x outputWidth x OutputFrameRate x OutPutBitDepth x 2 / compValue. This formula will always return the same values for streams having same height, width, frame rate and output depth.

I think if the video is cropped (in case of black bands) this formula should be adjusted like this: croppedOutputHeight x croppedWidthHeight x Output OutputFrameRate x OutPutBitDepth x 2 / compValue.

I have seen another method to calculate a good bitrate. For example, for x264 input video, sample 5% of the input video stream (take a few seconds for each sample calculated) and compress it with CRF 18 and assume that the resulting file is the reference for a lossless quality, determine the lossless biterate and apply a factor just like you did in setVideoBitrate() and compvalue for x265 and AV1 codecs Do you think, is it possible to add this method ?

Here is an example of command : ffmpeg -y -i "input.mkv" -c:v libx264 -pix_fmt yuv420p -vf "scale=<OutputWidth>:<OutputHeigth>) ,select=lt(mod(n\,<nbFramesPerSample>)\,<nbOfSamples>" -strict -1 -profile:v main -crf 18 -f rawvideo "compressibilitycheck.dat" replace : per 1280x720 or cropped size ;) and by real values.

Kind regards

paulpacifico commented 6 months ago

Hi,

The cropped values will also be used for the next release.

Thanks, Paul.

endmarsfr commented 5 months ago

Hi,

Thanks for fixing cropped values. what do you think about proposed method for bitrate calculation ? The actual method returns always sames value for different videos because they have same size.

regards

paulpacifico commented 5 months ago

That's an interesting way to bitrate calculation, but first CRF will always be better than a fixed bitrate, if the first seconds of your video is black (or very low in details) that will not work... Finally, why not using CRF 18 in this case?

Those 'auto' modes are just for very beginner who don't know which values to write. Paul.

endmarsfr commented 5 months ago

I need to find the best quality/size ratio. For example, for a 1280x720, a CRF18 with high quality video will be larger than a CRF35.

I suggest using VMAF to evaluate video quality, a target of 95 for VMAF will be a good compromise. I suggest to find the best CRF value for VMAF target of 95. VMAF calculation takes a long time, we can't calculate it for the whole video. I suggest to sub-sample the video and do a CRF search to calculate VMAF.

I invite you to have a look at https://github.com/alexheretic/ab-av1 ./ab-av1.exe crf-search -imyvideo.mkv--vfilter scale=1280:-1 --preset 8 --min-vmaf 95 do the job