1 /*
2  * Image format
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  * Copyright (c) 2004 Michael Niedermayer
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config_components.h"
24 
25 #define _DEFAULT_SOURCE
26 #define _BSD_SOURCE
27 #include <sys/stat.h>
28 #include "libavutil/avstring.h"
29 #include "libavutil/log.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/parseutils.h"
33 #include "libavutil/intreadwrite.h"
34 #include "libavcodec/gif.h"
35 #include "avformat.h"
36 #include "avio_internal.h"
37 #include "internal.h"
38 #include "img2.h"
39 #include "jpegxl_probe.h"
40 #include "libavcodec/mjpeg.h"
41 #include "libavcodec/vbn.h"
42 #include "libavcodec/xwd.h"
43 #include "subtitles.h"
44 
45 #if HAVE_GLOB
46 /* Locally define as 0 (bitwise-OR no-op) any missing glob options that
47    are non-posix glibc/bsd extensions. */
48 #ifndef GLOB_NOMAGIC
49 #define GLOB_NOMAGIC 0
50 #endif
51 #ifndef GLOB_BRACE
52 #define GLOB_BRACE 0
53 #endif
54 
55 #endif /* HAVE_GLOB */
56 
57 static const int sizes[][2] = {
58     { 640, 480 },
59     { 720, 480 },
60     { 720, 576 },
61     { 352, 288 },
62     { 352, 240 },
63     { 160, 128 },
64     { 512, 384 },
65     { 640, 352 },
66     { 640, 240 },
67 };
68 
infer_size(int *width_ptr, int *height_ptr, int size)69 static int infer_size(int *width_ptr, int *height_ptr, int size)
70 {
71     int i;
72 
73     for (i = 0; i < FF_ARRAY_ELEMS(sizes); i++) {
74         if ((sizes[i][0] * sizes[i][1]) == size) {
75             *width_ptr  = sizes[i][0];
76             *height_ptr = sizes[i][1];
77             return 0;
78         }
79     }
80 
81     return -1;
82 }
83 
is_glob(const char *path)84 static int is_glob(const char *path)
85 {
86 #if HAVE_GLOB
87     size_t span = 0;
88     const char *p = path;
89 
90     while (p = strchr(p, '%')) {
91         if (*(++p) == '%') {
92             ++p;
93             continue;
94         }
95         if (span = strspn(p, "*?[]{}"))
96             break;
97     }
98     /* Did we hit a glob char or get to the end? */
99     return span != 0;
100 #else
101     return 0;
102 #endif
103 }
104 
105 /**
106  * Get index range of image files matched by path.
107  *
108  * @param pfirst_index pointer to index updated with the first number in the range
109  * @param plast_index  pointer to index updated with the last number in the range
110  * @param path         path which has to be matched by the image files in the range
111  * @param start_index  minimum accepted value for the first index in the range
112  * @return -1 if no image file could be found
113  */
find_image_range(AVIOContext *pb, int *pfirst_index, int *plast_index, const char *path, int start_index, int start_index_range)114 static int find_image_range(AVIOContext *pb, int *pfirst_index, int *plast_index,
115                             const char *path, int start_index, int start_index_range)
116 {
117     char buf[1024];
118     int range, last_index, range1, first_index;
119 
120     /* find the first image */
121     for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
122         if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {
123             *pfirst_index =
124             *plast_index  = 1;
125             if (pb || avio_check(buf, AVIO_FLAG_READ) > 0)
126                 return 0;
127             return -1;
128         }
129         if (avio_check(buf, AVIO_FLAG_READ) > 0)
130             break;
131     }
132     if (first_index == start_index + start_index_range)
133         goto fail;
134 
135     /* find the last image */
136     last_index = first_index;
137     for (;;) {
138         range = 0;
139         for (;;) {
140             if (!range)
141                 range1 = 1;
142             else
143                 range1 = 2 * range;
144             if (av_get_frame_filename(buf, sizeof(buf), path,
145                                       last_index + range1) < 0)
146                 goto fail;
147             if (avio_check(buf, AVIO_FLAG_READ) <= 0)
148                 break;
149             range = range1;
150             /* just in case... */
151             if (range >= (1 << 30))
152                 goto fail;
153         }
154         /* we are sure than image last_index + range exists */
155         if (!range)
156             break;
157         last_index += range;
158     }
159     *pfirst_index = first_index;
160     *plast_index  = last_index;
161     return 0;
162 
163 fail:
164     return -1;
165 }
166 
img_read_probe(const AVProbeData *p)167 static int img_read_probe(const AVProbeData *p)
168 {
169     if (p->filename && ff_guess_image2_codec(p->filename)) {
170         if (av_filename_number_test(p->filename))
171             return AVPROBE_SCORE_MAX;
172         else if (is_glob(p->filename))
173             return AVPROBE_SCORE_MAX;
174         else if (p->filename[strcspn(p->filename, "*?{")]) // probably PT_GLOB
175             return AVPROBE_SCORE_EXTENSION + 2; // score chosen to be a tad above the image pipes
176         else if (p->buf_size == 0)
177             return 0;
178         else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif"))
179             return 5;
180         else
181             return AVPROBE_SCORE_EXTENSION;
182     }
183     return 0;
184 }
185 
ff_img_read_header(AVFormatContext *s1)186 int ff_img_read_header(AVFormatContext *s1)
187 {
188     VideoDemuxData *s = s1->priv_data;
189     int first_index = 1, last_index = 1;
190     AVStream *st;
191     enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
192 
193     s1->ctx_flags |= AVFMTCTX_NOHEADER;
194 
195     st = avformat_new_stream(s1, NULL);
196     if (!st) {
197         return AVERROR(ENOMEM);
198     }
199 
200     if (s->pixel_format &&
201         (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
202         av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n",
203                s->pixel_format);
204         return AVERROR(EINVAL);
205     }
206 
207     av_strlcpy(s->path, s1->url, sizeof(s->path));
208     s->img_number = 0;
209     s->img_count  = 0;
210 
211     /* find format */
212     if (s1->iformat->flags & AVFMT_NOFILE)
213         s->is_pipe = 0;
214     else {
215         s->is_pipe       = 1;
216         ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL;
217     }
218 
219     if (s->ts_from_file == 2) {
220 #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
221         av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
222         return AVERROR(ENOSYS);
223 #endif
224         avpriv_set_pts_info(st, 64, 1, 1000000000);
225     } else if (s->ts_from_file)
226         avpriv_set_pts_info(st, 64, 1, 1);
227     else {
228         avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
229         st->avg_frame_rate = st->r_frame_rate = s->framerate;
230     }
231 
232     if (s->width && s->height) {
233         st->codecpar->width  = s->width;
234         st->codecpar->height = s->height;
235     }
236 
237     if (!s->is_pipe) {
238         if (s->pattern_type == PT_DEFAULT) {
239             if (s1->pb) {
240                 s->pattern_type = PT_NONE;
241             } else
242                 s->pattern_type = PT_GLOB_SEQUENCE;
243         }
244 
245         if (s->pattern_type == PT_GLOB_SEQUENCE) {
246         s->use_glob = is_glob(s->path);
247         if (s->use_glob) {
248 #if HAVE_GLOB
249             char *p = s->path, *q, *dup;
250             int gerr;
251 #endif
252 
253             av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
254                    "use pattern_type 'glob' instead\n");
255 #if HAVE_GLOB
256             dup = q = av_strdup(p);
257             while (*q) {
258                 /* Do we have room for the next char and a \ insertion? */
259                 if ((p - s->path) >= (sizeof(s->path) - 2))
260                   break;
261                 if (*q == '%' && strspn(q + 1, "%*?[]{}"))
262                     ++q;
263                 else if (strspn(q, "\\*?[]{}"))
264                     *p++ = '\\';
265                 *p++ = *q++;
266             }
267             *p = 0;
268             av_free(dup);
269 
270             gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
271             if (gerr != 0) {
272                 return AVERROR(ENOENT);
273             }
274             first_index = 0;
275             last_index = s->globstate.gl_pathc - 1;
276 #endif
277         }
278         }
279         if ((s->pattern_type == PT_GLOB_SEQUENCE && !s->use_glob) || s->pattern_type == PT_SEQUENCE) {
280             if (find_image_range(s1->pb, &first_index, &last_index, s->path,
281                                  s->start_number, s->start_number_range) < 0) {
282                 av_log(s1, AV_LOG_ERROR,
283                        "Could find no file with path '%s' and index in the range %d-%d\n",
284                        s->path, s->start_number, s->start_number + s->start_number_range - 1);
285                 return AVERROR(ENOENT);
286             }
287         } else if (s->pattern_type == PT_GLOB) {
288 #if HAVE_GLOB
289             int gerr;
290             gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
291             if (gerr != 0) {
292                 return AVERROR(ENOENT);
293             }
294             first_index = 0;
295             last_index = s->globstate.gl_pathc - 1;
296             s->use_glob = 1;
297 #else
298             av_log(s1, AV_LOG_ERROR,
299                    "Pattern type 'glob' was selected but globbing "
300                    "is not supported by this libavformat build\n");
301             return AVERROR(ENOSYS);
302 #endif
303         } else if (s->pattern_type != PT_GLOB_SEQUENCE && s->pattern_type != PT_NONE) {
304             av_log(s1, AV_LOG_ERROR,
305                    "Unknown value '%d' for pattern_type option\n", s->pattern_type);
306             return AVERROR(EINVAL);
307         }
308         s->img_first  = first_index;
309         s->img_last   = last_index;
310         s->img_number = first_index;
311         /* compute duration */
312         if (!s->ts_from_file) {
313             st->start_time = 0;
314             st->duration   = last_index - first_index + 1;
315         }
316     }
317 
318     if (s1->video_codec_id) {
319         st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
320         st->codecpar->codec_id   = s1->video_codec_id;
321     } else if (s1->audio_codec_id) {
322         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
323         st->codecpar->codec_id   = s1->audio_codec_id;
324     } else if (s1->iformat->raw_codec_id) {
325         st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
326         st->codecpar->codec_id   = s1->iformat->raw_codec_id;
327     } else {
328         const char *str = strrchr(s->path, '.');
329         s->split_planes       = str && !av_strcasecmp(str + 1, "y");
330         st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
331         if (s1->pb) {
332             int probe_buffer_size = 2048;
333             uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE);
334             const AVInputFormat *fmt = NULL;
335             void *fmt_iter = NULL;
336             AVProbeData pd = { 0 };
337 
338             if (!probe_buffer)
339                 return AVERROR(ENOMEM);
340 
341             probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size);
342             if (probe_buffer_size < 0) {
343                 av_free(probe_buffer);
344                 return probe_buffer_size;
345             }
346             memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE);
347 
348             pd.buf = probe_buffer;
349             pd.buf_size = probe_buffer_size;
350             pd.filename = s1->url;
351 
352             while ((fmt = av_demuxer_iterate(&fmt_iter))) {
353                 if (fmt->read_header != ff_img_read_header ||
354                     !fmt->read_probe ||
355                     (fmt->flags & AVFMT_NOFILE) ||
356                     !fmt->raw_codec_id)
357                     continue;
358                 if (fmt->read_probe(&pd) > 0) {
359                     st->codecpar->codec_id = fmt->raw_codec_id;
360                     break;
361                 }
362             }
363             if (s1->flags & AVFMT_FLAG_CUSTOM_IO) {
364                 avio_seek(s1->pb, 0, SEEK_SET);
365                 av_freep(&probe_buffer);
366             } else
367                 ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size);
368         }
369         if (st->codecpar->codec_id == AV_CODEC_ID_NONE)
370             st->codecpar->codec_id = ff_guess_image2_codec(s->path);
371         if (st->codecpar->codec_id == AV_CODEC_ID_LJPEG)
372             st->codecpar->codec_id = AV_CODEC_ID_MJPEG;
373         if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX
374             st->codecpar->codec_id = AV_CODEC_ID_NONE;
375     }
376     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
377         pix_fmt != AV_PIX_FMT_NONE)
378         st->codecpar->format = pix_fmt;
379 
380     return 0;
381 }
382 
383 /**
384  * Add this frame's source path and basename to packet's sidedata
385  * as a dictionary, so it can be used by filters like 'drawtext'.
386  */
add_filename_as_pkt_side_data(char *filename, AVPacket *pkt)387 static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) {
388     AVDictionary *d = NULL;
389     char *packed_metadata = NULL;
390     size_t metadata_len;
391     int ret;
392 
393     av_dict_set(&d, "lavf.image2dec.source_path", filename, 0);
394     av_dict_set(&d, "lavf.image2dec.source_basename", av_basename(filename), 0);
395 
396     packed_metadata = av_packet_pack_dictionary(d, &metadata_len);
397     av_dict_free(&d);
398     if (!packed_metadata)
399         return AVERROR(ENOMEM);
400     ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
401                                   packed_metadata, metadata_len);
402     if (ret < 0) {
403         av_freep(&packed_metadata);
404         return ret;
405     }
406     return 0;
407 }
408 
ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)409 int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
410 {
411     VideoDemuxData *s = s1->priv_data;
412     char filename_bytes[1024];
413     char *filename = filename_bytes;
414     int i, res;
415     int size[3]           = { 0 }, ret[3] = { 0 };
416     AVIOContext *f[3]     = { NULL };
417     AVCodecParameters *par = s1->streams[0]->codecpar;
418 
419     if (!s->is_pipe) {
420         /* loop over input */
421         if (s->loop && s->img_number > s->img_last) {
422             s->img_number = s->img_first;
423         }
424         if (s->img_number > s->img_last)
425             return AVERROR_EOF;
426         if (s->pattern_type == PT_NONE) {
427             av_strlcpy(filename_bytes, s->path, sizeof(filename_bytes));
428         } else if (s->use_glob) {
429 #if HAVE_GLOB
430             filename = s->globstate.gl_pathv[s->img_number];
431 #endif
432         } else {
433         if (av_get_frame_filename(filename_bytes, sizeof(filename_bytes),
434                                   s->path,
435                                   s->img_number) < 0 && s->img_number > 1)
436             return AVERROR(EIO);
437         }
438         for (i = 0; i < 3; i++) {
439             if (s1->pb &&
440                 !strcmp(filename_bytes, s->path) &&
441                 !s->loop &&
442                 !s->split_planes) {
443                 f[i] = s1->pb;
444             } else if (s1->io_open(s1, &f[i], filename, AVIO_FLAG_READ, NULL) < 0) {
445                 if (i >= 1)
446                     break;
447                 av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",
448                        filename);
449                 return AVERROR(EIO);
450             }
451             size[i] = avio_size(f[i]);
452 
453             if (!s->split_planes)
454                 break;
455             filename[strlen(filename) - 1] = 'U' + i;
456         }
457 
458         if (par->codec_id == AV_CODEC_ID_NONE) {
459             AVProbeData pd = { 0 };
460             const AVInputFormat *ifmt;
461             uint8_t header[PROBE_BUF_MIN + AVPROBE_PADDING_SIZE];
462             int ret;
463             int score = 0;
464 
465             ret = avio_read(f[0], header, PROBE_BUF_MIN);
466             if (ret < 0)
467                 return ret;
468             memset(header + ret, 0, sizeof(header) - ret);
469             avio_skip(f[0], -ret);
470             pd.buf = header;
471             pd.buf_size = ret;
472             pd.filename = filename;
473 
474             ifmt = av_probe_input_format3(&pd, 1, &score);
475             if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id)
476                 par->codec_id = ifmt->raw_codec_id;
477         }
478 
479         if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
480             infer_size(&par->width, &par->height, size[0]);
481     } else {
482         f[0] = s1->pb;
483         if (avio_feof(f[0]) && s->loop && s->is_pipe)
484             avio_seek(f[0], 0, SEEK_SET);
485         if (avio_feof(f[0]))
486             return AVERROR_EOF;
487         if (s->frame_size > 0) {
488             size[0] = s->frame_size;
489         } else if (!ffstream(s1->streams[0])->parser) {
490             size[0] = avio_size(s1->pb);
491         } else {
492             size[0] = 4096;
493         }
494     }
495 
496     res = av_new_packet(pkt, size[0] + size[1] + size[2]);
497     if (res < 0) {
498         goto fail;
499     }
500     pkt->stream_index = 0;
501     pkt->flags       |= AV_PKT_FLAG_KEY;
502     if (s->ts_from_file) {
503         struct stat img_stat;
504         if (stat(filename, &img_stat)) {
505             res = AVERROR(EIO);
506             goto fail;
507         }
508         pkt->pts = (int64_t)img_stat.st_mtime;
509 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
510         if (s->ts_from_file == 2)
511             pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
512 #endif
513         av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
514     } else if (!s->is_pipe) {
515         pkt->pts      = s->pts;
516     }
517 
518     if (s->is_pipe)
519         pkt->pos = avio_tell(f[0]);
520 
521     /*
522      * export_path_metadata must be explicitly enabled via
523      * command line options for path metadata to be exported
524      * as packet side_data.
525      */
526     if (!s->is_pipe && s->export_path_metadata == 1) {
527         res = add_filename_as_pkt_side_data(filename, pkt);
528         if (res < 0)
529             goto fail;
530     }
531 
532     pkt->size = 0;
533     for (i = 0; i < 3; i++) {
534         if (f[i]) {
535             ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
536             if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) {
537                 if (avio_seek(f[i], 0, SEEK_SET) >= 0) {
538                     pkt->pos = 0;
539                     ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
540                 }
541             }
542             if (!s->is_pipe && f[i] != s1->pb)
543                 ff_format_io_close(s1, &f[i]);
544             if (ret[i] > 0)
545                 pkt->size += ret[i];
546         }
547     }
548 
549     if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
550         if (ret[0] < 0) {
551             res = ret[0];
552         } else if (ret[1] < 0) {
553             res = ret[1];
554         } else if (ret[2] < 0) {
555             res = ret[2];
556         } else {
557             res = AVERROR_EOF;
558         }
559         goto fail;
560     } else {
561         memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
562         s->img_count++;
563         s->img_number++;
564         s->pts++;
565         return 0;
566     }
567 
568 fail:
569     if (!s->is_pipe) {
570         for (i = 0; i < 3; i++) {
571             if (f[i] != s1->pb)
572                 ff_format_io_close(s1, &f[i]);
573         }
574     }
575     return res;
576 }
577 
img_read_close(struct AVFormatContext* s1)578 static int img_read_close(struct AVFormatContext* s1)
579 {
580 #if HAVE_GLOB
581     VideoDemuxData *s = s1->priv_data;
582     if (s->use_glob) {
583         globfree(&s->globstate);
584     }
585 #endif
586     return 0;
587 }
588 
img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)589 static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
590 {
591     VideoDemuxData *s1 = s->priv_data;
592     AVStream *st = s->streams[0];
593 
594     if (s1->ts_from_file) {
595         int index = av_index_search_timestamp(st, timestamp, flags);
596         if(index < 0)
597             return -1;
598         s1->img_number = ffstream(st)->index_entries[index].pos;
599         return 0;
600     }
601 
602     if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
603         return -1;
604     s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
605     s1->pts = timestamp;
606     return 0;
607 }
608 
609 #define OFFSET(x) offsetof(VideoDemuxData, x)
610 #define DEC AV_OPT_FLAG_DECODING_PARAM
611 #define COMMON_OPTIONS \
612     { "framerate",    "set the video framerate", OFFSET(framerate),    AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
613     { "pixel_format", "set video pixel format",  OFFSET(pixel_format), AV_OPT_TYPE_STRING,     {.str = NULL}, 0, 0,       DEC }, \
614     { "video_size",   "set video size",          OFFSET(width),        AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0,       DEC }, \
615     { "loop",         "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL,   {.i64 = 0   }, 0, 1,       DEC }, \
616     { NULL },
617 
618 #if CONFIG_IMAGE2_DEMUXER
619 const AVOption ff_img_options[] = {
620     { "pattern_type", "set pattern type",                    OFFSET(pattern_type), AV_OPT_TYPE_INT,    {.i64=PT_DEFAULT}, 0,       INT_MAX, DEC, "pattern_type"},
621     { "glob_sequence","select glob/sequence pattern type",   0, AV_OPT_TYPE_CONST,  {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
622     { "glob",         "select glob pattern type",            0, AV_OPT_TYPE_CONST,  {.i64=PT_GLOB         }, INT_MIN, INT_MAX, DEC, "pattern_type" },
623     { "sequence",     "select sequence pattern type",        0, AV_OPT_TYPE_CONST,  {.i64=PT_SEQUENCE     }, INT_MIN, INT_MAX, DEC, "pattern_type" },
624     { "none",         "disable pattern matching",            0, AV_OPT_TYPE_CONST,  {.i64=PT_NONE         }, INT_MIN, INT_MAX, DEC, "pattern_type" },
625     { "start_number", "set first number in the sequence",    OFFSET(start_number), AV_OPT_TYPE_INT,    {.i64 = 0   }, INT_MIN, INT_MAX, DEC },
626     { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.i64 = 5}, 1, INT_MAX, DEC },
627     { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT,    {.i64 = 0   }, 0, 2,       DEC, "ts_type" },
628     { "none", "none",                   0, AV_OPT_TYPE_CONST,    {.i64 = 0   }, 0, 2,       DEC, "ts_type" },
629     { "sec",  "second precision",       0, AV_OPT_TYPE_CONST,    {.i64 = 1   }, 0, 2,       DEC, "ts_type" },
630     { "ns",   "nano second precision",  0, AV_OPT_TYPE_CONST,    {.i64 = 2   }, 0, 2,       DEC, "ts_type" },
631     { "export_path_metadata", "enable metadata containing input path information", OFFSET(export_path_metadata), AV_OPT_TYPE_BOOL,   {.i64 = 0   }, 0, 1,       DEC }, \
632     COMMON_OPTIONS
633 };
634 
635 static const AVClass img2_class = {
636     .class_name = "image2 demuxer",
637     .item_name  = av_default_item_name,
638     .option     = ff_img_options,
639     .version    = LIBAVUTIL_VERSION_INT,
640 };
641 const AVInputFormat ff_image2_demuxer = {
642     .name           = "image2",
643     .long_name      = NULL_IF_CONFIG_SMALL("image2 sequence"),
644     .priv_data_size = sizeof(VideoDemuxData),
645     .read_probe     = img_read_probe,
646     .read_header    = ff_img_read_header,
647     .read_packet    = ff_img_read_packet,
648     .read_close     = img_read_close,
649     .read_seek      = img_read_seek,
650     .flags          = AVFMT_NOFILE,
651     .priv_class     = &img2_class,
652 };
653 #endif
654 
655 static const AVOption img2pipe_options[] = {
656     { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
657     COMMON_OPTIONS
658 };
659 static const AVClass imagepipe_class = {
660     .class_name = "imagepipe demuxer",
661     .item_name  = av_default_item_name,
662     .option     = img2pipe_options,
663     .version    = LIBAVUTIL_VERSION_INT,
664 };
665 
666 #if CONFIG_IMAGE2PIPE_DEMUXER
667 const AVInputFormat ff_image2pipe_demuxer = {
668     .name           = "image2pipe",
669     .long_name      = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
670     .priv_data_size = sizeof(VideoDemuxData),
671     .read_header    = ff_img_read_header,
672     .read_packet    = ff_img_read_packet,
673     .priv_class     = &imagepipe_class,
674 };
675 #endif
676 
bmp_probe(const AVProbeData *p)677 static int bmp_probe(const AVProbeData *p)
678 {
679     const uint8_t *b = p->buf;
680     int ihsize;
681 
682     if (AV_RB16(b) != 0x424d)
683         return 0;
684 
685     ihsize = AV_RL32(b+14);
686     if (ihsize < 12 || ihsize > 255)
687         return 0;
688 
689     if (!AV_RN32(b + 6)) {
690         return AVPROBE_SCORE_EXTENSION + 1;
691     }
692     return AVPROBE_SCORE_EXTENSION / 4;
693 }
694 
cri_probe(const AVProbeData *p)695 static int cri_probe(const AVProbeData *p)
696 {
697     const uint8_t *b = p->buf;
698 
699     if (   AV_RL32(b) == 1
700         && AV_RL32(b + 4) == 4
701         && AV_RN32(b + 8) == AV_RN32("DVCC"))
702         return AVPROBE_SCORE_MAX - 1;
703     return 0;
704 }
705 
dds_probe(const AVProbeData *p)706 static int dds_probe(const AVProbeData *p)
707 {
708     const uint8_t *b = p->buf;
709 
710     if (   AV_RB64(b) == 0x444453207c000000
711         && AV_RL32(b +  8)
712         && AV_RL32(b + 12))
713         return AVPROBE_SCORE_MAX - 1;
714     return 0;
715 }
716 
dpx_probe(const AVProbeData *p)717 static int dpx_probe(const AVProbeData *p)
718 {
719     const uint8_t *b = p->buf;
720     int w, h;
721     int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
722 
723     if (p->buf_size < 0x304+8)
724         return 0;
725     w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
726     h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
727     if (w <= 0 || h <= 0)
728         return 0;
729 
730     if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
731         return AVPROBE_SCORE_EXTENSION + 1;
732     return 0;
733 }
734 
exr_probe(const AVProbeData *p)735 static int exr_probe(const AVProbeData *p)
736 {
737     const uint8_t *b = p->buf;
738 
739     if (AV_RL32(b) == 20000630)
740         return AVPROBE_SCORE_EXTENSION + 1;
741     return 0;
742 }
743 
j2k_probe(const AVProbeData *p)744 static int j2k_probe(const AVProbeData *p)
745 {
746     const uint8_t *b = p->buf;
747 
748     if (AV_RB64(b) == 0x0000000c6a502020 ||
749         AV_RB32(b) == 0xff4fff51)
750         return AVPROBE_SCORE_EXTENSION + 1;
751     return 0;
752 }
753 
jpeg_probe(const AVProbeData *p)754 static int jpeg_probe(const AVProbeData *p)
755 {
756     const uint8_t *b = p->buf;
757     int i, state = SOI, got_header = 0;
758 
759     if (AV_RB16(b) != 0xFFD8 ||
760         AV_RB32(b) == 0xFFD8FFF7)
761     return 0;
762 
763     b += 2;
764     for (i = 0; i < p->buf_size - 3; i++) {
765         int c;
766         if (b[i] != 0xFF)
767             continue;
768         c = b[i + 1];
769         switch (c) {
770         case SOI:
771             return 0;
772         case SOF0:
773         case SOF1:
774         case SOF2:
775         case SOF3:
776         case SOF5:
777         case SOF6:
778         case SOF7:
779             i += AV_RB16(&b[i + 2]) + 1;
780             if (state != SOI)
781                 return 0;
782             state = SOF0;
783             break;
784         case SOS:
785             i += AV_RB16(&b[i + 2]) + 1;
786             if (state != SOF0 && state != SOS)
787                 return 0;
788             state = SOS;
789             break;
790         case EOI:
791             if (state != SOS)
792                 return 0;
793             state = EOI;
794             break;
795         case DQT:
796         case APP0:
797             if (AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F'))
798                 got_header = 1;
799         case APP1:
800             if (AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f'))
801                 got_header = 1;
802         case APP2:
803         case APP3:
804         case APP4:
805         case APP5:
806         case APP6:
807         case APP7:
808         case APP8:
809         case APP9:
810         case APP10:
811         case APP11:
812         case APP12:
813         case APP13:
814         case APP14:
815         case APP15:
816         case COM:
817             i += AV_RB16(&b[i + 2]) + 1;
818             break;
819         default:
820             if (  (c > TEM && c < SOF0)
821                 || c == JPG)
822                 return 0;
823         }
824     }
825 
826     if (state == EOI)
827         return AVPROBE_SCORE_EXTENSION + 1;
828     if (state == SOS)
829         return AVPROBE_SCORE_EXTENSION / 2 + got_header;
830     return AVPROBE_SCORE_EXTENSION / 8 + 1;
831 }
832 
jpegls_probe(const AVProbeData *p)833 static int jpegls_probe(const AVProbeData *p)
834 {
835     const uint8_t *b = p->buf;
836 
837     if (AV_RB32(b) == 0xffd8fff7)
838          return AVPROBE_SCORE_EXTENSION + 1;
839     return 0;
840 }
841 
jpegxl_probe(const AVProbeData *p)842 static int jpegxl_probe(const AVProbeData *p)
843 {
844     const uint8_t *b = p->buf;
845 
846     /* ISOBMFF-based container */
847     /* 0x4a584c20 == "JXL " */
848     if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
849         return AVPROBE_SCORE_EXTENSION + 1;
850     /* Raw codestreams all start with 0xff0a */
851     if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
852         return 0;
853 #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
854     if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)
855         return AVPROBE_SCORE_MAX - 2;
856 #endif
857     return 0;
858 }
859 
pcx_probe(const AVProbeData *p)860 static int pcx_probe(const AVProbeData *p)
861 {
862     const uint8_t *b = p->buf;
863 
864     if (   p->buf_size < 128
865         || b[0] != 10
866         || b[1] > 5
867         || b[2] > 1
868         || av_popcount(b[3]) != 1 || b[3] > 8
869         || AV_RL16(&b[4]) > AV_RL16(&b[8])
870         || AV_RL16(&b[6]) > AV_RL16(&b[10])
871         || b[64])
872         return 0;
873     b += 73;
874     while (++b < p->buf + 128)
875         if (*b)
876             return AVPROBE_SCORE_EXTENSION / 4;
877 
878     return AVPROBE_SCORE_EXTENSION + 1;
879 }
880 
qdraw_probe(const AVProbeData *p)881 static int qdraw_probe(const AVProbeData *p)
882 {
883     const uint8_t *b = p->buf;
884 
885     if (   p->buf_size >= 528
886         && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
887         && AV_RB16(b + 520)
888         && AV_RB16(b + 518))
889         return AVPROBE_SCORE_MAX * 3 / 4;
890     if (   (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
891         && AV_RB16(b + 8)
892         && AV_RB16(b + 6))
893         return AVPROBE_SCORE_EXTENSION / 4;
894     return 0;
895 }
896 
pictor_probe(const AVProbeData *p)897 static int pictor_probe(const AVProbeData *p)
898 {
899     const uint8_t *b = p->buf;
900 
901     if (AV_RL16(b) == 0x1234)
902         return AVPROBE_SCORE_EXTENSION / 4;
903     return 0;
904 }
905 
png_probe(const AVProbeData *p)906 static int png_probe(const AVProbeData *p)
907 {
908     const uint8_t *b = p->buf;
909 
910     if (AV_RB64(b) == 0x89504e470d0a1a0a)
911         return AVPROBE_SCORE_MAX - 1;
912     return 0;
913 }
914 
psd_probe(const AVProbeData *p)915 static int psd_probe(const AVProbeData *p)
916 {
917     const uint8_t *b = p->buf;
918     int ret = 0;
919     uint16_t color_mode;
920 
921     if (AV_RL32(b) == MKTAG('8','B','P','S')) {
922         ret += 1;
923     } else {
924         return 0;
925     }
926 
927     if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */
928         ret += 1;
929     } else {
930         return 0;
931     }
932 
933     if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */
934         ret += 1;
935 
936     color_mode = AV_RB16(b+24);
937     if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
938         ret += 1;
939 
940     return AVPROBE_SCORE_EXTENSION + ret;
941 }
942 
sgi_probe(const AVProbeData *p)943 static int sgi_probe(const AVProbeData *p)
944 {
945     const uint8_t *b = p->buf;
946 
947     if (AV_RB16(b) == 474 &&
948         (b[2] & ~1) == 0 &&
949         (b[3] & ~3) == 0 && b[3] &&
950         (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4))
951         return AVPROBE_SCORE_EXTENSION + 1;
952     return 0;
953 }
954 
sunrast_probe(const AVProbeData *p)955 static int sunrast_probe(const AVProbeData *p)
956 {
957     const uint8_t *b = p->buf;
958 
959     if (AV_RB32(b) == 0x59a66a95)
960         return AVPROBE_SCORE_EXTENSION + 1;
961     return 0;
962 }
963 
svg_probe(const AVProbeData *p)964 static int svg_probe(const AVProbeData *p)
965 {
966     const uint8_t *b = p->buf;
967     const uint8_t *end = p->buf + p->buf_size;
968 
969     if (memcmp(p->buf, "<?xml", 5))
970         return 0;
971     while (b < end) {
972         int inc = ff_subtitles_next_line(b);
973         if (!inc)
974             break;
975         b += inc;
976         if (b >= end - 4)
977             return 0;
978         if (!memcmp(b, "<svg", 4))
979             return AVPROBE_SCORE_EXTENSION + 1;
980     }
981     return 0;
982 }
983 
tiff_probe(const AVProbeData *p)984 static int tiff_probe(const AVProbeData *p)
985 {
986     const uint8_t *b = p->buf;
987 
988     if (AV_RB32(b) == 0x49492a00 ||
989         AV_RB32(b) == 0x4D4D002a)
990         return AVPROBE_SCORE_EXTENSION + 1;
991     return 0;
992 }
993 
webp_probe(const AVProbeData *p)994 static int webp_probe(const AVProbeData *p)
995 {
996     const uint8_t *b = p->buf;
997 
998     if (AV_RB32(b)     == 0x52494646 &&
999         AV_RB32(b + 8) == 0x57454250)
1000         return AVPROBE_SCORE_MAX - 1;
1001     return 0;
1002 }
1003 
pnm_magic_check(const AVProbeData *p, int magic)1004 static int pnm_magic_check(const AVProbeData *p, int magic)
1005 {
1006     const uint8_t *b = p->buf;
1007 
1008     return b[0] == 'P' && b[1] == magic + '0';
1009 }
1010 
pnm_probe(const AVProbeData *p)1011 static inline int pnm_probe(const AVProbeData *p)
1012 {
1013     const uint8_t *b = p->buf;
1014 
1015     while (b[2] == '\r')
1016         b++;
1017     if (b[2] == '\n' && (b[3] == '#' || (b[3] >= '0' && b[3] <= '9')))
1018         return AVPROBE_SCORE_EXTENSION + 2;
1019     return 0;
1020 }
1021 
pbm_probe(const AVProbeData *p)1022 static int pbm_probe(const AVProbeData *p)
1023 {
1024     return pnm_magic_check(p, 1) || pnm_magic_check(p, 4) ? pnm_probe(p) : 0;
1025 }
1026 
pfm_probe(const AVProbeData *p)1027 static int pfm_probe(const AVProbeData *p)
1028 {
1029     return pnm_magic_check(p, 'F' - '0') ||
1030            pnm_magic_check(p, 'f' - '0') ? pnm_probe(p) : 0;
1031 }
1032 
phm_probe(const AVProbeData *p)1033 static int phm_probe(const AVProbeData *p)
1034 {
1035     return pnm_magic_check(p, 'H' - '0') ||
1036            pnm_magic_check(p, 'h' - '0') ? pnm_probe(p) : 0;
1037 }
1038 
pgmx_probe(const AVProbeData *p)1039 static inline int pgmx_probe(const AVProbeData *p)
1040 {
1041     return pnm_magic_check(p, 2) || pnm_magic_check(p, 5) ? pnm_probe(p) : 0;
1042 }
1043 
pgm_probe(const AVProbeData *p)1044 static int pgm_probe(const AVProbeData *p)
1045 {
1046     int ret = pgmx_probe(p);
1047     return ret && !av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1048 }
1049 
pgmyuv_probe(const AVProbeData *p)1050 static int pgmyuv_probe(const AVProbeData *p) // custom FFmpeg format recognized by file extension
1051 {
1052     int ret = pgmx_probe(p);
1053     return ret && av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1054 }
1055 
pgx_probe(const AVProbeData *p)1056 static int pgx_probe(const AVProbeData *p)
1057 {
1058     const uint8_t *b = p->buf;
1059     if (!memcmp(b, "PG ML ", 6))
1060         return AVPROBE_SCORE_EXTENSION + 1;
1061     return 0;
1062 }
1063 
ppm_probe(const AVProbeData *p)1064 static int ppm_probe(const AVProbeData *p)
1065 {
1066     return pnm_magic_check(p, 3) || pnm_magic_check(p, 6) ? pnm_probe(p) : 0;
1067 }
1068 
pam_probe(const AVProbeData *p)1069 static int pam_probe(const AVProbeData *p)
1070 {
1071     return pnm_magic_check(p, 7) ? pnm_probe(p) : 0;
1072 }
1073 
xbm_probe(const AVProbeData *p)1074 static int xbm_probe(const AVProbeData *p)
1075 {
1076     if (!memcmp(p->buf, "/* XBM X10 format */", 20))
1077         return AVPROBE_SCORE_MAX;
1078 
1079     if (!memcmp(p->buf, "#define", 7))
1080         return AVPROBE_SCORE_MAX - 1;
1081     return 0;
1082 }
1083 
xpm_probe(const AVProbeData *p)1084 static int xpm_probe(const AVProbeData *p)
1085 {
1086     const uint8_t *b = p->buf;
1087 
1088     if (AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) == '/')
1089         return AVPROBE_SCORE_MAX - 1;
1090     return 0;
1091 }
1092 
xwd_probe(const AVProbeData *p)1093 static int xwd_probe(const AVProbeData *p)
1094 {
1095     const uint8_t *b = p->buf;
1096     unsigned width, bpp, bpad, lsize;
1097 
1098     if (   p->buf_size < XWD_HEADER_SIZE
1099         || AV_RB32(b     ) < XWD_HEADER_SIZE                          // header size
1100         || AV_RB32(b +  4) != XWD_VERSION                             // version
1101         || AV_RB32(b +  8) != XWD_Z_PIXMAP                            // format
1102         || AV_RB32(b + 12) > 32 || !AV_RB32(b + 12)                   // depth
1103         || AV_RB32(b + 16) == 0                                       // width
1104         || AV_RB32(b + 20) == 0                                       // height
1105         || AV_RB32(b + 28) > 1                                        // byteorder
1106         || AV_RB32(b + 32) & ~56 || av_popcount(AV_RB32(b + 32)) != 1 // bitmap unit
1107         || AV_RB32(b + 36) > 1                                        // bitorder
1108         || AV_RB32(b + 40) & ~56 || av_popcount(AV_RB32(b + 40)) != 1 // padding
1109         || AV_RB32(b + 44) > 32 || !AV_RB32(b + 44)                   // bpp
1110         || AV_RB32(b + 68) > 256)                                     // colours
1111         return 0;
1112 
1113     width = AV_RB32(b + 16);
1114     bpad  = AV_RB32(b + 40);
1115     bpp   = AV_RB32(b + 44);
1116     lsize = AV_RB32(b + 48);
1117     if (lsize < FFALIGN(width * bpp, bpad) >> 3)
1118         return 0;
1119 
1120     return AVPROBE_SCORE_MAX / 2 + 1;
1121 }
1122 
gif_probe(const AVProbeData *p)1123 static int gif_probe(const AVProbeData *p)
1124 {
1125     /* check magick */
1126     if (memcmp(p->buf, gif87a_sig, 6) && memcmp(p->buf, gif89a_sig, 6))
1127         return 0;
1128 
1129     /* width or height contains zero? */
1130     if (!AV_RL16(&p->buf[6]) || !AV_RL16(&p->buf[8]))
1131         return 0;
1132 
1133     return AVPROBE_SCORE_MAX - 1;
1134 }
1135 
photocd_probe(const AVProbeData *p)1136 static int photocd_probe(const AVProbeData *p)
1137 {
1138     if (!memcmp(p->buf, "PCD_OPA", 7))
1139         return AVPROBE_SCORE_MAX - 1;
1140 
1141     if (p->buf_size < 0x807 || memcmp(p->buf + 0x800, "PCD_IPI", 7))
1142         return 0;
1143 
1144     return AVPROBE_SCORE_MAX - 1;
1145 }
1146 
qoi_probe(const AVProbeData *p)1147 static int qoi_probe(const AVProbeData *p)
1148 {
1149     if (memcmp(p->buf, "qoif", 4))
1150         return 0;
1151 
1152     if (AV_RB32(p->buf + 4) == 0 || AV_RB32(p->buf + 8) == 0)
1153         return 0;
1154 
1155     if (p->buf[12] != 3 && p->buf[12] != 4)
1156         return 0;
1157 
1158     if (p->buf[13] > 1)
1159         return 0;
1160 
1161     return AVPROBE_SCORE_MAX - 1;
1162 }
1163 
gem_probe(const AVProbeData *p)1164 static int gem_probe(const AVProbeData *p)
1165 {
1166     const uint8_t *b = p->buf;
1167     if ( AV_RB16(b     ) >= 1 && AV_RB16(b    ) <= 3  &&
1168          AV_RB16(b +  2) >= 8 && AV_RB16(b + 2) <= 779 &&
1169         (AV_RB16(b +  4) > 0  && AV_RB16(b + 4) <= 32) && /* planes */
1170         (AV_RB16(b +  6) > 0  && AV_RB16(b + 6) <= 8) && /* pattern_size */
1171          AV_RB16(b +  8) &&
1172          AV_RB16(b + 10) &&
1173          AV_RB16(b + 12) &&
1174          AV_RB16(b + 14)) {
1175         if (AV_RN32(b + 16) == AV_RN32("STTT") ||
1176             AV_RN32(b + 16) == AV_RN32("TIMG") ||
1177             AV_RN32(b + 16) == AV_RN32("XIMG"))
1178             return AVPROBE_SCORE_EXTENSION + 1;
1179         return AVPROBE_SCORE_EXTENSION / 4;
1180     }
1181     return 0;
1182 }
1183 
vbn_probe(const AVProbeData *p)1184 static int vbn_probe(const AVProbeData *p)
1185 {
1186     const uint8_t *b = p->buf;
1187     if (AV_RL32(b    ) == VBN_MAGIC &&
1188         AV_RL32(b + 4) == VBN_MAJOR &&
1189         AV_RL32(b + 8) == VBN_MINOR)
1190         return AVPROBE_SCORE_MAX - 1;
1191     return 0;
1192 }
1193 
1194 #define IMAGEAUTO_DEMUXER_0(imgname, codecid)
1195 #define IMAGEAUTO_DEMUXER_1(imgname, codecid)\
1196 const AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1197     .name           = AV_STRINGIFY(imgname) "_pipe",\
1198     .long_name      = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1199     .priv_data_size = sizeof(VideoDemuxData),\
1200     .read_probe     = imgname ## _probe,\
1201     .read_header    = ff_img_read_header,\
1202     .read_packet    = ff_img_read_packet,\
1203     .priv_class     = &imagepipe_class,\
1204     .flags          = AVFMT_GENERIC_INDEX, \
1205     .raw_codec_id   = codecid,\
1206 };
1207 
1208 #define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \
1209         IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid)
1210 #define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \
1211         IMAGEAUTO_DEMUXER_2(imgname, codecid, config)
1212 #define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \
1213         IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid,   \
1214                             CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER)
1215 #define IMAGEAUTO_DEMUXER(imgname, codecid)                     \
1216         IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid)
1217 
1218 IMAGEAUTO_DEMUXER(bmp,       BMP)
1219 IMAGEAUTO_DEMUXER(cri,       CRI)
1220 IMAGEAUTO_DEMUXER(dds,       DDS)
1221 IMAGEAUTO_DEMUXER(dpx,       DPX)
1222 IMAGEAUTO_DEMUXER(exr,       EXR)
1223 IMAGEAUTO_DEMUXER(gem,       GEM)
1224 IMAGEAUTO_DEMUXER(gif,       GIF)
1225 IMAGEAUTO_DEMUXER_EXT(j2k,   JPEG2000, J2K)
1226 IMAGEAUTO_DEMUXER_EXT(jpeg,  MJPEG, JPEG)
1227 IMAGEAUTO_DEMUXER(jpegls,    JPEGLS)
1228 IMAGEAUTO_DEMUXER(jpegxl,    JPEGXL)
1229 IMAGEAUTO_DEMUXER(pam,       PAM)
1230 IMAGEAUTO_DEMUXER(pbm,       PBM)
1231 IMAGEAUTO_DEMUXER(pcx,       PCX)
1232 IMAGEAUTO_DEMUXER(pfm,       PFM)
1233 IMAGEAUTO_DEMUXER(pgm,       PGM)
1234 IMAGEAUTO_DEMUXER(pgmyuv,    PGMYUV)
1235 IMAGEAUTO_DEMUXER(pgx,       PGX)
1236 IMAGEAUTO_DEMUXER(phm,       PHM)
1237 IMAGEAUTO_DEMUXER(photocd,   PHOTOCD)
1238 IMAGEAUTO_DEMUXER(pictor,    PICTOR)
1239 IMAGEAUTO_DEMUXER(png,       PNG)
1240 IMAGEAUTO_DEMUXER(ppm,       PPM)
1241 IMAGEAUTO_DEMUXER(psd,       PSD)
1242 IMAGEAUTO_DEMUXER(qdraw,     QDRAW)
1243 IMAGEAUTO_DEMUXER(qoi,       QOI)
1244 IMAGEAUTO_DEMUXER(sgi,       SGI)
1245 IMAGEAUTO_DEMUXER(sunrast,   SUNRAST)
1246 IMAGEAUTO_DEMUXER(svg,       SVG)
1247 IMAGEAUTO_DEMUXER(tiff,      TIFF)
1248 IMAGEAUTO_DEMUXER(vbn,       VBN)
1249 IMAGEAUTO_DEMUXER(webp,      WEBP)
1250 IMAGEAUTO_DEMUXER(xbm,       XBM)
1251 IMAGEAUTO_DEMUXER(xpm,       XPM)
1252 IMAGEAUTO_DEMUXER(xwd,       XWD)
1253