Repository: yt-dlp
Issue: Postprocessing: Conversion failed! on already downloaded .opus files when using `--embed-metadata` and `--embed-thumbnail`
Labels: bug,external issue,core:post-processor

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Provide a description that is worded well enough to be understood

The initial download works fine, and adds the thumbnail and other metadata to the downloaded file. However when the command is run again and the file already exists, it gives this error and leaves behind temporary files. I haven't tested many different codecs, but I can confirm that this happens with .opus files and does not happen with .mp3 files. It only happens when both `--embed-metadata` and `--embed-thumbnail` are enabled.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
yt-dlp https://soundcloud.com/one-thousand-and-one/test-track --embed-metadata --embed-thumbnail -vU
[debug] Command-line config: ['https://soundcloud.com/one-thousand-and-one/test-track', '--embed-metadata', '--embed-thumbnail', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2024.11.04 from yt-dlp/yt-dlp [197d0b03b] (pip)
[debug] Python 3.13.0 (CPython arm64 64bit) - macOS-14.4-arm64-arm-64bit-Mach-O (OpenSSL 3.4.0 22 Oct 2024)
[debug] exe versions: ffmpeg 7.0.1 (setts), ffprobe 7.0.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, sqlite3-3.47.0, urllib3-2.2.3, websockets-13.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1838 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: stable@2024.11.04 from yt-dlp/yt-dlp
yt-dlp is up to date (stable@2024.11.04 from yt-dlp/yt-dlp)
[debug] Loading soundcloud.client_id from cache
[soundcloud] Extracting URL: https://soundcloud.com/one-thousand-and-one/test-track
[soundcloud] one-thousand-and-one/test-track: Downloading info JSON
[soundcloud] 1855267053: Downloading hls_mp3 format info JSON
[soundcloud] 1855267053: Downloading http_mp3 format info JSON
[soundcloud] 1855267053: Downloading hls_opus format info JSON
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec, channels, acodec, size, br, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 1855267053: Downloading 1 format(s): hls_opus_64
Deleting existing file testing - test track [1855267053].jpg
[info] Downloading video thumbnail original ...
[info] Writing video thumbnail original to: testing - test track [1855267053].jpg
[debug] Invoking hlsnative downloader on "https://cf-hls-opus-media.sndcdn.com/playlist/be017829-5fd5-4ba3-96e2-f508d119ff52.64.opus/playlist.m3u8?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLWhscy1vcHVzLW1lZGlhLnNuZGNkbi5jb20vcGxheWxpc3QvYmUwMTc4MjktNWZkNS00YmEzLTk2ZTItZjUwOGQxMTlmZjUyLjY0Lm9wdXMvcGxheWxpc3QubTN1OCoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE3MzExODc1Nzd9fX1dfQ__&Signature=QWxWNVVhY23gwkCcIPFU~jauXi6q9dy0HyJqLkfrdrsIqvALxZgYjJhta2EhAx4yOSmiKhNqZskNrupiCiQW9Dda8xqn18QH5Riyk6yEdZDBU54A1L~Q4YTCWalrj9-tkiB8zOqbfvrApbimEgtWIrFomGDMTVyGgd8ioeKsIskTkCnlaI~zBv0k8Mx-lSRxRWrTZc1mWFf7Xq8s8DP6piiBnEKoC0SejyQr4D9eb1lGeH~nNI-m9WIG8yZ4UGXskbC3iXDjkDu5e67~BWKQAt-T7NjrJMMCxIx0zsRCQaPKk~WjB6pDYFXhX2dqpetjE6w1xmXSnczeAdd9cXVKCg__&Key-Pair-Id=APKAI6TU7MMXM5DG6EPQ"
[download] testing - test track [1855267053].opus has already been downloaded
[download] 100% of   16.90KiB
[Metadata] Adding metadata to "testing - test track [1855267053].opus"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:testing - test track [1855267053].opus' -map 0 -dn -ignore_unknown -c copy -write_id3v1 1 -metadata 'title=testing - test track' -metadata date=20240623 -metadata 'description=test description:
9439290883' -metadata 'synopsis=test description:
9439290883' -metadata purl=https://soundcloud.com/one-thousand-and-one/test-track -metadata comment=https://soundcloud.com/one-thousand-and-one/test-track -metadata artist=7x11x13-testing -metadata genre=Testing -movflags +faststart 'file:testing - test track [1855267053].temp.opus'
[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=/opt/homebrew/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 --enable-neon
  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
[ogg @ 0x12e704a60] 1035 bytes of comment header remain
Input #0, ogg, from 'file:testing - test track [1855267053].opus':
  Duration: 00:00:01.01, start: 0.000000, bitrate: 137 kb/s
  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
      Metadata:
        encoder         : Lavc58.91.100 libopus
        title           : testing - test track
        date            : 20240623
        purl            : https://soundcloud.com/one-thousand-and-one/test-track
        synopsis        : test description:
                        : 9439290883
        genre           : Testing
        artist          : 7x11x13-testing
        comment         : test description:
                        : 9439290883
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 180x180 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn (attached pic)
      Metadata:
        comment         : Cover (front)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
[opus @ 0x12e6062b0] Unsupported codec id in stream 1
[out#0/opus @ 0x600003ecc3c0] Could not write header (incorrect codec parameters ?): Invalid argument
Conversion failed!

ERROR: Postprocessing: Conversion failed!
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/YoutubeDL.py", line 3557, in process_info
    replace_info_dict(self.post_process(dl_filename, info_dict, files_to_move))
                      ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/YoutubeDL.py", line 3741, in post_process
    info = self.run_all_pps('post_process', info, additional_pps=info.get('__postprocessors'))
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/YoutubeDL.py", line 3723, in run_all_pps
    info = self.run_pp(pp, info)
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/YoutubeDL.py", line 3701, in run_pp
    files_to_delete, infodict = pp.run(infodict)
                                ~~~~~~^^^^^^^^^^
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/postprocessor/common.py", line 23, in run
    ret = func(self, info, *args, **kwargs)
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/postprocessor/common.py", line 128, in wrapper
    return func(self, info)
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 712, in run
    self.run_ffmpeg_multiple_files(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        (filename, metadata_filename), temp_filename,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        itertools.chain(self._options(info['ext']), *options))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 330, in run_ffmpeg_multiple_files
    return self.real_run_ffmpeg(
           ~~~~~~~~~~~~~~~~~~~~^
        [(path, []) for path in input_paths],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        [(out_path, opts)], **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/yt-dlp/2024.11.4/libexec/lib/python3.13/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!
```