nilaoda/N_m3u8DL-RE · error · Exception
Download init file failed!
Error message
Download init file failed!
What it means
During download of an HLS/DASH stream, SimpleDownloadManager.DownloadStreamAsync fetches the MP4 initialization segment (MediaInit) before any media segments. If the init download completes without Success it throws, aborting the whole stream download since segments cannot be decoded without init data.
Solutions
- Re-run with --no-proxy or check the init URL manually with curl to confirm reachability
- Retry the download — transient network failures are the usual cause
- Check authentication headers/cookies required by the init segment URL
- Verify the playlist's EXT-X-MAP / initialization attribute URL is still valid
Defensive patterns
Strategy: retry
Validate before calling
// preflight the init URL
using var hc = new HttpClient();
using var resp = await hc.SendAsync(new HttpRequestMessage(HttpMethod.Head, playlist.MediaInit.Url));
if (!resp.IsSuccessStatusCode) throw new Exception($"init segment unreachable: {(int)resp.StatusCode}"); Type guard
static bool IsSuccess(DownloadResult r) => r is { Success: true }; Try / catch
try { await DownloadStreamAsync(...); }
catch (Exception ex) when (ex.Message == "Download init file failed!")
{
logger.Warn("init segment download failed, retrying...");
await RetryAsync(DownloadStreamAsync, 3);
} Prevention
- Use fresh auth cookies/tokens; signed init URLs expire quickly
- Preflight init URLs with a HEAD request before a long download
- Ensure stable network/proxy for the whole run
When it happens
Trigger: Downloader.DownloadSegmentAsync returns a DownloadResult with Success == false for streamSpec.Playlist.MediaInit — HTTP failure, 403/404 on the init URL, network timeout, or a null/failed result stored in FileDic.
Common situations: Init segment URL expired (signed URLs), server returning 403 for the init request, proxy blocking the request, or playlist referencing an init file that was removed from the CDN.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Download first segment failed!
- Download init file failed!
- Download first segment failed!
- ResString.badM3u8
- ResString.keyProcessorNotFound
AI-assisted analysis of nilaoda/N_m3u8DL-RE@e113dee70c (2026-09-13).
Data as JSON: /api/errors/aa016f48184bb9de.
Report an issue: GitHub.
Appendix: source
Thrown at src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs:173
Logger.WarnMarkUp($"[darkorange3_1]{ResString.autoBinaryMerge4}[/]");
}
// 下载init
if (streamSpec.Playlist?.MediaInit != null)
{
// 对于fMP4,自动开启二进制合并
if (!DownloaderConfig.MyOptions.BinaryMerge && streamSpec.MediaType != MediaType.SUBTITLES)
{
DownloaderConfig.MyOptions.BinaryMerge = true;
Logger.WarnMarkUp($"[darkorange3_1]{ResString.autoBinaryMerge}[/]");
}
var path = Path.Combine(tmpDir, "_init.mp4.tmp");
var result = await Downloader.DownloadSegmentAsync(streamSpec.Playlist.MediaInit, path, speedContainer, headers);
FileDic[streamSpec.Playlist.MediaInit] = result;
if (result is not { Success: true })
{
throw new Exception("Download init file failed!");
}
mp4InitFile = result.ActualFilePath;
task.Increment(1);
// 读取mp4信息
if (result is { Success: true })
{
mp4Info = MP4DecryptUtil.GetMP4Info(result.ActualFilePath);
// MPD的cenc:default_KID优先
if (streamSpec.Playlist?.MediaInit?.EncryptInfo.KID != null)
{
currentKID = streamSpec.Playlist.MediaInit.EncryptInfo.KID;
Logger.WarnMarkUp($"[grey]KID (from MPD): {currentKID}[/]");
}
else
{
currentKID = mp4Info.KID;
}View on GitHub (pinned to e113dee70c)