Match the suggested bitrate to the actual Kush Gauge formula.

As defined in Kush Amerasinghe's paper 'H.264 For the rest of us'.

PiperOrigin-RevId: 446988272
This commit is contained in:
samrobinson 2022-05-06 16:03:18 +01:00 committed by Ian Baker
parent e008a78ea6
commit ff7629aba5
2 changed files with 20 additions and 7 deletions

View file

@ -504,11 +504,24 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
&& allowedMimeTypes.contains(mimeType);
}
/** Computes the video bit rate using the Kush Gauge. */
/**
* Computes the video bit rate using the Kush Gauge.
*
* <p>{@code kushGaugeBitrate = height * width * frameRate * 0.07 * motionFactor}.
*
* <p>Motion factors:
*
* <ul>
* <li>Low motion video - 1
* <li>Medium motion video - 2
* <li>High motion video - 4
* </ul>
*/
private static int getSuggestedBitrate(int width, int height, float frameRate) {
// TODO(b/210591626) Implement bitrate estimation.
// 1080p30 -> 6.2Mbps, 720p30 -> 2.7Mbps.
return (int) (width * height * frameRate * 0.1);
// Assume medium motion factor.
// 1080p60 -> 16.6Mbps, 720p30 -> 3.7Mbps.
return (int) (width * height * frameRate * 0.07 * 2);
}
@RequiresNonNull("#1.sampleMimeType")

View file

@ -74,8 +74,8 @@ public class DefaultEncoderFactoryTest {
assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
assertThat(actualVideoFormat.width).isEqualTo(1920);
assertThat(actualVideoFormat.height).isEqualTo(1080);
// 1920 * 1080 * 30 * 0.1
assertThat(actualVideoFormat.averageBitrate).isEqualTo(6_220_800);
// 1920 * 1080 * 30 * 0.07 * 2.
assertThat(actualVideoFormat.averageBitrate).isEqualTo(8_709_120);
}
@Test
@ -92,8 +92,8 @@ public class DefaultEncoderFactoryTest {
assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
assertThat(actualVideoFormat.width).isEqualTo(1920);
assertThat(actualVideoFormat.height).isEqualTo(1080);
// 1920 * 1080 * 30 * 0.1
assertThat(actualVideoFormat.averageBitrate).isEqualTo(6_220_800);
// 1920 * 1080 * 30 * 0.07 * 2.
assertThat(actualVideoFormat.averageBitrate).isEqualTo(8_709_120);
}
@Test