40 #define GLOB_NOMAGIC 0
66 *width_ptr =
sizes[i][0];
67 *height_ptr =
sizes[i][1];
81 while (p = strchr(p,
'%')) {
86 if (span = strspn(p,
"*?[]{}"))
106 const char *path,
int start_index,
int start_index_range)
109 int range, last_index, range1, first_index;
112 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
123 if (first_index == start_index + start_index_range)
127 last_index = first_index;
136 last_index + range1) < 0)
142 if (range >= (1 << 30))
150 *pfirst_index = first_index;
151 *plast_index = last_index;
180 int first_index, last_index;
211 #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
212 av_log(s1,
AV_LOG_ERROR,
"POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
231 char *p = s->
path, *q, *dup;
236 "use pattern_type 'glob' instead\n");
241 if ((p - s->
path) >= (
sizeof(s->
path) - 2))
243 if (*q ==
'%' && strspn(q + 1,
"%*?[]{}"))
245 else if (strspn(q,
"\\*?[]{}"))
252 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &s->globstate);
257 last_index = s->globstate.gl_pathc - 1;
265 "Could find no file with path '%s' and index in the range %d-%d\n",
272 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &s->globstate);
277 last_index = s->globstate.gl_pathc - 1;
281 "Pattern type 'glob' was selected but globbing "
282 "is not supported by this libavformat build\n");
287 "Unknown value '%d' for pattern_type option\n", s->
pattern_type);
296 st->
duration = last_index - first_index + 1;
310 const char *str = strrchr(s->
path,
'.');
314 int probe_buffer_size = 2048;
322 probe_buffer_size =
avio_read(s1->
pb, probe_buffer, probe_buffer_size);
323 if (probe_buffer_size < 0) {
325 return probe_buffer_size;
329 pd.
buf = probe_buffer;
363 char filename_bytes[1024];
364 char *filename = filename_bytes;
366 int size[3] = { 0 },
ret[3] = { 0 };
379 filename = s->globstate.gl_pathv[s->
img_number];
387 for (i = 0; i < 3; i++) {
400 filename[strlen(filename) - 1] =
'U' + i;
413 memset(header + ret, 0,
sizeof(header) - ret);
447 struct stat img_stat;
448 if (stat(filename, &img_stat))
450 pkt->
pts = (int64_t)img_stat.st_mtime;
451 #
if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
453 pkt->
pts = 1000000000*pkt->
pts + img_stat.st_mtim.tv_nsec;
464 for (i = 0; i < 3; i++) {
480 if (
ret[0] <= 0 ||
ret[1] < 0 ||
ret[2] < 0) {
484 }
else if (
ret[1] < 0) {
486 }
else if (
ret[2] < 0)
502 globfree(&s->globstate);
528 #define OFFSET(x) offsetof(VideoDemuxData, x)
529 #define DEC AV_OPT_FLAG_DECODING_PARAM
534 {
"pattern_type",
"set pattern type",
OFFSET(pattern_type),
AV_OPT_TYPE_INT, {.i64=PT_GLOB_SEQUENCE}, 0, INT_MAX,
DEC,
"pattern_type"},
535 {
"glob_sequence",
"select glob/sequence pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
536 {
"glob",
"select glob pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
537 {
"sequence",
"select sequence pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
540 {
"start_number",
"set first number in the sequence",
OFFSET(start_number),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
DEC },
541 {
"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 },
544 {
"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" },
551 #if CONFIG_IMAGE2_DEMUXER
552 static const AVClass img2_class = {
568 .priv_class = &img2_class,
571 #if CONFIG_IMAGE2PIPE_DEMUXER
572 static const AVClass img2pipe_class = {
579 .
name =
"image2pipe",
584 .priv_class = &img2pipe_class,
597 if (ihsize < 12 || ihsize > 255)
616 if (w <= 0 || h <= 0)
637 if (
AV_RB64(b) == 0x0000000c6a502020 ||
646 int i,
state = 0xD8, exif_size = 0;
654 exif_size =
AV_RB16(b + 2) + 2;
657 for (i = 0; i + exif_size < p->
buf_size - 2; i++) {
687 if ( (c >= 0x02 && c <= 0xBF)
720 if (
AV_RB64(b) == 0x89504e470d0a1a0a)
731 (b[3] & ~3) == 0 && b[3] &&
750 if (
AV_RB32(b) == 0x49492a00 ||
760 if (
AV_RB32(b) == 0x52494646 &&
766 #define IMAGEAUTO_DEMUXER(imgname, codecid)\
767 static const AVClass imgname ## _class = {\
768 .class_name = AV_STRINGIFY(imgname) " demuxer",\
769 .item_name = av_default_item_name,\
770 .option = ff_img_options,\
771 .version = LIBAVUTIL_VERSION_INT,\
773 AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
774 .name = AV_STRINGIFY(imgname) "_pipe",\
775 .long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
776 .priv_data_size = sizeof(VideoDemuxData),\
777 .read_probe = imgname ## _probe,\
778 .read_header = ff_img_read_header,\
779 .read_packet = ff_img_read_packet,\
780 .priv_class = & imgname ## _class,\
781 .flags = AVFMT_GENERIC_INDEX, \
782 .raw_codec_id = codecid,\