ytdlp.org
On this page

Error guide

Fix "File name too long" (Errno 36) in yt-dlp

The video extracts fine, the format is picked, and then yt-dlp stops before writing a single byte. The cause is the file name, not the download: the title is too long for your file system. It mostly shows up on sites where the "title" is the whole post caption, and almost always in scripts and pipelines, because that's where nobody is looking at the titles.

What the error looks like

[info] <id>: Downloading 1 format(s): <format>
ERROR: unable to open for writing: [Errno 36] File name too long: 'Полный текст подписи к ролику, который ... .mp4.part'

The giveaway is that metadata works. yt-dlp --print title "URL" succeeds on the same link, and -j returns the full JSON. Only the step that opens <title>.<ext>.part fails.

Why it happens

yt-dlp's default output template is %(title)s [%(id)s].%(ext)s, and most scripts use %(title)s.%(ext)s. Both put the entire title in the file name.

On YouTube a title is capped at 100 characters, so that's rarely a problem. On Facebook reels, TikTok, X and Instagram, the title is often the post's whole caption, hashtags included. Linux file systems such as ext4 allow 255 bytes per file name, and bytes are the catch:

  • Latin letters are 1 byte each in UTF-8.
  • Cyrillic, Greek, Hebrew and Arabic letters are 2 bytes.
  • Chinese, Japanese and Korean characters are 3 bytes, most emoji 4.

A 130-character Russian caption is already 260 bytes. That's why the error seems random: the same script works for months on English titles and then fails on the first long caption in another script.

Fix: cut the title by bytes in the output template

yt-dlp's template syntax can truncate a field to a number of bytes with .NB:

yt-dlp -o "%(title).150B [%(id)s].%(ext)s" "URL"

%(title).150B keeps at most 150 bytes of the title and never splits a multi-byte character. 150 leaves room for the [id], the extension and the temporary suffixes yt-dlp adds while it works (.part, and .f137-style names when it merges video and audio). Keep the [%(id)s] so two posts with the same caption don't overwrite each other.

Check the name before you download anything:

yt-dlp --simulate --print filename -o "%(title).150B [%(id)s].%(ext)s" "URL"

In Python, it's the same template in outtmpl:

import yt_dlp

opts = {"outtmpl": "%(title).150B [%(id)s].%(ext)s"}
with yt_dlp.YoutubeDL(opts) as ydl:
    ydl.download([url])

If you put the template in a config file, every run picks it up. The output template guide covers the rest of the syntax.

Why --trim-filenames isn't enough

--trim-filenames N looks like the obvious fix, and on English titles it works. But it counts characters, not bytes (its help text says so: "the specified number of characters"). We tested it on yt-dlp 2026.11.23 with a 200-character Cyrillic title:

CommandResult
-o "%(title)s.%(ext)s"Errno 36
--trim-filenames 150 -o "%(title)s.%(ext)s"Errno 36 (150 characters = 300 bytes)
--trim-filenames 100 -o "%(title)s.%(ext)s"works, 204 bytes
-o "%(title).150B.%(ext)s"works, 154 bytes

So --trim-filenames only protects you if you size it for the worst script you'll ever see, which means about 80 characters for CJK text and fewer once emoji are involved. The byte cut doesn't need that guess. There's an open request to make it count bytes (yt-dlp#12386, open since February 2025), but for now the template is the reliable fix.

Don't reach for --restrict-filenames

--restrict-filenames keeps only ASCII. On a title written entirely in Cyrillic or Japanese, that leaves one underscore: the file is called _.mp4, and the next download with the same kind of title overwrites it. It's fine if all your sources are English and you want shell-safe names, but it isn't a fix for this error.

Use the id when you don't need the title

If a program, not a person, reads your downloads, the safest name is the one that can't be too long:

yt-dlp -o "%(id)s.%(ext)s" --write-info-json "URL"

The id is short and unique per site, and --write-info-json keeps the full title, caption and everything else next to the file, so you lose nothing. Store the title in your database, not in the file name. Getting video metadata shows what's in that JSON.

In a pipeline, also fail fast

On its own, Errno 36 isn't a network error, so retrying the same command gives the same result every time. If your job runner retries failed downloads, treat this error as permanent (or rerun once with the id-only template) instead of burning every attempt on it. More on keeping unattended runs healthy in yt-dlp automation.

Automation

Running this on a schedule? See the API version.

Paste a link and watch one API call do what your batch script does — extraction, retries, and site breakage handled.

Building this into an app? See the API your backend calls instead

Frequently asked questions

Why does yt-dlp say "File name too long"?

The default output template puts the whole title in the file name. On Facebook reels, TikTok, X and Instagram the title is often the full caption, and Linux file systems such as ext4 cap a single file name at 255 bytes. yt-dlp extracts the video fine, then fails the moment it opens the .part file for writing.

Why doesn't --trim-filenames fix it?

--trim-filenames counts characters, not bytes. Latin letters are one byte each, but Cyrillic, Greek and Arabic letters are two bytes in UTF-8, and Chinese, Japanese, Korean and most emoji are three or four. --trim-filenames 150 on a Cyrillic title still gives a 300-byte name and the same error. Cut by bytes in the template instead: -o "%(title).150B.%(ext)s".

What's a safe output template for an automated pipeline?

-o "%(title).150B [%(id)s].%(ext)s". The .150B cut keeps the name well under 255 bytes in any script and leaves room for the .part and .fNNN suffixes yt-dlp adds while downloading, and the id keeps two posts with the same caption from overwriting each other.

Does --restrict-filenames help?

Only for Latin text. It replaces every non-ASCII character, so a title written entirely in Cyrillic or Japanese collapses to a single underscore and every download gets the same name. Use a byte cut in the template if your sources aren't all English.