Skip to main content
The -o option controls output file names while -P specifies the path where files should be saved. Output templates allow you to dynamically name files based on video metadata.

Basic Usage

Simple Templates

The simplest usage is a literal filename:
Hard-coding file extensions is not recommended as it may break post-processing. Use %(ext)s to use the correct extension automatically.

Template Syntax

Templates use Python string formatting with special sequences:
Sequences are replaced with actual values when downloading:

Available Fields

Basic Video Information

  • id - Video identifier
  • title - Video title
  • fulltitle - Video title ignoring live timestamp
  • ext - Video file extension
  • display_id - Alternative identifier
  • description - Video description

Playlist Information

  • playlist - Playlist title or ID
  • playlist_id - Playlist identifier
  • playlist_title - Name of the playlist
  • playlist_index - Position in playlist (padded)
  • playlist_count - Total items in playlist
  • playlist_uploader - Playlist uploader name
  • n_entries - Total extracted items

Media Metadata

  • width - Video width
  • height - Video height
  • fps - Frame rate
  • vcodec - Video codec
  • vbr - Video bitrate

Special Fields

  • webpage_url - URL to the video webpage
  • epoch - UNIX epoch when info was extracted
  • autonumber - Auto-incrementing number (padded to 5 digits)
  • format_id - Format identifier
  • resolution - Textual resolution description
Use -j to see all available fields for a particular URL:

Advanced Formatting

Object Traversal

Access nested fields using dot notation:
Python slicing with colons:

Numeric Formatting

Use Python’s printf-style formatting:

Date/Time Formatting

Format dates using > separator with strftime codes:

Alternatives

Provide fallback fields using , separator:

Replacement Values

Use & separator to replace non-empty fields:

Default Values

Set defaults for empty fields using | separator:

Special Conversions

yt-dlp supports additional format types beyond standard Python:
  • B - Bytes conversion
  • j - JSON (use # for pretty-print, + for Unicode)
  • h - HTML escaping
  • l - Comma-separated list (# for newline-separated)
  • q - Shell-quoted string
  • D - Decimal suffixes like 10M (# to use 1024 as factor)
  • S - Sanitize as filename (# for restricted)
  • U - Unicode normalization (NFC, use # for NFD)

Output Paths

Use -P to specify paths for different file types:
Available path types:
  • home - Final download location (default)
  • temp - Temporary/intermediate files
  • subtitle - Subtitle files
  • thumbnail - Thumbnail files
  • description - Description files
  • annotation - Annotation files
  • infojson - Info JSON files

Type-Specific Templates

Set different templates for different file types:
Available template types:
  • subtitle
  • thumbnail
  • description
  • infojson
  • pl_thumbnail
  • pl_description
  • pl_infojson
  • chapter
  • pl_video

Practical Examples

Advanced Use Cases

Conditional Prefix

Add playlist index only when available:

Hierarchical Organization

Course Downloads

Split Chapters

Special Characters

Percent Literals

Use %% for a literal percent sign:

Output to Stdout

Use -o - to output to stdout:

Filename Restrictions

Cross-Platform Compatibility

Sanitization

The S conversion automatically sanitizes filenames:

Getting Actual Filename

Due to post-processing, the actual output filename may differ:

Common Patterns

Clean Organization

Archive Format

Music Downloads

Safe Default