FFmpeg  4.4.6
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 #define _DEFAULT_SOURCE
24 #define _BSD_SOURCE
25 #include <sys/stat.h>
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/log.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/parseutils.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavcodec/gif.h"
34 #include "avformat.h"
35 #include "avio_internal.h"
36 #include "internal.h"
37 #include "img2.h"
38 #include "libavcodec/mjpeg.h"
39 #include "libavcodec/xwd.h"
40 #include "subtitles.h"
41 
42 #if HAVE_GLOB
43 /* Locally define as 0 (bitwise-OR no-op) any missing glob options that
44  are non-posix glibc/bsd extensions. */
45 #ifndef GLOB_NOMAGIC
46 #define GLOB_NOMAGIC 0
47 #endif
48 #ifndef GLOB_BRACE
49 #define GLOB_BRACE 0
50 #endif
51 
52 #endif /* HAVE_GLOB */
53 
54 static const int sizes[][2] = {
55  { 640, 480 },
56  { 720, 480 },
57  { 720, 576 },
58  { 352, 288 },
59  { 352, 240 },
60  { 160, 128 },
61  { 512, 384 },
62  { 640, 352 },
63  { 640, 240 },
64 };
65 
66 static int infer_size(int *width_ptr, int *height_ptr, int size)
67 {
68  int i;
69 
70  for (i = 0; i < FF_ARRAY_ELEMS(sizes); i++) {
71  if ((sizes[i][0] * sizes[i][1]) == size) {
72  *width_ptr = sizes[i][0];
73  *height_ptr = sizes[i][1];
74  return 0;
75  }
76  }
77 
78  return -1;
79 }
80 
81 static int is_glob(const char *path)
82 {
83 #if HAVE_GLOB
84  size_t span = 0;
85  const char *p = path;
86 
87  while (p = strchr(p, '%')) {
88  if (*(++p) == '%') {
89  ++p;
90  continue;
91  }
92  if (span = strspn(p, "*?[]{}"))
93  break;
94  }
95  /* Did we hit a glob char or get to the end? */
96  return span != 0;
97 #else
98  return 0;
99 #endif
100 }
101 
102 /**
103  * Get index range of image files matched by path.
104  *
105  * @param pfirst_index pointer to index updated with the first number in the range
106  * @param plast_index pointer to index updated with the last number in the range
107  * @param path path which has to be matched by the image files in the range
108  * @param start_index minimum accepted value for the first index in the range
109  * @return -1 if no image file could be found
110  */
111 static int find_image_range(AVIOContext *pb, int *pfirst_index, int *plast_index,
112  const char *path, int start_index, int start_index_range)
113 {
114  char buf[1024];
115  int range, last_index, range1, first_index;
116 
117  /* find the first image */
118  for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
119  if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0) {
120  *pfirst_index =
121  *plast_index = 1;
122  if (pb || avio_check(buf, AVIO_FLAG_READ) > 0)
123  return 0;
124  return -1;
125  }
126  if (avio_check(buf, AVIO_FLAG_READ) > 0)
127  break;
128  }
129  if (first_index == start_index + start_index_range)
130  goto fail;
131 
132  /* find the last image */
133  last_index = first_index;
134  for (;;) {
135  range = 0;
136  for (;;) {
137  if (!range)
138  range1 = 1;
139  else
140  range1 = 2 * range;
141  if (av_get_frame_filename(buf, sizeof(buf), path,
142  last_index + range1) < 0)
143  goto fail;
144  if (avio_check(buf, AVIO_FLAG_READ) <= 0)
145  break;
146  range = range1;
147  /* just in case... */
148  if (range >= (1 << 30))
149  goto fail;
150  }
151  /* we are sure than image last_index + range exists */
152  if (!range)
153  break;
154  last_index += range;
155  }
156  *pfirst_index = first_index;
157  *plast_index = last_index;
158  return 0;
159 
160 fail:
161  return -1;
162 }
163 
164 static int img_read_probe(const AVProbeData *p)
165 {
166  if (p->filename && ff_guess_image2_codec(p->filename)) {
168  return AVPROBE_SCORE_MAX;
169  else if (is_glob(p->filename))
170  return AVPROBE_SCORE_MAX;
171  else if (p->filename[strcspn(p->filename, "*?{")]) // probably PT_GLOB
172  return AVPROBE_SCORE_EXTENSION + 2; // score chosen to be a tad above the image pipes
173  else if (p->buf_size == 0)
174  return 0;
175  else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif"))
176  return 5;
177  else
179  }
180  return 0;
181 }
182 
184 {
185  VideoDemuxData *s = s1->priv_data;
186  int first_index = 1, last_index = 1;
187  AVStream *st;
189 
190  s1->ctx_flags |= AVFMTCTX_NOHEADER;
191 
192  st = avformat_new_stream(s1, NULL);
193  if (!st) {
194  return AVERROR(ENOMEM);
195  }
196 
197  if (s->pixel_format &&
198  (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
199  av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n",
200  s->pixel_format);
201  return AVERROR(EINVAL);
202  }
203 
204  av_strlcpy(s->path, s1->url, sizeof(s->path));
205  s->img_number = 0;
206  s->img_count = 0;
207 
208  /* find format */
209  if (s1->iformat->flags & AVFMT_NOFILE)
210  s->is_pipe = 0;
211  else {
212  s->is_pipe = 1;
214  }
215 
216  if (s->ts_from_file == 2) {
217 #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
218  av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
219  return AVERROR(ENOSYS);
220 #endif
221  avpriv_set_pts_info(st, 64, 1, 1000000000);
222  } else if (s->ts_from_file)
223  avpriv_set_pts_info(st, 64, 1, 1);
224  else {
225  avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
226  st->avg_frame_rate = s->framerate;
227  }
228 
229  if (s->width && s->height) {
230  st->codecpar->width = s->width;
231  st->codecpar->height = s->height;
232  }
233 
234  if (!s->is_pipe) {
235  if (s->pattern_type == PT_DEFAULT) {
236  if (s1->pb) {
237  s->pattern_type = PT_NONE;
238  } else
239  s->pattern_type = PT_GLOB_SEQUENCE;
240  }
241 
242  if (s->pattern_type == PT_GLOB_SEQUENCE) {
243  s->use_glob = is_glob(s->path);
244  if (s->use_glob) {
245 #if HAVE_GLOB
246  char *p = s->path, *q, *dup;
247  int gerr;
248 #endif
249 
250  av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
251  "use pattern_type 'glob' instead\n");
252 #if HAVE_GLOB
253  dup = q = av_strdup(p);
254  while (*q) {
255  /* Do we have room for the next char and a \ insertion? */
256  if ((p - s->path) >= (sizeof(s->path) - 2))
257  break;
258  if (*q == '%' && strspn(q + 1, "%*?[]{}"))
259  ++q;
260  else if (strspn(q, "\\*?[]{}"))
261  *p++ = '\\';
262  *p++ = *q++;
263  }
264  *p = 0;
265  av_free(dup);
266 
267  gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
268  if (gerr != 0) {
269  return AVERROR(ENOENT);
270  }
271  first_index = 0;
272  last_index = s->globstate.gl_pathc - 1;
273 #endif
274  }
275  }
276  if ((s->pattern_type == PT_GLOB_SEQUENCE && !s->use_glob) || s->pattern_type == PT_SEQUENCE) {
277  if (find_image_range(s1->pb, &first_index, &last_index, s->path,
278  s->start_number, s->start_number_range) < 0) {
280  "Could find no file with path '%s' and index in the range %d-%d\n",
281  s->path, s->start_number, s->start_number + s->start_number_range - 1);
282  return AVERROR(ENOENT);
283  }
284  } else if (s->pattern_type == PT_GLOB) {
285 #if HAVE_GLOB
286  int gerr;
287  gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
288  if (gerr != 0) {
289  return AVERROR(ENOENT);
290  }
291  first_index = 0;
292  last_index = s->globstate.gl_pathc - 1;
293  s->use_glob = 1;
294 #else
296  "Pattern type 'glob' was selected but globbing "
297  "is not supported by this libavformat build\n");
298  return AVERROR(ENOSYS);
299 #endif
300  } else if (s->pattern_type != PT_GLOB_SEQUENCE && s->pattern_type != PT_NONE) {
302  "Unknown value '%d' for pattern_type option\n", s->pattern_type);
303  return AVERROR(EINVAL);
304  }
305  s->img_first = first_index;
306  s->img_last = last_index;
307  s->img_number = first_index;
308  /* compute duration */
309  if (!s->ts_from_file) {
310  st->start_time = 0;
311  st->duration = last_index - first_index + 1;
312  }
313  }
314 
315  if (s1->video_codec_id) {
317  st->codecpar->codec_id = s1->video_codec_id;
318  } else if (s1->audio_codec_id) {
320  st->codecpar->codec_id = s1->audio_codec_id;
321  } else if (s1->iformat->raw_codec_id) {
323  st->codecpar->codec_id = s1->iformat->raw_codec_id;
324  } else {
325  const char *str = strrchr(s->path, '.');
326  s->split_planes = str && !av_strcasecmp(str + 1, "y");
328  if (s1->pb) {
329  int probe_buffer_size = 2048;
330  uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE);
331  const AVInputFormat *fmt = NULL;
332  void *fmt_iter = NULL;
333  AVProbeData pd = { 0 };
334 
335  if (!probe_buffer)
336  return AVERROR(ENOMEM);
337 
338  probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size);
339  if (probe_buffer_size < 0) {
340  av_free(probe_buffer);
341  return probe_buffer_size;
342  }
343  memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE);
344 
345  pd.buf = probe_buffer;
346  pd.buf_size = probe_buffer_size;
347  pd.filename = s1->url;
348 
349  while ((fmt = av_demuxer_iterate(&fmt_iter))) {
350  if (fmt->read_header != ff_img_read_header ||
351  !fmt->read_probe ||
352  (fmt->flags & AVFMT_NOFILE) ||
353  !fmt->raw_codec_id)
354  continue;
355  if (fmt->read_probe(&pd) > 0) {
356  st->codecpar->codec_id = fmt->raw_codec_id;
357  break;
358  }
359  }
360  if (s1->flags & AVFMT_FLAG_CUSTOM_IO) {
361  avio_seek(s1->pb, 0, SEEK_SET);
362  av_freep(&probe_buffer);
363  } else
364  ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size);
365  }
366  if (st->codecpar->codec_id == AV_CODEC_ID_NONE)
368  if (st->codecpar->codec_id == AV_CODEC_ID_LJPEG)
370  if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX
372  }
373  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
375  st->codecpar->format = pix_fmt;
376 
377  return 0;
378 }
379 
380 /**
381  * Add this frame's source path and basename to packet's sidedata
382  * as a dictionary, so it can be used by filters like 'drawtext'.
383  */
384 static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) {
385  AVDictionary *d = NULL;
386  char *packed_metadata = NULL;
387  buffer_size_t metadata_len;
388  int ret;
389 
390  av_dict_set(&d, "lavf.image2dec.source_path", filename, 0);
391  av_dict_set(&d, "lavf.image2dec.source_basename", av_basename(filename), 0);
392 
393  packed_metadata = av_packet_pack_dictionary(d, &metadata_len);
394  av_dict_free(&d);
395  if (!packed_metadata)
396  return AVERROR(ENOMEM);
398  packed_metadata, metadata_len);
399  if (ret < 0) {
400  av_freep(&packed_metadata);
401  return ret;
402  }
403  return 0;
404 }
405 
407 {
408  VideoDemuxData *s = s1->priv_data;
409  char filename_bytes[1024];
410  char *filename = filename_bytes;
411  int i, res;
412  int size[3] = { 0 }, ret[3] = { 0 };
413  AVIOContext *f[3] = { NULL };
414  AVCodecParameters *par = s1->streams[0]->codecpar;
415 
416  if (!s->is_pipe) {
417  /* loop over input */
418  if (s->loop && s->img_number > s->img_last) {
419  s->img_number = s->img_first;
420  }
421  if (s->img_number > s->img_last)
422  return AVERROR_EOF;
423  if (s->pattern_type == PT_NONE) {
424  av_strlcpy(filename_bytes, s->path, sizeof(filename_bytes));
425  } else if (s->use_glob) {
426 #if HAVE_GLOB
427  filename = s->globstate.gl_pathv[s->img_number];
428 #endif
429  } else {
430  if (av_get_frame_filename(filename_bytes, sizeof(filename_bytes),
431  s->path,
432  s->img_number) < 0 && s->img_number > 1)
433  return AVERROR(EIO);
434  }
435  for (i = 0; i < 3; i++) {
436  if (s1->pb &&
437  !strcmp(filename_bytes, s->path) &&
438  !s->loop &&
439  !s->split_planes) {
440  f[i] = s1->pb;
441  } else if (s1->io_open(s1, &f[i], filename, AVIO_FLAG_READ, NULL) < 0) {
442  if (i >= 1)
443  break;
444  av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",
445  filename);
446  return AVERROR(EIO);
447  }
448  size[i] = avio_size(f[i]);
449 
450  if (!s->split_planes)
451  break;
452  filename[strlen(filename) - 1] = 'U' + i;
453  }
454 
455  if (par->codec_id == AV_CODEC_ID_NONE) {
456  AVProbeData pd = { 0 };
457  const AVInputFormat *ifmt;
459  int ret;
460  int score = 0;
461 
462  ret = avio_read(f[0], header, PROBE_BUF_MIN);
463  if (ret < 0)
464  return ret;
465  memset(header + ret, 0, sizeof(header) - ret);
466  avio_skip(f[0], -ret);
467  pd.buf = header;
468  pd.buf_size = ret;
469  pd.filename = filename;
470 
471  ifmt = av_probe_input_format3(&pd, 1, &score);
472  if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id)
473  par->codec_id = ifmt->raw_codec_id;
474  }
475 
476  if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width)
477  infer_size(&par->width, &par->height, size[0]);
478  } else {
479  f[0] = s1->pb;
480  if (avio_feof(f[0]) && s->loop && s->is_pipe)
481  avio_seek(f[0], 0, SEEK_SET);
482  if (avio_feof(f[0]))
483  return AVERROR_EOF;
484  if (s->frame_size > 0) {
485  size[0] = s->frame_size;
486  } else if (!s1->streams[0]->parser) {
487  size[0] = avio_size(s1->pb);
488  } else {
489  size[0] = 4096;
490  }
491  }
492 
493  res = av_new_packet(pkt, size[0] + size[1] + size[2]);
494  if (res < 0) {
495  goto fail;
496  }
497  pkt->stream_index = 0;
499  if (s->ts_from_file) {
500  struct stat img_stat;
501  av_assert0(!s->is_pipe); // The ts_from_file option is not supported by piped input demuxers
502  if (stat(filename, &img_stat)) {
503  res = AVERROR(EIO);
504  goto fail;
505  }
506  pkt->pts = (int64_t)img_stat.st_mtime;
508  if (s->ts_from_file == 2)
509  pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec;
510 #endif
511  av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME);
512  } else if (!s->is_pipe) {
513  pkt->pts = s->pts;
514  }
515 
516  if (s->is_pipe)
517  pkt->pos = avio_tell(f[0]);
518 
519  /*
520  * export_path_metadata must be explicitly enabled via
521  * command line options for path metadata to be exported
522  * as packet side_data.
523  */
524  if (!s->is_pipe && s->export_path_metadata == 1) {
525  res = add_filename_as_pkt_side_data(filename, pkt);
526  if (res < 0)
527  goto fail;
528  }
529 
530  pkt->size = 0;
531  for (i = 0; i < 3; i++) {
532  if (f[i]) {
533  ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
534  if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) {
535  if (avio_seek(f[i], 0, SEEK_SET) >= 0) {
536  pkt->pos = 0;
537  ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
538  }
539  }
540  if (!s->is_pipe && f[i] != s1->pb)
541  ff_format_io_close(s1, &f[i]);
542  if (ret[i] > 0)
543  pkt->size += ret[i];
544  }
545  }
546 
547  if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
548  if (ret[0] < 0) {
549  res = ret[0];
550  } else if (ret[1] < 0) {
551  res = ret[1];
552  } else if (ret[2] < 0) {
553  res = ret[2];
554  } else {
555  res = AVERROR_EOF;
556  }
557  goto fail;
558  } else {
559  memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
560  s->img_count++;
561  s->img_number++;
562  s->pts++;
563  return 0;
564  }
565 
566 fail:
567  if (!s->is_pipe) {
568  for (i = 0; i < 3; i++) {
569  if (f[i] != s1->pb)
570  ff_format_io_close(s1, &f[i]);
571  }
572  }
573  return res;
574 }
575 
576 static int img_read_close(struct AVFormatContext* s1)
577 {
578 #if HAVE_GLOB
579  VideoDemuxData *s = s1->priv_data;
580  if (s->use_glob) {
581  globfree(&s->globstate);
582  }
583 #endif
584  return 0;
585 }
586 
587 static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
588 {
589  VideoDemuxData *s1 = s->priv_data;
590  AVStream *st = s->streams[0];
591 
592  if (s1->ts_from_file) {
593  int index = av_index_search_timestamp(st, timestamp, flags);
594  if(index < 0)
595  return -1;
596  s1->img_number = st->index_entries[index].pos;
597  return 0;
598  }
599 
600  if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first)
601  return -1;
602  s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first;
603  s1->pts = timestamp;
604  return 0;
605 }
606 
607 #define OFFSET(x) offsetof(VideoDemuxData, x)
608 #define DEC AV_OPT_FLAG_DECODING_PARAM
609 #define COMMON_OPTIONS \
610  { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
611  { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \
612  { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \
613  { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
614  { NULL },
615 
616 #if CONFIG_IMAGE2_DEMUXER
617 const AVOption ff_img_options[] = {
618  { "pattern_type", "set pattern type", OFFSET(pattern_type), AV_OPT_TYPE_INT, {.i64=PT_DEFAULT}, 0, INT_MAX, DEC, "pattern_type"},
619  { "glob_sequence","select glob/sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
620  { "glob", "select glob pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX, DEC, "pattern_type" },
621  { "sequence", "select sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX, DEC, "pattern_type" },
622  { "none", "disable pattern matching", 0, AV_OPT_TYPE_CONST, {.i64=PT_NONE }, INT_MIN, INT_MAX, DEC, "pattern_type" },
623  { "start_number", "set first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, DEC },
624  { "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 },
625  { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC, "ts_type" },
626  { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 2, DEC, "ts_type" },
627  { "sec", "second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 2, DEC, "ts_type" },
628  { "ns", "nano second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2, DEC, "ts_type" },
629  { "export_path_metadata", "enable metadata containing input path information", OFFSET(export_path_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
630  COMMON_OPTIONS
631 };
632 
633 static const AVClass img2_class = {
634  .class_name = "image2 demuxer",
635  .item_name = av_default_item_name,
636  .option = ff_img_options,
637  .version = LIBAVUTIL_VERSION_INT,
638 };
640  .name = "image2",
641  .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
642  .priv_data_size = sizeof(VideoDemuxData),
648  .flags = AVFMT_NOFILE,
649  .priv_class = &img2_class,
650 };
651 #endif
652 
654  { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC },
656 };
657 
658 #if CONFIG_IMAGE2PIPE_DEMUXER
659 static const AVClass img2pipe_class = {
660  .class_name = "image2pipe demuxer",
661  .item_name = av_default_item_name,
662  .option = ff_img2pipe_options,
663  .version = LIBAVUTIL_VERSION_INT,
664 };
666  .name = "image2pipe",
667  .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"),
668  .priv_data_size = sizeof(VideoDemuxData),
671  .priv_class = &img2pipe_class,
672 };
673 #endif
674 
675 static int bmp_probe(const AVProbeData *p)
676 {
677  const uint8_t *b = p->buf;
678  int ihsize;
679 
680  if (AV_RB16(b) != 0x424d)
681  return 0;
682 
683  ihsize = AV_RL32(b+14);
684  if (ihsize < 12 || ihsize > 255)
685  return 0;
686 
687  if (!AV_RN32(b + 6)) {
688  return AVPROBE_SCORE_EXTENSION + 1;
689  }
690  return AVPROBE_SCORE_EXTENSION / 4;
691 }
692 
693 static int cri_probe(const AVProbeData *p)
694 {
695  const uint8_t *b = p->buf;
696 
697  if ( AV_RL32(b) == 1
698  && AV_RL32(b + 4) == 4
699  && AV_RN32(b + 8) == AV_RN32("DVCC"))
700  return AVPROBE_SCORE_MAX - 1;
701  return 0;
702 }
703 
704 static int dds_probe(const AVProbeData *p)
705 {
706  const uint8_t *b = p->buf;
707 
708  if ( AV_RB64(b) == 0x444453207c000000
709  && AV_RL32(b + 8)
710  && AV_RL32(b + 12))
711  return AVPROBE_SCORE_MAX - 1;
712  return 0;
713 }
714 
715 static int dpx_probe(const AVProbeData *p)
716 {
717  const uint8_t *b = p->buf;
718  int w, h;
719  int is_big = (AV_RN32(b) == AV_RN32("SDPX"));
720 
721  if (p->buf_size < 0x304+8)
722  return 0;
723  w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304);
724  h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308);
725  if (w <= 0 || h <= 0)
726  return 0;
727 
728  if (is_big || AV_RN32(b) == AV_RN32("XPDS"))
729  return AVPROBE_SCORE_EXTENSION + 1;
730  return 0;
731 }
732 
733 static int exr_probe(const AVProbeData *p)
734 {
735  const uint8_t *b = p->buf;
736 
737  if (AV_RL32(b) == 20000630)
738  return AVPROBE_SCORE_EXTENSION + 1;
739  return 0;
740 }
741 
742 static int j2k_probe(const AVProbeData *p)
743 {
744  const uint8_t *b = p->buf;
745 
746  if (AV_RB64(b) == 0x0000000c6a502020 ||
747  AV_RB32(b) == 0xff4fff51)
748  return AVPROBE_SCORE_EXTENSION + 1;
749  return 0;
750 }
751 
752 static int jpeg_probe(const AVProbeData *p)
753 {
754  const uint8_t *b = p->buf;
755  int i, state = SOI;
756 
757  if (AV_RB16(b) != 0xFFD8 ||
758  AV_RB32(b) == 0xFFD8FFF7)
759  return 0;
760 
761  b += 2;
762  for (i = 0; i < p->buf_size - 3; i++) {
763  int c;
764  if (b[i] != 0xFF)
765  continue;
766  c = b[i + 1];
767  switch (c) {
768  case SOI:
769  return 0;
770  case SOF0:
771  case SOF1:
772  case SOF2:
773  case SOF3:
774  case SOF5:
775  case SOF6:
776  case SOF7:
777  i += AV_RB16(&b[i + 2]) + 1;
778  if (state != SOI)
779  return 0;
780  state = SOF0;
781  break;
782  case SOS:
783  i += AV_RB16(&b[i + 2]) + 1;
784  if (state != SOF0 && state != SOS)
785  return 0;
786  state = SOS;
787  break;
788  case EOI:
789  if (state != SOS)
790  return 0;
791  state = EOI;
792  break;
793  case APP0:
794  case APP1:
795  case APP2:
796  case APP3:
797  case APP4:
798  case APP5:
799  case APP6:
800  case APP7:
801  case APP8:
802  case APP9:
803  case APP10:
804  case APP11:
805  case APP12:
806  case APP13:
807  case APP14:
808  case APP15:
809  case DQT: /* fallthrough */
810  case COM:
811  i += AV_RB16(&b[i + 2]) + 1;
812  break;
813  default:
814  if ( (c > TEM && c < SOF0)
815  || c == JPG)
816  return 0;
817  }
818  }
819 
820  if (state == EOI)
821  return AVPROBE_SCORE_EXTENSION + 1;
822  if (state == SOS)
823  return AVPROBE_SCORE_EXTENSION / 2;
824  return AVPROBE_SCORE_EXTENSION / 8 + 1;
825 }
826 
827 static int jpegls_probe(const AVProbeData *p)
828 {
829  const uint8_t *b = p->buf;
830 
831  if (AV_RB32(b) == 0xffd8fff7)
832  return AVPROBE_SCORE_EXTENSION + 1;
833  return 0;
834 }
835 
836 static int pcx_probe(const AVProbeData *p)
837 {
838  const uint8_t *b = p->buf;
839 
840  if ( p->buf_size < 128
841  || b[0] != 10
842  || b[1] > 5
843  || b[2] > 1
844  || av_popcount(b[3]) != 1 || b[3] > 8
845  || AV_RL16(&b[4]) > AV_RL16(&b[8])
846  || AV_RL16(&b[6]) > AV_RL16(&b[10])
847  || b[64])
848  return 0;
849  b += 73;
850  while (++b < p->buf + 128)
851  if (*b)
852  return AVPROBE_SCORE_EXTENSION / 4;
853 
854  return AVPROBE_SCORE_EXTENSION + 1;
855 }
856 
857 static int qdraw_probe(const AVProbeData *p)
858 {
859  const uint8_t *b = p->buf;
860 
861  if ( p->buf_size >= 528
862  && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
863  && AV_RB16(b + 520)
864  && AV_RB16(b + 518))
865  return AVPROBE_SCORE_MAX * 3 / 4;
866  if ( (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
867  && AV_RB16(b + 8)
868  && AV_RB16(b + 6))
869  return AVPROBE_SCORE_EXTENSION / 4;
870  return 0;
871 }
872 
873 static int pictor_probe(const AVProbeData *p)
874 {
875  const uint8_t *b = p->buf;
876 
877  if (AV_RL16(b) == 0x1234)
878  return AVPROBE_SCORE_EXTENSION / 4;
879  return 0;
880 }
881 
882 static int png_probe(const AVProbeData *p)
883 {
884  const uint8_t *b = p->buf;
885 
886  if (AV_RB64(b) == 0x89504e470d0a1a0a)
887  return AVPROBE_SCORE_MAX - 1;
888  return 0;
889 }
890 
891 static int psd_probe(const AVProbeData *p)
892 {
893  const uint8_t *b = p->buf;
894  int ret = 0;
895  uint16_t color_mode;
896 
897  if (AV_RL32(b) == MKTAG('8','B','P','S')) {
898  ret += 1;
899  } else {
900  return 0;
901  }
902 
903  if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */
904  ret += 1;
905  } else {
906  return 0;
907  }
908 
909  if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */
910  ret += 1;
911 
912  color_mode = AV_RB16(b+24);
913  if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
914  ret += 1;
915 
916  return AVPROBE_SCORE_EXTENSION + ret;
917 }
918 
919 static int sgi_probe(const AVProbeData *p)
920 {
921  const uint8_t *b = p->buf;
922 
923  if (AV_RB16(b) == 474 &&
924  (b[2] & ~1) == 0 &&
925  (b[3] & ~3) == 0 && b[3] &&
926  (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4))
927  return AVPROBE_SCORE_EXTENSION + 1;
928  return 0;
929 }
930 
931 static int sunrast_probe(const AVProbeData *p)
932 {
933  const uint8_t *b = p->buf;
934 
935  if (AV_RB32(b) == 0x59a66a95)
936  return AVPROBE_SCORE_EXTENSION + 1;
937  return 0;
938 }
939 
940 static int svg_probe(const AVProbeData *p)
941 {
942  const uint8_t *b = p->buf;
943  const uint8_t *end = p->buf + p->buf_size;
944 
945  if (memcmp(p->buf, "<?xml", 5))
946  return 0;
947  while (b < end) {
948  int inc = ff_subtitles_next_line(b);
949  if (!inc)
950  break;
951  b += inc;
952  if (b >= end - 4)
953  return 0;
954  if (!memcmp(b, "<svg", 4))
955  return AVPROBE_SCORE_EXTENSION + 1;
956  }
957  return 0;
958 }
959 
960 static int tiff_probe(const AVProbeData *p)
961 {
962  const uint8_t *b = p->buf;
963 
964  if (AV_RB32(b) == 0x49492a00 ||
965  AV_RB32(b) == 0x4D4D002a)
966  return AVPROBE_SCORE_EXTENSION + 1;
967  return 0;
968 }
969 
970 static int webp_probe(const AVProbeData *p)
971 {
972  const uint8_t *b = p->buf;
973 
974  if (AV_RB32(b) == 0x52494646 &&
975  AV_RB32(b + 8) == 0x57454250)
976  return AVPROBE_SCORE_MAX - 1;
977  return 0;
978 }
979 
980 static int pnm_magic_check(const AVProbeData *p, int magic)
981 {
982  const uint8_t *b = p->buf;
983 
984  return b[0] == 'P' && b[1] == magic + '0';
985 }
986 
987 static inline int pnm_probe(const AVProbeData *p)
988 {
989  const uint8_t *b = p->buf;
990 
991  while (b[2] == '\r')
992  b++;
993  if (b[2] == '\n' && (b[3] == '#' || (b[3] >= '0' && b[3] <= '9')))
994  return AVPROBE_SCORE_EXTENSION + 2;
995  return 0;
996 }
997 
998 static int pbm_probe(const AVProbeData *p)
999 {
1000  return pnm_magic_check(p, 1) || pnm_magic_check(p, 4) || pnm_magic_check(p, 22) || pnm_magic_check(p, 54) ? pnm_probe(p) : 0;
1001 }
1002 
1003 static inline int pgmx_probe(const AVProbeData *p)
1004 {
1005  return pnm_magic_check(p, 2) || pnm_magic_check(p, 5) ? pnm_probe(p) : 0;
1006 }
1007 
1008 static int pgm_probe(const AVProbeData *p)
1009 {
1010  int ret = pgmx_probe(p);
1011  return ret && !av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1012 }
1013 
1014 static int pgmyuv_probe(const AVProbeData *p) // custom FFmpeg format recognized by file extension
1015 {
1016  int ret = pgmx_probe(p);
1017  return ret && av_match_ext(p->filename, "pgmyuv") ? ret : 0;
1018 }
1019 
1020 static int pgx_probe(const AVProbeData *p)
1021 {
1022  const uint8_t *b = p->buf;
1023  if (!memcmp(b, "PG ML ", 6))
1024  return AVPROBE_SCORE_EXTENSION + 1;
1025  return 0;
1026 }
1027 
1028 static int ppm_probe(const AVProbeData *p)
1029 {
1030  return pnm_magic_check(p, 3) || pnm_magic_check(p, 6) ? pnm_probe(p) : 0;
1031 }
1032 
1033 static int pam_probe(const AVProbeData *p)
1034 {
1035  return pnm_magic_check(p, 7) ? pnm_probe(p) : 0;
1036 }
1037 
1038 static int xbm_probe(const AVProbeData *p)
1039 {
1040  if (!memcmp(p->buf, "/* XBM X10 format */", 20))
1041  return AVPROBE_SCORE_MAX;
1042 
1043  if (!memcmp(p->buf, "#define", 7))
1044  return AVPROBE_SCORE_MAX - 1;
1045  return 0;
1046 }
1047 
1048 static int xpm_probe(const AVProbeData *p)
1049 {
1050  const uint8_t *b = p->buf;
1051 
1052  if (AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) == '/')
1053  return AVPROBE_SCORE_MAX - 1;
1054  return 0;
1055 }
1056 
1057 static int xwd_probe(const AVProbeData *p)
1058 {
1059  const uint8_t *b = p->buf;
1060  unsigned width, bpp, bpad, lsize;
1061 
1062  if ( p->buf_size < XWD_HEADER_SIZE
1063  || AV_RB32(b ) < XWD_HEADER_SIZE // header size
1064  || AV_RB32(b + 4) != XWD_VERSION // version
1065  || AV_RB32(b + 8) != XWD_Z_PIXMAP // format
1066  || AV_RB32(b + 12) > 32 || !AV_RB32(b + 12) // depth
1067  || AV_RB32(b + 16) == 0 // width
1068  || AV_RB32(b + 20) == 0 // height
1069  || AV_RB32(b + 28) > 1 // byteorder
1070  || AV_RB32(b + 32) & ~56 || av_popcount(AV_RB32(b + 32)) != 1 // bitmap unit
1071  || AV_RB32(b + 36) > 1 // bitorder
1072  || AV_RB32(b + 40) & ~56 || av_popcount(AV_RB32(b + 40)) != 1 // padding
1073  || AV_RB32(b + 44) > 32 || !AV_RB32(b + 44) // bpp
1074  || AV_RB32(b + 68) > 256) // colours
1075  return 0;
1076 
1077  width = AV_RB32(b + 16);
1078  bpad = AV_RB32(b + 40);
1079  bpp = AV_RB32(b + 44);
1080  lsize = AV_RB32(b + 48);
1081  if (lsize < FFALIGN(width * bpp, bpad) >> 3)
1082  return 0;
1083 
1084  return AVPROBE_SCORE_MAX / 2 + 1;
1085 }
1086 
1087 static int gif_probe(const AVProbeData *p)
1088 {
1089  /* check magick */
1090  if (memcmp(p->buf, gif87a_sig, 6) && memcmp(p->buf, gif89a_sig, 6))
1091  return 0;
1092 
1093  /* width or height contains zero? */
1094  if (!AV_RL16(&p->buf[6]) || !AV_RL16(&p->buf[8]))
1095  return 0;
1096 
1097  return AVPROBE_SCORE_MAX - 1;
1098 }
1099 
1100 static int photocd_probe(const AVProbeData *p)
1101 {
1102  if (!memcmp(p->buf, "PCD_OPA", 7))
1103  return AVPROBE_SCORE_MAX - 1;
1104 
1105  if (p->buf_size < 0x807 || memcmp(p->buf + 0x800, "PCD_IPI", 7))
1106  return 0;
1107 
1108  return AVPROBE_SCORE_MAX - 1;
1109 }
1110 
1111 #define IMAGEAUTO_DEMUXER(imgname, codecid)\
1112 static const AVClass imgname ## _class = {\
1113  .class_name = AV_STRINGIFY(imgname) " demuxer",\
1114  .item_name = av_default_item_name,\
1115  .option = ff_img2pipe_options,\
1116  .version = LIBAVUTIL_VERSION_INT,\
1117 };\
1118 AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1119  .name = AV_STRINGIFY(imgname) "_pipe",\
1120  .long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1121  .priv_data_size = sizeof(VideoDemuxData),\
1122  .read_probe = imgname ## _probe,\
1123  .read_header = ff_img_read_header,\
1124  .read_packet = ff_img_read_packet,\
1125  .priv_class = & imgname ## _class,\
1126  .flags = AVFMT_GENERIC_INDEX, \
1127  .raw_codec_id = codecid,\
1128 };
1129 
AVInputFormat ff_image2_demuxer
AVInputFormat ff_image2pipe_demuxer
uint8_t
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:37
Main libavformat public API header.
#define AVINDEX_KEYFRAME
Definition: avformat.h:811
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition: avformat.h:455
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1177
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:458
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:451
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition: avformat.h:1371
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:794
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:477
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
#define AVIO_FLAG_READ
read-only
Definition: avio.h:674
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:342
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:364
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:337
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:633
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:1097
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
uint8_t * av_packet_pack_dictionary(AVDictionary *dict, int *size)
Definition: avpacket.c:511
#define AV_RL16
Definition: intreadwrite.h:42
#define AV_RB32
Definition: intreadwrite.h:130
#define AV_RB16
Definition: intreadwrite.h:53
#define AV_RL32
Definition: intreadwrite.h:146
#define AV_RB64
Definition: intreadwrite.h:164
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define f(width, name)
Definition: cbs_vp9.c:255
static struct @321 state
#define fail()
Definition: checkasm.h:133
#define MKTAG(a, b, c, d)
Definition: common.h:478
#define av_popcount
Definition: common.h:176
#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
Definition: config.h:380
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static enum AVPixelFormat pix_fmt
static int loop
Definition: ffplay.c:341
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:545
GIF format definitions.
static const uint8_t gif89a_sig[6]
Definition: gif.h:35
static const uint8_t gif87a_sig[6]
Definition: gif.h:34
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_CODEC_ID_PNG
Definition: codec_id.h:110
@ AV_CODEC_ID_XPM
Definition: codec_id.h:278
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:62
@ AV_CODEC_ID_PSD
Definition: codec_id.h:272
@ AV_CODEC_ID_PICTOR
Definition: codec_id.h:190
@ AV_CODEC_ID_GIF
Definition: codec_id.h:146
@ AV_CODEC_ID_PHOTOCD
Definition: codec_id.h:304
@ AV_CODEC_ID_PGM
Definition: codec_id.h:113
@ AV_CODEC_ID_NONE
Definition: codec_id.h:47
@ AV_CODEC_ID_PGX
Definition: codec_id.h:244
@ AV_CODEC_ID_JPEG2000
Definition: codec_id.h:137
@ AV_CODEC_ID_SUNRAST
Definition: codec_id.h:159
@ AV_CODEC_ID_SGI
Definition: codec_id.h:150
@ AV_CODEC_ID_PAM
Definition: codec_id.h:115
@ AV_CODEC_ID_XBM
Definition: codec_id.h:209
@ AV_CODEC_ID_PBM
Definition: codec_id.h:112
@ AV_CODEC_ID_CRI
Definition: codec_id.h:307
@ AV_CODEC_ID_PCX
Definition: codec_id.h:158
@ AV_CODEC_ID_PGMYUV
Definition: codec_id.h:114
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:145
@ AV_CODEC_ID_XWD
Definition: codec_id.h:207
@ AV_CODEC_ID_PPM
Definition: codec_id.h:111
@ AV_CODEC_ID_ALIAS_PIX
Definition: codec_id.h:226
@ AV_CODEC_ID_BMP
Definition: codec_id.h:127
@ AV_CODEC_ID_EXR
Definition: codec_id.h:229
@ AV_CODEC_ID_LJPEG
Definition: codec_id.h:58
@ AV_CODEC_ID_WEBP
Definition: codec_id.h:221
@ AV_CODEC_ID_JPEGLS
Definition: codec_id.h:60
@ AV_CODEC_ID_QDRAW
Definition: codec_id.h:107
@ AV_CODEC_ID_SVG
Definition: codec_id.h:283
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:56
@ AV_CODEC_ID_DPX
Definition: codec_id.h:177
@ AV_CODEC_ID_DDS
Definition: codec_id.h:239
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
FF_ENABLE_DEPRECATION_WARNINGS 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: avpacket.c:309
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
Definition: packet.h:172
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4509
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
Definition: allformats.c:558
ff_const59 AVInputFormat * av_probe_input_format3(ff_const59 AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
Definition: format.c:153
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: utils.c:2013
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:38
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Definition: utils.c:4794
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:333
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:2130
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
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:70
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:134
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
const char * av_basename(const char *path)
Thread safe basename.
Definition: avstring.c:260
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int index
Definition: gxfenc.c:89
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition: img2.c:106
@ PT_NONE
Definition: img2.h:37
@ PT_DEFAULT
Definition: img2.h:38
@ PT_SEQUENCE
Definition: img2.h:36
@ PT_GLOB
Definition: img2.h:35
@ PT_GLOB_SEQUENCE
Definition: img2.h:34
const AVOption ff_img_options[]
static int is_glob(const char *path)
Definition: img2dec.c:81
#define IMAGEAUTO_DEMUXER(imgname, codecid)
Definition: img2dec.c:1111
static int pbm_probe(const AVProbeData *p)
Definition: img2dec.c:998
static int jpegls_probe(const AVProbeData *p)
Definition: img2dec.c:827
static int photocd_probe(const AVProbeData *p)
Definition: img2dec.c:1100
static int xwd_probe(const AVProbeData *p)
Definition: img2dec.c:1057
static int xbm_probe(const AVProbeData *p)
Definition: img2dec.c:1038
static int sgi_probe(const AVProbeData *p)
Definition: img2dec.c:919
static int img_read_close(struct AVFormatContext *s1)
Definition: img2dec.c:576
#define COMMON_OPTIONS
Definition: img2dec.c:609
static int cri_probe(const AVProbeData *p)
Definition: img2dec.c:693
static int exr_probe(const AVProbeData *p)
Definition: img2dec.c:733
static int tiff_probe(const AVProbeData *p)
Definition: img2dec.c:960
static int ppm_probe(const AVProbeData *p)
Definition: img2dec.c:1028
const AVOption ff_img2pipe_options[]
Definition: img2dec.c:653
static int pnm_probe(const AVProbeData *p)
Definition: img2dec.c:987
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: img2dec.c:587
static int xpm_probe(const AVProbeData *p)
Definition: img2dec.c:1048
static int j2k_probe(const AVProbeData *p)
Definition: img2dec.c:742
static int pgx_probe(const AVProbeData *p)
Definition: img2dec.c:1020
static int psd_probe(const AVProbeData *p)
Definition: img2dec.c:891
static int sunrast_probe(const AVProbeData *p)
Definition: img2dec.c:931
static int dpx_probe(const AVProbeData *p)
Definition: img2dec.c:715
static int pgm_probe(const AVProbeData *p)
Definition: img2dec.c:1008
static int find_image_range(AVIOContext *pb, 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:111
static const int sizes[][2]
Definition: img2dec.c:54
static int pcx_probe(const AVProbeData *p)
Definition: img2dec.c:836
static int qdraw_probe(const AVProbeData *p)
Definition: img2dec.c:857
static int infer_size(int *width_ptr, int *height_ptr, int size)
Definition: img2dec.c:66
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:384
static int bmp_probe(const AVProbeData *p)
Definition: img2dec.c:675
static int pgmyuv_probe(const AVProbeData *p)
Definition: img2dec.c:1014
static int dds_probe(const AVProbeData *p)
Definition: img2dec.c:704
static int svg_probe(const AVProbeData *p)
Definition: img2dec.c:940
int ff_img_read_header(AVFormatContext *s1)
Definition: img2dec.c:183
static int pnm_magic_check(const AVProbeData *p, int magic)
Definition: img2dec.c:980
static int gif_probe(const AVProbeData *p)
Definition: img2dec.c:1087
static int webp_probe(const AVProbeData *p)
Definition: img2dec.c:970
static int pam_probe(const AVProbeData *p)
Definition: img2dec.c:1033
#define OFFSET(x)
Definition: img2dec.c:607
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: img2dec.c:406
static int pgmx_probe(const AVProbeData *p)
Definition: img2dec.c:1003
static int pictor_probe(const AVProbeData *p)
Definition: img2dec.c:873
static int img_read_probe(const AVProbeData *p)
Definition: img2dec.c:164
static int jpeg_probe(const AVProbeData *p)
Definition: img2dec.c:752
static int png_probe(const AVProbeData *p)
Definition: img2dec.c:882
#define DEC
Definition: img2dec.c:608
int i
Definition: input.c:407
#define AV_RN32(p)
Definition: intreadwrite.h:364
#define PROBE_BUF_MIN
size of probe buffer, for guessing file type from file contents
Definition: internal.h:33
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4945
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:5692
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
common internal API header
int buffer_size_t
Definition: internal.h:306
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
uint8_t w
Definition: llviddspenc.c:39
#define FFALIGN(x, a)
Definition: macros.h:48
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
@ EOI
Definition: mjpeg.h:71
@ 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
int frame_size
Definition: mxfenc.c:2206
AVOptions.
misc parsing utilities
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2501
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
#define s1
Definition: regdef.h:38
static const uint8_t header[24]
Definition: sdr2.c:67
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
int width
Video only.
Definition: codec_par.h:126
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
Format I/O context.
Definition: avformat.h:1232
Bytestream IO Context.
Definition: avio.h:161
int64_t pos
Definition: avformat.h:804
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:659
int(* read_header)(struct AVFormatContext *)
Read the format header and initialize the AVFormatContext structure.
Definition: avformat.h:712
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:693
int(* read_probe)(const AVProbeData *)
Tell if a given file has a chance of being parsed as this format.
Definition: avformat.h:705
int(* read_packet)(struct AVFormatContext *, AVPacket *pkt)
Read one packet and put it in 'pkt'.
Definition: avformat.h:722
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int stream_index
Definition: packet.h:371
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int size
Definition: packet.h:370
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
uint8_t * data
Definition: packet.h:369
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:389
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
const char * filename
Definition: avformat.h:442
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:444
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
Stream structure.
Definition: avformat.h:873
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:922
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:912
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:946
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:1090
enum AVStreamParseType need_parsing
Definition: avformat.h:1081
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:187
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
AVPacket * pkt
Definition: movenc.c:59
#define width
int size
const char * b
Definition: vf_curves.c:118
if(ret< 0)
Definition: vf_mcdeint.c:282
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