3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2004 Michael Niedermayer
6 * This file is part of FFmpeg.
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.
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.
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
23 #define _DEFAULT_SOURCE
26 #include "libavutil/avstring.h"
27 #include "libavutil/log.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/intreadwrite.h"
33 #include "avio_internal.h"
36 #include "libavcodec/mjpeg.h"
39 /* Locally define as 0 (bitwise-OR no-op) any missing glob options that
40 are non-posix glibc/bsd extensions. */
42 #define GLOB_NOMAGIC 0
48 #endif /* HAVE_GLOB */
50 static const int sizes[][2] = {
62 static int infer_size(int *width_ptr, int *height_ptr, int size)
66 for (i = 0; i < FF_ARRAY_ELEMS(sizes); i++) {
67 if ((sizes[i][0] * sizes[i][1]) == size) {
68 *width_ptr = sizes[i][0];
69 *height_ptr = sizes[i][1];
77 static int is_glob(const char *path)
83 while (p = strchr(p, '%')) {
88 if (span = strspn(p, "*?[]{}"))
91 /* Did we hit a glob char or get to the end? */
99 * Get index range of image files matched by path.
101 * @param pfirst_index pointer to index updated with the first number in the range
102 * @param plast_index pointer to index updated with the last number in the range
103 * @param path path which has to be matched by the image files in the range
104 * @param start_index minimum accepted value for the first index in the range
105 * @return -1 if no image file could be found
107 static int find_image_range(AVIOContext *pb, int *pfirst_index, int *plast_index,
108 const char *path, int start_index, int start_index_range)
111 int range, last_index, range1, first_index;
113 /* find the first image */
114 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
115 if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {
118 if (pb || avio_check(buf, AVIO_FLAG_READ) > 0)
122 if (avio_check(buf, AVIO_FLAG_READ) > 0)
125 if (first_index == start_index + start_index_range)
128 /* find the last image */
129 last_index = first_index;
137 if (av_get_frame_filename(buf, sizeof(buf), path,
138 last_index + range1) < 0)
140 if (avio_check(buf, AVIO_FLAG_READ) <= 0)
143 /* just in case... */
144 if (range >= (1 << 30))
147 /* we are sure than image last_index + range exists */
152 *pfirst_index = first_index;
153 *plast_index = last_index;
160 static int img_read_probe(AVProbeData *p)
162 if (p->filename && ff_guess_image2_codec(p->filename)) {
163 if (av_filename_number_test(p->filename))
164 return AVPROBE_SCORE_MAX;
165 else if (is_glob(p->filename))
166 return AVPROBE_SCORE_MAX;
167 else if (p->filename[strcspn(p->filename, "*?{")]) // probably PT_GLOB
168 return AVPROBE_SCORE_EXTENSION + 2; // score chosen to be a tad above the image pipes
169 else if (p->buf_size == 0)
171 else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif"))
174 return AVPROBE_SCORE_EXTENSION;
179 int ff_img_read_header(AVFormatContext *s1)
181 VideoDemuxData *s = s1->priv_data;
182 int first_index = 1, last_index = 1;
184 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
186 s1->ctx_flags |= AVFMTCTX_NOHEADER;
188 st = avformat_new_stream(s1, NULL);
190 return AVERROR(ENOMEM);
193 if (s->pixel_format &&
194 (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
195 av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n",
197 return AVERROR(EINVAL);
200 av_strlcpy(s->path, s1->filename, sizeof(s->path));
205 if (s1->iformat->flags & AVFMT_NOFILE)
209 st->need_parsing = AVSTREAM_PARSE_FULL;
212 if (s->ts_from_file == 2) {
213 #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
214 av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
215 return AVERROR(ENOSYS);
217 avpriv_set_pts_info(st, 64, 1, 1000000000);
218 } else if (s->ts_from_file)
219 avpriv_set_pts_info(st, 64, 1, 1);
221 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
223 if (s->width && s->height) {
224 st->codecpar->width = s->width;
225 st->codecpar->height = s->height;
229 if (s->pattern_type == PT_DEFAULT) {
231 s->pattern_type = PT_NONE;
233 s->pattern_type = PT_GLOB_SEQUENCE;
236 if (s->pattern_type == PT_GLOB_SEQUENCE) {
237 s->use_glob = is_glob(s->path);
240 char *p = s->path, *q, *dup;
244 av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
245 "use pattern_type 'glob' instead\n");
247 dup = q = av_strdup(p);
249 /* Do we have room for the next char and a \ insertion? */
250 if ((p - s->path) >= (sizeof(s->path) - 2))
252 if (*q == '%' && strspn(q + 1, "%*?[]{}"))
254 else if (strspn(q, "\\*?[]{}"))
261 gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
263 return AVERROR(ENOENT);
266 last_index = s->globstate.gl_pathc - 1;
270 if ((s->pattern_type == PT_GLOB_SEQUENCE && !s->use_glob) || s->pattern_type == PT_SEQUENCE) {
271 if (find_image_range(s1->pb, &first_index, &last_index, s->path,
272 s->start_number, s->start_number_range) < 0) {
273 av_log(s1, AV_LOG_ERROR,
274 "Could find no file with path '%s' and index in the range %d-%d\n",
275 s->path, s->start_number, s->start_number + s->start_number_range - 1);
276 return AVERROR(ENOENT);
278 } else if (s->pattern_type == PT_GLOB) {
281 gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
283 return AVERROR(ENOENT);
286 last_index = s->globstate.gl_pathc - 1;
289 av_log(s1, AV_LOG_ERROR,
290 "Pattern type 'glob' was selected but globbing "
291 "is not supported by this libavformat build\n");
292 return AVERROR(ENOSYS);
294 } else if (s->pattern_type != PT_GLOB_SEQUENCE && s->pattern_type != PT_NONE) {
295 av_log(s1, AV_LOG_ERROR,
296 "Unknown value '%d' for pattern_type option\n", s->pattern_type);
297 return AVERROR(EINVAL);
299 s->img_first = first_index;
300 s->img_last = last_index;
301 s->img_number = first_index;
302 /* compute duration */
303 if (!s->ts_from_file) {
305 st->duration = last_index - first_index + 1;
309 if (s1->video_codec_id) {
310 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
311 st->codecpar->codec_id = s1->video_codec_id;
312 } else if (s1->audio_codec_id) {
313 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
314 st->codecpar->codec_id = s1->audio_codec_id;
315 } else if (s1->iformat->raw_codec_id) {
316 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
317 st->codecpar->codec_id = s1->iformat->raw_codec_id;
319 const char *str = strrchr(s->path, '.');
320 s->split_planes = str && !av_strcasecmp(str + 1, "y");
321 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
323 int probe_buffer_size = 2048;
324 uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE);
325 AVInputFormat *fmt = NULL;
326 AVProbeData pd = { 0 };
329 return AVERROR(ENOMEM);
331 probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size);
332 if (probe_buffer_size < 0) {
333 av_free(probe_buffer);
334 return probe_buffer_size;
336 memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE);
338 pd.buf = probe_buffer;
339 pd.buf_size = probe_buffer_size;
340 pd.filename = s1->filename;
342 while ((fmt = av_iformat_next(fmt))) {
343 if (fmt->read_header != ff_img_read_header ||
345 (fmt->flags & AVFMT_NOFILE) ||
348 if (fmt->read_probe(&pd) > 0) {
349 st->codecpar->codec_id = fmt->raw_codec_id;
353 if (s1->flags & AVFMT_FLAG_CUSTOM_IO) {
354 avio_seek(s1->pb, 0, SEEK_SET);
356 ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size);
358 if (st->codecpar->codec_id == AV_CODEC_ID_NONE)
359 st->codecpar->codec_id = ff_guess_image2_codec(s->path);
360 if (st->codecpar->codec_id == AV_CODEC_ID_LJPEG)
361 st->codecpar->codec_id = AV_CODEC_ID_MJPEG;
362 if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX
363 st->codecpar->codec_id = AV_CODEC_ID_NONE;
365 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
366 pix_fmt != AV_PIX_FMT_NONE)
367 st->codecpar->format = pix_fmt;
372 int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
374 VideoDemuxData *s = s1->priv_data;
375 char filename_bytes[1024];
376 char *filename = filename_bytes;
378 int size[3] = { 0 }, ret[3] = { 0 };
379 AVIOContext *f[3] = { NULL };
380 AVCodecParameters *par = s1->streams[0]->codecpar;
383 /* loop over input */
384 if (s->loop && s->img_number > s->img_last) {
385 s->img_number = s->img_first;
387 if (s->img_number > s->img_last)
389 if (s->pattern_type == PT_NONE) {
390 av_strlcpy(filename_bytes, s->path, sizeof(filename_bytes));
391 } else if (s->use_glob) {
393 filename = s->globstate.gl_pathv[s->img_number];
396 if (av_get_frame_filename(filename_bytes, sizeof(filename_bytes),
398 s->img_number) < 0 && s->img_number > 1)
401 for (i = 0; i < 3; i++) {
403 !strcmp(filename_bytes, s->path) &&
407 } else if (s1->io_open(s1, &f[i], filename, AVIO_FLAG_READ, NULL) < 0) {
410 av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",
414 size[i] = avio_size(f[i]);
416 if (!s->split_planes)
418 filename[strlen(filename) - 1] = 'U' + i;
421 if (par->codec_id == AV_CODEC_ID_NONE) {
422 AVProbeData pd = { 0 };
424 uint8_t header[PROBE_BUF_MIN + AVPROBE_PADDING_SIZE];
428 ret = avio_read(f[0], header, PROBE_BUF_MIN);
431 memset(header + ret, 0, sizeof(header) - ret);
432 avio_skip(f[0], -ret);
435 pd.filename = filename;
437 ifmt = av_probe_input_format3(&pd, 1, &score);
438 if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id)
439 par->codec_id = ifmt->raw_codec_id;
442 if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
443 infer_size(&par->width, &par->height, size[0]);
446 if (avio_feof(f[0]) && s->loop && s->is_pipe)
447 avio_seek(f[0], 0, SEEK_SET);
450 if (s->frame_size > 0) {
451 size[0] = s->frame_size;
452 } else if (!s1->streams[0]->parser) {
453 size[0] = avio_size(s1->pb);
459 res = av_new_packet(pkt, size[0] + size[1] + size[2]);
463 pkt->stream_index = 0;
464 pkt->flags |= AV_PKT_FLAG_KEY;
465 if (s->ts_from_file) {
466 struct stat img_stat;
467 if (stat(filename, &img_stat)) {
471 pkt->pts = (int64_t)img_stat.st_mtime;
472 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
473 if (s->ts_from_file == 2)
474 pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
476 av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
477 } else if (!s->is_pipe) {
482 pkt->pos = avio_tell(f[0]);
485 for (i = 0; i < 3; i++) {
487 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
488 if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) {
489 if (avio_seek(f[i], 0, SEEK_SET) >= 0) {
491 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
494 if (!s->is_pipe && f[i] != s1->pb)
495 ff_format_io_close(s1, &f[i]);
501 if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
502 av_packet_unref(pkt);
505 } else if (ret[1] < 0) {
507 } else if (ret[2] < 0) {
522 for (i = 0; i < 3; i++) {
524 ff_format_io_close(s1, &f[i]);
530 static int img_read_close(struct AVFormatContext* s1)
533 VideoDemuxData *s = s1->priv_data;
535 globfree(&s->globstate);
541 static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
543 VideoDemuxData *s1 = s->priv_data;
544 AVStream *st = s->streams[0];
546 if (s1->ts_from_file) {
547 int index = av_index_search_timestamp(st, timestamp, flags);
550 s1->img_number = st->index_entries[index].pos;
554 if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
556 s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
561 #define OFFSET(x) offsetof(VideoDemuxData, x)
562 #define DEC AV_OPT_FLAG_DECODING_PARAM
563 const AVOption ff_img_options[] = {
564 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC },
565 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC },
567 { "pattern_type", "set pattern type", OFFSET(pattern_type), AV_OPT_TYPE_INT, {.i64=PT_DEFAULT}, 0, INT_MAX, DEC, "pattern_type"},
568 { "glob_sequence","select glob/sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
569 { "glob", "select glob pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX, DEC, "pattern_type" },
570 { "sequence", "select sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX, DEC, "pattern_type" },
571 { "none", "disable pattern matching", 0, AV_OPT_TYPE_CONST, {.i64=PT_NONE }, INT_MIN, INT_MAX, DEC, "pattern_type" },
573 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
574 { "start_number", "set first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, DEC },
575 { "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 },
576 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
577 { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
578 { "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" },
579 { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 2, DEC, "ts_type" },
580 { "sec", "second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 2, DEC, "ts_type" },
581 { "ns", "nano second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2, DEC, "ts_type" },
585 #if CONFIG_IMAGE2_DEMUXER
586 static const AVClass img2_class = {
587 .class_name = "image2 demuxer",
588 .item_name = av_default_item_name,
589 .option = ff_img_options,
590 .version = LIBAVUTIL_VERSION_INT,
592 AVInputFormat ff_image2_demuxer = {
594 .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
595 .priv_data_size = sizeof(VideoDemuxData),
596 .read_probe = img_read_probe,
597 .read_header = ff_img_read_header,
598 .read_packet = ff_img_read_packet,
599 .read_close = img_read_close,
600 .read_seek = img_read_seek,
601 .flags = AVFMT_NOFILE,
602 .priv_class = &img2_class,
605 #if CONFIG_IMAGE2PIPE_DEMUXER
606 static const AVClass img2pipe_class = {
607 .class_name = "image2pipe demuxer",
608 .item_name = av_default_item_name,
609 .option = ff_img_options,
610 .version = LIBAVUTIL_VERSION_INT,
612 AVInputFormat ff_image2pipe_demuxer = {
613 .name = "image2pipe",
614 .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
615 .priv_data_size = sizeof(VideoDemuxData),
616 .read_header = ff_img_read_header,
617 .read_packet = ff_img_read_packet,
618 .priv_class = &img2pipe_class,
622 static int bmp_probe(AVProbeData *p)
624 const uint8_t *b = p->buf;
627 if (AV_RB16(b) != 0x424d)
630 ihsize = AV_RL32(b+14);
631 if (ihsize < 12 || ihsize > 255)
634 if (!AV_RN32(b + 6)) {
635 return AVPROBE_SCORE_EXTENSION + 1;
637 return AVPROBE_SCORE_EXTENSION / 4;
640 static int dds_probe(AVProbeData *p)
642 const uint8_t *b = p->buf;
644 if ( AV_RB64(b) == 0x444453207c000000
647 return AVPROBE_SCORE_MAX - 1;
651 static int dpx_probe(AVProbeData *p)
653 const uint8_t *b = p->buf;
655 int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
657 if (p->buf_size < 0x304+8)
659 w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
660 h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
661 if (w <= 0 || h <= 0)
664 if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
665 return AVPROBE_SCORE_EXTENSION + 1;
669 static int exr_probe(AVProbeData *p)
671 const uint8_t *b = p->buf;
673 if (AV_RL32(b) == 20000630)
674 return AVPROBE_SCORE_EXTENSION + 1;
678 static int j2k_probe(AVProbeData *p)
680 const uint8_t *b = p->buf;
682 if (AV_RB64(b) == 0x0000000c6a502020 ||
683 AV_RB32(b) == 0xff4fff51)
684 return AVPROBE_SCORE_EXTENSION + 1;
688 static int jpeg_probe(AVProbeData *p)
690 const uint8_t *b = p->buf;
693 if (AV_RB16(b) != 0xFFD8 ||
694 AV_RB32(b) == 0xFFD8FFF7)
698 for (i = 0; i < p->buf_size - 3; i++) {
713 i += AV_RB16(&b[i + 2]) + 1;
719 i += AV_RB16(&b[i + 2]) + 1;
720 if (state != SOF0 && state != SOS)
746 i += AV_RB16(&b[i + 2]) + 1;
749 if ( (c > TEM && c < SOF0)
756 return AVPROBE_SCORE_EXTENSION + 1;
757 return AVPROBE_SCORE_EXTENSION / 8;
760 static int jpegls_probe(AVProbeData *p)
762 const uint8_t *b = p->buf;
764 if (AV_RB32(b) == 0xffd8fff7)
765 return AVPROBE_SCORE_EXTENSION + 1;
769 static int pcx_probe(AVProbeData *p)
771 const uint8_t *b = p->buf;
773 if ( p->buf_size < 128
777 || av_popcount(b[3]) != 1 || b[3] > 8
778 || AV_RL16(&b[4]) > AV_RL16(&b[8])
779 || AV_RL16(&b[6]) > AV_RL16(&b[10])
783 while (++b < p->buf + 128)
785 return AVPROBE_SCORE_EXTENSION / 4;
787 return AVPROBE_SCORE_EXTENSION + 1;
790 static int qdraw_probe(AVProbeData *p)
792 const uint8_t *b = p->buf;
794 if ( p->buf_size >= 528
795 && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
798 return AVPROBE_SCORE_MAX * 3 / 4;
799 if ( (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
802 return AVPROBE_SCORE_EXTENSION / 4;
806 static int pictor_probe(AVProbeData *p)
808 const uint8_t *b = p->buf;
810 if (AV_RL16(b) == 0x1234)
811 return AVPROBE_SCORE_EXTENSION / 4;
815 static int png_probe(AVProbeData *p)
817 const uint8_t *b = p->buf;
819 if (AV_RB64(b) == 0x89504e470d0a1a0a)
820 return AVPROBE_SCORE_MAX - 1;
824 static int sgi_probe(AVProbeData *p)
826 const uint8_t *b = p->buf;
828 if (AV_RB16(b) == 474 &&
830 (b[3] & ~3) == 0 && b[3] &&
831 (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4))
832 return AVPROBE_SCORE_EXTENSION + 1;
836 static int sunrast_probe(AVProbeData *p)
838 const uint8_t *b = p->buf;
840 if (AV_RB32(b) == 0x59a66a95)
841 return AVPROBE_SCORE_EXTENSION + 1;
845 static int tiff_probe(AVProbeData *p)
847 const uint8_t *b = p->buf;
849 if (AV_RB32(b) == 0x49492a00 ||
850 AV_RB32(b) == 0x4D4D002a)
851 return AVPROBE_SCORE_EXTENSION + 1;
855 static int webp_probe(AVProbeData *p)
857 const uint8_t *b = p->buf;
859 if (AV_RB32(b) == 0x52494646 &&
860 AV_RB32(b + 8) == 0x57454250)
861 return AVPROBE_SCORE_MAX - 1;
865 #define IMAGEAUTO_DEMUXER(imgname, codecid)\
866 static const AVClass imgname ## _class = {\
867 .class_name = AV_STRINGIFY(imgname) " demuxer",\
868 .item_name = av_default_item_name,\
869 .option = ff_img_options,\
870 .version = LIBAVUTIL_VERSION_INT,\
872 AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
873 .name = AV_STRINGIFY(imgname) "_pipe",\
874 .long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
875 .priv_data_size = sizeof(VideoDemuxData),\
876 .read_probe = imgname ## _probe,\
877 .read_header = ff_img_read_header,\
878 .read_packet = ff_img_read_packet,\
879 .priv_class = & imgname ## _class,\
880 .flags = AVFMT_GENERIC_INDEX, \
881 .raw_codec_id = codecid,\
884 IMAGEAUTO_DEMUXER(bmp, AV_CODEC_ID_BMP)
885 IMAGEAUTO_DEMUXER(dds, AV_CODEC_ID_DDS)
886 IMAGEAUTO_DEMUXER(dpx, AV_CODEC_ID_DPX)
887 IMAGEAUTO_DEMUXER(exr, AV_CODEC_ID_EXR)
888 IMAGEAUTO_DEMUXER(j2k, AV_CODEC_ID_JPEG2000)
889 IMAGEAUTO_DEMUXER(jpeg, AV_CODEC_ID_MJPEG)
890 IMAGEAUTO_DEMUXER(jpegls, AV_CODEC_ID_JPEGLS)
891 IMAGEAUTO_DEMUXER(pcx, AV_CODEC_ID_PCX)
892 IMAGEAUTO_DEMUXER(pictor, AV_CODEC_ID_PICTOR)
893 IMAGEAUTO_DEMUXER(png, AV_CODEC_ID_PNG)
894 IMAGEAUTO_DEMUXER(qdraw, AV_CODEC_ID_QDRAW)
895 IMAGEAUTO_DEMUXER(sgi, AV_CODEC_ID_SGI)
896 IMAGEAUTO_DEMUXER(sunrast, AV_CODEC_ID_SUNRAST)
897 IMAGEAUTO_DEMUXER(tiff, AV_CODEC_ID_TIFF)
898 IMAGEAUTO_DEMUXER(webp, AV_CODEC_ID_WEBP)