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 AVInputFormat *fmt;
425 void *opaque = NULL;
427 int ret;
428 int score_max = 0;
429
431 if (ret < 0) {
432 av_bprint_finalize(&filename, NULL);
433 return ret;
434 }
435 memset(header + ret, 0, sizeof(header) - ret);
436 avio_skip(f[0], -ret);
437 pd.buf = header;
438 pd.buf_size = ret;
439 pd.filename = filename.str;
440
441 /* Only consider image demuxers, so that other formats claiming
442 * the same file don't shadow them */
443 while ((fmt = av_demuxer_iterate(&opaque))) {
444 const FFInputFormat *ifmt = ffifmt(fmt);
445 if (ifmt->read_packet != ff_img_read_packet || !ifmt->raw_codec_id)
446 continue;
447 int score = ifmt->read_probe(&pd);
448 if (score > score_max) {
449 score_max = score;
450 par->codec_id = ifmt->raw_codec_id;
451 } else if (score == score_max) {
453 }
454 }
455 }
456
457 if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
458 infer_size(&par->width, &par->height, size[0]);
459 } else {
460 f[0] = s1->pb;
461 if (avio_feof(f[0]) && s->loop && s->is_pipe)
462 avio_seek(f[0], 0, SEEK_SET);
463 if (avio_feof(f[0]))
464 return AVERROR_EOF;
465 if (s->frame_size > 0) {
466 size[0] = s->frame_size;
467 } else if (!ffstream(s1->streams[0])->parser) {
468 size[0] = avio_size(s1->pb);
469 } else {
470 size[0] = 4096;
471 }
472 }
473
474 int total_size = 0;
475 for (int i = 0; i < 3; i++) {
476 if ((uint64_t)size[i] > INT_MAX - total_size)
477 return AVERROR_INVALIDDATA;
478
479 total_size += size[i];
480 }
481
482 res = av_new_packet(pkt, total_size);
483 if (res < 0) {
484 goto fail;
485 }
486 pkt->stream_index = 0;
487 pkt->flags |= AV_PKT_FLAG_KEY;
488 if (s->ts_from_file) {
489 struct stat img_stat;
490 av_assert0(!s->is_pipe); // The ts_from_file option is not supported by piped input demuxers
491 if (stat(filename.str, &img_stat)) {
492 res = AVERROR(errno);
493 goto fail;
494 }
495 pkt->pts = (int64_t)img_stat.st_mtime;
496#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
497 if (s->ts_from_file == 2)
498 pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
499#endif
500 av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
501 } else if (!s->is_pipe) {
502 pkt->pts = s->pts;
503 }
504
505 if (s->is_pipe)
506 pkt->pos = avio_tell(f[0]);
507
508 /*
509 * export_path_metadata must be explicitly enabled via
510 * command line options for path metadata to be exported
511 * as packet side_data.
512 */
513 if (!s->is_pipe && s->export_path_metadata == 1) {
514 res = add_filename_as_pkt_side_data(filename.str, pkt);
515 if (res < 0)
516 goto fail;
517 }
518 av_bprint_finalize(&filename, NULL);
519
520 pkt->size = 0;
521 for (i = 0; i < 3; i++) {
522 if (f[i]) {
523 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
524 if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) {
525 if (avio_seek(f[i], 0, SEEK_SET) >= 0) {
526 pkt->pos = 0;
527 ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
528 }
529 }
530 if (!s->is_pipe && f[i] != s1->pb)
531 ff_format_io_close(s1, &f[i]);
532 if (ret[i] > 0)
533 pkt->size += ret[i];
534 }
535 }
536
537 if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
538 if (ret[0] < 0) {
539 res = ret[0];
540 } else if (ret[1] < 0) {
541 res = ret[1];
542 } else if (ret[2] < 0) {
543 res = ret[2];
544 } else {
545 res = AVERROR_EOF;
546 }
547 goto fail;
548 } else {
549 memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
550 s->img_count++;
551 s->img_number++;
552 s->pts++;
553 return 0;
554 }
555
556fail:
557 av_bprint_finalize(&filename, NULL);
558 if (!s->is_pipe) {
559 for (i = 0; i < 3; i++) {
560 if (f[i] != s1->pb)
561 ff_format_io_close(s1, &f[i]);
562 }
563 }
564 return res;
565}
566
567static int img_read_close(struct AVFormatContext* s1)
568{
569#if HAVE_GLOB
571 if (s->use_glob) {
572 globfree(&s->globstate);
573 }
574#endif
575 return 0;
576}
577
578static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
579{
580 VideoDemuxData *s1 = s->priv_data;
581 AVStream *st = s->streams[0];
582
583 if (s1->ts_from_file) {
584 int index = av_index_search_timestamp(st, timestamp, flags);
585 if(index < 0)
586 return -1;
588 return 0;
589 }
590
591 if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
592 return -1;
593 s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
594 s1->pts = timestamp;
595 return 0;
596}
597
598#define OFFSET(x) offsetof(VideoDemuxData, x)
599#define DEC AV_OPT_FLAG_DECODING_PARAM
600#define COMMON_OPTIONS \
601 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
602 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \
603 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \
604 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
605 { NULL },
606
607#if CONFIG_IMAGE2_DEMUXER
608const AVOption ff_img_options[] = {
609 { "pattern_type", "set pattern type", OFFSET(pattern_type), AV_OPT_TYPE_INT, {.i64=PT_DEFAULT}, 0, INT_MAX, DEC, .unit = "pattern_type"},
610 { "glob", "select glob pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
611 { "sequence", "select sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
612 { "none", "disable pattern matching", 0, AV_OPT_TYPE_CONST, {.i64=PT_NONE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" },
613 { "start_number", "set first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, DEC },
614 { "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 },
615 { "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" },
616 { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 2, DEC, .unit = "ts_type" },
617 { "sec", "second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 2, DEC, .unit = "ts_type" },
618 { "ns", "nanosecond precision", 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2, DEC, .unit = "ts_type" },
619 { "export_path_metadata", "enable metadata containing input path information", OFFSET(export_path_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
621};
622
623static const AVClass img2_class = {
624 .class_name = "image2 demuxer",
625 .item_name = av_default_item_name,
626 .option = ff_img_options,
627 .version = LIBAVUTIL_VERSION_INT,
628};
630 .p.name = "image2",
631 .p.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
632 .p.flags = AVFMT_NOFILE,
633 .p.priv_class = &img2_class,
634 .priv_data_size = sizeof(VideoDemuxData),
640};
641#endif
642
643static const AVOption img2pipe_options[] = {
644 { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
646};
647static const AVClass imagepipe_class = {
648 .class_name = "imagepipe demuxer",
649 .item_name = av_default_item_name,
650 .option = img2pipe_options,
651 .version = LIBAVUTIL_VERSION_INT,
652};
653
654#if CONFIG_IMAGE2PIPE_DEMUXER
656 .p.name = "image2pipe",
657 .p.long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
658 .p.priv_class = &imagepipe_class,
659 .priv_data_size = sizeof(VideoDemuxData),
662};
663#endif
664
665static int bmp_probe(const AVProbeData *p)
666{
667 const uint8_t *b = p->buf;
668 int ihsize;
669
670 if (AV_RB16(b) != 0x424d)
671 return 0;
672
673 ihsize = AV_RL32(b+14);
674 if (ihsize < 12 || ihsize > 255)
675 return 0;
676
677 if (!AV_RN32(b + 6)) {
678 return AVPROBE_SCORE_EXTENSION + 1;
679 }
680 return AVPROBE_SCORE_EXTENSION / 4;
681}
682
683static int cri_probe(const AVProbeData *p)
684{
685 const uint8_t *b = p->buf;
686
687 if ( AV_RL32(b) == 1
688 && AV_RL32(b + 4) == 4
689 && AV_RN32(b + 8) == AV_RN32("DVCC"))
690 return AVPROBE_SCORE_MAX - 1;
691 return 0;
692}
693
694static int dds_probe(const AVProbeData *p)
695{
696 const uint8_t *b = p->buf;
697
698 if ( AV_RB64(b) == 0x444453207c000000
699 && AV_RL32(b + 8)
700 && AV_RL32(b + 12))
701 return AVPROBE_SCORE_MAX - 1;
702 return 0;
703}
704
705static int dpx_probe(const AVProbeData *p)
706{
707 const uint8_t *b = p->buf;
708 int w, h;
709 int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
710
711 if (p->buf_size < 0x304+8)
712 return 0;
713 w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
714 h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
715 if (w <= 0 || h <= 0)
716 return 0;
717
718 if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
719 return AVPROBE_SCORE_EXTENSION + 1;
720 return 0;
721}
722
723static int exr_probe(const AVProbeData *p)
724{
725 const uint8_t *b = p->buf;
726
727 if (AV_RL32(b) == 20000630)
728 return AVPROBE_SCORE_EXTENSION + 1;
729 return 0;
730}
731
732static int j2k_probe(const AVProbeData *p)
733{
734 const uint8_t *b = p->buf;
735
736 if (AV_RB64(b) == 0x0000000c6a502020 ||
737 AV_RB32(b) == 0xff4fff51)
738 return AVPROBE_SCORE_EXTENSION + 1;
739 return 0;
740}
741
742static int jpeg_probe(const AVProbeData *p)
743{
744 const uint8_t *b = p->buf;
745 int i, state = SOI, got_header = 0;
746
747 if (AV_RB16(b) != 0xFFD8 ||
748 AV_RB32(b) == 0xFFD8FFF7)
749 return 0;
750
751 b += 2;
752 for (i = 0; i < p->buf_size - 3; i++) {
753 int c;
754 if (b[i] != 0xFF)
755 continue;
756 c = b[i + 1];
757 switch (c) {
758 case SOI:
759 return 0;
760 case SOF0:
761 case SOF1:
762 case SOF2:
763 case SOF3:
764 case SOF5:
765 case SOF6:
766 case SOF7:
767 i += AV_RB16(&b[i + 2]) + 1;
768 if (state != SOI)
769 return 0;
770 state = SOF0;
771 break;
772 case SOS:
773 i += AV_RB16(&b[i + 2]) + 1;
774 if (state != SOF0 && state != SOS)
775 return 0;
776 state = SOS;
777 break;
778 case EOI:
779 if (state != SOS)
780 return 0;
781 state = EOI;
782 break;
783 case APP0:
784 if (c == APP0 && AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F'))
785 got_header = 1;
787 case APP1:
788 if (c == APP1 && AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f'))
789 got_header = 1;
791 case APP2:
792 case APP3:
793 case APP4:
794 case APP5:
795 case APP6:
796 case APP7:
797 case APP8:
798 case APP9:
799 case APP10:
800 case APP11:
801 case APP12:
802 case APP13:
803 case APP14:
804 case APP15:
805 case DQT: /* fallthrough */
806 case COM:
807 i += AV_RB16(&b[i + 2]) + 1;
808 break;
809 default:
810 if ( (c > TEM && c < SOF0)
811 || c == JPG)
812 return 0;
813 }
814 }
815
816 if (state == EOI)
817 return AVPROBE_SCORE_EXTENSION + 1;
818 if (state == SOS)
819 return AVPROBE_SCORE_EXTENSION / 2 + got_header;
820 return AVPROBE_SCORE_EXTENSION / 8 + 1;
821}
822
823static int jpegls_probe(const AVProbeData *p)
824{
825 const uint8_t *b = p->buf;
826
827 if (AV_RB32(b) == 0xffd8fff7)
828 return AVPROBE_SCORE_EXTENSION + 1;
829 return 0;
830}
831
832static int jpegxl_probe(const AVProbeData *p)
833{
834 const uint8_t *b = p->buf;
835
836 /* ISOBMFF-based container */
837 /* 0x4a584c20 == "JXL " */
839 return AVPROBE_SCORE_EXTENSION + 1;
840 /* Raw codestreams all start with 0xff0a */
842 return 0;
843#if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
844 if (ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, NULL, 5) >= 0)
845 return AVPROBE_SCORE_MAX - 2;
846#endif
847 return 0;
848}
849
850static int jpegxs_probe(const AVProbeData *p)
851{
852 const uint8_t *b = p->buf;
853
854 if (AV_RB32(b) == 0xff10ff50)
855 return AVPROBE_SCORE_EXTENSION + 1;
856 return 0;
857}
858
859static int pcx_probe(const AVProbeData *p)
860{
861 const uint8_t *b = p->buf;
862
863 if ( p->buf_size < 128
864 || b[0] != 10
865 || b[1] > 5
866 || b[2] > 1
867 || av_popcount(b[3]) != 1 || b[3] > 8
868 || AV_RL16(&b[4]) > AV_RL16(&b[8])
869 || AV_RL16(&b[6]) > AV_RL16(&b[10])
870 || b[64])
871 return 0;
872 b += 73;
873 while (++b < p->buf + 128)
874 if (*b)
875 return AVPROBE_SCORE_EXTENSION / 4;
876
877 return AVPROBE_SCORE_EXTENSION + 1;
878}
879
880static int qdraw_probe(const AVProbeData *p)
881{
882 const uint8_t *b = p->buf;
883
884 if ( p->buf_size >= 528
885 && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
886 && AV_RB16(b + 520)
887 && AV_RB16(b + 518))
888 return AVPROBE_SCORE_MAX * 3 / 4;
889 if ( (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
890 && AV_RB16(b + 8)
891 && AV_RB16(b + 6))
892 return AVPROBE_SCORE_EXTENSION / 4;
893 return 0;
894}
895
896static int pictor_probe(const AVProbeData *p)
897{
898 const uint8_t *b = p->buf;
899
900 if (AV_RL16(b) == 0x1234)
901 return AVPROBE_SCORE_EXTENSION / 4;
902 return 0;
903}
904
905static int png_probe(const AVProbeData *p)
906{
907 const uint8_t *b = p->buf;
908 int size = p->buf_size;
909 int pos = 8;
910
911 if (AV_RB64(b) != PNGSIG)
912 return 0;
913
914 /* png_pipe demuxes a sequence of images, so the bytes after a whole
915 * image in the buffer have to match another signature as far as the
916 * buffer goes. Anything else is an unrelated payload behind a PNG,
917 * like the 1x1 image some CDNs prepend to MPEG-TS segments, and the
918 * signature alone must not outscore the demuxer of that payload. */
919 while (size - pos >= 12) {
920 uint32_t len = AV_RB32(b + pos);
921 uint32_t tag = AV_RB32(b + pos + 4);
922
923 if (len > size - pos - 12)
924 break;
925 pos += 12 + len;
926 if (tag == MKBETAG('I', 'E', 'N', 'D')) {
927 int n = FFMIN(size - pos, 8);
928 if (n && (AV_RB64(b + pos) ^ PNGSIG) >> (64 - 8 * n))
929 return AVPROBE_SCORE_RETRY;
930 pos += n;
931 }
932 }
933
934 return AVPROBE_SCORE_MAX - 1;
935}
936
937static int psd_probe(const AVProbeData *p)
938{
939 const uint8_t *b = p->buf;
940 int ret = 0;
941 uint16_t color_mode;
942
943 if (AV_RL32(b) == MKTAG('8','B','P','S')) {
944 ret += 1;
945 } else {
946 return 0;
947 }
948
949 if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */
950 ret += 1;
951 } else {
952 return 0;
953 }
954
955 if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */
956 ret += 1;
957
958 color_mode = AV_RB16(b+24);
959 if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
960 ret += 1;
961
963}
964
965static int sgi_probe(const AVProbeData *p)
966{
967 const uint8_t *b = p->buf;
968
969 if (AV_RB16(b) == 474 &&
970 (b[2] & ~1) == 0 &&
971 (b[3] & ~3) == 0 && b[3] &&
972 (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4))
973 return AVPROBE_SCORE_EXTENSION + 1;
974 return 0;
975}
976
977static int sunrast_probe(const AVProbeData *p)
978{
979 const uint8_t *b = p->buf;
980
981 if (AV_RB32(b) == 0x59a66a95)
982 return AVPROBE_SCORE_EXTENSION + 1;
983 return 0;
984}
985
986static int svg_probe(const AVProbeData *p)
987{
988 const uint8_t *b = p->buf;
989 const uint8_t *end = p->buf + p->buf_size;
990 while (b < end && av_isspace(*b))
991 b++;
992 if (b >= end - 5)
993 return 0;
994 if (!memcmp(b, "<svg", 4))
995 return AVPROBE_SCORE_EXTENSION + 1;
996 if (memcmp(p->buf, "<?xml", 5) && memcmp(b, "<!--", 4))
997 return 0;
998 while (b < end) {
1000 if (!inc)
1001 break;
1002 b += inc;
1003 if (b >= end - 4)
1004 return 0;
1005 if (!memcmp(b, "<svg", 4))
1006 return AVPROBE_SCORE_EXTENSION + 1;
1007 }
1008 return 0;
1009}
1010
1011static int tiff_probe(const AVProbeData *p)
1012{
1013 const uint8_t *b = p->buf;
1014
1015 if (AV_RB32(b) == 0x49492a00 ||
1016 AV_RB32(b) == 0x4D4D002a)
1017 return AVPROBE_SCORE_EXTENSION + 1;
1018 return 0;
1019}
1020
1021static int rw2_probe(const AVProbeData *p)
1022{
1023 if (AV_RB32(p->buf) == 0x49495500 && AV_RL32(p->buf + 4) >= 8)
1024 return AVPROBE_SCORE_MAX;
1025 return 0;
1026}
1027
1028static int webp_probe(const AVProbeData *p)
1029{
1030 const uint8_t *b = p->buf;
1031
1032 if (AV_RB32(b) == 0x52494646 &&
1033 AV_RB32(b + 8) == 0x57454250)
1034 return AVPROBE_SCORE_MAX - 1;
1035 return 0;
1036}
1037
1038static int pnm_magic_check(const AVProbeData *p, int magic)
1039{
1040 const uint8_t *b = p->buf;
1041
1042 return b[0] == 'P' && b[1] == magic + '0';
1043}
1044
1045static inline int pnm_probe(const AVProbeData *p)
1046{
1047 const uint8_t *b = p->buf;
1048
1049 while (b[2] == '\r')
1050 b++;
1051 if (b[2] == '\n' && (b[3] == '#' || (b[3] >= '0' && b[3] <= '9')))
1052 return AVPROBE_SCORE_EXTENSION + 2;
1053 return 0;
1054}
1055
1056static int pbm_probe(const AVProbeData *p)
1057{
1058 return pnm_magic_check(p, 1) || pnm_magic_check(p, 4) ? pnm_probe(p) : 0;
1059}
1060
1061static int pfm_probe(const AVProbeData *p)
1062{
1063 return pnm_magic_check(p, 'F' - '0') ||
1064 pnm_magic_check(p, 'f' - '0') ? pnm_probe(p) : 0;
1065}
1066
1067static int phm_probe(const AVProbeData *p)
1068{
1069 return pnm_magic_check(p, 'H' - '0') ||
1070 pnm_magic_check(p, 'h' - '0') ? pnm_probe(p) : 0;
1071}
1072
1073static inline int pgmx_probe(const AVProbeData *p)
1074{
1075 return pnm_magic_check(p, 2) || pnm_magic_check(p, 5) ? pnm_probe(p) : 0;
1076}
1077
1078static int pgm_probe(const AVProbeData *p)
1079{
1080 int ret = pgmx_probe(p);
1081 return ret && !av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1082}
1083
1084static int pgmyuv_probe(const AVProbeData *p) // custom FFmpeg format recognized by file extension
1085{
1086 int ret = pgmx_probe(p);
1087 return ret && av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1088}
1089
1090static int pgx_probe(const AVProbeData *p)
1091{
1092 const uint8_t *b = p->buf;
1093 if (!memcmp(b, "PG ML ", 6))
1094 return AVPROBE_SCORE_EXTENSION + 1;
1095 return 0;
1096}
1097
1098static int ppm_probe(const AVProbeData *p)
1099{
1100 return pnm_magic_check(p, 3) || pnm_magic_check(p, 6) ? pnm_probe(p) : 0;
1101}
1102
1103static int pam_probe(const AVProbeData *p)
1104{
1105 return pnm_magic_check(p, 7) ? pnm_probe(p) : 0;
1106}
1107
1108static int hdr_probe(const AVProbeData *p)
1109{
1110 if (!memcmp(p->buf, "#?RADIANCE\n", 11) || !memcmp(p->buf, "#?RGBE\n", 7))
1111 return AVPROBE_SCORE_MAX;
1112 return 0;
1113}
1114
1115static int xbm_probe(const AVProbeData *p)
1116{
1117 if (!memcmp(p->buf, "/* XBM X10 format */", 20))
1118 return AVPROBE_SCORE_MAX;
1119
1120 if (!memcmp(p->buf, "#define", 7))
1121 return AVPROBE_SCORE_MAX - 1;
1122 return 0;
1123}
1124
1125static int xpm_probe(const AVProbeData *p)
1126{
1127 const uint8_t *b = p->buf;
1128
1129 if (AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) == '/')
1130 return AVPROBE_SCORE_MAX - 1;
1131 return 0;
1132}
1133
1134static int xwd_probe(const AVProbeData *p)
1135{
1136 const uint8_t *b = p->buf;
1137 unsigned width, bpp, bpad, lsize;
1138
1139 if ( p->buf_size < XWD_HEADER_SIZE
1140 || AV_RB32(b ) < XWD_HEADER_SIZE // header size
1141 || AV_RB32(b + 4) != XWD_VERSION // version
1142 || AV_RB32(b + 8) != XWD_Z_PIXMAP // format
1143 || AV_RB32(b + 12) > 32 || !AV_RB32(b + 12) // depth
1144 || AV_RB32(b + 16) == 0 // width
1145 || AV_RB32(b + 20) == 0 // height
1146 || AV_RB32(b + 28) > 1 // byteorder
1147 || AV_RB32(b + 32) & ~56 || av_popcount(AV_RB32(b + 32)) != 1 // bitmap unit
1148 || AV_RB32(b + 36) > 1 // bitorder
1149 || AV_RB32(b + 40) & ~56 || av_popcount(AV_RB32(b + 40)) != 1 // padding
1150 || AV_RB32(b + 44) > 32 || !AV_RB32(b + 44) // bpp
1151 || AV_RB32(b + 68) > 256) // colours
1152 return 0;
1153
1154 width = AV_RB32(b + 16);
1155 bpad = AV_RB32(b + 40);
1156 bpp = AV_RB32(b + 44);
1157 lsize = AV_RB32(b + 48);
1158 if (lsize < FFALIGN(width * bpp, bpad) >> 3)
1159 return 0;
1160
1161 return AVPROBE_SCORE_MAX / 2 + 1;
1162}
1163
1164static int gif_probe(const AVProbeData *p)
1165{
1166 /* check magick */
1167 if (memcmp(p->buf, gif87a_sig, 6) && memcmp(p->buf, gif89a_sig, 6))
1168 return 0;
1169
1170 /* width or height contains zero? */
1171 if (!AV_RL16(&p->buf[6]) || !AV_RL16(&p->buf[8]))
1172 return 0;
1173
1174 return AVPROBE_SCORE_MAX - 1;
1175}
1176
1177static int photocd_probe(const AVProbeData *p)
1178{
1179 if (!memcmp(p->buf, "PCD_OPA", 7))
1180 return AVPROBE_SCORE_MAX - 1;
1181
1182 if (p->buf_size < 0x807 || memcmp(p->buf + 0x800, "PCD_IPI", 7))
1183 return 0;
1184
1185 return AVPROBE_SCORE_MAX - 1;
1186}
1187
1188static int qoi_probe(const AVProbeData *p)
1189{
1190 if (memcmp(p->buf, "qoif", 4))
1191 return 0;
1192
1193 if (AV_RB32(p->buf + 4) == 0 || AV_RB32(p->buf + 8) == 0)
1194 return 0;
1195
1196 if (p->buf[12] != 3 && p->buf[12] != 4)
1197 return 0;
1198
1199 if (p->buf[13] > 1)
1200 return 0;
1201
1202 return AVPROBE_SCORE_MAX - 1;
1203}
1204
1205static int gem_probe(const AVProbeData *p)
1206{
1207 const uint8_t *b = p->buf;
1208 if ( AV_RB16(b ) >= 1 && AV_RB16(b ) <= 3 &&
1209 AV_RB16(b + 2) >= 8 && AV_RB16(b + 2) <= 779 &&
1210 (AV_RB16(b + 4) > 0 && AV_RB16(b + 4) <= 32) && /* planes */
1211 (AV_RB16(b + 6) > 0 && AV_RB16(b + 6) <= 8) && /* pattern_size */
1212 AV_RB16(b + 8) &&
1213 AV_RB16(b + 10) &&
1214 AV_RB16(b + 12) &&
1215 AV_RB16(b + 14)) {
1216 if (AV_RN32(b + 16) == AV_RN32("STTT") ||
1217 AV_RN32(b + 16) == AV_RN32("TIMG") ||
1218 AV_RN32(b + 16) == AV_RN32("XIMG"))
1219 return AVPROBE_SCORE_EXTENSION + 1;
1220 return AVPROBE_SCORE_EXTENSION / 4;
1221 }
1222 return 0;
1223}
1224
1225static int vbn_probe(const AVProbeData *p)
1226{
1227 const uint8_t *b = p->buf;
1228 if (AV_RL32(b ) == VBN_MAGIC &&
1229 AV_RL32(b + 4) == VBN_MAJOR &&
1230 AV_RL32(b + 8) == VBN_MINOR)
1231 return AVPROBE_SCORE_MAX - 1;
1232 return 0;
1233}
1234
1235#define IMAGEAUTO_DEMUXER_0(imgname, codecid)
1236#define IMAGEAUTO_DEMUXER_1(imgname, codecid)\
1237const FFInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1238 .p.name = AV_STRINGIFY(imgname) "_pipe",\
1239 .p.long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1240 .p.priv_class = &imagepipe_class,\
1241 .p.flags = AVFMT_GENERIC_INDEX,\
1242 .priv_data_size = sizeof(VideoDemuxData),\
1243 .read_probe = imgname ## _probe,\
1244 .read_header = ff_img_read_header,\
1245 .read_packet = ff_img_read_packet,\
1246 .raw_codec_id = codecid,\
1247};
1248
1249#define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \
1250 IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid)
1251#define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \
1252 IMAGEAUTO_DEMUXER_2(imgname, codecid, config)
1253#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \
1254 IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid, \
1255 CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER)
1256#define IMAGEAUTO_DEMUXER(imgname, codecid) \
1257 IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid)
1258
1259IMAGEAUTO_DEMUXER(bmp, BMP)
1260IMAGEAUTO_DEMUXER(cri, CRI)
1261IMAGEAUTO_DEMUXER(dds, DDS)
1262IMAGEAUTO_DEMUXER(dpx, DPX)
1263IMAGEAUTO_DEMUXER(exr, EXR)
1264IMAGEAUTO_DEMUXER(gem, GEM)
1265IMAGEAUTO_DEMUXER(gif, GIF)
1266IMAGEAUTO_DEMUXER_EXT(hdr, RADIANCE_HDR, HDR)
1267IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K)
1268IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG)
1269IMAGEAUTO_DEMUXER(jpegxs, JPEGXS)
1270IMAGEAUTO_DEMUXER(jpegls, JPEGLS)
1271IMAGEAUTO_DEMUXER(jpegxl, JPEGXL)
1272IMAGEAUTO_DEMUXER(pam, PAM)
1273IMAGEAUTO_DEMUXER(pbm, PBM)
1274IMAGEAUTO_DEMUXER(pcx, PCX)
1275IMAGEAUTO_DEMUXER(pfm, PFM)
1276IMAGEAUTO_DEMUXER(pgm, PGM)
1277IMAGEAUTO_DEMUXER(pgmyuv, PGMYUV)
1278IMAGEAUTO_DEMUXER(pgx, PGX)
1279IMAGEAUTO_DEMUXER(phm, PHM)
1280IMAGEAUTO_DEMUXER(photocd, PHOTOCD)
1281IMAGEAUTO_DEMUXER(pictor, PICTOR)
1282IMAGEAUTO_DEMUXER(png, PNG)
1283IMAGEAUTO_DEMUXER(ppm, PPM)
1284IMAGEAUTO_DEMUXER(psd, PSD)
1285IMAGEAUTO_DEMUXER(qdraw, QDRAW)
1286IMAGEAUTO_DEMUXER(qoi, QOI)
1287IMAGEAUTO_DEMUXER(rw2, RW2)
1288IMAGEAUTO_DEMUXER(sgi, SGI)
1289IMAGEAUTO_DEMUXER(sunrast, SUNRAST)
1290IMAGEAUTO_DEMUXER(svg, SVG)
1291IMAGEAUTO_DEMUXER(tiff, TIFF)
1292IMAGEAUTO_DEMUXER(vbn, VBN)
1293IMAGEAUTO_DEMUXER(webp, WEBP)
1294IMAGEAUTO_DEMUXER(xbm, XBM)
1295IMAGEAUTO_DEMUXER(xpm, XPM)
1296IMAGEAUTO_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:992
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:865
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:1352
#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:1561
#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:630
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:507
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:620
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:1119
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:195
static AVPacket * pkt
static enum AVPixelFormat pix_fmt
char * path
Definition ffplay.c:385
int ret
Definition ffplay.c:391
static int loop
Definition ffplay.c:367
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
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:247
@ 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:1256
static int jpegxs_probe(const AVProbeData *p)
Definition img2dec.c:850
static int pbm_probe(const AVProbeData *p)
Definition img2dec.c:1056
static int jpegls_probe(const AVProbeData *p)
Definition img2dec.c:823
static int pfm_probe(const AVProbeData *p)
Definition img2dec.c:1061
static int hdr_probe(const AVProbeData *p)
Definition img2dec.c:1108
static int photocd_probe(const AVProbeData *p)
Definition img2dec.c:1177
static int phm_probe(const AVProbeData *p)
Definition img2dec.c:1067
static int xwd_probe(const AVProbeData *p)
Definition img2dec.c:1134
static int jpegxl_probe(const AVProbeData *p)
Definition img2dec.c:832
static int xbm_probe(const AVProbeData *p)
Definition img2dec.c:1115
static int sgi_probe(const AVProbeData *p)
Definition img2dec.c:965
static int img_read_close(struct AVFormatContext *s1)
Definition img2dec.c:567
static int cri_probe(const AVProbeData *p)
Definition img2dec.c:683
static int exr_probe(const AVProbeData *p)
Definition img2dec.c:723
static int tiff_probe(const AVProbeData *p)
Definition img2dec.c:1011
static int ppm_probe(const AVProbeData *p)
Definition img2dec.c:1098
static int pnm_probe(const AVProbeData *p)
Definition img2dec.c:1045
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:578
static int xpm_probe(const AVProbeData *p)
Definition img2dec.c:1125
static int j2k_probe(const AVProbeData *p)
Definition img2dec.c:732
static int pgx_probe(const AVProbeData *p)
Definition img2dec.c:1090
static int psd_probe(const AVProbeData *p)
Definition img2dec.c:937
static int sunrast_probe(const AVProbeData *p)
Definition img2dec.c:977
static int dpx_probe(const AVProbeData *p)
Definition img2dec.c:705
static int rw2_probe(const AVProbeData *p)
Definition img2dec.c:1021
static int vbn_probe(const AVProbeData *p)
Definition img2dec.c:1225
static int pgm_probe(const AVProbeData *p)
Definition img2dec.c:1078
static const int sizes[][2]
Definition img2dec.c:63
static int pcx_probe(const AVProbeData *p)
Definition img2dec.c:859
static int qdraw_probe(const AVProbeData *p)
Definition img2dec.c:880
#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name)
Definition img2dec.c:1253
static int infer_size(int *width_ptr, int *height_ptr, int size)
Definition img2dec.c:75
static const AVOption img2pipe_options[]
Definition img2dec.c:643
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:665
static int pgmyuv_probe(const AVProbeData *p)
Definition img2dec.c:1084
static int dds_probe(const AVProbeData *p)
Definition img2dec.c:694
static int svg_probe(const AVProbeData *p)
Definition img2dec.c:986
static int qoi_probe(const AVProbeData *p)
Definition img2dec.c:1188
int ff_img_read_header(AVFormatContext *s1)
Definition img2dec.c:172
static int pnm_magic_check(const AVProbeData *p, int magic)
Definition img2dec.c:1038
static int gif_probe(const AVProbeData *p)
Definition img2dec.c:1164
static int webp_probe(const AVProbeData *p)
Definition img2dec.c:1028
static int pam_probe(const AVProbeData *p)
Definition img2dec.c:1103
static int gem_probe(const AVProbeData *p)
Definition img2dec.c:1205
#define OFFSET(x)
Definition img2dec.c:598
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition img2dec.c:365
static const AVClass imagepipe_class
Definition img2dec.c:647
static int pgmx_probe(const AVProbeData *p)
Definition img2dec.c:1073
static int pictor_probe(const AVProbeData *p)
Definition img2dec.c:896
static int img_read_probe(const AVProbeData *p)
Definition img2dec.c:155
static int jpeg_probe(const AVProbeData *p)
Definition img2dec.c:742
static int png_probe(const AVProbeData *p)
Definition img2dec.c:905
#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:384
#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:1401
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition avformat.h:1627
AVIOContext * pb
I/O context.
Definition avformat.h:1443
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1553
int ctx_flags
Flags signalling stream properties.
Definition avformat.h:1450
char * url
input or output URL.
Definition avformat.h:1518
const struct AVInputFormat * iformat
The input container format.
Definition avformat.h:1413
enum AVCodecID video_codec_id
Forced video codec_id.
Definition avformat.h:1621
void * priv_data
Format private data.
Definition avformat.h:1429
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1469
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:2022
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:118
int(* read_probe)(const AVProbeData *)
Tell if a given file has a chance of being parsed as this format.
Definition demux.h:101
int(* read_header)(struct AVFormatContext *)
Read the format header and initialize the AVFormatContext structure.
Definition demux.h:108
struct AVCodecParserContext * parser
Definition internal.h:341
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:196
enum AVStreamParseType need_parsing
Definition internal.h:340
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
static struct @232240247175332074307271266321204261331170211232 state
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