advplyr / audiobookshelf

Self-hosted audiobook and podcast server
https://audiobookshelf.org
GNU General Public License v3.0
6.71k stars 473 forks source link

[Bug]: Cancelling playback of audiobook before it starts crashes server / causes container to stop #844

Closed Leondre closed 1 year ago

Leondre commented 2 years ago

Describe the issue

100% reproducible on my end. Simply stop playback of an audiobook while it is still loading and the container will crash.

spinnyboi

[2022-07-18 19:55:21]  INFO: [PlaybackSessionManager] startSession: Closing open session "Hateful Things" for user "root"
[2022-07-18 19:55:21]  INFO: [STREAM] START STREAM - Num Segments: 2275
[2022-07-18 19:55:21]  INFO: [INFO] FFMPEG transcoding started with command: ffmpeg -seek_timestamp 1 -f concat -safe 0 -i /metadata/streams/play_vhq6y64kf8qvx1nike/files.txt -y -loglevel error -map 0:a -c:a copy -f hls -copyts -avoid_negative_ts make_non_negative -max_delay 5000000 -max_muxing_queue_size 2048 -hls_time 6 -hls_segment_type mpegts -start_number 0 -hls_playlist_type vod -hls_list_size 0 -hls_allow_cache 0 -hls_segment_filename /metadata/streams/play_vhq6y64kf8qvx1nike/output-%d.ts /metadata/streams/play_vhq6y64kf8qvx1nike/final-output.m3u8
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: [adts @ 0x148eb72be640] Scalable configurations are not allowed in ADTS
[2022-07-18 19:55:21]  INFO: Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
[2022-07-18 19:55:21]  INFO: Error initializing output stream 0:0 -- 
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: [Stream] Re-attempting stream with AAC encode
[2022-07-18 19:55:21]  INFO: [HlsRouter] Stream play_vhq6y64kf8qvx1nike is currently resetting
[2022-07-18 19:55:22]  INFO: Closing Stream play_vhq6y64kf8qvx1nike
[2022-07-18 19:55:22]  INFO: Deleted session data /metadata/streams/play_vhq6y64kf8qvx1nike
[2022-07-18 19:55:31]  INFO: Stream Reset New Start Time 0:00.0
[2022-07-18 19:55:31]  INFO: [STREAM] START STREAM - Num Segments: 2275

** Press ANY KEY to close this window ** 

Steps to reproduce the issue

  1. Start playing an audiobook
  2. While the play/pause button indicates the file is loading/transcoding, press the x button.
  3. Receive crash.

Audiobookshelf version

v2.1.0

How are you running audiobookshelf?

Docker

advplyr commented 2 years ago

What browser are you using and what is the audio file you are playing that is requiring a transcode?

Leondre commented 2 years ago

I am using firefox (102.0.1) and all of my audio files are in m4b. Converted using openaudible if that helps at all.

BCNelson commented 2 years ago

I can't reproduce on firefox 102.0 or chrome 103.0.5060.114. It is a little hard to be sure as I need to be pretty fast. I tried on several diffrent books from Google Play, and openaudible

advplyr commented 2 years ago

I'm not sure how the audio player was made to look like that screenshot.

Leondre commented 2 years ago

I can't replicate it using edge, in fact none of the files that transcode when trying to play them on firefox do so with edge. Tried firefox in safe mode, same issue so it doesn't seem to be extension related. Also able to replicate on another machine using firefox. Both with and without using nginx as a reverse proxy.

If I can provide any more logs just let me know where from.

That screenshot was just cropped, this is on said other machine in firefox while waiting for playback to start. Sits there for about 20 seconds and then starts playing.

Screenshot 2022-07-19 142420

advplyr commented 2 years ago

Firefox has some issue with direct playing m4b files. We have discussed this in Discord but m4b file will direct play in any chromium based browser. Edge/chrome/brave

ohare93 commented 2 years ago

It seems like I am also getting this crash. Playback from the iOS app, docker version hosted on Unraid. Crashes silently (no entry in the logs) sometimes after opening and hitting play.

itzexor commented 2 years ago

@advplyr i'm not sure if this is the exact issue here, but I ran into a case where multiple m4bs, direct drm-stripped from audible, were causing a re-encode when other m4bs work fine direct. My issue turned out to be some bit that audible sets on specific books, someone did a write up on it here: https://rentry.co/n4ost

after using that example script with bento4 mp4 tools to fix my entire library, this problem no longer occurs. I believe it may be the issue here due to this line: [2022-07-18 19:55:21] INFO: [adts @ 0x148eb72be640] Scalable configurations are not allowed in ADTS

excerpt from page linked above: Trying to extract the AAC audio to an ADTS file with ffmpeg yields the error “Scalable configurations are not allowed in ADTS”, which would suggest this bit is something to do with Scalable Sampling Rate AAC.

Whether that's actually the issue here or not, you should probably be aware of it. I never had this issue with any software for direct listening, and only noticed it when I had higher than expected cpu usage on the host + a large delay in the stream starting. Running that script is now part of my post-procesing when I get a new Audible book. Also, contrary to the stated frequency on this issue, I've had it with completely normal books not just audio plays and audible shorts or whatever they say it's used on there.

advplyr commented 2 years ago

@itzexor Thanks for that info. There was just someone in discord having issues with direct playing m4b and I believe a re-encode fixed it. Were you using firefox when testing this? I believe chromium browsers do a better job with m4b but I have since tested m4b in firefox and all of mine are able to direct play.

itzexor commented 2 years ago

yes i was use firefox, but i think it may also have occurred with the android client. it has been some weeks since i found that so i can't remember the exact details.

itzexor commented 2 years ago

If you have an audible plus account, I think this one should be available free for testing and it should be pretty small download. This book exhibits the bug: https://www.audible.com/pd/Killer-by-Nature-Audiobook/B076XNN4KF

edit: Here's a list of items in my library which the fix script repairs, mostly audible originals and such as stated in the writeup, but at the bottom of the list is several novels that also have the issue.

itzexor commented 2 years ago

Sorry to spam this thread so much, but I also remembered that I did have the same initial issue as here where cancelling the playback would crash the container. I think it only happens when you close the player in the browser during the fallback period, where it's trying to play or whatever but hasn't fallen back to a transcode yet. So you should be able to test that issue if you can find a broken m4b and figure out what is going on there, the underlying cause for the delay/transcode I think is this bit issue tho.

Pimmetje commented 1 year ago
[2023-02-01 06:50:55] INFO: Deleted session data /metadata/streams/play_s4k2n9ixi583j0ait1
/server/libs/njodb/index.js:103
        throw error;
        ^

[Error: ENOENT: no such file or directory, open '/metadata/streams/play_s4k2n9ixi583j0ait1/files.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/metadata/streams/play_s4k2n9ixi583j0ait1/files.txt'
}
npm notice
npm notice New major version of npm available! 8.19.3 -> 9.3.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.1>
npm notice Run `npm install -g npm@9.3.1` to update!
npm notice

Not sure if this is the same but it looks like it. It's a raise condition. It happened when i started playback and my browser had a issue. Not sure what happened. But at the end the container was stopped/crashed.

ohare93 commented 1 year ago

For the past month, this bug has been completely absent 👍 it seems the recent updates have helped stabilise whatever was causing it. Thanks! 🎉

advplyr commented 1 year ago

@ohare93 Thanks for that follow up. A lot has changed since this original issue so we can consider it closed until someone reproduces.