23 #define _DEFAULT_SOURCE 45 #define GLOB_NOMAGIC 0 86 while (p = strchr(p,
'%')) {
91 if (span = strspn(p,
"*?[]{}"))
111 const char *path,
int start_index,
int start_index_range)
114 int range, last_index, range1, first_index;
117 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
128 if (first_index == start_index + start_index_range)
132 last_index = first_index;
141 last_index + range1) < 0)
147 if (range >= (1 << 30))
155 *pfirst_index = first_index;
156 *plast_index = last_index;
185 int first_index = 1, last_index = 1;
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");
243 char *p = s->
path, *q, *dup;
248 "use pattern_type 'glob' instead\n");
253 if ((p - s->
path) >= (
sizeof(s->
path) - 2))
255 if (*q ==
'%' && strspn(q + 1,
"%*?[]{}"))
257 else if (strspn(q,
"\\*?[]{}"))
264 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &s->globstate);
269 last_index = s->globstate.gl_pathc - 1;
277 "Could find no file with path '%s' and index in the range %d-%d\n",
284 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &s->globstate);
289 last_index = s->globstate.gl_pathc - 1;
293 "Pattern type 'glob' was selected but globbing " 294 "is not supported by this libavformat build\n");
299 "Unknown value '%d' for pattern_type option\n", s->
pattern_type);
308 st->
duration = last_index - first_index + 1;
322 const char *str = strrchr(s->
path,
'.');
326 int probe_buffer_size = 2048;
329 void *fmt_iter =
NULL;
335 probe_buffer_size =
avio_read(s1->
pb, probe_buffer, probe_buffer_size);
336 if (probe_buffer_size < 0) {
338 return probe_buffer_size;
342 pd.
buf = probe_buffer;
380 char filename_bytes[1024];
381 char *filename = filename_bytes;
383 int size[3] = { 0 }, ret[3] = { 0 };
398 filename = s->globstate.gl_pathv[s->
img_number];
406 for (i = 0; i < 3; i++) {
408 !strcmp(filename_bytes, s->
path) &&
423 filename[strlen(filename) - 1] =
'U' +
i;
436 memset(header + ret, 0,
sizeof(header) - ret);
471 struct stat img_stat;
472 if (stat(filename, &img_stat)) {
476 pkt->
pts = (int64_t)img_stat.st_mtime;
479 pkt->
pts = 1000000000*pkt->
pts + img_stat.st_mtim.tv_nsec;
490 for (i = 0; i < 3; i++) {
506 if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
510 }
else if (ret[1] < 0) {
512 }
else if (ret[2] < 0) {
527 for (i = 0; i < 3; i++) {
540 globfree(&s->globstate);
566 #define OFFSET(x) offsetof(VideoDemuxData, x) 567 #define DEC AV_OPT_FLAG_DECODING_PARAM 568 #define COMMON_OPTIONS \ 569 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \ 570 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \ 571 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \ 572 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \ 575 #if CONFIG_IMAGE2_DEMUXER 582 {
"start_number",
"set first number in the sequence",
OFFSET(start_number),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
DEC },
583 {
"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 },
584 {
"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" },
591 static const AVClass img2_class = {
607 .priv_class = &img2_class,
616 #if CONFIG_IMAGE2PIPE_DEMUXER 617 static const AVClass img2pipe_class = {
624 .
name =
"image2pipe",
629 .priv_class = &img2pipe_class,
642 if (ihsize < 12 || ihsize > 255)
655 if (
AV_RB64(b) == 0x444453207c000000
672 if (w <= 0 || h <= 0)
693 if (
AV_RB64(b) == 0x0000000c6a502020 ||
709 for (i = 0; i < p->
buf_size - 3; i++) {
731 if (state !=
SOF0 && state !=
SOS)
791 || av_popcount(b[3]) != 1 || b[3] > 8
797 while (++b < p->
buf + 128)
809 && (
AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
813 if ( (
AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
833 if (
AV_RB64(b) == 0x89504e470d0a1a0a)
850 if ((b[4] == 0) && (b[5] == 1)) {
860 if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
872 (b[3] & ~3) == 0 && b[3] &&
892 if (memcmp(p->
buf,
"<?xml", 5))
901 if (!memcmp(b,
"<svg", 4))
911 if (
AV_RB32(b) == 0x49492a00 ||
921 if (
AV_RB32(b) == 0x52494646 &&
931 return b[0] ==
'P' && b[1] == magic +
'0';
940 if (b[2] ==
'\n' && (b[3] ==
'#' || (b[3] >=
'0' && b[3] <=
'9')))
981 if (
AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) ==
'/')
989 unsigned width, bpp, bpad, lsize;
1010 if (lsize <
FFALIGN(width * bpp, bpad) >> 3)
1029 #define IMAGEAUTO_DEMUXER(imgname, codecid)\ 1030 static const AVClass imgname ## _class = {\ 1031 .class_name = AV_STRINGIFY(imgname) " demuxer",\ 1032 .item_name = av_default_item_name,\ 1033 .option = ff_img2pipe_options,\ 1034 .version = LIBAVUTIL_VERSION_INT,\ 1036 AVInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\ 1037 .name = AV_STRINGIFY(imgname) "_pipe",\ 1038 .long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\ 1039 .priv_data_size = sizeof(VideoDemuxData),\ 1040 .read_probe = imgname ## _probe,\ 1041 .read_header = ff_img_read_header,\ 1042 .read_packet = ff_img_read_packet,\ 1043 .priv_class = & imgname ## _class,\ 1044 .flags = AVFMT_GENERIC_INDEX, \ 1045 .raw_codec_id = codecid,\
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
static enum AVPixelFormat pix_fmt
int height
Set by a private option.
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
int64_t avio_size(AVIOContext *s)
Get the filesize.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
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.
static int svg_probe(const AVProbeData *p)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
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...
static int psd_probe(const AVProbeData *p)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static int img_read_close(struct AVFormatContext *s1)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AVIO_FLAG_READ
read-only
static const uint8_t gif87a_sig[6]
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
const AVOption ff_img_options[]
int ctx_flags
Flags signalling stream properties.
MJPEG encoder and decoder.
This struct describes the properties of an encoded stream.
static int dds_probe(const AVProbeData *p)
char * pixel_format
Set by a private option.
static int pgmyuv_probe(const AVProbeData *p)
#define IMAGEAUTO_DEMUXER(imgname, codecid)
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url...
static int pam_probe(const AVProbeData *p)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int bmp_probe(const AVProbeData *p)
int pattern_type
PatternType.
static av_cold int end(AVCodecContext *avctx)
enum AVStreamParseType need_parsing
static int pictor_probe(const AVProbeData *p)
int ff_img_read_header(AVFormatContext *s1)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
int flags
Flags modifying the (de)muxer behaviour.
static int pcx_probe(const AVProbeData *p)
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
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.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
enum AVCodecID video_codec_id
Forced video codec_id.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int is_glob(const char *path)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
static const int sizes[][2]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
ff_const59 struct AVInputFormat * iformat
The input container format.
char * url
input or output URL.
enum AVMediaType codec_type
General type of the encoded data.
static int dpx_probe(const AVProbeData *p)
static int xpm_probe(const AVProbeData *p)
static int pgmx_probe(const AVProbeData *p)
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.
static int j2k_probe(const AVProbeData *p)
int flags
A combination of AV_PKT_FLAG values.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static int img_read_probe(const AVProbeData *p)
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.
enum AVCodecID audio_codec_id
Forced audio codec_id.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
ff_const59 AVInputFormat * av_probe_input_format3(ff_const59 AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
static int sunrast_probe(const AVProbeData *p)
#define FF_ARRAY_ELEMS(a)
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
static int read_header(FFV1Context *f)
static int sgi_probe(const AVProbeData *p)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int xwd_probe(const AVProbeData *p)
static int jpeg_probe(const AVProbeData *p)
char * av_strdup(const char *s)
Duplicate a string.
AVIOContext * pb
I/O context.
int split_planes
use independent file for each Y, U, V plane
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
static int pgm_probe(const AVProbeData *p)
Describe the class of an AVClass context structure.
static int infer_size(int *width_ptr, int *height_ptr, int size)
This structure contains the data a format has to probe a file.
static int pnm_probe(const AVProbeData *p)
#define flags(name, subs,...)
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...
static int exr_probe(const AVProbeData *p)
int64_t duration
Decoding: duration of the stream, in stream time base.
static int qdraw_probe(const AVProbeData *p)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static const uint8_t gif89a_sig[6]
enum AVCodecID ff_guess_image2_codec(const char *filename)
static int gif_probe(const AVProbeData *p)
static int tiff_probe(const AVProbeData *p)
AVRational framerate
Set by a private option.
static int ppm_probe(const AVProbeData *p)
struct AVCodecParserContext * parser
void * priv_data
Format private data.
const AVOption ff_img2pipe_options[]
static int pbm_probe(const AVProbeData *p)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
static int pnm_magic_check(const AVProbeData *p, int magic)
#define MKTAG(a, b, c, d)
AVPixelFormat
Pixel format.
This structure stores compressed data.
static int png_probe(const AVProbeData *p)
static int jpegls_probe(const AVProbeData *p)
static int webp_probe(const AVProbeData *p)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)