[Bug]: mp3 transcodes carry no duration information (no Xing header, no Content-Length, Accept-Ranges: none)
I confirm that:
- I have searched the existing open AND closed issues to see if an issue already exists for the bug I've encountered
- I'm using the latest version (your issue may have been fixed already)
Version
0.63.2 — defect verified still present in v0.64.0 source (see Current Behavior)
Current Behavior
#6105 fixed piped FLAC transcodes losing total_samples, on the grounds that "decoders need it to turn a timestamp into a byte offset". mp3 targets have the same defect for the same reason — ffmpeg writes to a pipe and cannot rewind to fill in the Xing/Info frame — but patchFLACDuration is gated on the FLAC magic bytes, so mp3 output passes through untouched:
func setFLACTotalSamples(prefix []byte, duration float32) {
if string(prefix[:4]) != "fLaC" || prefix[4]&0x7F != 0 {
return
}core/ffmpeg has no mp3 header handling at all in v0.64.0, and the default profile writes to a pipe:
ffmpeg -ss %t -i %s -map 0:a:0 -map_metadata 0 -map_metadata 0:s:a:0 -b:a %bk -v 0 -f mp3 -The result is an uncached mp3 transcode that declares its length nowhere:
- no
Xing/Info/VBRIframe in the bitstream - no
Content-Length— chunked, sinceServeonly sets one when the client passesestimateContentLength=true Accept-Ranges: none, set explicitly for non-seekable streams
Observed response for an uncached transcode, default mp3 profile at 128 kbps:
HTTP/1.1 200 OK
Accept-Ranges: none
Content-Type: audio/mpeg
Transfer-Encoding: chunkedFirst 4 KB of the body: Xing absent, Info absent, VBRI absent. The ID3 prefix and the LAME string are present, so the encoder ran normally — only the seek/duration frame is missing.
Once the same track is served from the transcoding cache it is a real file, Seekable() is true, http.ServeContent answers 206 with a Content-Length, and none of the above applies.
Symptom that led here. Web player, Firefox 156 / Android 16, server-side player profile "mp3 audio" at 128 kbps, mobile network:
- 21 streams in one session, 16 ended early and the player advanced to the next track
- tracks up to ~145 s play to completion; longer tracks stop somewhere between 74 s and 176 s
- the server is not truncating:
body_bytes_sentat the reverse proxy matches the full expected size on every one of them (e.g. 4,176,138 bytes for a 261 s track at 128 kbps, delivered in 2-5 s), and Navidrome logs no error reportPlaybackpings confirm playback genuinely stops at those points rather than this being prefetch
Because the transcoding cache only holds part of the library, a large library on shuffle rarely gets a hit (135 streams over 8 days, cached=true on none of them), so in practice every play takes the unseekable path.
I have not isolated what Firefox does with a stream that has no length and refuses ranges, so I am reporting the missing header as the defect rather than asserting the whole client-side chain. The header is missing regardless, and by the reasoning in #6105 it should not be.
Expected Behavior
An mp3 transcode should carry its duration the same way a FLAC transcode does since #6105 — via a Xing/Info frame written from TranscodeOptions.Duration, which is already threaded through for the FLAC case.
Concretely: extend the #6105 wrapper to mp3, with the magic-byte gate testing for an ID3 prefix or an mp3 sync word instead of fLaC, and emit a Xing/Info frame carrying the frame and byte counts. That would leave a decoder able to map a timestamp to a byte offset on a piped mp3, which today it cannot do from either the bitstream or the HTTP headers.
Steps To Reproduce
- Configure a player with the default "mp3 audio" transcoding profile at 128 kbps.
- Request a track that is not already in the transcoding cache:
GET /rest/stream?...&format=mp3&maxBitRate=128&id=<id> - Response headers show
Accept-Ranges: none,Transfer-Encoding: chunked, and noContent-Length. - Inspect the first 4 KB of the body: no
Xing, noInfo, noVBRIframe. - Request the same track again, now served from the cache:
http.ServeContentanswers withAccept-Ranges: bytesand a correctContent-Length, and range requests return 206.
Environment
- OS: Debian 13 host; Navidrome runs in a Podman container from the deluan/navidrome image
- Browser: Firefox 156 on Android 16
- Client: Navidrome web player (NavidromeUI), server-side player profile "mp3 audio" at 128 kbps
- Reverse proxy: nginx (Nginx Proxy Manager) in front of NavidromeHow Navidrome is installed?
Docker
Configuration
# Configured entirely through environment variables; navidrome.toml is empty.
# Only the settings relevant to this report are shown.
ND_TRANSCODINGCACHESIZE=2GB
ND_MUSICFOLDER=/music
ND_DATAFOLDER=/data
ND_LOGLEVEL=info
# Transcoding profile the player uses. The command is the upstream default,
# byte for byte:
name = mp3 audio
target_format = mp3
default_bit_rate = 192
command = ffmpeg -ss %t -i %s -map 0:a:0 -map_metadata 0 -map_metadata 0:s:a:0 -b:a %bk -v 0 -f mp3 -
# Player row: NavidromeUI [Firefox/Android], transcoding = "mp3 audio", max_bit_rate = 128
# Library: 1823 tracks, 1662 flac / 159 mp3 sources.Relevant log output
# ND_LOGLEVEL=info. Worth noting: all four default transcoding profiles pass
# "-v 0" to ffmpeg, so ffmpeg's own diagnostics are suppressed whatever
# Navidrome's log level is. The warning that #6105 quotes for FLAC
# ("unable to rewrite FLAC header") cannot surface through Navidrome as shipped.
# Two consecutive tracks from the session described above. "Smoke and Mirrors"
# is 261 s long; the next track starts 75 s later. Nothing at all is logged in
# between: no error, no warning. (user and requestId redacted.)
Sep 19 11:26:51 navidrome level=info msg="Streaming file" artist="[redacted]" bitDepth=16 bitRate=128 cached=false channels=2 format=mp3 originalBitRate=920 originalFormat=flac sampleRate=44100 title="[redacted]" transcoding=true
Sep 19 11:28:06 navidrome level=info msg="Streaming file" artist="[redacted]" bitDepth=16 bitRate=128 cached=false channels=2 format=mp3 originalBitRate=954 originalFormat=flac sampleRate=44100 title="[redacted]" transcoding=true
# Cross-referenced with media_file.duration and the reverse proxy's
# body_bytes_sent for the same requests:
#
# duration | bytes delivered | equivalent audio | actually played
# ---------+-----------------+------------------+----------------
# 261 s | 4,176,138 | 261 s | 74 s
# 268 s | 4,297,322 | 268 s | 119 s
# 310 s | 4,961,396 | 310 s | 95 s
# 350 s | 5,604,260 | 350 s | 116 s
# 143 s | 2,288,889 | 143 s | 144 s (complete)
# 117 s | 1,872,741 | 117 s | 118 s (complete)
#
# 21 streams in that session, every one cached=false, every one delivered in
# full in 2-5 s. 16 ended early. "Actually played" is measured from the
# reportPlayback now-playing pings, which stop when the next track's begin.
#
# Over 8 days: 135 streams, cached=true on none of them.Anything else?
On the version checkbox, so nothing is hidden: the measurements above were taken on 0.63.2. I re-read core/ffmpeg/flac_streaminfo.go and core/ffmpeg/ffmpeg.go at tag v0.64.0 before filing, and the mp3 path is unhandled there — setFLACTotalSamples returns early on anything that is not fLaC, and there is no Xing/write_xing handling anywhere in the package. So this is not fixed by upgrading.
Unrelated, spotted while reading Serve: EstimatedContentLength() computes Duration * bitRate / 8 * 1024, using 1024 where a kbps bitrate needs 1000 — a 2.4% overestimate. On a 285 s track at 128 kbps it announces 4,669,440 bytes for a body that is actually 4,561,876, so a client trusting the header waits for ~107 KB that never arrive. Happy to split that into its own issue if you would rather keep them separate.
Related: #6105 (same defect, fixed for FLAC), #6035 (truncated transcodes delivered as complete).
Code of Conduct
- I agree to follow Navidrome's Code of Conduct
Source: navidrome/navidrome