Repository: yt-dlp
Issue: [Feature Request] Merge, Add metadata and other ffmpeg operations simultaneously
Labels: enhancement,core:post-processor

<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
- First of, make sure you are using the latest version of yt-dlp. Run `yt-dlp --version` and ensure your version is 2021.03.01. If it's not, see https://github.com/yt-dlp/yt-dlp on how to update. Issues with outdated version will be REJECTED.
- Search the bugtracker for similar site feature requests: https://github.com/yt-dlp/yt-dlp. DO NOT post duplicates.
- Finally, put x into all relevant boxes like this [x] (Dont forget to delete the empty space)
-->

- [x] I'm reporting a site feature request
- [x] I've verified that I'm running yt-dlp version **2021.03.01**
- [x] I've searched the bugtracker for similar site feature requests including closed ones


## Description

<!--
Provide an explanation of your site feature request in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
-->

Currently yt-dlp is merging the video & audio, adding metadata, and embedding thumbnail separately. It doesn't make any noticeable difference for small videos but when video length reach >1 hr, it is very noticeable.

Following are the logs for the test (I have already downloaded both video only and audio only files):

For command
 ```
time yt-dlp -o '/home/youtube/%(uploader)s/[%(upload_date)s] - %(title)s-%(id)s.%(ext)s' -f 299+251 -k --merge-output-format=mkv -v --add-metadata --embed-thumbnail "https://www.youtube.com/watch?v=eBL5MOaTr80"
```

and this is the output 

```[debug] Command-line config: ['-o', '/home/youtube/%(uploader)s/[%(upload_date)s] - %(title)s-%(id)s.%(ext)s', '-f', '299+251', '-k', '--merge-output-format=mkv', '-v', '--add-metadata', '--embed-thumbnail', 'https://www.youtube.com/watch?v=eBL5MOaTr80']
[debug] Loading archive file None
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] yt-dlp version 2021.03.01 
[debug] Python version 3.7.10 (CPython 64bit) - Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
[debug] exe versions: ffmpeg 3.4.8, ffprobe 3.4.8
[debug] Proxy map: {}
[youtube] eBL5MOaTr80: Downloading webpage
[youtube] eBL5MOaTr80: Downloading MPD manifest
[debug] Sort order given by user: 
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[info] Downloading format(s) 299+251
[youtube] eBL5MOaTr80: Downloading thumbnail  ...
[youtube] eBL5MOaTr80: Writing thumbnail to: /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.jpg
[debug] Invoking downloader on 'https://r4---sn-q4fl6nlr.googlevideo.com/videoplayback?expire=1614631766&ei=9v48YIWyMo3mkgaX_77YAw&ip=my_ip_address&id=o-AJdvBVS1PA1R91YZgMM8a5y9JilvqU58eduZDXq2_nZR&itag=299&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C299%2C302%2C303&source=youtube&requiressl=yes&mh=Ky&mm=31%2C29&mn=sn-q4fl6nlr%2Csn-q4flrne7&ms=au%2Crdu&mv=u&mvi=4&pl=24&vprv=1&mime=video%2Fmp4&ns=vMbCLkWLcH8hW5g625qilaMF&gir=yes&clen=1776481988&otfp=1&dur=3740.333&lmt=1603202225393071&mt=1614609721&fvip=4&keepalive=yes&fexp=24007247&c=WEB&n=J1xMpWdToowdwwQP95&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cotfp%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAJMYLTLQxfUuV-wmGtTMi_TulFdFvfN9FHartbrQuM8XAiEAijZsfTiMzJaMttwae2oP8g73aQtrBVfyDeRBUhEtlIA%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&lsig=AG3C_xAwRgIhANiyF5nVBVqNdHMuA1teGFkyROuJWnlFIxeza47zW_KSAiEAqpE_52f_B8GrdzpIr5PgEJ1VolRHgh-2hfPLl_0pxFw%3D'
[download] /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f299.mp4 has already been downloaded
[download] 100% of 1.65GiB
[debug] Invoking downloader on 'https://r4---sn-q4fl6nlr.googlevideo.com/videoplayback?expire=1614631766&ei=9v48YIWyMo3mkgaX_77YAw&ip=my_ip_address&id=o-AJdvBVS1PA1R91YZgMM8a5y9JilvqU58eduZDXq2_nZR&itag=251&source=youtube&requiressl=yes&mh=Ky&mm=31%2C29&mn=sn-q4fl6nlr%2Csn-q4flrne7&ms=au%2Crdu&mv=u&mvi=4&pl=24&vprv=1&mime=audio%2Fwebm&ns=vMbCLkWLcH8hW5g625qilaMF&gir=yes&clen=59222889&otfp=1&dur=3740.341&lmt=1602942372790418&mt=1614609721&fvip=4&keepalive=yes&fexp=24007247&c=WEB&txp=7211222&n=J1xMpWdToowdwwQP95&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cotfp%2Cdur%2Clmt&sig=AOq0QJ8wRAIgYIo6y3dYGL8NRc-Pqfjo3y3eeK40W1VqMgYBo3QiEQUCIDdGaHk4kKE7AZSnbDSDkWzhaQQiB9FeJ94xCY_kyqL2&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl&lsig=AG3C_xAwRgIhANiyF5nVBVqNdHMuA1teGFkyROuJWnlFIxeza47zW_KSAiEAqpE_52f_B8GrdzpIr5PgEJ1VolRHgh-2hfPLl_0pxFw%3D'
[download] /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f251.webm has already been downloaded
[download] 100% of 56.48MiB
[Merger] Merging formats into "/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f299.mp4' -i 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f251.webm' -c copy -map 0:v:0 -map 1:a:0 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.temp.mkv'
[Metadata] Adding metadata to '/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv'
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv' -map 0 -dn -c copy -metadata 'title=[Arknights CN] Random Blemishine stuff' -metadata date=20201017 -metadata 'description=Powered by Restream https://restream.io/

My Discord Server: https://discord.gg/kbhVGst
My Twitch Channel: https://www.twitch.tv/25thnight_
CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
Thank you.' -metadata 'comment=Powered by Restream https://restream.io/

My Discord Server: https://discord.gg/kbhVGst
My Twitch Channel: https://www.twitch.tv/25thnight_
CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
Thank you.' -metadata 'purl=https://www.youtube.com/watch?v=eBL5MOaTr80' -metadata artist=25thNight 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.temp.mkv'
[debug] ffprobe command line: ffprobe -hide_banner -show_format -show_streams -print_format json 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv'
[EmbedThumbnail] Adding thumbnail to "/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv' -c copy -map 0 -dn -attach '/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.jpg' -metadata:s:2 mimetype=image/jpeg -metadata:s:2 filename=cover.jpg 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.temp.mkv'

real	1m16.462s
user	0m25.305s
sys	0m9.965s
```
Now I tried to do them simultaneously with this command (which does virtually the same thing):
```
time yt-dlp -f 299,251 -v -o '/content/youtube/%(uploader)s/[%(upload_date)s] - %(title)s-%(id)s.f%(format_id)s.%(ext)s' "https://www.youtube.com/watch?v=eBL5MOaTr80" && time ffmpeg -y -loglevel repeat+info -i 'file:/content/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f299.mp4' -i 'file:/content/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f251.webm' -c copy -map 0:v:0 -map 1:a:0 -metadata 'title=[Arknights CN] Random Blemishine stuff' -metadata date=20201017 -metadata 'description=Powered by Restream https://restream.io/

My Discord Server: https://discord.gg/kbhVGst
My Twitch Channel: https://www.twitch.tv/25thnight_
CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
Thank you.' -metadata 'comment=Powered by Restream https://restream.io/

My Discord Server: https://discord.gg/kbhVGst
My Twitch Channel: https://www.twitch.tv/25thnight_
CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
Thank you.' -metadata 'purl=https://www.youtube.com/watch?v=eBL5MOaTr80' -metadata artist=25thNight -attach '/content/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.info.json' -metadata:s:2 mimetype=application/json -attach '/content/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.jpg' -metadata:s:3 mimetype=image/jpeg -metadata:s:3 filename=cover.jpg 'file:/content/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv'
```

And the output is:
```
[debug] Loading archive file None
[youtube] eBL5MOaTr80: Downloading webpage
[youtube] eBL5MOaTr80: Downloading MPD manifest
[debug] Sort order given by user: 
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[info] Downloading format(s) 299, 251
[info] eBL5MOaTr80: downloading video in 2 formats
[download] /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f299.mp4 has already been downloaded
[download] /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f251.webm has already been downloaded

[debug] Command-line config: ['-f', '299,251', '-v', '-o', '/home/youtube/%(uploader)s/[%(upload_date)s] - %(title)s-%(id)s.f%(format_id)s.%(ext)s', 'https://www.youtube.com/watch?v=eBL5MOaTr80']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] yt-dlp version 2021.03.01 
[debug] Python version 3.7.10 (CPython 64bit) - Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
[debug] exe versions: ffmpeg 3.4.8, ffprobe 3.4.8
[debug] Proxy map: {}

real	0m3.259s
user	0m1.538s
sys	0m0.404s



ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f299.mp4':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    creation_time   : 2020-10-17T13:44:38.000000Z
  Duration: 01:02:20.33, start: 0.000000, bitrate: 3799 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 0 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      creation_time   : 2020-10-17T13:44:38.000000Z
      handler_name    : ISO Media file produced by Google Inc.
Input #1, matroska,webm, from 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.f251.webm':
  Metadata:
    encoder         : google/video-file
  Duration: 01:02:20.34, start: -0.007000, bitrate: 126 kb/s
    Stream #1:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, matroska, to 'file:/home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.mkv':
  Metadata:
    major_brand     : dash
    minor_version   : 0
    compatible_brands: iso6avc1mp41
    title           : [Arknights CN] Random Blemishine stuff
    date            : 20201017
    description     : Powered by Restream https://restream.io/
                    : 
                    : My Discord Server: https://discord.gg/kbhVGst
                    : My Twitch Channel: https://www.twitch.tv/25thnight_
                    : CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
                    : Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
                    : Thank you.
    comment         : Powered by Restream https://restream.io/
                    : 
                    : My Discord Server: https://discord.gg/kbhVGst
                    : My Twitch Channel: https://www.twitch.tv/25thnight_
                    : CC#0 Prep Guide Video: https://youtu.be/t9JE0vK5ovE
                    : Making these videos take up quite some time of my day, if you like the video please consider becoming a Patron:  https://www.patreon.com/25thNight?fan_landing=true
                    : Thank you.
    purl            : https://www.youtube.com/watch?v=eBL5MOaTr80
    artist          : 25thNight
    encoder         : Lavf57.83.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 0 kb/s, 60 fps, 60 tbr, 1k tbn, 15360 tbc (default)
    Metadata:
      creation_time   : 2020-10-17T13:44:38.000000Z
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(eng): Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, stereo, fltp (default)
    Stream #0:2: Attachment: none
    Metadata:
      filename        : [20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.info.json
      mimetype        : application/json
    Stream #0:3: Attachment: none
    Metadata:
      mimetype        : image/jpeg
      filename        : cover.jpg
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
  File /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.info.json -> Stream #0:2
  File /home/youtube/25thNight/[20201017] - [Arknights CN] Random Blemishine stuff-eBL5MOaTr80.jpg -> Stream #0:3
Press [q] to stop, [?] for help
frame=224420 fps=6568 q=-1.0 Lsize= 1792398kB time=01:02:20.32 bitrate=3925.7kbits/s speed= 109x    
video:1732133kB audio:56548kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.207820%

real	0m34.239s
user	0m8.827s
sys	0m4.683s
```
Simultaneously doing this is much faster as seen from the time (almost half) and the time difference only gets better for the longer videos.