Go to the documentation of this file.
23 #include "config_components.h"
25 #define _DEFAULT_SOURCE
52 #define GLOB_NOMAGIC 0
93 while (p = strchr(p,
'%')) {
98 if (span = strspn(p,
"*?[]{}"))
118 const char *path,
int start_index,
int start_index_range)
121 int range, last_index, range1, first_index;
124 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
135 if (first_index == start_index + start_index_range)
139 last_index = first_index;
148 last_index + range1) < 0)
154 if (
range >= (1 << 30))
162 *pfirst_index = first_index;
163 *plast_index = last_index;
192 int first_index = 1, last_index = 1;
203 if (
s->pixel_format &&
222 if (
s->ts_from_file == 2) {
223 #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
224 av_log(s1,
AV_LOG_ERROR,
"POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
228 }
else if (
s->ts_from_file)
235 if (
s->width &&
s->height) {
252 char *p =
s->path, *q, *dup;
257 "use pattern_type 'glob' instead\n");
262 if ((p -
s->path) >= (
sizeof(
s->path) - 2))
264 if (*q ==
'%' && strspn(q + 1,
"%*?[]{}"))
266 else if (strspn(q,
"\\*?[]{}"))
273 gerr = glob(
s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &
s->globstate);
278 last_index =
s->globstate.gl_pathc - 1;
284 s->start_number,
s->start_number_range) < 0) {
286 "Could find no file with path '%s' and index in the range %d-%d\n",
287 s->path,
s->start_number,
s->start_number +
s->start_number_range - 1);
290 }
else if (
s->pattern_type ==
PT_GLOB) {
293 gerr = glob(
s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &
s->globstate);
298 last_index =
s->globstate.gl_pathc - 1;
302 "Pattern type 'glob' was selected but globbing "
303 "is not supported by this libavformat build\n");
308 "Unknown value '%d' for pattern_type option\n",
s->pattern_type);
311 s->img_first = first_index;
312 s->img_last = last_index;
313 s->img_number = first_index;
315 if (!
s->ts_from_file) {
317 st->
duration = last_index - first_index + 1;
331 const char *str = strrchr(
s->path,
'.');
335 int probe_buffer_size = 2048;
338 void *fmt_iter =
NULL;
344 probe_buffer_size =
avio_read(s1->
pb, probe_buffer, probe_buffer_size);
345 if (probe_buffer_size < 0) {
347 return probe_buffer_size;
351 pd.
buf = probe_buffer;
393 char *packed_metadata =
NULL;
397 av_dict_set(&d,
"lavf.image2dec.source_path", filename, 0);
402 if (!packed_metadata)
405 packed_metadata, metadata_len);
416 char filename_bytes[1024];
417 char *filename = filename_bytes;
419 int size[3] = { 0 },
ret[3] = { 0 };
425 if (
s->loop &&
s->img_number >
s->img_last) {
426 s->img_number =
s->img_first;
428 if (
s->img_number >
s->img_last)
431 av_strlcpy(filename_bytes,
s->path,
sizeof(filename_bytes));
432 }
else if (
s->use_glob) {
434 filename =
s->globstate.gl_pathv[
s->img_number];
439 s->img_number) < 0 &&
s->img_number > 1)
442 for (
i = 0;
i < 3;
i++) {
444 !strcmp(filename_bytes,
s->path) &&
457 if (!
s->split_planes)
459 filename[strlen(filename) - 1] =
'U' +
i;
491 if (
s->frame_size > 0) {
492 size[0] =
s->frame_size;
506 if (
s->ts_from_file) {
507 struct stat img_stat;
509 if (stat(filename, &img_stat)) {
514 #
if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
515 if (
s->ts_from_file == 2)
516 pkt->
pts = 1000000000*
pkt->
pts + img_stat.st_mtim.tv_nsec;
519 }
else if (!
s->is_pipe) {
531 if (!
s->is_pipe &&
s->export_path_metadata == 1) {
538 for (
i = 0;
i < 3;
i++) {
547 if (!
s->is_pipe &&
f[
i] != s1->
pb)
554 if (
ret[0] <= 0 ||
ret[1] < 0 ||
ret[2] < 0) {
557 }
else if (
ret[1] < 0) {
559 }
else if (
ret[2] < 0) {
575 for (
i = 0;
i < 3;
i++) {
588 globfree(&
s->globstate);
614 #define OFFSET(x) offsetof(VideoDemuxData, x)
615 #define DEC AV_OPT_FLAG_DECODING_PARAM
616 #define COMMON_OPTIONS \
617 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
618 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \
619 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \
620 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
623 #if CONFIG_IMAGE2_DEMUXER
630 {
"start_number",
"set first number in the sequence",
OFFSET(start_number),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
DEC },
631 {
"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 },
632 {
"ts_from_file",
"set frame timestamp from file's one",
OFFSET(ts_from_file),
AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2,
DEC, .unit =
"ts_type" },
635 {
"ns",
"nano second precision", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2,
DEC, .unit =
"ts_type" },
636 {
"export_path_metadata",
"enable metadata containing input path information",
OFFSET(export_path_metadata),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1,
DEC }, \
640 static const AVClass img2_class = {
650 .p.priv_class = &img2_class,
671 #if CONFIG_IMAGE2PIPE_DEMUXER
673 .
p.
name =
"image2pipe",
684 const uint8_t *
b = p->
buf;
691 if (ihsize < 12 || ihsize > 255)
702 const uint8_t *
b = p->
buf;
713 const uint8_t *
b = p->
buf;
715 if (
AV_RB64(
b) == 0x444453207c000000
724 const uint8_t *
b = p->
buf;
732 if (
w <= 0 ||
h <= 0)
742 const uint8_t *
b = p->
buf;
751 const uint8_t *
b = p->
buf;
753 if (
AV_RB64(
b) == 0x0000000c6a502020 ||
761 const uint8_t *
b = p->
buf;
842 const uint8_t *
b = p->
buf;
851 const uint8_t *
b = p->
buf;
860 #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
869 const uint8_t *
b = p->
buf;
881 while (++b < p->buf + 128)
890 const uint8_t *
b = p->
buf;
893 && (
AV_RB64(
b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
897 if ( (
AV_RB64(
b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
906 const uint8_t *
b = p->
buf;
915 const uint8_t *
b = p->
buf;
917 if (
AV_RB64(
b) == 0x89504e470d0a1a0a)
924 const uint8_t *
b = p->
buf;
934 if ((
b[4] == 0) && (
b[5] == 1)) {
944 if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
952 const uint8_t *
b = p->
buf;
956 (
b[3] & ~3) == 0 &&
b[3] &&
964 const uint8_t *
b = p->
buf;
973 const uint8_t *
b = p->
buf;
979 if (!memcmp(
b,
"<svg", 4))
981 if (memcmp(p->
buf,
"<?xml", 5) && memcmp(
b,
"<!--", 4))
990 if (!memcmp(
b,
"<svg", 4))
998 const uint8_t *
b = p->
buf;
1008 const uint8_t *
b = p->
buf;
1018 const uint8_t *
b = p->
buf;
1020 return b[0] ==
'P' &&
b[1] == magic +
'0';
1025 const uint8_t *
b = p->
buf;
1027 while (
b[2] ==
'\r')
1029 if (
b[2] ==
'\n' && (
b[3] ==
'#' || (
b[3] >=
'0' &&
b[3] <=
'9')))
1070 const uint8_t *
b = p->
buf;
1071 if (!memcmp(
b,
"PG ML ", 6))
1088 if (!memcmp(p->
buf,
"#?RADIANCE\n", 11))
1095 if (!memcmp(p->
buf,
"/* XBM X10 format */", 20))
1098 if (!memcmp(p->
buf,
"#define", 7))
1105 const uint8_t *
b = p->
buf;
1107 if (
AV_RB64(
b) == 0x2f2a2058504d202a && *(
b+8) ==
'/')
1114 const uint8_t *
b = p->
buf;
1115 unsigned width, bpp, bpad, lsize;
1157 if (!memcmp(p->
buf,
"PCD_OPA", 7))
1160 if (p->
buf_size < 0x807 || memcmp(p->
buf + 0x800,
"PCD_IPI", 7))
1168 if (memcmp(p->
buf,
"qoif", 4))
1174 if (p->
buf[12] != 3 && p->
buf[12] != 4)
1185 const uint8_t *
b = p->
buf;
1205 const uint8_t *
b = p->
buf;
1213 #define IMAGEAUTO_DEMUXER_0(imgname, codecid)
1214 #define IMAGEAUTO_DEMUXER_1(imgname, codecid)\
1215 const FFInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1216 .p.name = AV_STRINGIFY(imgname) "_pipe",\
1217 .p.long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1218 .p.priv_class = &imagepipe_class,\
1219 .p.flags = AVFMT_GENERIC_INDEX,\
1220 .priv_data_size = sizeof(VideoDemuxData),\
1221 .read_probe = imgname ## _probe,\
1222 .read_header = ff_img_read_header,\
1223 .read_packet = ff_img_read_packet,\
1224 .raw_codec_id = codecid,\
1227 #define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \
1228 IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid)
1229 #define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \
1230 IMAGEAUTO_DEMUXER_2(imgname, codecid, config)
1231 #define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \
1232 IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid, \
1233 CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER)
1234 #define IMAGEAUTO_DEMUXER(imgname, codecid) \
1235 IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
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
enum AVMediaType codec_type
General type of the encoded data.
static int pam_probe(const AVProbeData *p)
int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, FFJXLMetadata *meta, int validate)
This struct describes the properties of an encoded stream.
static int cri_probe(const AVProbeData *p)
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
static int pnm_magic_check(const AVProbeData *p, int magic)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
AVStream ** streams
A list of all streams in the file.
static int webp_probe(const AVProbeData *p)
int ff_img_read_header(AVFormatContext *s1)
static int dds_probe(const AVProbeData *p)
AVRational avg_frame_rate
Average framerate.
static const AVClass imagepipe_class
static int psd_probe(const AVProbeData *p)
enum AVCodecID ff_guess_image2_codec(const char *filename)
static int qoi_probe(const AVProbeData *p)
static int phm_probe(const AVProbeData *p)
static int pcx_probe(const AVProbeData *p)
int buf_size
Size of buf except extra allocated bytes.
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
enum AVCodecID video_codec_id
Forced video codec_id.
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const char * av_basename(const char *path)
Thread safe basename.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
static int is_glob(const char *path)
#define FF_JPEGXL_CONTAINER_SIGNATURE_LE
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.
static int svg_probe(const AVProbeData *p)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
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 av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define IMAGEAUTO_DEMUXER(imgname, codecid)
static int pgmx_probe(const AVProbeData *p)
static int img_read_close(struct AVFormatContext *s1)
static const AVOption img2pipe_options[]
int64_t duration
Decoding: duration of the stream, in stream time base.
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
static const uint8_t gif89a_sig[6]
static int pictor_probe(const AVProbeData *p)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int ctx_flags
Flags signalling stream properties.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static int img_read_probe(const AVProbeData *p)
int flags
Flags modifying the (de)muxer behaviour.
const struct AVInputFormat * iformat
The input container format.
static enum AVPixelFormat pix_fmt
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
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 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 ...
static int bmp_probe(const AVProbeData *p)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int pgmyuv_probe(const AVProbeData *p)
static int j2k_probe(const AVProbeData *p)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static int xpm_probe(const AVProbeData *p)
enum AVStreamParseType need_parsing
enum AVCodecID audio_codec_id
Forced audio codec_id.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int gem_probe(const AVProbeData *p)
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
const AVOption ff_img_options[]
static const int sizes[][2]
static int xwd_probe(const AVProbeData *p)
static int photocd_probe(const AVProbeData *p)
const char * av_default_item_name(void *ptr)
Return the context name.
AVIOContext * pb
I/O context.
static int xbm_probe(const AVProbeData *p)
This structure contains the data a format has to probe a file.
static int jpegxl_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.
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
static int inc(int num, int period)
static int sunrast_probe(const AVProbeData *p)
static int vbn_probe(const AVProbeData *p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
char * url
input or output URL.
static int pfm_probe(const AVProbeData *p)
static int dpx_probe(const AVProbeData *p)
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
#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name)
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
static const uint8_t header[24]
uint8_t * av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
static int gif_probe(const AVProbeData *p)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static const uint8_t gif87a_sig[6]
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE
static int pgm_probe(const AVProbeData *p)
static int infer_size(int *width_ptr, int *height_ptr, int size)
static int sgi_probe(const AVProbeData *p)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
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 pgx_probe(const AVProbeData *p)
static int pnm_probe(const AVProbeData *p)
#define AV_INPUT_BUFFER_PADDING_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
static int jpeg_probe(const AVProbeData *p)
static int png_probe(const AVProbeData *p)
static int jpegls_probe(const AVProbeData *p)
static int hdr_probe(const AVProbeData *p)
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int ppm_probe(const AVProbeData *p)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int exr_probe(const AVProbeData *p)
AVRational r_frame_rate
Real base framerate of the stream.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static int pbm_probe(const AVProbeData *p)
#define AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
static int read_probe(const AVProbeData *p)
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.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
static int tiff_probe(const AVProbeData *p)
#define flags(name, subs,...)
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.
struct AVCodecParserContext * parser
#define MKTAG(a, b, c, d)
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.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
void * priv_data
Format private data.
static int qdraw_probe(const AVProbeData *p)
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
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
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.