yt-dlp / yt-dlp

A feature-rich command-line audio/video downloader
https://discord.gg/H5MNcFW63r
The Unlicense
90.81k stars 7.05k forks source link

Can you add an option to not only remux but transcode if the target container doesn't support the current format? #10494

Open stephane-archer opened 4 months ago

stephane-archer commented 4 months ago

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

Checklist

Provide a description that is worded well enough to be understood

yt-dlp -vU --merge-output-format mov "https://www.youtube.com/watch?v=PorfLSr3DDI&pp=ygULY3BwIGNvbiBnZGI%3D"
[mov @ 0x7f961a705fc0] vp9 only supported in MP4.

Can you add an option to not only remux but transcode if the target container doesn't support the current format?

Provide verbose output that clearly demonstrates the problem

Complete Verbose Output

[debug] Command-line config: ['-vU', '--merge-output-format', 'mov', 'https://www.youtube.com/watch?v=PorfLSr3DDI&pp=ygULY3BwIGNvbiBnZGI%3D']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No ANSI), error utf-8 (No ANSI), screen utf-8 (No ANSI)
[debug] yt-dlp version stable@2024.07.09 from yt-dlp/yt-dlp [7ead7332a] (pip)
[debug] Python 3.12.4 (CPython x86_64 64bit) - macOS-14.5-x86_64-i386-64bit (OpenSSL 3.3.1 4 Jun 2024)
[debug] exe versions: ffmpeg 7.0.1 (setts), ffprobe 7.0.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.07.04, mutagen-1.47.0, requests-2.32.3, sqlite3-3.46.0, urllib3-2.2.2, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1834 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
[debug] Downloading _update_spec from https://github.com/yt-dlp/yt-dlp/releases/latest/download/_update_spec
Current version: stable@2024.07.09 from yt-dlp/yt-dlp
Latest version: stable@2024.07.16 from yt-dlp/yt-dlp
ERROR: You installed yt-dlp with pip or using the wheel from PyPi; Use that to update
[youtube] Extracting URL: https://www.youtube.com/watch?v=PorfLSr3DDI&pp=ygULY3BwIGNvbiBnZGI%3D
[youtube] PorfLSr3DDI: Downloading webpage
[youtube] PorfLSr3DDI: Downloading ios player API JSON
[youtube] PorfLSr3DDI: Downloading player d60b0ef9
[debug] Saving youtube-nsig.d60b0ef9 to cache
[debug] [youtube] Decrypted nsig 2x4BhYI6aWIcaR5Q => OvOFku7bHADBIQ
[debug] Loading youtube-nsig.d60b0ef9 from cache
[debug] [youtube] Decrypted nsig Roy6tDfqsovS8axq => X9oQP2vlOxOI6A
[youtube] PorfLSr3DDI: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] PorfLSr3DDI: Downloading 1 format(s): 248+251
[debug] Invoking http downloader on "https://rr4---sn-25glenld.googlevideo.com/videoplayback?expire=1721316328&ei=iN-YZvz1GYmHhcIPt_OAkAk&ip=2a01%3Acb00%3Ab1d%3A1400%3A9903%3A61fe%3Aaada%3A9107&id=o-AFhcokix9ALF3O0H09e4SHdX9yt5T70iAzwaRng2CQUC&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C394%2C395%2C396%2C397%2C398%2C399&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=__&mm=31%2C26&mn=sn-25glenld%2Csn-4g5e6nzl&ms=au%2Conr&mv=m&mvi=4&pl=43&initcwndbps=1727500&bui=AXc671LXQpI7_1nBQosZu0NEqLgy-3QMXDfH5Udi7co10Na2TObNfJF1pZ53U8Mv5be3fgFTyJ2xclL7&spc=NO7bAdBg7SN1hVp9GOLpP3PNCa-Et6sZsoPvxB7FiyOtRF0_Js4D7jRXlvI9&vprv=1&svpuc=1&mime=video%2Fwebm&ns=6HTbdWTRMc3udzxbeUkROvEQ&rqh=1&gir=yes&clen=128486702&dur=886.052&lmt=1445417381187105&mt=1721294465&fvip=4&keepalive=yes&c=WEB&sefc=1&n=X9oQP2vlOxOI6A&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRAIgMPB_bOdYrBV_9N_FaeqsB_v_SxLPnvjNJRehIU6ZZ0YCIEfqMPDL_jmiuAOZEvnVWGDFSI_WNmYVPrVh-MnADFR4&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHlkHjAwRgIhAJ2VN_bLKPNIE2hWagk4QdswCzuihIV7dV3ETtGXun3KAiEAu7Rw5qw10GuJ462TBIlNRGMmvr1xJM1Jzhl5jZO16UU%3D"
[download] CppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB" [PorfLSr3DDI].f248.webm has already been downloaded

[download] 100% of  122.53MiB
[debug] Invoking http downloader on "https://rr4---sn-25glenld.googlevideo.com/videoplayback?expire=1721316328&ei=iN-YZvz1GYmHhcIPt_OAkAk&ip=2a01%3Acb00%3Ab1d%3A1400%3A9903%3A61fe%3Aaada%3A9107&id=o-AFhcokix9ALF3O0H09e4SHdX9yt5T70iAzwaRng2CQUC&itag=251&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=__&mm=31%2C26&mn=sn-25glenld%2Csn-4g5e6nzl&ms=au%2Conr&mv=m&mvi=4&pl=43&initcwndbps=1727500&bui=AXc671LXQpI7_1nBQosZu0NEqLgy-3QMXDfH5Udi7co10Na2TObNfJF1pZ53U8Mv5be3fgFTyJ2xclL7&spc=NO7bAdBg7SN1hVp9GOLpP3PNCa-Et6sZsoPvxB7FiyOtRF0_Js4D7jRXlvI9&vprv=1&svpuc=1&mime=audio%2Fwebm&ns=6HTbdWTRMc3udzxbeUkROvEQ&rqh=1&gir=yes&clen=13017178&dur=886.101&lmt=1445417007612292&mt=1721294465&fvip=4&keepalive=yes&c=WEB&sefc=1&n=X9oQP2vlOxOI6A&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRQIhAJT-DJeqHSbWsPyIFym-AkhXtuZq8xjdWEJlPieoAucGAiAc6z0QxEB4A-Jr-dSPUSVGBM5cdRHbwXZ2E62DjX1keA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHlkHjAwRgIhAJ2VN_bLKPNIE2hWagk4QdswCzuihIV7dV3ETtGXun3KAiEAu7Rw5qw10GuJ462TBIlNRGMmvr1xJM1Jzhl5jZO16UU%3D"
[download] CppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB" [PorfLSr3DDI].f251.webm has already been downloaded

[download] 100% of   12.41MiB
[Merger] Merging formats into "CppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB" [PorfLSr3DDI].mov"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:CppCon 2015: Greg Law " Give me 15 minutes & I'"'"'ll change your view of GDB" [PorfLSr3DDI].f248.webm' -i 'file:CppCon 2015: Greg Law " Give me 15 minutes & I'"'"'ll change your view of GDB" [PorfLSr3DDI].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -movflags +faststart 'file:CppCon 2015: Greg Law " Give me 15 minutes & I'"'"'ll change your view of GDB" [PorfLSr3DDI].temp.mov'
[debug] ffmpeg version 7.0.1 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.3.9.4)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/7.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
Input #0, matroska,webm, from 'file:CppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB" [PorfLSr3DDI].f248.webm':
  Metadata:
    encoder         : google
  Duration: 00:14:46.05, start: 0.000000, bitrate: 1160 kb/s
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn (default)
Input #1, matroska,webm, from 'file:CppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB" [PorfLSr3DDI].f251.webm':
  Metadata:
    encoder         : google
  Duration: 00:14:46.10, start: -0.007000, bitrate: 117 kb/s
  Stream #1:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
[mov @ 0x7fd507209040] vp9 only supported in MP4.
[out#0/mov @ 0x7fd507208cc0] Could not write header (incorrect codec parameters ?): Invalid argument
Conversion failed!

ERROR: Postprocessing: Conversion failed!
Traceback (most recent call last):
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 3556, in process_info
    replace_info_dict(self.post_process(dl_filename, info_dict, files_to_move))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 3738, in post_process
    info = self.run_all_pps('post_process', info, additional_pps=info.get('__postprocessors'))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 3720, in run_all_pps
    info = self.run_pp(pp, info)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 3698, in run_pp
    files_to_delete, infodict = pp.run(infodict)
                                ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/postprocessor/common.py", line 23, in run
    ret = func(self, info, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/postprocessor/common.py", line 128, in wrapper
    return func(self, info)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 840, in run
    self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 330, in run_ffmpeg_multiple_files
    return self.real_run_ffmpeg(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/yt-dlp/2024.7.9/libexec/lib/python3.12/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 368, in real_run_ffmpeg
    raise FFmpegPostProcessorError(stderr.strip().splitlines()[-1])
yt_dlp.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!
dirkf commented 4 months ago

Or ask for .mkv and sort out any desired conversion locally. Or pass additional ffmpeg arguments to force transcoding during the merge step (may fall into the category of "possible but inadvisable").

The message vp9 only supported in MP4 from ffmpeg is misleading. MP4 and MOV are technically similar containers, so the same muxer code handles both, but they support different content types. The message lacks the introductory context "Out of the two major container formats that this code implements, ...".

stephane-archer commented 4 months ago

why would it be in the category of "possible but inadvisable"? otherwise my next command would be ffmpeg -i downloadedvideo.mkv output.mov because my next program can't read mkv

bashonly commented 4 months ago

can your next program read mp4?

--merge-output mp4 --remux mp4

should work in most cases

bashonly commented 4 months ago

or if you only want to download codecs that are supported by the mov container:

-S vcodec:h264,res,acodec:aac --merge-output mov --remux mov
stephane-archer commented 4 months ago

@bashonly the next program is final cut: https://support.apple.com/en-gb/guide/final-cut-pro/ver2833f855/mac so it supports the mp4 container but not the vp9 codec, (h265 works) Does this next line make sense to get the best quality with a compatible format? is there a way to sort formats for video and audio separately? -S vcodec:h265,vcodec:h264,quality,res,acodec:aac --merge-output mov --remux mov

bashonly commented 4 months ago

vcodec:h265,vcodec:h264 is not valid syntax

youtube doesn't serve h265 anyways, so I think -S vcodec:h264,res,acodec:aac --merge-output mov --remux mov should be enough

stephane-archer commented 4 months ago

@bashonly what about: yt-dlp -f 'bestvideo*[vcodec*=avc1]+bestaudio[acodec*=mp4a]' --merge-output mov $argv is it better to use -f or -S?

bashonly commented 4 months ago

It's better to use -S. Format sorting is "smart" and knows that h264 == avc == avc1, etc. With -f you need to be exact, and the representation of the codec can vary from site to site.

stephane-archer commented 4 months ago

@bashonly Moving back to the original subject of the opened issue, does yt-dlp --recode mov always transcode, or is able to remux compatible format with the target container?

bashonly commented 4 months ago

--recode will always re-encode. --remux will losslessly remux; but it only works if the codecs are compatible with the target container. Re-encoding can change the codec+container; remuxing can only change the container.

stephane-archer commented 4 months ago

so we can imagine an option like: --smart-recode or the fact of using --recode and --remux at the same time should avoid useless re-encode?

bashonly commented 4 months ago

Related: #7607