Add support for extracting audio track types

Co-authored-By: AudricV <74829229+AudricV@users.noreply.github.com>
This commit is contained in:
Bnyro 2023-07-16 17:11:27 +02:00
parent 9e3dc8bde4
commit 2dc4c15dd8
2 changed files with 47 additions and 10 deletions

View File

@ -24,7 +24,9 @@ data class PipedStream(
val fps: Int? = null, val fps: Int? = null,
val audioTrackName: String? = null, val audioTrackName: String? = null,
val audioTrackId: String? = null, val audioTrackId: String? = null,
val contentLength: Long = -1 val contentLength: Long = -1,
val audioTrackType: String? = null,
val audioTrackLocale: String? = null
) { ) {
private fun getQualityString(fileName: String): String { private fun getQualityString(fileName: String): String {
return "${fileName}_${quality?.replace(" ", "_")}_$format." + return "${fileName}_${quality?.replace(" ", "_")}_$format." +

View File

@ -19,8 +19,10 @@ object DashHelper {
private data class AdapSetInfo( private data class AdapSetInfo(
val mimeType: String, val mimeType: String,
val formats: MutableList<PipedStream> = mutableListOf(),
val audioTrackId: String? = null, val audioTrackId: String? = null,
val formats: MutableList<PipedStream> = mutableListOf() val audioTrackType: String? = null,
val audioLocale: String? = null
) )
fun createManifest( fun createManifest(
@ -75,7 +77,6 @@ object DashHelper {
adapSetInfos.add( adapSetInfos.add(
AdapSetInfo( AdapSetInfo(
stream.mimeType!!, stream.mimeType!!,
null,
mutableListOf(stream) mutableListOf(stream)
) )
) )
@ -94,8 +95,10 @@ object DashHelper {
adapSetInfos.add( adapSetInfos.add(
AdapSetInfo( AdapSetInfo(
stream.mimeType!!, stream.mimeType!!,
mutableListOf(stream),
stream.audioTrackId, stream.audioTrackId,
mutableListOf(stream) stream.audioTrackType,
stream.audioTrackLocale
) )
) )
} }
@ -105,10 +108,22 @@ object DashHelper {
adapSetElement.setAttribute("mimeType", adapSet.mimeType) adapSetElement.setAttribute("mimeType", adapSet.mimeType)
adapSetElement.setAttribute("startWithSAP", "1") adapSetElement.setAttribute("startWithSAP", "1")
adapSetElement.setAttribute("subsegmentAlignment", "true") adapSetElement.setAttribute("subsegmentAlignment", "true")
if (adapSet.audioTrackId != null) { if (adapSet.audioTrackId != null) {
adapSetElement.setAttribute("lang", adapSet.audioTrackId.substring(0, 2)) adapSetElement.setAttribute("lang", adapSet.audioTrackId.substring(0, 2))
} else if (adapSet.audioLocale != null) {
adapSetElement.setAttribute("lang", adapSet.audioLocale)
} }
val roleElement = doc.createElement("Role")
roleElement.setAttribute("schemeIdUri", "urn:mpeg:dash:role:2011")
roleElement.setAttribute(
"value",
getRoleValueFromAudioTrackType(adapSet.audioTrackType)
)
adapSetElement.appendChild(roleElement)
val isVideo = adapSet.mimeType.contains("video") val isVideo = adapSet.mimeType.contains("video")
if (isVideo) { if (isVideo) {
@ -162,18 +177,38 @@ object DashHelper {
val baseUrl = doc.createElement("BaseURL") val baseUrl = doc.createElement("BaseURL")
baseUrl.appendChild(doc.createTextNode(ProxyHelper.unwrapUrl(stream.url!!, rewriteUrls))) baseUrl.appendChild(doc.createTextNode(ProxyHelper.unwrapUrl(stream.url!!, rewriteUrls)))
val segmentBase = doc.createElement("SegmentBase") representation.appendChild(audioChannelConfiguration)
representation.appendChild(baseUrl)
representation.appendChild(createSegmentBaseElement(doc, stream))
return representation
}
private fun createSegmentBaseElement(
document: Document,
stream: PipedStream
): Element {
val segmentBase = document.createElement("SegmentBase")
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}") segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")
val initialization = doc.createElement("Initialization") val initialization = document.createElement("Initialization")
initialization.setAttribute("range", "${stream.initStart}-${stream.initEnd}") initialization.setAttribute("range", "${stream.initStart}-${stream.initEnd}")
segmentBase.appendChild(initialization) segmentBase.appendChild(initialization)
representation.appendChild(audioChannelConfiguration) return segmentBase
representation.appendChild(baseUrl) }
representation.appendChild(segmentBase)
return representation private fun getRoleValueFromAudioTrackType(audioTrackType: String?): String {
if (audioTrackType == null) {
return "main"
}
return when (audioTrackType.lowercase()) {
"descriptive" -> "description"
"dubbed" -> "dub"
"original" -> "main"
else -> "alternate"
}
} }
private fun createVideoRepresentation( private fun createVideoRepresentation(