24 #include "libavutil/avstring.h"
25 #include "libavutil/log.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/parseutils.h"
37 #define GLOB_NOMAGIC 0
59 enum { PT_GLOB_SEQUENCE, PT_GLOB, PT_SEQUENCE } pattern_type;
88 *width_ptr =
sizes[i][0];
89 *height_ptr =
sizes[i][1];
101 const char *p = path;
103 while (p = strchr(p,
'%')) {
108 if (span = strspn(p,
"*?[]{}"))
128 const char *path,
int start_index,
int start_index_range)
131 int range, last_index, range1, first_index;
134 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
145 if (first_index == start_index + start_index_range)
149 last_index = first_index;
158 last_index + range1) < 0)
164 if (range >= (1 << 30))
172 *pfirst_index = first_index;
173 *plast_index = last_index;
198 int first_index, last_index;
242 char *p = s->
path, *q, *dup;
246 "use pattern_type 'glob' instead\n");
251 if ((p - s->
path) >= (
sizeof(s->
path) - 2))
253 if (*q ==
'%' && strspn(q + 1,
"%*?[]{}"))
255 else if (strspn(q,
"\\*?[]{}"))
262 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
267 last_index = s->globstate.gl_pathc - 1;
275 "Could find no file with path '%s' and index in the range %d-%d\n",
282 gerr = glob(s->
path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
287 last_index = s->globstate.gl_pathc - 1;
291 "Pattern type 'glob' was selected but globbing "
292 "is not supported by this libavformat build\n");
297 "Unknown value '%d' for pattern_type option\n", s->
pattern_type);
306 st->
duration = last_index - first_index + 1;
317 const char *str = strrchr(s->
path,
'.');
334 char filename_bytes[1024];
335 char *filename = filename_bytes;
337 int size[3] = { 0 },
ret[3] = { 0 };
350 filename = s->globstate.gl_pathv[s->
img_number];
358 for (i = 0; i < 3; i++) {
371 filename[strlen(filename) - 1] =
'U' + i;
392 struct stat img_stat;
393 if (stat(filename, &img_stat))
395 pkt->
pts = (int64_t)img_stat.st_mtime;
402 for (i = 0; i < 3; i++) {
412 if (
ret[0] <= 0 ||
ret[1] < 0 ||
ret[2] < 0) {
428 globfree(&s->globstate);
454 #define OFFSET(x) offsetof(VideoDemuxData, x)
455 #define DEC AV_OPT_FLAG_DECODING_PARAM
460 {
"pattern_type",
"set pattern type",
OFFSET(pattern_type),
AV_OPT_TYPE_INT, {.i64=PT_GLOB_SEQUENCE}, 0, INT_MAX,
DEC,
"pattern_type"},
461 {
"glob_sequence",
"select glob/sequence pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
462 {
"glob",
"select glob pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
463 {
"sequence",
"select sequence pattern type", 0,
AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX,
DEC,
"pattern_type" },
466 {
"start_number",
"set first number in the sequence",
OFFSET(start_number),
AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX,
DEC },
467 {
"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 },
470 {
"ts_from_file",
"set frame timestamp from file's one",
OFFSET(ts_from_file),
AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1,
DEC },
474 #if CONFIG_IMAGE2_DEMUXER
475 static const AVClass img2_class = {
491 .priv_class = &img2_class,
494 #if CONFIG_IMAGE2PIPE_DEMUXER
495 static const AVClass img2pipe_class = {
502 .
name =
"image2pipe",
507 .priv_class = &img2pipe_class,
int height
Set by a private option.
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
void av_free_packet(AVPacket *pkt)
Free a packet.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
enum VideoDemuxData::@147 pattern_type
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static int img_read_close(struct AVFormatContext *s1)
AVCodecContext * codec
Codec context associated with this stream.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ctx_flags
Format-specific flags, see AVFMTCTX_xx.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
char * pixel_format
Set by a private option.
const char * av_default_item_name(void *ctx)
Return the context 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...
enum AVStreamParseType need_parsing
static int img_read_header(AVFormatContext *s1)
static int img_read_probe(AVProbeData *p)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static av_cold int read_close(AVFormatContext *ctx)
enum AVPixelFormat pix_fmt
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.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
const OptionDef options[]
enum AVCodecID video_codec_id
Forced video codec_id.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int is_glob(const char *path)
static const uint8_t frame_size[4]
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
void * priv_data
Format private data.
char filename[1024]
input or output filename
static const int sizes[][2]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
AVPixelFormat
Pixel format.
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.
int flags
A combination of AV_PKT_FLAG values.
#define FF_ARRAY_ELEMS(a)
enum AVCodecID audio_codec_id
Forced audio codec_id.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int width
picture width / height.
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Return in 'buf' the path with 'd' replaced by a number.
static int read_header(FFV1Context *f)
enum AVMediaType codec_type
int split_planes
use independent file for each Y, U, V plane
main external API structure.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
rational number numerator/denominator
static int infer_size(int *width_ptr, int *height_ptr, int size)
offset must point to AVRational
offset must point to two consecutive integers
This structure contains the data a format has to probe a file.
int64_t duration
Decoding: duration of the stream, in stream time base.
static int find_image_range(int *pfirst_index, int *plast_index, const char *path, int start_index, int start_index_range)
Get index range of image files matched by path.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
enum AVCodecID ff_guess_image2_codec(const char *filename)
AVRational framerate
Set by a private option.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...