diff --git a/server/objects/Stream.js b/server/objects/Stream.js index f7012188..c49372b0 100644 --- a/server/objects/Stream.js +++ b/server/objects/Stream.js @@ -254,8 +254,14 @@ class Stream extends EventEmitter { this.ffmpeg = Ffmpeg() this.furthestSegmentCreated = 0 - var adjustedStartTime = Math.max(this.startTime - this.maxSeekBackTime, 0) - var trackStartTime = await writeConcatFile(this.tracks, this.concatFilesPath, adjustedStartTime) + const adjustedStartTime = Math.max(this.startTime - this.maxSeekBackTime, 0) + const trackStartTime = await writeConcatFile(this.tracks, this.concatFilesPath, adjustedStartTime) + if (trackStartTime == null) { + // Close stream show error + this.ffmpeg = null + this.close('Failed to write stream concat file') + return + } this.ffmpeg.addInput(this.concatFilesPath) // seek_timestamp : https://ffmpeg.org/ffmpeg.html @@ -343,7 +349,8 @@ class Stream extends EventEmitter { // Temporary workaround for https://github.com/advplyr/audiobookshelf/issues/172 and https://github.com/advplyr/audiobookshelf/issues/2157 const aacErrorMsg = 'ffmpeg exited with code 1' - if (audioCodec === 'copy' && this.isAACEncodable && err.message?.startsWith(aacErrorMsg)) { + const errorMessageSuggestsReEncode = err.message?.startsWith(aacErrorMsg) && !err.message?.includes('No such file or directory') + if (audioCodec === 'copy' && this.isAACEncodable && errorMessageSuggestsReEncode) { Logger.info(`[Stream] Re-attempting stream with AAC encode`) this.transcodeOptions.forceAAC = true this.reset(this.startTime) diff --git a/server/utils/ffmpegHelpers.js b/server/utils/ffmpegHelpers.js index 40968465..7ec63302 100644 --- a/server/utils/ffmpegHelpers.js +++ b/server/utils/ffmpegHelpers.js @@ -35,9 +35,14 @@ async function writeConcatFile(tracks, outputPath, startTime = 0) { return line }) var inputstr = trackPaths.join('\n\n') - await fs.writeFile(outputPath, inputstr) - return firstTrackStartTime + try { + await fs.writeFile(outputPath, inputstr) + return firstTrackStartTime + } catch (error) { + Logger.error(`[ffmpegHelpers] Failed to write stream concat file at "${outputPath}"`, error) + return null + } } module.exports.writeConcatFile = writeConcatFile