Fix:Force AAC when transcoding ALAC audio file streams #1372

This commit is contained in:
advplyr 2023-01-07 15:58:57 -06:00
parent 7a7708403f
commit ff10287d05
4 changed files with 22 additions and 4 deletions

View File

@ -748,7 +748,6 @@ export default {
if (this.libraryItem.episodesDownloading) {
this.episodeDownloadsQueued = this.libraryItem.episodesDownloading || []
}
console.log('Media metadata', this.mediaMetadata)
// use this items library id as the current
if (this.libraryId) {

View File

@ -71,6 +71,10 @@ class Stream extends EventEmitter {
if (!this.tracks.length) return null
return this.tracks[0].mimeType
}
get tracksCodec() {
if (!this.tracks.length) return null
return this.tracks[0].codec
}
get mimeTypesToForceAAC() {
return [
AudioMimeType.FLAC,
@ -81,6 +85,11 @@ class Stream extends EventEmitter {
AudioMimeType.WEBMA
]
}
get codecsToForceAAC() {
return [
'alac'
]
}
get userToken() {
return this.user.token
}
@ -130,7 +139,7 @@ class Stream extends EventEmitter {
}
async checkSegmentNumberRequest(segNum) {
var segStartTime = segNum * this.segmentLength
const segStartTime = segNum * this.segmentLength
if (this.startTime > segStartTime) {
Logger.warn(`[STREAM] Segment #${segNum} Request @${secondsToTimestamp(segStartTime)} is before start time (${secondsToTimestamp(this.startTime)}) - Reset Transcode`)
await this.reset(segStartTime - (this.segmentLength * 2))
@ -139,7 +148,7 @@ class Stream extends EventEmitter {
return false
}
var distanceFromFurthestSegment = segNum - this.furthestSegmentCreated
const distanceFromFurthestSegment = segNum - this.furthestSegmentCreated
if (distanceFromFurthestSegment > 10) {
Logger.info(`Segment #${segNum} requested is ${distanceFromFurthestSegment} segments from latest (${secondsToTimestamp(segStartTime)}) - Reset Transcode`)
await this.reset(segStartTime - (this.segmentLength * 2))
@ -264,7 +273,11 @@ class Stream extends EventEmitter {
const logLevel = process.env.NODE_ENV === 'production' ? 'error' : 'warning'
const audioCodec = (this.mimeTypesToForceAAC.includes(this.tracksMimeType) || this.transcodeForceAAC) ? 'aac' : 'copy'
let audioCodec = 'copy'
if (this.transcodeForceAAC || this.mimeTypesToForceAAC.includes(this.tracksMimeType) || this.codecsToForceAAC.includes(this.tracksCodec)) {
Logger.debug(`[Stream] Forcing AAC for tracks with mime type ${this.tracksMimeType} and codec ${this.tracksCodec}`)
audioCodec = 'aac'
}
this.ffmpeg.addOption([
`-loglevel ${logLevel}`,

View File

@ -9,6 +9,7 @@ class AudioTrack {
this.title = null
this.contentUrl = null
this.mimeType = null
this.codec = null
this.metadata = null
}
@ -20,6 +21,7 @@ class AudioTrack {
title: this.title,
contentUrl: this.contentUrl,
mimeType: this.mimeType,
codec: this.codec,
metadata: this.metadata ? this.metadata.toJSON() : null
}
}
@ -31,6 +33,7 @@ class AudioTrack {
this.title = audioFile.metadata.filename || ''
this.contentUrl = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(audioFile.metadata.relPath))
this.mimeType = audioFile.mimeType
this.codec = audioFile.codec || null
this.metadata = audioFile.metadata.clone()
}

View File

@ -8,6 +8,7 @@ class VideoTrack {
this.title = null
this.contentUrl = null
this.mimeType = null
this.codec = null
this.metadata = null
}
@ -18,6 +19,7 @@ class VideoTrack {
title: this.title,
contentUrl: this.contentUrl,
mimeType: this.mimeType,
codec: this.codec,
metadata: this.metadata ? this.metadata.toJSON() : null
}
}
@ -28,6 +30,7 @@ class VideoTrack {
this.title = videoFile.metadata.filename || ''
this.contentUrl = Path.join(`${global.RouterBasePath}/s/item/${itemId}`, encodeUriPath(videoFile.metadata.relPath))
this.mimeType = videoFile.mimeType
this.codec = videoFile.codec
this.metadata = videoFile.metadata.clone()
}