1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00

avformat/img2dec: only probe image demuxers for the codec

When the codec is not specified, image2 probes the first file with
av_probe_input_format3() and only uses the result if the winner is an
image demuxer. Any other format scoring higher for the same file thus
leaves the codec unset, even if an image demuxer would match.

Probe only the image demuxers instead. This is needed for the upcoming
jpeg_mpf demuxer, which outscores jpeg_pipe on MPF files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas
2026-10-23 19:02:17 +02:00
committed by James Almer
parent 5d20365bb4
commit a84069e128

View File

@@ -421,10 +421,11 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
if (par->codec_id == AV_CODEC_ID_NONE) {
AVProbeData pd = { 0 };
const FFInputFormat *ifmt;
const AVInputFormat *fmt;
void *opaque = NULL;
uint8_t header[PROBE_BUF_MIN + AVPROBE_PADDING_SIZE];
int ret;
int score = 0;
int score_max = 0;
ret = avio_read(f[0], header, PROBE_BUF_MIN);
if (ret < 0) {
@@ -437,9 +438,20 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
pd.buf_size = ret;
pd.filename = filename.str;
ifmt = ffifmt(av_probe_input_format3(&pd, 1, &score));
if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id)
par->codec_id = ifmt->raw_codec_id;
/* Only consider image demuxers, so that other formats claiming
* the same file don't shadow them */
while ((fmt = av_demuxer_iterate(&opaque))) {
const FFInputFormat *ifmt = ffifmt(fmt);
if (ifmt->read_packet != ff_img_read_packet || !ifmt->raw_codec_id)
continue;
int score = ifmt->read_probe(&pd);
if (score > score_max) {
score_max = score;
par->codec_id = ifmt->raw_codec_id;
} else if (score == score_max) {
par->codec_id = AV_CODEC_ID_NONE;
}
}
}
if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)