Compare commits
5 Commits
71b08e6898
...
fix/hlsmux
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd26812a9c | ||
|
|
b716608379 | ||
| 0ecc3d8210 | |||
| 309e1e9457 | |||
|
|
699481f6f8 |
@@ -753,17 +753,32 @@ class HlsMuxer(
|
||||
dos.writeShort(-1) // pre-defined
|
||||
|
||||
output.write(buildAvcCBox(sps, pps))
|
||||
output.write(buildPaspBox())
|
||||
|
||||
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 {
|
||||
val output = ByteArrayOutputStream()
|
||||
val dos = DataOutputStream(output)
|
||||
|
||||
val profileIdc = if (sps.isNotEmpty()) sps[0].toInt() and 0xFF else 0x42
|
||||
val profileCompat = if (sps.size > 1) sps[1].toInt() and 0xFF else 0x00
|
||||
val levelIdc = if (sps.size > 2) sps[2].toInt() and 0xFF else 0x1F
|
||||
// SPS NAL unit format: [NAL header, profile_idc, constraint_flags, level_idc, ...]
|
||||
// Skip byte 0 (NAL header, typically 0x67) to get the actual profile data
|
||||
val profileIdc = if (sps.size > 1) sps[1].toInt() and 0xFF else 0x42
|
||||
val profileCompat = if (sps.size > 2) sps[2].toInt() and 0xFF else 0x00
|
||||
val levelIdc = if (sps.size > 3) sps[3].toInt() and 0xFF else 0x1F
|
||||
|
||||
dos.writeByte(1) // configuration version
|
||||
dos.writeByte(profileIdc) // AVC profile
|
||||
|
||||
@@ -44,7 +44,8 @@ class RecordingSession(
|
||||
data class Video(val path: String, val durationMs: Long, val size: Size)
|
||||
|
||||
// Normalize path - expo-file-system passes file:// URIs but File expects raw paths
|
||||
private val outputPath: File = File(filePath.removePrefix("file://"))
|
||||
// Handle both file:// and file:/ variants
|
||||
private val outputPath: File = File(filePath.replace(Regex("^file:/+"), "/"))
|
||||
|
||||
private val bitRate = getBitRate()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user