-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:Available Fields
Basic Video Information
- Identity
- Uploader
- Dates
- Statistics
id- Video identifiertitle- Video titlefulltitle- Video title ignoring live timestampext- Video file extensiondisplay_id- Alternative identifierdescription- Video description
Playlist Information
playlist- Playlist title or IDplaylist_id- Playlist identifierplaylist_title- Name of the playlistplaylist_index- Position in playlist (padded)playlist_count- Total items in playlistplaylist_uploader- Playlist uploader namen_entries- Total extracted items
Media Metadata
- Video
- Audio
- Series/Music
width- Video widthheight- Video heightfps- Frame ratevcodec- Video codecvbr- Video bitrate
Special Fields
webpage_url- URL to the video webpageepoch- UNIX epoch when info was extractedautonumber- Auto-incrementing number (padded to 5 digits)format_id- Format identifierresolution- Textual resolution description
Use
-j to see all available fields for a particular URL:Advanced Formatting
Object Traversal
Access nested fields using dot notation: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 conversionj- JSON (use#for pretty-print,+for Unicode)h- HTML escapingl- Comma-separated list (#for newline-separated)q- Shell-quoted stringD- 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:
home- Final download location (default)temp- Temporary/intermediate filessubtitle- Subtitle filesthumbnail- Thumbnail filesdescription- Description filesannotation- Annotation filesinfojson- Info JSON files
Type-Specific Templates
Set different templates for different file types:subtitlethumbnaildescriptioninfojsonpl_thumbnailpl_descriptionpl_infojsonchapterpl_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
TheS conversion automatically sanitizes filenames: