mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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:
parent
521e067807
commit
5df6a5815a
2 changed files with 20 additions and 7 deletions
|
|
@ -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 {
|
||||||
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 {
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue