Repository: yt-dlp
Issue: [Reddit] Thumbnail format conversion fails since it's JPG with .PNG extension
Labels: site-bug

### 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 that a **supported** site is broken
- [X] I've verified that I'm running yt-dlp version **2023.03.04** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [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)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Ukraine

### Provide a description that is worded well enough to be understood

When downloading any video from Reddit with `--write-thumbnail --convert-thumbnails jpg` args, ffmpeg fails to convert the thumbnail because yt-dlp downloaded `JPG` file with `.png` extension (`format=pjpg` query param in the URL despite the URL file extension is `.png`)

```json
    {
      "url": "https://external-preview.redd.it/Osz9UnNJQx9S24UMZJEQ_v_iOn-58yE3vAT0lXLUDTM.png?format=pjpg&auto=webp&v=enabled&s=bc0f71ad17544d26e82cf0bcf35e412ca61e966d",
      "width": 848,
      "height": 464,
      "id": "4",
      "resolution": "848x464"
    }
```

Headers:
```bash
curl -I "https://external-preview.redd.it/Osz9UnNJQx9S24UMZJEQ_v_iOn-58yE3vAT0lXLUDTM.png?format=pjpg&auto=webp&v=enabled&s=bc0f71ad17544d26e82cf0bcf35e412ca61e966d"
***
content-type: image/jpeg
reddit-io-info: ifsz=614173 idim=848x464 ifmt=png ofsz=47655 odim=848x464 ofmt=pjpg
***
```



Fails on both ffmpeg versions 4 & 5:
```bash
[debug] ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
[debug] ffmpeg version 5.1.3 Copyright (c) 2000-2022 the FFmpeg developers
``` 

### 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 -vU https://www.reddit.com/r/CombatFootage/comments/12s4sd3/attack_on_russian_trench_by_foreign_fighters_pows/ --write-thumbnail --convert-thumbnails jpg
[debug] Command-line config: ['-vU', 'https://www.reddit.com/r/CombatFootage/comments/12s4sd3/attack_on_russian_trench_by_foreign_fighters_pows/', '--write-thumbnail', '--convert-thumbnails', 'jpg']
[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@2023.03.04 [392389b7d] (pip)
[debug] Python 3.11.3 (CPython x86_64 64bit) - Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31 (OpenSSL 1.1.1f  31 Mar 2020, glibc 2.31)
[debug] exe versions: ffmpeg 4.2.7, ffprobe 4.2.7
[debug] Optional libraries: Cryptodome-3.17, brotli-1.0.9, certifi-2022.12.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-11.0.2
[debug] Proxy map: {}
[debug] Loaded 1786 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.03.04, Current version: stable@2023.03.04
yt-dlp is up to date (stable@2023.03.04)
[Reddit] Extracting URL: https://www.reddit.com/r/CombatFootage/comments/12s4sd3/attack_on_russian_trench_by_foreign_fighters_pows/
[Reddit] 12s4sd3: Downloading JSON metadata
[Reddit] 12s4sd3: Downloading m3u8 information
[Reddit] 12s4sd3: Downloading MPD manifest
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] igsekhv69xua1: Downloading 1 format(s): dash-video_803102+dash-audio_0_131975
Deleting existing file Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].png
[info] Downloading video thumbnail 4 ...
[info] Writing video thumbnail 4 to: Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].png
[ThumbnailsConvertor] Converting thumbnail "Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].png" to jpg
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -f image2 -pattern_type none -i 'file:Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].png' -update 1 -bsf:v mjpeg2jpeg -movflags +faststart 'file:Attack on Russian trench,by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].jpg'
[debug] ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[png @ 0x55ff138b5f00] Invalid PNG signature 0xFFD8FFDB00430005.
[image2 @ 0x55ff138b4440] decoding for stream 0 failed
[image2 @ 0x55ff138b4440] Could not find codec parameters for stream 0 (Video: png, none(pc)): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, image2, from 'file:Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, none(pc), 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[png @ 0x55ff138ce640] Invalid PNG signature 0xFFD8FFDB00430005.
Error while decoding stream #0:0: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

ERROR: Preprocessing: Conversion failed!
Traceback (most recent call last):
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 3491, in pre_process
    info = self.run_all_pps(key, info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 3484, in run_all_pps
    info = self.run_pp(pp, info)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/YoutubeDL.py", line 3462, in run_pp
    files_to_delete, infodict = pp.run(infodict)
                                ^^^^^^^^^^^^^^^^
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/postprocessor/common.py", line 24, in run
    ret = func(self, info, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 1119, in run
    thumbnail_dict['filepath'] = self.convert_thumbnail(original_thumbnail, target_ext)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 1096, in convert_thumbnail
    self.real_run_ffmpeg(
  File "/home/troppie/.pyenv/versions/3.11.3/lib/python3.11/site-packages/yt_dlp/postprocessor/ffmpeg.py", line 362, in real_run_ffmpeg
    raise FFmpegPostProcessorError(stderr.strip().splitlines()[-1])
yt_dlp.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!

[download] Attack on Russian trench, by foreign fighters. POWs taken in the end. Date and location unknown [igsekhv69xua1].mp4 has already been downloaded
ERROR: Preprocessing: Conversion failed!
```