FFmpeg
Loading...
Searching...
No Matches
img2dec.c
Go to the documentation of this file.
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"
25
26#define _DEFAULT_SOURCE
27#define _BSD_SOURCE
28#include <sys/stat.h>
29#include "libavutil/avassert.h"
30#include "libavutil/avstring.h"
31#include "libavutil/bprint.h"
32#include "libavutil/log.h"
33#include "libavutil/mem.h"
34#include "libavutil/opt.h"
35#include "libavutil/pixdesc.h"
37#include "libavcodec/gif.h"
38#include "avformat.h"
39#include "avio_internal.h"
40#include "demux.h"
41#include "internal.h"
42#include "img2.h"
43#include "os_support.h"
45#include "libavcodec/mjpeg.h"
46#include "libavcodec/png.h"
47#include "libavcodec/vbn.h"
48#include "libavcodec/xwd.h"
49#include "subtitles.h"
50
51#if HAVE_GLOB
52/* Locally define as 0 (bitwise-OR no-op) any missing glob options that
53 are non-posix glibc/bsd extensions. */
54#ifndef GLOB_NOMAGIC
55#define GLOB_NOMAGIC 0
56#endif
57#ifndef GLOB_BRACE
58#define GLOB_BRACE 0
59#endif
60
61#endif /* HAVE_GLOB */
62
63static const int sizes[][2] = {
64 { 640, 480 },
65 { 720, 480 },
66 { 720, 576 },
67 { 352, 288 },
68 { 352, 240 },
69 { 160, 128 },
70 { 512, 384 },
71 { 640, 352 },
72 { 640, 240 },
73};
74
75static int infer_size(int *width_ptr, int *height_ptr, int size)
76{
77 int i;
78
79 for (i = 0; i < FF_ARRAY_ELEMS(sizes); i++) {
80 if ((sizes[i][0] * sizes[i][1]) == size) {
81 *width_ptr = sizes[i][0];
82 *height_ptr = sizes[i][1];
83 return 0;
84 }
85 }
86
87 return -1;
88}
89
90/**
91 * Get index range of image files matched by path.
92 *
93 * @param pfirst_index pointer to index updated with the first number in the range
94 * @param plast_index pointer to index updated with the last number in the range
95 * @param path path which has to be matched by the image files in the range
96 * @param start_index minimum accepted value for the first index in the range
97 * @return -1 if no image file could be found
98 */
99static int find_image_range(int *pfirst_index, int *plast_index,
100 const char *path, int start_index, int start_index_range)
101{
102 int range, last_index, range1, first_index, ret;
103 AVBPrint filename;
104
106 /* find the first image */
107 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
108 av_bprint_clear(&filename);
109 ret = ff_bprint_get_frame_filename(&filename, path, first_index, 0);
110 if (ret < 0)
111 goto fail;
112 if (avio_check(filename.str, AVIO_FLAG_READ) > 0)
113 break;
114 }
115 if (first_index == start_index + start_index_range) {
116 ret = AVERROR(EINVAL);
117 goto fail;
118 }
119
120 /* find the last image */
121 last_index = first_index;
122 for (;;) {
123 range = 0;
124 for (;;) {
125 if (!range)
126 range1 = 1;
127 else
128 range1 = 2 * range;
129 av_bprint_clear(&filename);
130 ret = ff_bprint_get_frame_filename(&filename, path, last_index + range1, 0);
131 if (ret < 0)
132 goto fail;
133 if (avio_check(filename.str, AVIO_FLAG_READ) <= 0)
134 break;
135 range = range1;
136 /* just in case... */
137 if (range >= (1 << 30)) {
138 ret = AVERROR(EINVAL);
139 goto fail;
140 }
141 }
142 /* we are sure than image last_index + range exists */
143 if (!range)
144 break;
145 last_index += range;
146 }
147 *pfirst_index = first_index;
148 *plast_index = last_index;
149 ret = 0;
150fail:
151 av_bprint_finalize(&filename, NULL);
152 return ret;
153}
154
155static int img_read_probe(const AVProbeData *p)
156{
157 if (p->filename && ff_guess_image2_codec(p->filename)) {
158 if (av_filename_number_test(p->filename))
159 return AVPROBE_SCORE_MAX;
160 else if (p->filename[strcspn(p->filename, "*?{")]) // probably PT_GLOB
161 return AVPROBE_SCORE_EXTENSION + 2; // score chosen to be a tad above the image pipes
162 else if (p->buf_size == 0)
163 return 0;
164 else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif"))
165 return 5;
166 else
168 }
169 return 0;
170}
171
173{
175 int first_index = 1, last_index = 1;
176 AVStream *st;
178
180
181 st = avformat_new_stream(s1, NULL);
182 if (!st) {
183 return AVERROR(ENOMEM);
184 }
185
186 if (s->pixel_format &&
187 (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
188 av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n",
189 s->pixel_format);
190 return AVERROR(EINVAL);
191 }
192
193 s->img_number = 0;
194 s->img_count = 0;
195
196 /* find format */
197 if (s1->iformat->flags & AVFMT_NOFILE)
198 s->is_pipe = 0;
199 else {
200 s->is_pipe = 1;
202 }
203
204 if (s->ts_from_file == 2) {
205#if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
206 av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
207 return AVERROR(ENOSYS);
208#endif
209 avpriv_set_pts_info(st, 64, 1, 1000000000);
210 } else if (s->ts_from_file)
211 avpriv_set_pts_info(st, 64, 1, 1);
212 else {
213 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
214 st->avg_frame_rate = st->r_frame_rate = s->framerate;
215 }
216
217 if (s->width && s->height) {
218 st->codecpar->width = s->width;
219 st->codecpar->height = s->height;
220 }
221
222 if (!s->is_pipe) {
223 if (s->pattern_type == PT_DEFAULT) {
224 if (s1->pb) {
225 s->pattern_type = PT_NONE;
226 } else
227 s->pattern_type = PT_SEQUENCE;
228 }
229 if (s->pattern_type == PT_SEQUENCE) {
230 if (find_image_range(&first_index, &last_index, s1->url,
231 s->start_number, s->start_number_range) < 0) {
232 if (s1->pb || avio_check(s1->url, AVIO_FLAG_READ) > 0) {
233 // Fallback to normal mode
234 s->pattern_type = PT_NONE;
235 } else {
237 "Could find no file or sequence with path '%s' and index in the range %d-%d\n",
238 s1->url, s->start_number, s->start_number + s->start_number_range - 1);
239 return AVERROR(ENOENT);
240 }
241 }
242 } else if (s->pattern_type == PT_GLOB) {
243#if HAVE_GLOB
244 int gerr;
245 gerr = glob(s1->url, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
246 if (gerr != 0) {
247 return AVERROR(ENOENT);
248 }
249 first_index = 0;
250 last_index = s->globstate.gl_pathc - 1;
251 s->use_glob = 1;
252#else
254 "Pattern type 'glob' was selected but globbing "
255 "is not supported by this libavformat build\n");
256 return AVERROR(ENOSYS);
257#endif
258 } else if (s->pattern_type != PT_NONE) {
260 "Unknown value '%d' for pattern_type option\n", s->pattern_type);
261 return AVERROR(EINVAL);
262 }
263 s->img_first = first_index;
264 s->img_last = last_index;
265 s->img_number = first_index;
266 /* compute duration */
267 if (!s->ts_from_file) {
268 st->start_time = 0;
269 st->duration = last_index - first_index + 1;
270 }
271 }
272
273 if (s1->video_codec_id) {
276 } else if (s1->audio_codec_id) {
279 } else if (ffifmt(s1->iformat)->raw_codec_id) {
282 } else {
283 const char *str = strrchr(s1->url, '.');
284 s->split_planes = str && !av_strcasecmp(str + 1, "y");
286 if (s1->pb) {
287 int probe_buffer_size = 2048;
288 uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE);
289 const AVInputFormat *fmt = NULL;
290 void *fmt_iter = NULL;
291 AVProbeData pd = { 0 };
292
293 if (!probe_buffer)
294 return AVERROR(ENOMEM);
295
296 probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size);
297 if (probe_buffer_size < 0) {
298 av_free(probe_buffer);
299 return probe_buffer_size;
300 }
301 memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE);
302
303 pd.buf = probe_buffer;
304 pd.buf_size = probe_buffer_size;
305 pd.filename = s1->url;
306
307 while ((fmt = av_demuxer_iterate(&fmt_iter))) {
308 const FFInputFormat *fmt2 = ffifmt(fmt);
309 if (fmt2->read_header != ff_img_read_header ||
310 !fmt2->read_probe ||
311 (fmt->flags & AVFMT_NOFILE) ||
312 !fmt2->raw_codec_id)
313 continue;
314 if (fmt2->read_probe(&pd) > 0) {
315 st->codecpar->codec_id = fmt2->raw_codec_id;
316 break;
317 }
318 }
319 if (s1->flags & AVFMT_FLAG_CUSTOM_IO) {
320 avio_seek(s1->pb, 0, SEEK_SET);
321 av_freep(&probe_buffer);
322 } else
323 ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size);
324 }
329 if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distinguish this from BRENDER_PIX
331 }
334 st->codecpar->format = pix_fmt;
335
336 return 0;
337}
338
339/**
340 * Add this frame's source path and basename to packet's sidedata
341 * as a dictionary, so it can be used by filters like 'drawtext'.
342 */
343static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) {
344 AVDictionary *d = NULL;
345 char *packed_metadata = NULL;
346 size_t metadata_len;
347 int ret;
348
349 av_dict_set(&d, "lavf.image2dec.source_path", filename, 0);
350 av_dict_set(&d, "lavf.image2dec.source_basename", av_basename(filename), 0);
351
352 packed_metadata = av_packet_pack_dictionary(d, &metadata_len);
353 av_dict_free(&d);
354 if (!packed_metadata)
355 return AVERROR(ENOMEM);
357 packed_metadata, metadata_len);
358 if (ret < 0) {
359 av_freep(&packed_metadata);
360 return ret;
361 }
362 return 0;
363}
364
366{
368 AVBPrint filename;
369 int i, res;
370 int ret[3] = { 0 };
371 int64_t size[3] = { 0 };
372 AVIOContext *f[3] = { NULL };
373 AVCodecParameters *par = s1->streams[0]->codecpar;
374
376 if (!s->is_pipe) {
377 /* loop over input */
378 if (s->loop && s->img_number > s->img_last) {
379 s->img_number = s->img_first;
380 }
381 if (s->img_number > s->img_last)
382 return AVERROR_EOF;
383 if (s->pattern_type == PT_NONE) {
384 av_bprintf(&filename, "%s", s1->url);
385 } else if (s->use_glob) {
386#if HAVE_GLOB
387 av_bprintf(&filename, "%s", s->globstate.gl_pathv[s->img_number]);
388#endif
389 } else {
390 int ret = ff_bprint_get_frame_filename(&filename, s1->url, s->img_number, 0);
391 if (ret < 0) {
392 av_bprint_finalize(&filename, NULL);
393 return ret;
394 }
395 }
396 if (!av_bprint_is_complete(&filename)) {
397 av_bprint_finalize(&filename, NULL);
398 return AVERROR(ENOMEM);
399 }
400 for (i = 0; i < 3; i++) {
401 if (s1->pb &&
402 !strcmp(filename.str, s1->url) &&
403 !s->loop &&
404 !s->split_planes) {
405 f[i] = s1->pb;
406 } else if ((res = s1->io_open(s1, &f[i], filename.str, AVIO_FLAG_READ, NULL)) < 0) {
407 if (i >= 1)
408 break;
409 av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",
410 filename.str);
411 av_bprint_finalize(&filename, NULL);
412 return res;
413 }
414 size[i] = avio_size(f[i]);
415
416 if (!s->split_planes)
417 break;
418 filename.str[filename.len - 1] = 'U' + i;
419 }
420 av_bprint_finalize(&filename, NULL);
421
422 if (par->codec_id == AV_CODEC_ID_NONE) {
423 AVProbeData pd = { 0 };
424 const FFInputFormat *ifmt;
426 int ret;
427 int score = 0;
428
429 ret = avio_read(f[0], header, PROBE_BUF_MIN);
430 if (ret < 0) {
431 av_bprint_finalize(&filename, NULL);
432 return ret;
433 }
434 memset(header + ret, 0, sizeof(header) - ret);
435 avio_skip(f[0], -ret);
436 pd.buf = header;
437 pd.buf_size = ret;
438 pd.filename = filename.str;
439
440 ifmt = ffifmt(av_probe_input_format3(&pd, 1, &score));
441 if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id)
442 par->codec_id = ifmt->raw_codec_id;
443 }
444
445 if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
446 infer_size(&par->width, &par->height, size[0]);
447 } else {
448 f[0] = s1->pb;
449 if (avio_feof(f[0]) && s->loop && s->is_pipe)
450 avio_seek(f[0], 0, SEEK_SET);
451 if (avio_feof(f[0]))
452 return AVERROR_EOF;
453 if (s->frame_size > 0) {
454 size[0] = s->frame_size;
455 } else if (!ffstream(s1->streams[0])->parser) {
456 size[0] = avio_size(s1->pb);
457 } else {
458 size[0] = 4096;
459 }
460 }
461
462 int total_size = 0;
463 for (int i = 0; i < 3; i++) {
464 if ((uint64_t)size[i] > INT_MAX - total_size)
465 return AVERROR_INVALIDDATA;
466
467 total_size += size[i];
468 }
469
470 res = av_new_packet(pkt, total_size);
471 if (res < 0) {
472 goto fail;
473 }
474 pkt->stream_index = 0;
475 pkt->flags |= AV_PKT_FLAG_KEY;
476 if (s->ts_from_file) {
477 struct stat img_stat;
478 av_assert0(!s->is_pipe); // The ts_from_file option is not supported by piped input demuxers
479 if (stat(filename.str, &img_stat)) {
480 res = AVERROR(errno);
481 goto fail;
482 }
483 pkt->pts = (int64_t)img_stat.st_mtime;
484#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
485 if (s->ts_from_file == 2)
486 pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
487#endif
488 av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
489 } else if (!s->is_pipe) {
490 pkt->pts = s->pts;
491 }
492
493 if (s->is_pipe)
494 pkt->pos = avio_tell(f[0]);
495
496 /*
497 * export_path_metadata must be explicitly enabled via
498 * command line options for path metadata to be exported
499 * as packet side_data.
500 */
501 if (!s->is_pipe && s->export_path_metadata == 1) {
502 res = add_filename_as_pkt_side_data(filename.str, pkt);
503 if (res < 0)
504 goto fail;
505 }
506 av_bprint_finalize(&filename, NULL);
507
508 pkt->size = 0;
509 for (i = 0; i < 3; i++) {
510 if (f[i]) {
511 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
512 if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) {
513 if (avio_seek(f[i], 0, SEEK_SET) >= 0) {
514 pkt->pos = 0;
515 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
516 }
517 }
518 if (!s->is_pipe && f[i] != s1->pb)
519 ff_format_io_close(s1, &f[i]);
520 if (ret[i] > 0)
521 pkt->size += ret[i];
522 }
523 }
524
525 if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
526 if (ret[0] < 0) {
527 res = ret[0];
528 } else if (ret[1] < 0) {
529 res = ret[1];
530 } else if (ret[2] < 0) {
531 res = ret[2];
532 } else {
533 res = AVERROR_EOF;
534 }
535 goto fail;
536 } else {
537 memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
538 s->img_count++;
539 s->img_number++;
540 s->pts++;
541 return 0;
542 }
543
544fail:
545 av_bprint_finalize(&filename, NULL);
546 if (!s->is_pipe) {
547 for (i = 0; i < 3; i++) {
548 if (f[i] != s1->pb)
549 ff_format_io_close(s1, &f[i]);
550 }
551 }
552 return res;
553}
554
555static int img_read_close(struct AVFormatContext* s1)
556{
557#if HAVE_GLOB
559 if (s->use_glob) {
560 globfree(&s->globstate);
561 }
562#endif
563 return 0;
564}
565
566static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
567{
568 VideoDemuxData *s1 = s->priv_data;
569 AVStream *st = s->streams[0];
570
571 if (s1->ts_from_file) {
572 int index = av_index_search_timestamp(st, timestamp, flags);
573 if(index < 0)
574 return -1;
576 return 0;
577 }
578
579 if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
580 return -1;
581 s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
582 s1->pts = timestamp;
583 return 0;
584}
585
586#define OFFSET(x) offsetof(VideoDemuxData, x)
587#define DEC AV_OPT_FLAG_DECODING_PARAM
588#define COMMON_OPTIONS \
589 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
590 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \
591 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \
592 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
593 { NULL },
594
595#if CONFIG_IMAGE2_DEMUXER
596const AVOption ff_img_options[] = {
597 { "pattern_type", "set pattern type", OFFSET(pattern_type), AV_OPT_TYPE_INT, {.i64=PT_DEFAULT}, 0, INT_MAX, DEC, .unit = "pattern_type"},
598 { "glob", "select glob pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
599 { "sequence", "select sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
600 { "none", "disable pattern matching", 0, AV_OPT_TYPE_CONST, {.i64=PT_NONE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
601 { "start_number", "set first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, DEC },
602 { "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 },
603 { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC, .unit = "ts_type" },
604 { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 2, DEC, .unit = "ts_type" },
605 { "sec", "second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 2, DEC, .unit = "ts_type" },
606 { "ns", "nanosecond precision", 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2, DEC, .unit = "ts_type" },
607 { "export_path_metadata", "enable metadata containing input path information", OFFSET(export_path_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
609};
610
611static const AVClass img2_class = {
612 .class_name = "image2 demuxer",
613 .item_name = av_default_item_name,
614 .option = ff_img_options,
615 .version = LIBAVUTIL_VERSION_INT,
616};
618 .p.name = "image2",
619 .p.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
620 .p.flags = AVFMT_NOFILE,
621 .p.priv_class = &img2_class,
622 .priv_data_size = sizeof(VideoDemuxData),
628};
629#endif
630
631static const AVOption img2pipe_options[] = {
632 { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
634};
635static const AVClass imagepipe_class = {
636 .class_name = "imagepipe demuxer",
637 .item_name = av_default_item_name,
638 .option = img2pipe_options,
639 .version = LIBAVUTIL_VERSION_INT,
640};
641
642#if CONFIG_IMAGE2PIPE_DEMUXER
644 .p.name = "image2pipe",
645 .p.long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
646 .p.priv_class = &imagepipe_class,
647 .priv_data_size = sizeof(VideoDemuxData),
650};
651#endif
652
653static int bmp_probe(const AVProbeData *p)
654{
655 const uint8_t *b = p->buf;
656 int ihsize;
657
658 if (AV_RB16(b) != 0x424d)
659 return 0;
660
661 ihsize = AV_RL32(b+14);
662 if (ihsize < 12 || ihsize > 255)
663 return 0;
664
665 if (!AV_RN32(b + 6)) {
666 return AVPROBE_SCORE_EXTENSION + 1;
667 }
668 return AVPROBE_SCORE_EXTENSION / 4;
669}
670
671static int cri_probe(const AVProbeData *p)
672{
673 const uint8_t *b = p->buf;
674
675 if ( AV_RL32(b) == 1
676 && AV_RL32(b + 4) == 4
677 && AV_RN32(b + 8) == AV_RN32("DVCC"))
678 return AVPROBE_SCORE_MAX - 1;
679 return 0;
680}
681
682static int dds_probe(const AVProbeData *p)
683{
684 const uint8_t *b = p->buf;
685
686 if ( AV_RB64(b) == 0x444453207c000000
687 && AV_RL32(b + 8)
688 && AV_RL32(b + 12))
689 return AVPROBE_SCORE_MAX - 1;
690 return 0;
691}
692
693static int dpx_probe(const AVProbeData *p)
694{
695 const uint8_t *b = p->buf;
696 int w, h;
697 int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
698
699 if (p->buf_size < 0x304+8)
700 return 0;
701 w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
702 h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
703 if (w <= 0 || h <= 0)
704 return 0;
705
706 if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
707 return AVPROBE_SCORE_EXTENSION + 1;
708 return 0;
709}
710
711static int exr_probe(const AVProbeData *p)
712{
713 const uint8_t *b = p->buf;
714
715 if (AV_RL32(b) == 20000630)
716 return AVPROBE_SCORE_EXTENSION + 1;
717 return 0;
718}
719
720static int j2k_probe(const AVProbeData *p)
721{
722 const uint8_t *b = p->buf;
723
724 if (AV_RB64(b) == 0x0000000c6a502020 ||
725 AV_RB32(b) == 0xff4fff51)
726 return AVPROBE_SCORE_EXTENSION + 1;
727 return 0;
728}
729
730static int jpeg_probe(const AVProbeData *p)
731{
732 const uint8_t *b = p->buf;
733 int i, state = SOI, got_header = 0;
734
735 if (AV_RB16(b) != 0xFFD8 ||
736 AV_RB32(b) == 0xFFD8FFF7)
737 return 0;
738
739 b += 2;
740 for (i = 0; i < p->buf_size - 3; i++) {
741 int c;
742 if (b[i] != 0xFF)
743 continue;
744 c = b[i + 1];
745 switch (c) {
746 case SOI:
747 return 0;
748 case SOF0:
749 case SOF1:
750 case SOF2:
751 case SOF3:
752 case SOF5:
753 case SOF6:
754 case SOF7:
755 i += AV_RB16(&b[i + 2]) + 1;
756 if (state != SOI)
757 return 0;
758 state = SOF0;
759 break;
760 case SOS:
761 i += AV_RB16(&b[i + 2]) + 1;
762 if (state != SOF0 && state != SOS)
763 return 0;
764 state = SOS;
765 break;
766 case EOI:
767 if (state != SOS)
768 return 0;
769 state = EOI;
770 break;
771 case APP0:
772 if (c == APP0 && AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F'))
773 got_header = 1;
775 case APP1:
776 if (c == APP1 && AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f'))
777 got_header = 1;
779 case APP2:
780 case APP3:
781 case APP4:
782 case APP5:
783 case APP6:
784 case APP7:
785 case APP8:
786 case APP9:
787 case APP10:
788 case APP11:
789 case APP12:
790 case APP13:
791 case APP14:
792 case APP15:
793 case DQT: /* fallthrough */
794 case COM:
795 i += AV_RB16(&b[i + 2]) + 1;
796 break;
797 default:
798 if ( (c > TEM && c < SOF0)
799 || c == JPG)
800 return 0;
801 }
802 }
803
804 if (state == EOI)
805 return AVPROBE_SCORE_EXTENSION + 1;
806 if (state == SOS)
807 return AVPROBE_SCORE_EXTENSION / 2 + got_header;
808 return AVPROBE_SCORE_EXTENSION / 8 + 1;
809}
810
811static int jpegls_probe(const AVProbeData *p)
812{
813 const uint8_t *b = p->buf;
814
815 if (AV_RB32(b) == 0xffd8fff7)
816 return AVPROBE_SCORE_EXTENSION + 1;
817 return 0;
818}
819
820static int jpegxl_probe(const AVProbeData *p)
821{
822 const uint8_t *b = p->buf;
823
824 /* ISOBMFF-based container */
825 /* 0x4a584c20 == "JXL " */
827 return AVPROBE_SCORE_EXTENSION + 1;
828 /* Raw codestreams all start with 0xff0a */
830 return 0;
831#if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
832 if (ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, NULL, 5) >= 0)
833 return AVPROBE_SCORE_MAX - 2;
834#endif
835 return 0;
836}
837
838static int jpegxs_probe(const AVProbeData *p)
839{
840 const uint8_t *b = p->buf;
841
842 if (AV_RB32(b) == 0xff10ff50)
843 return AVPROBE_SCORE_EXTENSION + 1;
844 return 0;
845}
846
847static int pcx_probe(const AVProbeData *p)
848{
849 const uint8_t *b = p->buf;
850
851 if ( p->buf_size < 128
852 || b[0] != 10
853 || b[1] > 5
854 || b[2] > 1
855 || av_popcount(b[3]) != 1 || b[3] > 8
856 || AV_RL16(&b[4]) > AV_RL16(&b[8])
857 || AV_RL16(&b[6]) > AV_RL16(&b[10])
858 || b[64])
859 return 0;
860 b += 73;
861 while (++b < p->buf + 128)
862 if (*b)
863 return AVPROBE_SCORE_EXTENSION / 4;
864
865 return AVPROBE_SCORE_EXTENSION + 1;
866}
867
868static int qdraw_probe(const AVProbeData *p)
869{
870 const uint8_t *b = p->buf;
871
872 if ( p->buf_size >= 528
873 && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
874 && AV_RB16(b + 520)
875 && AV_RB16(b + 518))
876 return AVPROBE_SCORE_MAX * 3 / 4;
877 if ( (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
878 && AV_RB16(b + 8)
879 && AV_RB16(b + 6))
880 return AVPROBE_SCORE_EXTENSION / 4;
881 return 0;
882}
883
884static int pictor_probe(const AVProbeData *p)
885{
886 const uint8_t *b = p->buf;
887
888 if (AV_RL16(b) == 0x1234)
889 return AVPROBE_SCORE_EXTENSION / 4;
890 return 0;
891}
892
893static int png_probe(const AVProbeData *p)
894{
895 const uint8_t *b = p->buf;
896 int size = p->buf_size;
897 int pos = 8;
898
899 if (AV_RB64(b) != PNGSIG)
900 return 0;
901
902 /* png_pipe demuxes a sequence of images, so the bytes after a whole
903 * image in the buffer have to match another signature as far as the
904 * buffer goes. Anything else is an unrelated payload behind a PNG,
905 * like the 1x1 image some CDNs prepend to MPEG-TS segments, and the
906 * signature alone must not outscore the demuxer of that payload. */
907 while (size - pos >= 12) {
908 uint32_t len = AV_RB32(b + pos);
909 uint32_t tag = AV_RB32(b + pos + 4);
910
911 if (len > size - pos - 12)
912 break;
913 pos += 12 + len;
914 if (tag == MKBETAG('I', 'E', 'N', 'D')) {
915 int n = FFMIN(size - pos, 8);
916 if (n && (AV_RB64(b + pos) ^ PNGSIG) >> (64 - 8 * n))
917 return AVPROBE_SCORE_RETRY;
918 pos += n;
919 }
920 }
921
922 return AVPROBE_SCORE_MAX - 1;
923}
924
925static int psd_probe(const AVProbeData *p)
926{
927 const uint8_t *b = p->buf;
928 int ret = 0;
929 uint16_t color_mode;
930
931 if (AV_RL32(b) == MKTAG('8','B','P','S')) {
932 ret += 1;
933 } else {
934 return 0;
935 }
936
937 if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */
938 ret += 1;
939 } else {
940 return 0;
941 }
942
943 if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */
944 ret += 1;
945
946 color_mode = AV_RB16(b+24);
947 if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
948 ret += 1;
949
950 return AVPROBE_SCORE_EXTENSION + ret;
951}
952
953static int sgi_probe(const AVProbeData *p)
954{
955 const uint8_t *b = p->buf;
956
957 if (AV_RB16(b) == 474 &&
958 (b[2] & ~1) == 0 &&
959 (b[3] & ~3) == 0 && b[3] &&
960 (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4))
961 return AVPROBE_SCORE_EXTENSION + 1;
962 return 0;
963}
964
965static int sunrast_probe(const AVProbeData *p)
966{
967 const uint8_t *b = p->buf;
968
969 if (AV_RB32(b) == 0x59a66a95)
970 return AVPROBE_SCORE_EXTENSION + 1;
971 return 0;
972}
973
974static int svg_probe(const AVProbeData *p)
975{
976 const uint8_t *b = p->buf;
977 const uint8_t *end = p->buf + p->buf_size;
978 while (b < end && av_isspace(*b))
979 b++;
980 if (b >= end - 5)
981 return 0;
982 if (!memcmp(b, "<svg", 4))
983 return AVPROBE_SCORE_EXTENSION + 1;
984 if (memcmp(p->buf, "<?xml", 5) && memcmp(b, "<!--", 4))
985 return 0;
986 while (b < end) {
988 if (!inc)
989 break;
990 b += inc;
991 if (b >= end - 4)
992 return 0;
993 if (!memcmp(b, "<svg", 4))
994 return AVPROBE_SCORE_EXTENSION + 1;
995 }
996 return 0;
997}
998
999static int tiff_probe(const AVProbeData *p)
1000{
1001 const uint8_t *b = p->buf;
1002
1003 if (AV_RB32(b) == 0x49492a00 ||
1004 AV_RB32(b) == 0x4D4D002a)
1005 return AVPROBE_SCORE_EXTENSION + 1;
1006 return 0;
1007}
1008
1009static int rw2_probe(const AVProbeData *p)
1010{
1011 if (AV_RB32(p->buf) == 0x49495500 && AV_RL32(p->buf + 4) >= 8)
1012 return AVPROBE_SCORE_MAX;
1013 return 0;
1014}
1015
1016static int webp_probe(const AVProbeData *p)
1017{
1018 const uint8_t *b = p->buf;
1019
1020 if (AV_RB32(b) == 0x52494646 &&
1021 AV_RB32(b + 8) == 0x57454250)
1022 return AVPROBE_SCORE_MAX - 1;
1023 return 0;
1024}
1025
1026static int pnm_magic_check(const AVProbeData *p, int magic)
1027{
1028 const uint8_t *b = p->buf;
1029
1030 return b[0] == 'P' && b[1] == magic + '0';
1031}
1032
1033static inline int pnm_probe(const AVProbeData *p)
1034{
1035 const uint8_t *b = p->buf;
1036
1037 while (b[2] == '\r')
1038 b++;
1039 if (b[2] == '\n' && (b[3] == '#' || (b[3] >= '0' && b[3] <= '9')))
1040 return AVPROBE_SCORE_EXTENSION + 2;
1041 return 0;
1042}
1043
1044static int pbm_probe(const AVProbeData *p)
1045{
1046 return pnm_magic_check(p, 1) || pnm_magic_check(p, 4) ? pnm_probe(p) : 0;
1047}
1048
1049static int pfm_probe(const AVProbeData *p)
1050{
1051 return pnm_magic_check(p, 'F' - '0') ||
1052 pnm_magic_check(p, 'f' - '0') ? pnm_probe(p) : 0;
1053}
1054
1055static int phm_probe(const AVProbeData *p)
1056{
1057 return pnm_magic_check(p, 'H' - '0') ||
1058 pnm_magic_check(p, 'h' - '0') ? pnm_probe(p) : 0;
1059}
1060
1061static inline int pgmx_probe(const AVProbeData *p)
1062{
1063 return pnm_magic_check(p, 2) || pnm_magic_check(p, 5) ? pnm_probe(p) : 0;
1064}
1065
1066static int pgm_probe(const AVProbeData *p)
1067{
1068 int ret = pgmx_probe(p);
1069 return ret && !av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1070}
1071
1072static int pgmyuv_probe(const AVProbeData *p) // custom FFmpeg format recognized by file extension
1073{
1074 int ret = pgmx_probe(p);
1075 return ret && av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1076}
1077
1078static int pgx_probe(const AVProbeData *p)
1079{
1080 const uint8_t *b = p->buf;
1081 if (!memcmp(b, "PG ML ", 6))
1082 return AVPROBE_SCORE_EXTENSION + 1;
1083 return 0;
1084}
1085
1086static int ppm_probe(const AVProbeData *p)
1087{
1088 return pnm_magic_check(p, 3) || pnm_magic_check(p, 6) ? pnm_probe(p) : 0;
1089}
1090
1091static int pam_probe(const AVProbeData *p)
1092{
1093 return pnm_magic_check(p, 7) ? pnm_probe(p) : 0;
1094}
1095
1096static int hdr_probe(const AVProbeData *p)
1097{
1098 if (!memcmp(p->buf, "#?RADIANCE\n", 11) || !memcmp(p->buf, "#?RGBE\n", 7))
1099 return AVPROBE_SCORE_MAX;
1100 return 0;
1101}
1102
1103static int xbm_probe(const AVProbeData *p)
1104{
1105 if (!memcmp(p->buf, "/* XBM X10 format */", 20))
1106 return AVPROBE_SCORE_MAX;
1107
1108 if (!memcmp(p->buf, "#define", 7))
1109 return AVPROBE_SCORE_MAX - 1;
1110 return 0;
1111}
1112
1113static int xpm_probe(const AVProbeData *p)
1114{
1115 const uint8_t *b = p->buf;
1116
1117 if (AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) == '/')
1118 return AVPROBE_SCORE_MAX - 1;
1119 return 0;
1120}
1121
1122static int xwd_probe(const AVProbeData *p)
1123{
1124 const uint8_t *b = p->buf;
1125 unsigned width, bpp, bpad, lsize;
1126
1127 if ( p->buf_size < XWD_HEADER_SIZE
1128 || AV_RB32(b ) < XWD_HEADER_SIZE // header size
1129 || AV_RB32(b + 4) != XWD_VERSION // version
1130 || AV_RB32(b + 8) != XWD_Z_PIXMAP // format
1131 || AV_RB32(b + 12) > 32 || !AV_RB32(b + 12) // depth
1132 || AV_RB32(b + 16) == 0 // width
1133 || AV_RB32(b + 20) == 0 // height
1134 || AV_RB32(b + 28) > 1 // byteorder
1135 || AV_RB32(b + 32) & ~56 || av_popcount(AV_RB32(b + 32)) != 1 // bitmap unit
1136 || AV_RB32(b + 36) > 1 // bitorder
1137 || AV_RB32(b + 40) & ~56 || av_popcount(AV_RB32(b + 40)) != 1 // padding
1138 || AV_RB32(b + 44) > 32 || !AV_RB32(b + 44) // bpp
1139 || AV_RB32(b + 68) > 256) // colours
1140 return 0;
1141
1142 width = AV_RB32(b + 16);
1143 bpad = AV_RB32(b + 40);
1144 bpp = AV_RB32(b + 44);
1145 lsize = AV_RB32(b + 48);
1146 if (lsize < FFALIGN(width * bpp, bpad) >> 3)
1147 return 0;
1148
1149 return AVPROBE_SCORE_MAX / 2 + 1;
1150}
1151
1152static int gif_probe(const AVProbeData *p)
1153{
1154 /* check magick */
1155 if (memcmp(p->buf, gif87a_sig, 6) && memcmp(p->buf, gif89a_sig, 6))
1156 return 0;
1157
1158 /* width or height contains zero? */
1159 if (!AV_RL16(&p->buf[6]) || !AV_RL16(&p->buf[8]))
1160 return 0;
1161
1162 return AVPROBE_SCORE_MAX - 1;
1163}
1164
1165static int photocd_probe(const AVProbeData *p)
1166{
1167 if (!memcmp(p->buf, "PCD_OPA", 7))
1168 return AVPROBE_SCORE_MAX - 1;
1169
1170 if (p->buf_size < 0x807 || memcmp(p->buf + 0x800, "PCD_IPI", 7))
1171 return 0;
1172
1173 return AVPROBE_SCORE_MAX - 1;
1174}
1175
1176static int qoi_probe(const AVProbeData *p)
1177{
1178 if (memcmp(p->buf, "qoif", 4))
1179 return 0;
1180
1181 if (AV_RB32(p->buf + 4) == 0 || AV_RB32(p->buf + 8) == 0)
1182 return 0;
1183
1184 if (p->buf[12] != 3 && p->buf[12] != 4)
1185 return 0;
1186
1187 if (p->buf[13] > 1)
1188 return 0;
1189
1190 return AVPROBE_SCORE_MAX - 1;
1191}
1192
1193static int gem_probe(const AVProbeData *p)
1194{
1195 const uint8_t *b = p->buf;
1196 if ( AV_RB16(b ) >= 1 && AV_RB16(b ) <= 3 &&
1197 AV_RB16(b + 2) >= 8 && AV_RB16(b + 2) <= 779 &&
1198 (AV_RB16(b + 4) > 0 && AV_RB16(b + 4) <= 32) && /* planes */
1199 (AV_RB16(b + 6) > 0 && AV_RB16(b + 6) <= 8) && /* pattern_size */
1200 AV_RB16(b + 8) &&
1201 AV_RB16(b + 10) &&
1202 AV_RB16(b + 12) &&
1203 AV_RB16(b + 14)) {
1204 if (AV_RN32(b + 16) == AV_RN32("STTT") ||
1205 AV_RN32(b + 16) == AV_RN32("TIMG") ||
1206 AV_RN32(b + 16) == AV_RN32("XIMG"))
1207 return AVPROBE_SCORE_EXTENSION + 1;
1208 return AVPROBE_SCORE_EXTENSION / 4;
1209 }
1210 return 0;
1211}
1212
1213static int vbn_probe(const AVProbeData *p)
1214{
1215 const uint8_t *b = p->buf;
1216 if (AV_RL32(b ) == VBN_MAGIC &&
1217 AV_RL32(b + 4) == VBN_MAJOR &&
1218 AV_RL32(b + 8) == VBN_MINOR)
1219 return AVPROBE_SCORE_MAX - 1;
1220 return 0;
1221}
1222
1223#define IMAGEAUTO_DEMUXER_0(imgname, codecid)
1224#define IMAGEAUTO_DEMUXER_1(imgname, codecid)\
1225const FFInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1226 .p.name = AV_STRINGIFY(imgname) "_pipe",\
1227 .p.long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1228 .p.priv_class = &imagepipe_class,\
1229 .p.flags = AVFMT_GENERIC_INDEX,\
1230 .priv_data_size = sizeof(VideoDemuxData),\
1231 .read_probe = imgname ## _probe,\
1232 .read_header = ff_img_read_header,\
1233 .read_packet = ff_img_read_packet,\
1234 .raw_codec_id = codecid,\
1235};
1236
1237#define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \
1238 IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid)
1239#define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \
1240 IMAGEAUTO_DEMUXER_2(imgname, codecid, config)
1241#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \
1242 IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid, \
1243 CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER)
1244#define IMAGEAUTO_DEMUXER(imgname, codecid) \
1245 IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid)
1246
1247IMAGEAUTO_DEMUXER(bmp, BMP)
1248IMAGEAUTO_DEMUXER(cri, CRI)
1249IMAGEAUTO_DEMUXER(dds, DDS)
1250IMAGEAUTO_DEMUXER(dpx, DPX)
1251IMAGEAUTO_DEMUXER(exr, EXR)
1252IMAGEAUTO_DEMUXER(gem, GEM)
1253IMAGEAUTO_DEMUXER(gif, GIF)
1254IMAGEAUTO_DEMUXER_EXT(hdr, RADIANCE_HDR, HDR)
1255IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K)
1256IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG)
1257IMAGEAUTO_DEMUXER(jpegxs, JPEGXS)
1258IMAGEAUTO_DEMUXER(jpegls, JPEGLS)
1259IMAGEAUTO_DEMUXER(jpegxl, JPEGXL)
1260IMAGEAUTO_DEMUXER(pam, PAM)
1261IMAGEAUTO_DEMUXER(pbm, PBM)
1262IMAGEAUTO_DEMUXER(pcx, PCX)
1263IMAGEAUTO_DEMUXER(pfm, PFM)
1264IMAGEAUTO_DEMUXER(pgm, PGM)
1265IMAGEAUTO_DEMUXER(pgmyuv, PGMYUV)
1266IMAGEAUTO_DEMUXER(pgx, PGX)
1267IMAGEAUTO_DEMUXER(phm, PHM)
1268IMAGEAUTO_DEMUXER(photocd, PHOTOCD)
1269IMAGEAUTO_DEMUXER(pictor, PICTOR)
1270IMAGEAUTO_DEMUXER(png, PNG)
1271IMAGEAUTO_DEMUXER(ppm, PPM)
1272IMAGEAUTO_DEMUXER(psd, PSD)
1273IMAGEAUTO_DEMUXER(qdraw, QDRAW)
1274IMAGEAUTO_DEMUXER(qoi, QOI)
1275IMAGEAUTO_DEMUXER(rw2, RW2)
1276IMAGEAUTO_DEMUXER(sgi, SGI)
1277IMAGEAUTO_DEMUXER(sunrast, SUNRAST)
1278IMAGEAUTO_DEMUXER(svg, SVG)
1279IMAGEAUTO_DEMUXER(tiff, TIFF)
1280IMAGEAUTO_DEMUXER(vbn, VBN)
1281IMAGEAUTO_DEMUXER(webp, WEBP)
1282IMAGEAUTO_DEMUXER(xbm, XBM)
1283IMAGEAUTO_DEMUXER(xpm, XPM)
1284IMAGEAUTO_DEMUXER(xwd, XWD)
const FFInputFormat ff_image2_demuxer
const FFInputFormat ff_image2pipe_demuxer
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition avformat.c:983
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:856
Main libavformat public API header.
#define AVINDEX_KEYFRAME
Definition avformat.h:630
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:485
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition avformat.h:487
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition avformat.h:1351
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:490
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition avformat.h:483
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition avformat.h:1560
#define AVPROBE_SCORE_RETRY
Definition avformat.h:480
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition avformat.h:613
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
Definition avio.c:739
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
#define AVIO_FLAG_READ
read-only
Definition avio.h:617
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **buf, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file.
Definition aviobuf.c:1110
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_UNLIMITED
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define av_popcount
Definition common.h:154
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define EOI
End Of Image marker.
Definition cpia.c:43
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
Definition demux.h:186
static AVPacket * pkt
static enum AVPixelFormat pix_fmt
static struct @346255127015250356166251341105367306144006377143 state
static int loop
Definition ffplay.c:407
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
static const uint8_t frame_size[4]
Definition g723_1.h:222
GIF format definitions.
static attribute_nonstring const uint8_t gif89a_sig[6]
Definition gif.h:37
static attribute_nonstring const uint8_t gif87a_sig[6]
Definition gif.h:36
#define fail
Definition test.h:479
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_ALIAS_PIX
Definition codec_id.h:226
@ AV_CODEC_ID_LJPEG
Definition codec_id.h:59
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition packet.h:169
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
uint8_t * av_packet_pack_dictionary(const AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
Definition packet.c:320
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition packet.c:197
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
Definition allformats.c:623
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
Definition format.c:156
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition seek.c:122
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
Definition format.c:41
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition utils.c:121
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition seek.c:245
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:226
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition avstring.h:218
const char * av_basename(const char *path)
Thread safe basename.
Definition avstring.c:256
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition img2.c:127
@ PT_NONE
Definition img2.h:36
@ PT_DEFAULT
Definition img2.h:37
@ PT_SEQUENCE
Definition img2.h:35
@ PT_GLOB
Definition img2.h:34
const AVOption ff_img_options[]
int ff_img_read_header(AVFormatContext *s1)
Definition img2dec.c:172
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition img2dec.c:365
#define IMAGEAUTO_DEMUXER(imgname, codecid)
Definition img2dec.c:1244
static int jpegxs_probe(const AVProbeData *p)
Definition img2dec.c:838
static int pbm_probe(const AVProbeData *p)
Definition img2dec.c:1044
static int jpegls_probe(const AVProbeData *p)
Definition img2dec.c:811
static int pfm_probe(const AVProbeData *p)
Definition img2dec.c:1049
static int hdr_probe(const AVProbeData *p)
Definition img2dec.c:1096
static int photocd_probe(const AVProbeData *p)
Definition img2dec.c:1165
static int phm_probe(const AVProbeData *p)
Definition img2dec.c:1055
static int xwd_probe(const AVProbeData *p)
Definition img2dec.c:1122
static int jpegxl_probe(const AVProbeData *p)
Definition img2dec.c:820
static int xbm_probe(const AVProbeData *p)
Definition img2dec.c:1103
static int sgi_probe(const AVProbeData *p)
Definition img2dec.c:953
static int img_read_close(struct AVFormatContext *s1)
Definition img2dec.c:555
static int cri_probe(const AVProbeData *p)
Definition img2dec.c:671
static int exr_probe(const AVProbeData *p)
Definition img2dec.c:711
static int tiff_probe(const AVProbeData *p)
Definition img2dec.c:999
static int ppm_probe(const AVProbeData *p)
Definition img2dec.c:1086
static int pnm_probe(const AVProbeData *p)
Definition img2dec.c:1033
static int find_image_range(int *pfirst_index, int *plast_index, const char *path, int start_index, int start_index_range)
Get index range of image files matched by path.
Definition img2dec.c:99
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition img2dec.c:566
static int xpm_probe(const AVProbeData *p)
Definition img2dec.c:1113
static int j2k_probe(const AVProbeData *p)
Definition img2dec.c:720
static int pgx_probe(const AVProbeData *p)
Definition img2dec.c:1078
static int psd_probe(const AVProbeData *p)
Definition img2dec.c:925
static int sunrast_probe(const AVProbeData *p)
Definition img2dec.c:965
static int dpx_probe(const AVProbeData *p)
Definition img2dec.c:693
static int rw2_probe(const AVProbeData *p)
Definition img2dec.c:1009
static int vbn_probe(const AVProbeData *p)
Definition img2dec.c:1213
static int pgm_probe(const AVProbeData *p)
Definition img2dec.c:1066
static const int sizes[][2]
Definition img2dec.c:63
static int pcx_probe(const AVProbeData *p)
Definition img2dec.c:847
static int qdraw_probe(const AVProbeData *p)
Definition img2dec.c:868
#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name)
Definition img2dec.c:1241
static int infer_size(int *width_ptr, int *height_ptr, int size)
Definition img2dec.c:75
static const AVOption img2pipe_options[]
Definition img2dec.c:631
static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt)
Add this frame's source path and basename to packet's sidedata as a dictionary, so it can be used by ...
Definition img2dec.c:343
static int bmp_probe(const AVProbeData *p)
Definition img2dec.c:653
static int pgmyuv_probe(const AVProbeData *p)
Definition img2dec.c:1072
static int dds_probe(const AVProbeData *p)
Definition img2dec.c:682
static int svg_probe(const AVProbeData *p)
Definition img2dec.c:974
static int qoi_probe(const AVProbeData *p)
Definition img2dec.c:1176
int ff_img_read_header(AVFormatContext *s1)
Definition img2dec.c:172
static int pnm_magic_check(const AVProbeData *p, int magic)
Definition img2dec.c:1026
static int gif_probe(const AVProbeData *p)
Definition img2dec.c:1152
static int webp_probe(const AVProbeData *p)
Definition img2dec.c:1016
static int pam_probe(const AVProbeData *p)
Definition img2dec.c:1091
static int gem_probe(const AVProbeData *p)
Definition img2dec.c:1193
#define OFFSET(x)
Definition img2dec.c:586
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition img2dec.c:365
static const AVClass imagepipe_class
Definition img2dec.c:635
static int pgmx_probe(const AVProbeData *p)
Definition img2dec.c:1061
static int pictor_probe(const AVProbeData *p)
Definition img2dec.c:884
static int img_read_probe(const AVProbeData *p)
Definition img2dec.c:155
static int jpeg_probe(const AVProbeData *p)
Definition img2dec.c:730
static int png_probe(const AVProbeData *p)
Definition img2dec.c:893
#define b
Definition input.c:43
#define AV_RN32(p)
#define AV_RL64(p)
#define AV_RL32(p)
#define AV_RB32(p)
#define AV_RB64(p)
#define AV_RL16(p)
#define AV_RB16(p)
#define FF_JPEGXL_CONTAINER_SIGNATURE_LE
Definition jpegxl.h:26
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE
Definition jpegxl.h:25
int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, FFJXLMetadata *meta, int validate)
int ff_bprint_get_frame_filename(struct AVBPrint *buf, const char *path, int64_t number, int flags)
Return in 'buf' the path with 'd' replaced by a number.
Definition utils.c:293
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
#define PROBE_BUF_MIN
size of probe buffer, for guessing file type from file contents
Definition internal.h:33
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
#define DEC
Definition librsvgdec.c:149
#define COMMON_OPTIONS
Definition libvpxenc.c:1986
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define MKBETAG(a, b, c, d)
Definition macros.h:56
#define FFALIGN(x, a)
Definition macros.h:78
enum AVColorRange range
Memory handling functions.
MJPEG encoder and decoder.
@ APP5
Definition mjpeg.h:84
@ APP15
Definition mjpeg.h:94
@ APP9
Definition mjpeg.h:88
@ JPG
Definition mjpeg.h:47
@ DQT
Definition mjpeg.h:73
@ SOF5
Definition mjpeg.h:44
@ SOF2
Definition mjpeg.h:41
@ APP6
Definition mjpeg.h:85
@ APP10
Definition mjpeg.h:89
@ APP1
Definition mjpeg.h:80
@ SOF1
Definition mjpeg.h:40
@ SOF6
Definition mjpeg.h:45
@ APP2
Definition mjpeg.h:81
@ APP8
Definition mjpeg.h:87
@ SOS
Definition mjpeg.h:72
@ SOF7
Definition mjpeg.h:46
@ APP11
Definition mjpeg.h:90
@ APP0
Definition mjpeg.h:79
@ APP13
Definition mjpeg.h:92
@ TEM
Definition mjpeg.h:113
@ APP14
Definition mjpeg.h:93
@ SOI
Definition mjpeg.h:70
@ APP3
Definition mjpeg.h:82
@ COM
Definition mjpeg.h:111
@ APP4
Definition mjpeg.h:83
@ APP7
Definition mjpeg.h:86
@ SOF3
Definition mjpeg.h:42
@ SOF0
Definition mjpeg.h:39
@ APP12
Definition mjpeg.h:91
uint32_t tag
Definition movenc.c:2128
#define av_realloc(p, s)
Definition ops_static.c:54
AVOptions.
miscellaneous OS support macros and functions.
static int inc(int num, int period)
Definition perlin.c:34
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3416
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
#define PNGSIG
Definition png.h:49
static const uint8_t header[24]
Definition sdr2.c:68
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
Describe the class of an AVClass context structure.
Definition log.h:76
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1400
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition avformat.h:1626
AVIOContext * pb
I/O context.
Definition avformat.h:1442
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1552
int ctx_flags
Flags signalling stream properties.
Definition avformat.h:1449
char * url
input or output URL.
Definition avformat.h:1517
const struct AVInputFormat * iformat
The input container format.
Definition avformat.h:1412
enum AVCodecID video_codec_id
Forced video codec_id.
Definition avformat.h:1620
void * priv_data
Format private data.
Definition avformat.h:1428
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1468
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition avformat.h:2021
Bytestream IO Context.
Definition avio.h:160
int64_t pos
Definition avformat.h:623
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, AVFMT_SHOW_IDS,...
Definition avformat.h:587
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
This structure contains the data a format has to probe a file.
Definition avformat.h:473
const char * filename
Definition avformat.h:474
int buf_size
Size of buf except extra allocated bytes.
Definition avformat.h:476
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition avformat.h:475
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:827
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:817
AVRational avg_frame_rate
Average framerate.
Definition avformat.h:857
AVRational r_frame_rate
Real base framerate of the stream.
Definition avformat.h:902
enum AVCodecID raw_codec_id
Raw demuxers store their codec ID here.
Definition demux.h:75
int(* read_packet)(struct AVFormatContext *, AVPacket *pkt)
Read one packet and put it in 'pkt'.
Definition demux.h:109
int(* read_probe)(const AVProbeData *)
Tell if a given file has a chance of being parsed as this format.
Definition demux.h:92
int(* read_header)(struct AVFormatContext *)
Read the format header and initialize the AVFormatContext structure.
Definition demux.h:99
struct AVCodecParserContext * parser
Definition internal.h:322
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:191
enum AVStreamParseType need_parsing
Definition internal.h:321
int img_number
Definition img2.h:44
int ts_from_file
Definition img2.h:61
int img_last
Definition img2.h:43
int64_t pts
Definition img2.h:45
int img_first
Definition img2.h:42
static av_always_inline int ff_subtitles_next_line(const char *ptr)
Get the number of characters to increment to jump to the next line, or to the end of the string.
Definition subtitles.h:205
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
#define width
Definition dsp.h:99
int size
VBN format definitions.
#define VBN_MAJOR
Definition vbn.h:30
#define VBN_MINOR
Definition vbn.h:31
#define VBN_MAGIC
Definition vbn.h:29
int len
static double c[64]
#define XWD_VERSION
Definition xwd.h:26
#define XWD_Z_PIXMAP
Definition xwd.h:32
#define XWD_HEADER_SIZE
Definition xwd.h:27