MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / getDecentVideoBitrate

Function getDecentVideoBitrate

src/video_encoder.ts:710–731  ·  view source on GitHub ↗
(codec: AVCodecID, width: number, height: number)

Source from the content-addressed store, hash-verified

708}
709
710export const getDecentVideoBitrate = (codec: AVCodecID, width: number, height: number) => {
711 const pixels = width * height;
712 const factor = 1;
713
714 const codecEfficiencyFactors = {
715 [AV_CODEC_ID_H264]: 1.0, // H.264/AVC (baseline)
716 [AV_CODEC_ID_HEVC]: 0.6, // H.265/HEVC (~40% more efficient than AVC)
717 [AV_CODEC_ID_VP9]: 0.6, // Similar to HEVC
718 [AV_CODEC_ID_AV1]: 0.4, // ~60% more efficient than AVC
719 [AV_CODEC_ID_VP8]: 1.2, // Slightly less efficient than AVC
720 };
721
722 const referencePixels = 1920 * 1080;
723 const referenceBitrate = 3000000;
724 const scaleFactor = Math.pow(pixels / referencePixels, 0.95); // Slight non-linear scaling
725 const baseBitrate = referenceBitrate * scaleFactor;
726
727 const codecAdjustedBitrate = baseBitrate * codecEfficiencyFactors[codec];
728 const finalBitrate = codecAdjustedBitrate * factor;
729
730 return Math.ceil(finalBitrate / 1000) * 1000;
731};

Callers 1

createCodecContextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected