harry0703/MoneyPrinterTurbo · error · ElevenLabsMusicError
ElevenLabs returned audio that FFmpeg cannot decode
Error message
ElevenLabs returned audio that FFmpeg cannot decode
What it means
Raised after a successful download when the audio ElevenLabs returned fails the local FFmpeg decode check (bgm_service.validate_audio_file with a 120s timeout). It means the HTTP call succeeded but the bytes on disk are not a decodable audio file — e.g. a JSON error body saved with 200, a truncated stream, or an unsupported codec.
Source
Thrown at app/services/elevenlabs_music.py:349
with response:
if not response.ok:
raise ElevenLabsMusicError(
"ElevenLabs generation failed "
f"({response.status_code}): "
f"{_safe_response_error(response)}"
)
total_bytes = _stream_audio(response, temp_audio_path)
except requests.RequestException as exc:
# 下载阶段断线也属于请求失败,必须进入任务降级逻辑,不能留下半条
# 音频或让已经生成的视频因为第三方网络波动整体失败。
raise ElevenLabsMusicError(
f"failed to request ElevenLabs music: {exc}"
) from exc
try:
bgm_service.validate_audio_file(temp_audio_path, timeout_seconds=120)
except (bgm_service.BgmUploadError, bgm_service.BgmServiceError) as exc:
raise ElevenLabsMusicError(
"ElevenLabs returned audio that FFmpeg cannot decode"
) from exc
os.replace(temp_audio_path, output_path)
temp_audio_path = ""
logger.info(
"ElevenLabs background music generated: "
f"output={output_path}, size={total_bytes} bytes"
)
return output_path
finally:
_remove_file(temp_audio_path)
def generate_bgm(
video_path: str,
output_path: str,
video_duration: float,
prompt: str = "",View on GitHub (pinned to 1f9f19c202)
Solutions
- Manually inspect the temp audio bytes (the finally block deletes it, so reproduce with a raw curl to /v1/music/video-to-music) to see whether it is JSON/HTML instead of audio
- Confirm ffmpeg is installed and on PATH — a missing FFmpeg makes every validation fail regardless of the audio
- Retry the request; truncated streams are usually transient server-side or network issues
- If ElevenLabs changed its output format, pin/switch music_model_id between music_v1 and music_v2 and retest
Example fix
# before
bgm_service.validate_audio_file(temp_audio_path, timeout_seconds=120) # opaque failure
# after
# capture format info for diagnosis before failing the task
probe = subprocess.run(
["ffprobe", "-v", "error", "-show_format", temp_audio_path],
capture_output=True, text=True, timeout=30,
)
logger.warning(f"elevenlabs audio probe: rc={probe.returncode} err={probe.stderr[:200]}")
bgm_service.validate_audio_file(temp_audio_path, timeout_seconds=120) Defensive patterns
Strategy: validation
Validate before calling
import shutil
assert shutil.which("ffmpeg") and shutil.which("ffprobe"), "ffmpeg/ffprobe required" Try / catch
try:
elm.generate_bgm(video, out, duration, prompt)
except elm.ElevenLabsMusicError as e:
if "cannot decode" in str(e):
log_probe_details(video) # ffprobe the raw response once, then give up BGM
raise_task_degradation() Prevention
- Verify ffmpeg/ffprobe are installed and on PATH in the deployment image
- Retry once — truncated audio streams are often transient
- Pin music_model_id to a known-good value when ElevenLabs ships format changes
When it happens
Trigger: _stream_audio wrote fewer bytes than expected (connection cut but requests did not raise), ElevenLabs returned an error payload with a 200 status, or the returned audio codec/container is not decodable by the bundled FFmpeg build. validate_audio_file then exits non-zero and raises BgmUploadError/BgmServiceError.
Common situations: MITM proxies that rewrite responses, partial writes when the process is SIGSTOPed mid-download, ElevenLabs serving a new audio format after an API update, or an FFmpeg binary missing from PATH so validation fails for every file.
Related errors
- uploaded file must contain a decodable audio stream
- background music file is empty or missing
- ElevenLabs subscription response does not include an account
- ElevenLabs video proxy generation timed out
- failed to run FFmpeg for ElevenLabs video proxy
AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14).
Data as JSON: /api/errors/b73a092125f84e75.
Report an issue: GitHub.