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