Skip to content

Fix invalid MP3 output by converting HLS segments with ffmpeg#17

Merged
rahaaatul merged 2 commits intorahaaatul:mainfrom
emiliowright:fix-hls-mp3-encoding
Mar 14, 2026
Merged

Fix invalid MP3 output by converting HLS segments with ffmpeg#17
rahaaatul merged 2 commits intorahaaatul:mainfrom
emiliowright:fix-hls-mp3-encoding

Conversation

@emiliowright
Copy link
Copy Markdown

Problem

HLS audio segments were being concatenated directly into a file with a .mp3 extension.

This results in files that:

  • Are not true MPEG Layer III MP3 files
  • May appear as MPEG Layer I/II in some players
  • Previously caused incorrect playback (fast speed / noise) before manual re-encoding

Although ffmpeg is required by the application, it was not being used for the final audio encoding step.

Root Cause

The download logic writes raw HLS transport stream segments directly into a file named .mp3, without container conversion or audio encoding.

Fix

  • Download HLS segments into a temporary .ts file
  • Use ffmpeg to convert the .ts into a proper MP3 (MPEG Audio Layer III)
  • Delete the temporary .ts file after successful conversion

Verification

Verified using:

  • ffprobe → confirms codec_long_name=MP3 (MPEG audio layer 3)
  • VLC playback → correct duration and normal audio

This ensures generated files are valid MP3s and align with the requirement that ffmpeg is installed.

@rahaaatul rahaaatul merged commit a105aac into rahaaatul:main Mar 14, 2026
3 of 4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants