Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transcoding to mp3 gives the song is not encoded correctly errors #52

Closed
zombiehoffa opened this issue Sep 11, 2021 · 10 comments
Closed

Comments

@zombiehoffa
Copy link

Hi,
using default mp3 audio settings for navidrome transcoding results in no songs being able to play because of an encoding error from sonos. Encoded songs play fine in other players and if I turn off transcoding the portion of my collection that is flac and mp3 in a supported bitrate play fine through bonob to my sonos system.

Looking at the logs I get output in navidrome for both transcoding and non transcoding bonob requests ie:
transcoding:
time="2021-09-11T15:27:18Z" level=info msg="Streaming file" artist="Charles Bradley" bitRate=192 cached=true format=mp3 originalBitRate=865 originalFormat=flac title="Dusty Blue" transcoding=true user=chris

time="2021-09-11T15:27:18Z" level=info msg="Now Playing" artist="Charles Bradley" player="bonob [bonob]" title="Dusty Blue" user=chris

non transcoding:
time="2021-09-11T15:24:49Z" level=info msg="Streaming file" artist="Charles Bradley" bitRate=0 cached=false format=raw originalBitRate=975 originalFormat=flac title="Strictly Reserved for You" transcoding=false user=chris

time="2021-09-11T15:24:49Z" level=info msg="Now Playing" artist="Charles Bradley" player="bonob [bonob]" title="Strictly Reserved for You" user=chris

but log output in bonob only incremements for non transcoding (there's a bunch of tokens in here so I will only clean this up and post it if really needed).

@simojenki
Copy link
Owner

I think this is because when transcoding is enabled ND reports the content-length as "0". Documentation at sonos indicates that content-length is a required response field;
https://developer.sonos.com/build/content-service-add-features/streaming-basics/

I've previously tried reading the entire stream in bonob so as to get the length, however on some tracks that causes a delay whilst the server caches the response, which in turn causes the sonos device to assume that the track is not going to play, and so it moves onto the next track in the playlist.

@zombiehoffa
Copy link
Author

zombiehoffa commented Sep 11, 2021

Can we just lie to sonos? Is there a setting.I should change in navidrome to change the behaviour? I know I can briefly get it to play a stream if I click play in sinks fast enough after changing the transcoding setting in navidrome. It definitely is ouputting transcoded mp3 and will play once before breaking.

@simojenki
Copy link
Owner

simojenki commented Sep 12, 2021

You can try using different players in ND by media type. See "BONOB_NAVIDROME_CUSTOM_CLIENTS" setting on README. That allows different transcoding settings by file type.

"will play once before breaking" <- the entire track, or just the first part of the track?

What formats are you trying to play/transcode? Sonos supports these -> https://developer.sonos.com/build/content-service-add-features/supported-audio-formats/. So mp3, and flac do not require transcoding.

I've noticed that transcoding;
flac -> mp3 breaks sonos/bonob/ND because sonos tries to use range queries for the mp3, which ND does not support.
flac -> flac (ie. downsampling) does work, as sonos does not seem to try and perform a range query.

So it would seem that behaviour can also be different depending on file types themselves.

@zombiehoffa
Copy link
Author

Mostly it's for dealing with some higher quality flac files that sample above what sonos supports. I didn't realize I could be so granular with bonob though, so Iw as just transcoding everything to mp3 for sonos. I will play around with it and see if I can get it to work. You wouldn't happen to have your suggest flac to flac transcoding command handy would you?

@simojenki
Copy link
Owner

In that case I would set BONOB_NAVIDROME_CUSTOM_CLIENTS="audio/flac", for the default bonob player i would disable transcoding so that the raw files (mp3, etc) just get passed straight through to sonos.
flac -> flac with downsample, could try something like this -> https://stackoverflow.com/questions/41420391/ffmpeg-flac-24-bit-96khz-to-16-bit-48khz

@zombiehoffa
Copy link
Author

For anyone that sees this later with the same problem, this is the transcoding command that started working on my sonos system after creating the custom navidrome client as above. I don't know if it's the best one, it's just the one that finally started playing after fiddling with it for a half hour (I ended up having to nuke the cached transcodes because some of the lines I tried created real flac cache files that didn't work, so maybe all this isn't totally necessary and the cache messing up playback led me down a more complex rabbit hole than necessary):
ffmpeg -i %s -af aresample=resampler=soxr:out_sample_fmt=s16:out_sample_rate=48000 -f flac -

I don't fully understand what all the stuff is doing other than the sampl

@simojenki
Copy link
Owner

I have documented this on the README for anyone else that requires downsampling of flacs

@padenj
Copy link

padenj commented Sep 23, 2022

I have a new installation of Navidrome and Bonob and I am getting the "song is not encoded correctly" error. I have tried following the steps in this issue and the notes on transcoding in the readme. I am not trying to do any specific transcoding, just trying to play my media through an older Sonos device (Play 5, gen 1) which requires the S1 app. Unfortunately it doesn't appear Bonob/Navidrome work out-of-the-box for S1.

I have installed Navidrom / Bonob on docker running on Debian 11. My Sonos devices are on the same network.

Here's where I am so far:

  • I tried creating a flac transcoder in Navidrome using the ffmpeg commands on this post and also the one in the Readme specifically for the S1 app. By default Navidrom only had opus and mp3 transcoders, I had to enable transcoder edits for Navidrom using the ND_ENABLETRANSCODINGCONFIG environment variable.
  • I tried adding the custom client environment variable to Bonob, note that this post names the variable "BONOB_NAVIDROME_CUSTOM_CLIENTS" while the readme says "BONOB_SUBSONIC_CUSTOM_CLIENTS". I tried both, but I did not see a new player created called "bonob+audio/flac".
  • I toggled the "bonob" player between no transcoding and using the flac transcoder I added. Both ways still result in the encoding error on the Sonos.

I am running the latest Sonos S1 v11.5. Most of my media are mp3 files.

I'm not sure what else to try. If anyone has steps for configuring an instance of Navidrome / Bonob from scratch and connecting to it through Sonos S1, that would be appreciated!

@zombiehoffa
Copy link
Author

I dunno man, I haven't changed anything and i used mine with s1 and now s2. It's been solid for me even through moving the whole thing to a different server. You need that custom player to pop into navidrome so you can tell it to use specific transcoding above. Try playing a song through your sonos from bonob that doesn't need transcoding (like load in an mp3 album or something), it might need to actaully play to show up. I have BONOB_NAVIDROME_CUSTOM_CLIENTS in my docker-compose for bonob.

@simojenki
Copy link
Owner

Sonos S1 should play mp3 and flac without transcoding (https://support.sonos.com/s/article/79?language=en_US). You should only need to use the transcoder if your content is in a format that the S1 cannot understand, ie. HD flacs.

The correct env far to set for custom clients is now, 'BNB_SUBSONIC_CUSTOM_CLIENTS'. 'BONOB_NAVIDROME_CUSTOM_CLIENTS' will still work, it is however deprecated.

To start with I would try testing without transcoding, play some mp3s and from there try some flacs that you know are 16bit so that the S1 can play them without transcoding.

If that works however you have some content that the S1 cannot support, then you will need to look into transcoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants