I've poured through the youtube-dl documentation. I've found what I thought was exactly what I wanted…but I've run into a snag, and I'm curious to see if any of the more advanced options of youtube-dl could help solve my problem. For some of the more advanced options, there isn't much documentation, and I'm still learning Python…so going through the source code has been an endeavor. haha.
- Download the best video + best audio (default to "best" if combo not
- Embed the thumbnail
- Include metadata info in file
- Output final file as MP4 – cannot be MKV
My current command:
youtube-dl -f "bestvideo+bestaudio[ext=m4a]/best" --embed-thumbnail --add-metadata [url]
In cases where the "bestvideo" is a webm file…it detects that WEBM + M4A are incompatible and will be merged into an MKV file rather than MP4 (like it normally would). Since this step is performed prior to the thumbnail embedding via AtomicParsley…An error is thrown, because MKV are not supported for thumbnail embedding.
UPDATE: I later remembered the above statement is not accurate. What
was actually happening was that WEBM video was working fine, but it
was WEBM audio that was causing the problem. YouTube uses Opus
encoding for WEBM audio, which when youtube-dl tried merging the two
files, it would end up having to use an MKV container rather than MP4
because ffmpeg doesn't safely allow WEBM/Opus within an MP4 container.
In order to force this conversion you must add "–strict 2" to ffmpeg
(can be passed in via a youtube-dl parameter). My solution was to
exclude WEBM audio formats by using "bestaudio[ext=m4a]". Once I did
this, all I simply needed to do was add "–merge-output-format mp4" to
my youtube-dl command (as recommended by the marked answer).
However…if the video only webm file were first converted to MP4, then none of this would be a problem.
So…does anyone know, if there is a way to tell youtube-dl that when it downloads the video file, to immediately convert it to a given type (MP4) before doing anything else?
- [youtube-dl] download thumbnail
- [youtube-dl] download video file (webm/mp4)
- [ffmpeg] if not mp4, convert video file to mp4 — extra step that I want to happen
- [youtube-dl] download audio file (m4a)
- [ffmpeg] merge files to mp4
- [ffmpeg] add metadata
- [atomicparsley] embed thumbnail
If not…then I think I might just go the route of writing this all myself in powershell. Like I could have youtube-dl download the audio, video, metadata and thumbnail to file, and then write a powershell script that does all I need to do. Maybe have youtube-dl call the powershell script after each iteration.