{"record":{"id":"76edb0e408cf903b","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-supports-videos-up-to-600-seconds","errorCode":null,"errorMessage":"ElevenLabs supports videos up to 600 seconds","messagePattern":"ElevenLabs supports videos up to 600 seconds","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":383,"sourceCode":"    output_path: str,\n    video_duration: float,\n    prompt: str = \"\",\n) -> str:\n    \"\"\"为一条已拼接视频生成时长和画面匹配的 ElevenLabs 背景音乐。\"\"\"\n    if not get_api_key():\n        raise ElevenLabsMusicError(\"ElevenLabs API key is required\")\n    if not os.path.isfile(video_path):\n        raise ElevenLabsMusicError(\"ElevenLabs input video does not exist\")\n    try:\n        duration = float(video_duration)\n    except (TypeError, ValueError) as exc:\n        raise ElevenLabsMusicError(\n            \"ElevenLabs video duration is invalid\"\n        ) from exc\n    if not math.isfinite(duration) or duration <= 0:\n        raise ElevenLabsMusicError(\"ElevenLabs video duration is invalid\")\n    if duration > MAX_VIDEO_DURATION_SECONDS:\n        raise ElevenLabsMusicError(\n            \"ElevenLabs supports videos up to 600 seconds\"\n        )\n    prompt = str(prompt or \"\").strip()\n    if len(prompt) > MAX_PROMPT_LENGTH:\n        raise ElevenLabsMusicError(\n            \"ElevenLabs music prompt exceeds 1000 characters\"\n        )\n\n    proxy_path = \"\"\n    try:\n        proxy_path = _create_video_proxy(video_path)\n        return _request_bgm(proxy_path, output_path, prompt)\n    except ElevenLabsMusicError:\n        raise\n    except OSError as exc:\n        raise ElevenLabsMusicError(\n            f\"ElevenLabs local file operation failed: {exc}\"\n        ) from exc","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L365-L401","documentation":"Duration cap in generate_bgm: the video is longer than MAX_VIDEO_DURATION_SECONDS (600s), the documented ElevenLabs video-to-music limit. Rejected client-side so a multi-hundred-MB upload is not attempted just to receive a 422/413.","triggerScenarios":"Any generate_bgm call where the validated duration exceeds 600 seconds — e.g. long-form compilations, a duration computed in the wrong unit (minutes passed as seconds), or a concat bug joining the same clips repeatedly.","commonSituations":"Unit mistakes (duration in milliseconds or minutes fed to a seconds parameter), 'loop video N times' features multiplying length past 10 minutes, or legitimately long content that simply exceeds the API plan.","solutions":["Check the duration unit first: a value like 10800 almost always means minutes/milliseconds were passed as seconds","Split the video into <=600s segments and generate/concat audio per segment if long content is required","Trim the video to <=600 seconds if full-length music is not a hard requirement"],"exampleFix":"# before\ngenerate_bgm(video, out, total_seconds, prompt)  # total_seconds = 1500\n\n# after\nMAX_LEN = 600\nsegments = split_video(video, MAX_LEN)  # each <= 600s\ntotal_seconds = min(total_seconds, MAX_LEN * len(segments))\naudio = generate_bgm(segments[0], out, total_seconds, prompt)  # per-segment strategy","handlingStrategy":"validation","validationCode":"from app.services.elevenlabs_music import MAX_VIDEO_DURATION_SECONDS\n\nassert 0 < duration <= MAX_VIDEO_DURATION_SECONDS","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Double-check duration units (seconds, not ms/minutes) before the call","Split long videos into <=600s segments for per-segment music generation"],"tags":["validation","limit","elevenlabs"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}