Commit 5df6a581 by samrobinson Committed by Ian Baker

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
parent 521e0678
...@@ -502,11 +502,24 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { ...@@ -502,11 +502,24 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
&& allowedMimeTypes.contains(mimeType); && 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) { private static int getSuggestedBitrate(int width, int height, float frameRate) {
// TODO(b/210591626) Implement bitrate estimation. // TODO(b/210591626) Implement bitrate estimation.
// 1080p30 -> 6.2Mbps, 720p30 -> 2.7Mbps. // Assume medium motion factor.
return (int) (width * height * frameRate * 0.1); // 1080p60 -> 16.6Mbps, 720p30 -> 3.7Mbps.
return (int) (width * height * frameRate * 0.07 * 2);
} }
@RequiresNonNull("#1.sampleMimeType") @RequiresNonNull("#1.sampleMimeType")
......
...@@ -74,8 +74,8 @@ public class DefaultEncoderFactoryTest { ...@@ -74,8 +74,8 @@ public class DefaultEncoderFactoryTest {
assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264); assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
assertThat(actualVideoFormat.width).isEqualTo(1920); assertThat(actualVideoFormat.width).isEqualTo(1920);
assertThat(actualVideoFormat.height).isEqualTo(1080); assertThat(actualVideoFormat.height).isEqualTo(1080);
// 1920 * 1080 * 30 * 0.1 // 1920 * 1080 * 30 * 0.07 * 2.
assertThat(actualVideoFormat.averageBitrate).isEqualTo(6_220_800); assertThat(actualVideoFormat.averageBitrate).isEqualTo(8_709_120);
} }
@Test @Test
...@@ -92,8 +92,8 @@ public class DefaultEncoderFactoryTest { ...@@ -92,8 +92,8 @@ public class DefaultEncoderFactoryTest {
assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264); assertThat(actualVideoFormat.sampleMimeType).isEqualTo(MimeTypes.VIDEO_H264);
assertThat(actualVideoFormat.width).isEqualTo(1920); assertThat(actualVideoFormat.width).isEqualTo(1920);
assertThat(actualVideoFormat.height).isEqualTo(1080); assertThat(actualVideoFormat.height).isEqualTo(1080);
// 1920 * 1080 * 30 * 0.1 // 1920 * 1080 * 30 * 0.07 * 2.
assertThat(actualVideoFormat.averageBitrate).isEqualTo(6_220_800); assertThat(actualVideoFormat.averageBitrate).isEqualTo(8_709_120);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment