sentriz/gonic

Transcoding Not Working Correctly with Client Bitrate Set to Unlimited

jeffgt14 opened this issue · 11 comments

gonic version: 0.16.2

if from docker, docker tag: Custom built from supplied dockerfile (added FLAC transcode and compiled Ffmpeg from source since soxr resampler isn't installed by default anymore)

Transcode added to transcode.go:
FLAC = NewProfile("audio/flac", "flac", 0, `ffmpeg -i <file> -ss <seek> -map 0:a:0 -af dynaudnorm -resampler soxr -precision 28 -dither_method triangular -sample_fmt s16 -ar 44100 -c:a flac -f flac -`)

Quite possibly related to f41dd08

FWIW this likely doesn't affect the current implementation of Gonic because you have no Lossless transcoding going on but I still think the code is flawed.

With DSub, when max bitrate is set to unlimited, the raw file is always sent over I believe because the max bit rate on the client is higher than the bit rate on the audio file. My intent here is my 24/96 high res files should get transcoded to 16/44 FLAC for streaming. I believe this line in the handlers_raw.go is causing this:

if format == "raw" || maxBitRate >= audioFile.AudioBitrate() {
		http.ServeFile(w, r, file.AbsPath())

I can trick gonic into transcoding correctly if I set the max bitrate in DSub to 320 because then it'll run through my ffmpeg command and I do not have a in the command so it'll transcode correctly to 16/44 FLAC every time even though the requested max bitrate is 320.

Tempo may be working correctly because I can actually see this in the gonic logs:

2023/12/29 14:12:10 trancoding to "audio/flac" with max bitrate 0k

I don't know if there's a "trace" debug level I can set to view more detailed logs on the actual transcode settings being applied. Tempo seems to display the bitrate of the original file instead of the transcoded file when playing but that could be an issue with what Tempo displays being incorrect.

not exactly sure what the behavour you expect is? could rephrase it in terms of transcode settings, incoming request with max bitrate, and expected response?

also i'm confused why the maxBitRate >= audioFile.AudioBitrate() check would be true, since for 24bit 94k FLAC, you'd have some check like 0 >= 1000 for example which is false

I may be deciphering the code wrong then. I don't know Go much at all so maybe it's something else causing the issue

My expectation is for every file to run through my transcoding command. In DSub, if I have max bitrate set to unlimited, Gonic sends to raw file instead of transcoding. So for FLAC 24/96, they get sent as that instead of transcoding to FLAC 16/44.

If I set max bitrate in DSub to something other than unlimited, then it transcodes correctly for me. My assumption is somehow Gonic is reading the Unlimited client request and just sends the raw file instead of transcoding.

Bitrate isn't really something that is set when transcoding the a Lossless format.

do you have the DSub transcoding setup in the gonic admin interface?

Transcoding is setup for "*"

i added some more logging, could you try again with those and check the logs?

This is with unlimited bitrate setting in DSub

2023/12/29 16:30:31 starting gonic v0.16.2
2023/12/29 16:30:31 provided config
2023/12/29 16:30:31     cache-path                /cache
2023/12/29 16:30:31     config-path
2023/12/29 16:30:31     db-path                   /data/gonic.db
2023/12/29 16:30:31     exclude-pattern
2023/12/29 16:30:31     expvar                    false
2023/12/29 16:30:31     genre-split
2023/12/29 16:30:31     http-log                  true
2023/12/29 16:30:31     jukebox-enabled           false
2023/12/29 16:30:31     jukebox-mpv-extra-args
2023/12/29 16:30:31     listen-addr               :80
2023/12/29 16:30:31     multi-value-album-artist  multi
2023/12/29 16:30:31     multi-value-artist        multi
2023/12/29 16:30:31     multi-value-genre         multi
2023/12/29 16:30:31     music-path                /Music
2023/12/29 16:30:31     playlists-path            /playlists
2023/12/29 16:30:31     podcast-path              /podcasts
2023/12/29 16:30:31     podcast-purge-age         0
2023/12/29 16:30:31     pprof                     false
2023/12/29 16:30:31     proxy-prefix              /
2023/12/29 16:30:31     scan-at-start-enabled     false
2023/12/29 16:30:31     scan-interval             0
2023/12/29 16:30:31     scan-watcher-enabled      false
2023/12/29 16:30:31     tls-cert
2023/12/29 16:30:31     tls-key
2023/12/29 16:30:31     version                   false
2023/12/29 16:30:31 starting job "http"
2023/12/29 16:30:31 starting job "podcast download"
2023/12/29 16:30:31 starting job "session clean"
2023/12/29 16:30:31 starting job "podcast refresh"
2023/12/29 16:30:43 response  200  GET /getAvatar?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&username=admin
2023/12/29 16:31:03 response  200  GET /home
2023/12/29 16:31:03 response  200  GET /static/style.css?v=0.16.2
2023/12/29 16:31:03 response  200  GET /static/main.js
2023/12/29 16:31:03 response  200  GET /static/gonic.png
2023/12/29 16:31:06 response  200  GET /home
2023/12/29 16:31:06 response  200  GET /static/style.css?v=0.16.2
2023/12/29 16:31:06 response  200  GET /static/main.js
2023/12/29 16:31:06 response  200  GET /static/gonic.png
2023/12/29 16:32:33 response  200  GET /getAlbumList?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&type=newest&size=20&offset=20
2023/12/29 16:32:35 response  200  GET /getCoverArt?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=al-6962
2023/12/29 16:32:36 response  200  GET /getMusicDirectory?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=al-2309
2023/12/29 16:32:43 response  200  GET /savePlayQueue?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8606&current=tr-8606&position=0
2023/12/29 16:32:43 serving raw file, requested max bitrate 2986k is greater or
equal to 2986k
2023/12/29 16:32:44 response  200  GET /savePlayQueue?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8606&current=tr-8606&position=0
2023/12/29 16:32:49 response  200  GET /stream?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8606&maxBitRate=2986

it seems dsub is requesting a max bitrate with &maxBitRate=2986

Yeah it looks like it's reading the original bitrate of the file and requesting that.

If I set max bitrate in DSub to 32kbps, it goes through my transcode command and transcodes to 16/44 FLAC.

2023/12/29 16:36:12 response  200  GET /getMusicDirectory?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=al-2306
2023/12/29 16:36:12 response  200  GET /getMusicDirectory?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=al-2309
2023/12/29 16:36:13 response  200  GET /savePlayQueue?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8606&current=tr-8606&position=31849
2023/12/29 16:36:15 response  200  GET /savePlayQueue?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8589&current=tr-8589&position=0
2023/12/29 16:36:15 trancoding to "audio/flac" with at bitrate 0k
2023/12/29 16:36:16 response  200  GET /savePlayQueue?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8589&current=tr-8589&position=0
2023/12/29 16:36:18 response  200  GET /stream?u=admin&s=okrgpl48r5c2d9dgigiucu2mf0&t=3a315d0babb1584866e81efebb996c81&v=1.2.0&c=DSub&id=tr-8589&maxBitRate=32

it looks like gonic is doing the correct thing then. not sure how this could supported without changes to the subsonic spec or something

I've just never seen this issue in any other server. Could just be how DSub requests the file since when bitrate is set to unlimited, it's requesting a max bitrate equal to the file on the server so it's always going to be >= the audio file bitrate and Gonic sends the raw file.

Not a deal breaker for me as I can just set an arbitrary bitrate in DSub to bypass the command. Thinking I can also change the if maxBitRate >= audioFile.AudioBitrate() to if maxBitRate > audioFile.AudioBitrate() prior to my build and have it work for my needs as well. Not sure if changing >= to just > would impact others though.

mm i think in general it doesnt makes sense to transcode when the client says unlimited, and maxbit rate is the same as the file. and dropping the equal comparison seems like a workaround

i believe though there is an upcoming @opensubsonic extension to request availible formats

then a client could say &format=flac then gonic will know to transcode regardless of any format. maybe it makes sense to postpone that til then