feat: audio transcoding endpoint for offline downloads (MP3/AAC)#97
Merged
Conversation
- GET api/mobile/stream/tfm/{channelId}/{tfmId}/transcoded?format=mp3|aac&bitrate=N
downloads the original into the streaming cache if needed, transcodes it
with FFmpeg and serves the result with Range support; transcodes are
cached on disk under _temp/transcoded so repeat requests are instant
- GET api/mobile/stream/transcode/info reports FFmpeg availability so
clients can warn the user and fall back to original downloads
- Returns 501 when FFmpeg is missing; per-target locks avoid duplicate
transcodes and a semaphore caps concurrent FFmpeg processes at 2
- MP3 keeps embedded cover art and tags; AAC (m4a) keeps tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The TFM Audio PWA can now offer offline playlist downloads in MP3/AAC so lossless files (FLAC) take 5-8x less space on the phone. This PR adds the server side: an FFmpeg-based transcoding endpoint with disk caching, plus a capabilities endpoint so clients can detect whether FFmpeg is installed and warn the user.
Endpoints
GET /api/mobile/stream/transcode/info— reports{ ffmpegAvailable, formats }. Clients must check this (or handle the 501 below) and fall back to original-format downloads when FFmpeg is missing.GET /api/mobile/stream/tfm/{channelId}/{tfmId}/transcoded?format=mp3|aac&bitrate=64..320&fileName=...—_temp(sequential 512KB Telegram download, same cache file the streaming endpoints use).libmp3lame/ nativeaac), writing to a.partfile and moving into place so partial results are never served.PhysicalFilewith full Range support. Repeat requests hit the disk cache under_temp/transcoded.Safeguards
transcode/inforeports it too).-map 0:v? -c:v copy -disposition:v:0 attached_pic); AAC/m4a keeps tags (-map_metadata 0).Notes
Test plan
GET /api/mobile/stream/transcode/inforeturnsffmpegAvailable: trueon a host with FFmpeg,falsewithout it.?format=mp3&bitrate=192: response is a valid MP3 (~5-8x smaller), with tags/cover; file appears underlocal/temp/_temp/transcoded/.?format=aacproduces a playable .m4a.🤖 Generated with Claude Code