Fix "Postprocessing: ffmpeg exited with code 1" in yt-dlp
ERROR: Postprocessing: Error opening output file Some Video.mp4.
Error opening output files: Invalid argument
ffmpeg exited with code 1
Quick answer
The download finished. The conversion afterwards failed — so no yt-dlp flag about formats or quality will help. The error is ffmpeg's, and the four things that cause it are a codec that does not fit the container, a filename the filesystem refuses, no disk space, or a locked file. Start by keeping the source files so a retry costs nothing:
yt-dlp --keep-video --restrict-filenames "URL"
Reading the real error
ffmpeg exited with code 1 is not the error. It is yt-dlp reporting that ffmpeg
failed; the reason is in the lines above it, and yt-dlp usually truncates them. Get the whole
thing:
yt-dlp -v --keep-video "URL"
What to look for in the output:
| ffmpeg says | It means |
|---|---|
Invalid argument | Filename or path — illegal character, or too long |
could not find tag for codec | The codec does not fit the container |
No space left on device | Disk full — merging needs room for a second copy |
Permission denied | Antivirus or another program holding the file |
Invalid data found | The download is corrupt; delete the .part files |
Cause 1 — codec and container do not fit
mp4 is a fussy container. It will not hold Opus audio, and it will not hold VP9 video in a way
most players accept. YouTube serves both routinely, so --merge-output-format mp4
fails on exactly the videos where those codecs turn up.
Two ways out. Ask for codecs mp4 can hold:
yt-dlp -f "bv*[vcodec^=avc1]+ba[acodec^=mp4a]/b[ext=mp4]/b" --merge-output-format mp4 "URL"
Or stop insisting on mp4. mkv holds anything, and every current player reads it:
yt-dlp --merge-output-format mkv "URL"
Cause 2 — the filename
Video titles contain colons, quotes, emoji and slashes. Windows refuses several of those outright, and every filesystem has a path length limit that a long title inside a deep folder will find:
yt-dlp --restrict-filenames --trim-filenames 120 "URL"
--restrict-filenames reduces names to ASCII with no spaces. Worth having on
permanently if files ever land on a network share or an external drive —
output templates covers naming properly.
Cause 3 — disk space
Merging is not free. ffmpeg writes a new file while the two source streams still exist, so the
peak requirement is roughly twice the finished size. A drive with 2 GB free will fail to merge a
1.5 GB video, and the error says Invalid argument rather than anything about space.
Put temporary files somewhere with room:
yt-dlp -P "temp:/var/tmp" -P "home:/media/archive" "URL"
Cause 4 — something is holding the file
On Windows, real-time antivirus scans each completed download, and ffmpeg cannot open a file being scanned. The symptom is intermittent, which is what makes it hard to place. Retrying is the fix:
yt-dlp --file-access-retries 5 "URL"
A cloud-sync folder — OneDrive, Dropbox, Google Drive — causes the same thing for the same reason. Download somewhere local and move the file afterwards.
Retrying without downloading again
If --keep-video was on, the two source files are still there and ffmpeg can be
run directly. -c copy means "do not re-encode", so this takes seconds:
ffmpeg -i "video.f137.mp4" -i "audio.f140.m4a" -c copy "output.mp4"
If it still fails
-
Only when extracting audio. A missing encoder rather than a broken file. On
Debian and Ubuntu,
sudo apt install libavcodec-extra. See the audio guide. -
Only with
--embed-subs. mp4 accepts a narrow set of subtitle formats. Add--convert-subs srt, or switch the container to mkv. -
Only with
--embed-thumbnail. WebP thumbnails do not embed into mp4.--convert-thumbnails jpgfixes it. - Every video, every option. Suspect the ffmpeg build. A minimal or stripped-down build lacks encoders yt-dlp assumes are present — the yt-dlp project's own builds are the ones to test against.
Frequently asked
Do I have to download the video again?
Why does the same command work on another video?
What does "Invalid argument" mean here?
Should I use --recode-video to force a format?
Related
- Fix "ffmpeg not found" and "You have requested merging" in yt-dlp yt-dlp downloads video and audio separately and needs ffmpeg to join them. How to install it on each OS, why "...
- Extract Audio with yt-dlp: MP3, M4A and Lossless Copies Ripping to MP3 re-encodes audio that was already compressed once. When that is fine, when to keep the original...
- yt-dlp Output Templates: Name and Sort Files Automatically The -o template turns a folder of random filenames into a library. Every field worth using, the numeric and da...