fix: Add pasp box to declare square pixels (1:1) for web playback
The codec string fix caused videos to appear squished on web players like Shaka. Adding an explicit pixel aspect ratio (pasp) box with 1:1 ratio tells the player not to apply any SAR scaling. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -753,10 +753,23 @@ class HlsMuxer(
|
|||||||
dos.writeShort(-1) // pre-defined
|
dos.writeShort(-1) // pre-defined
|
||||||
|
|
||||||
output.write(buildAvcCBox(sps, pps))
|
output.write(buildAvcCBox(sps, pps))
|
||||||
|
output.write(buildPaspBox())
|
||||||
|
|
||||||
return wrapBox("avc1", output.toByteArray())
|
return wrapBox("avc1", output.toByteArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds pixel aspect ratio box to explicitly declare square pixels (1:1).
|
||||||
|
* This helps players correctly interpret video dimensions without SAR scaling.
|
||||||
|
*/
|
||||||
|
private fun buildPaspBox(): ByteArray {
|
||||||
|
val output = ByteArrayOutputStream()
|
||||||
|
val dos = DataOutputStream(output)
|
||||||
|
dos.writeInt(1) // hSpacing (horizontal)
|
||||||
|
dos.writeInt(1) // vSpacing (vertical)
|
||||||
|
return wrapBox("pasp", output.toByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildAvcCBox(sps: ByteArray, pps: ByteArray): ByteArray {
|
private fun buildAvcCBox(sps: ByteArray, pps: ByteArray): ByteArray {
|
||||||
val output = ByteArrayOutputStream()
|
val output = ByteArrayOutputStream()
|
||||||
val dos = DataOutputStream(output)
|
val dos = DataOutputStream(output)
|
||||||
|
|||||||
Reference in New Issue
Block a user