23#include "config_components.h"
26#define _DEFAULT_SOURCE
100 const char *path,
int start_index,
int start_index_range)
102 int range, last_index, range1, first_index, ret;
107 for (first_index = start_index; first_index < start_index + start_index_range; first_index++) {
115 if (first_index == start_index + start_index_range) {
121 last_index = first_index;
137 if (
range >= (1 << 30)) {
147 *pfirst_index = first_index;
148 *plast_index = last_index;
160 else if (p->filename[strcspn(p->filename,
"*?{")])
162 else if (p->buf_size == 0)
175 int first_index = 1, last_index = 1;
186 if (
s->pixel_format &&
204 if (
s->ts_from_file == 2) {
205#if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
206 av_log(s1,
AV_LOG_ERROR,
"POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n");
210 }
else if (
s->ts_from_file)
217 if (
s->width &&
s->height) {
231 s->start_number,
s->start_number_range) < 0) {
237 "Could find no file or sequence with path '%s' and index in the range %d-%d\n",
238 s1->
url,
s->start_number,
s->start_number +
s->start_number_range - 1);
242 }
else if (
s->pattern_type ==
PT_GLOB) {
245 gerr = glob(s1->
url, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC,
NULL, &
s->globstate);
250 last_index =
s->globstate.gl_pathc - 1;
254 "Pattern type 'glob' was selected but globbing "
255 "is not supported by this libavformat build\n");
258 }
else if (
s->pattern_type !=
PT_NONE) {
260 "Unknown value '%d' for pattern_type option\n",
s->pattern_type);
263 s->img_first = first_index;
264 s->img_last = last_index;
265 s->img_number = first_index;
267 if (!
s->ts_from_file) {
269 st->
duration = last_index - first_index + 1;
283 const char *str = strrchr(s1->
url,
'.');
287 int probe_buffer_size = 2048;
290 void *fmt_iter =
NULL;
296 probe_buffer_size =
avio_read(s1->
pb, probe_buffer, probe_buffer_size);
297 if (probe_buffer_size < 0) {
299 return probe_buffer_size;
303 pd.
buf = probe_buffer;
345 char *packed_metadata =
NULL;
349 av_dict_set(&d,
"lavf.image2dec.source_path", filename, 0);
354 if (!packed_metadata)
357 packed_metadata, metadata_len);
378 if (
s->loop &&
s->img_number >
s->img_last) {
379 s->img_number =
s->img_first;
381 if (
s->img_number >
s->img_last)
385 }
else if (
s->use_glob) {
387 av_bprintf(&filename,
"%s",
s->globstate.gl_pathv[
s->img_number]);
400 for (
i = 0;
i < 3;
i++) {
402 !strcmp(filename.str, s1->
url) &&
416 if (!
s->split_planes)
418 filename.str[filename.len - 1] =
'U' +
i;
453 if (
s->frame_size > 0) {
454 size[0] =
s->frame_size;
463 for (
int i = 0;
i < 3;
i++) {
464 if ((uint64_t)
size[
i] > INT_MAX - total_size)
467 total_size +=
size[
i];
474 pkt->stream_index = 0;
476 if (
s->ts_from_file) {
477 struct stat img_stat;
479 if (stat(filename.str, &img_stat)) {
484#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
485 if (
s->ts_from_file == 2)
486 pkt->pts = 1000000000*
pkt->pts + img_stat.st_mtim.tv_nsec;
489 }
else if (!
s->is_pipe) {
501 if (!
s->is_pipe &&
s->export_path_metadata == 1) {
509 for (
i = 0;
i < 3;
i++) {
518 if (!
s->is_pipe &&
f[
i] != s1->
pb)
525 if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
528 }
else if (ret[1] < 0) {
530 }
else if (ret[2] < 0) {
547 for (
i = 0;
i < 3;
i++) {
560 globfree(&
s->globstate);
586#define OFFSET(x) offsetof(VideoDemuxData, x)
587#define DEC AV_OPT_FLAG_DECODING_PARAM
588#define COMMON_OPTIONS \
589 { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \
590 { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \
591 { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \
592 { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \
595#if CONFIG_IMAGE2_DEMUXER
601 {
"start_number",
"set first number in the sequence",
OFFSET(start_number),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
DEC },
602 {
"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 },
603 {
"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" },
606 {
"ns",
"nanosecond precision", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2,
DEC, .unit =
"ts_type" },
607 {
"export_path_metadata",
"enable metadata containing input path information",
OFFSET(export_path_metadata),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1,
DEC }, \
611static const AVClass img2_class = {
612 .class_name =
"image2 demuxer",
621 .p.priv_class = &img2_class,
636 .class_name =
"imagepipe demuxer",
642#if CONFIG_IMAGE2PIPE_DEMUXER
644 .p.name =
"image2pipe",
655 const uint8_t *
b = p->buf;
662 if (ihsize < 12 || ihsize > 255)
673 const uint8_t *
b = p->buf;
684 const uint8_t *
b = p->buf;
686 if (
AV_RB64(
b) == 0x444453207c000000
695 const uint8_t *
b = p->buf;
699 if (p->buf_size < 0x304+8)
703 if (
w <= 0 ||
h <= 0)
713 const uint8_t *
b = p->buf;
722 const uint8_t *
b = p->buf;
724 if (
AV_RB64(
b) == 0x0000000c6a502020 ||
732 const uint8_t *
b = p->buf;
740 for (
i = 0;
i < p->buf_size - 3;
i++) {
813 const uint8_t *
b = p->buf;
822 const uint8_t *
b = p->buf;
831#if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
840 const uint8_t *
b = p->buf;
849 const uint8_t *
b = p->buf;
851 if ( p->buf_size < 128
870 const uint8_t *
b = p->buf;
872 if ( p->buf_size >= 528
873 && (
AV_RB64(
b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
877 if ( (
AV_RB64(
b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00
886 const uint8_t *
b = p->buf;
895 const uint8_t *
b = p->buf;
896 int size = p->buf_size;
927 const uint8_t *
b = p->buf;
937 if ((
b[4] == 0) && (
b[5] == 1)) {
947 if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6))
955 const uint8_t *
b = p->buf;
959 (
b[3] & ~3) == 0 &&
b[3] &&
967 const uint8_t *
b = p->buf;
976 const uint8_t *
b = p->buf;
977 const uint8_t *end = p->buf + p->buf_size;
982 if (!memcmp(
b,
"<svg", 4))
984 if (memcmp(p->buf,
"<?xml", 5) && memcmp(
b,
"<!--", 4))
993 if (!memcmp(
b,
"<svg", 4))
1001 const uint8_t *
b = p->buf;
1018 const uint8_t *
b = p->buf;
1028 const uint8_t *
b = p->buf;
1030 return b[0] ==
'P' &&
b[1] == magic +
'0';
1035 const uint8_t *
b = p->buf;
1037 while (
b[2] ==
'\r')
1039 if (
b[2] ==
'\n' && (
b[3] ==
'#' || (
b[3] >=
'0' &&
b[3] <=
'9')))
1069 return ret && !
av_match_ext(p->filename,
"pgmyuv") ? ret : 0;
1075 return ret &&
av_match_ext(p->filename,
"pgmyuv") ? ret : 0;
1080 const uint8_t *
b = p->buf;
1081 if (!memcmp(
b,
"PG ML ", 6))
1098 if (!memcmp(p->buf,
"#?RADIANCE\n", 11) || !memcmp(p->buf,
"#?RGBE\n", 7))
1105 if (!memcmp(p->buf,
"/* XBM X10 format */", 20))
1108 if (!memcmp(p->buf,
"#define", 7))
1115 const uint8_t *
b = p->buf;
1117 if (
AV_RB64(
b) == 0x2f2a2058504d202a && *(
b+8) ==
'/')
1124 const uint8_t *
b = p->buf;
1125 unsigned width, bpp, bpad, lsize;
1167 if (!memcmp(p->buf,
"PCD_OPA", 7))
1170 if (p->buf_size < 0x807 || memcmp(p->buf + 0x800,
"PCD_IPI", 7))
1178 if (memcmp(p->buf,
"qoif", 4))
1184 if (p->buf[12] != 3 && p->buf[12] != 4)
1195 const uint8_t *
b = p->buf;
1215 const uint8_t *
b = p->buf;
1223#define IMAGEAUTO_DEMUXER_0(imgname, codecid)
1224#define IMAGEAUTO_DEMUXER_1(imgname, codecid)\
1225const FFInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\
1226 .p.name = AV_STRINGIFY(imgname) "_pipe",\
1227 .p.long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\
1228 .p.priv_class = &imagepipe_class,\
1229 .p.flags = AVFMT_GENERIC_INDEX,\
1230 .priv_data_size = sizeof(VideoDemuxData),\
1231 .read_probe = imgname ## _probe,\
1232 .read_header = ff_img_read_header,\
1233 .read_packet = ff_img_read_packet,\
1234 .raw_codec_id = codecid,\
1237#define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \
1238 IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid)
1239#define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \
1240 IMAGEAUTO_DEMUXER_2(imgname, codecid, config)
1241#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \
1242 IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid, \
1243 CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER)
1244#define IMAGEAUTO_DEMUXER(imgname, codecid) \
1245 IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_FLAG_READ
read-only
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
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 read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
#define EOI
End Of Image marker.
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
static enum AVPixelFormat pix_fmt
static struct @346255127015250356166251341105367306144006377143 state
static int read_header(FFV1Context *f, RangeCoder *c)
static const uint8_t frame_size[4]
static attribute_nonstring const uint8_t gif89a_sig[6]
static attribute_nonstring const uint8_t gif87a_sig[6]
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * av_packet_pack_dictionary(const AVDictionary *dict, size_t *size)
Pack a dictionary for use in 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.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
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.
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.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
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.
const char * av_basename(const char *path)
Thread safe basename.
#define LIBAVUTIL_VERSION_INT
enum AVCodecID ff_guess_image2_codec(const char *filename)
const AVOption ff_img_options[]
int ff_img_read_header(AVFormatContext *s1)
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
#define IMAGEAUTO_DEMUXER(imgname, codecid)
static int jpegxs_probe(const AVProbeData *p)
static int pbm_probe(const AVProbeData *p)
static int jpegls_probe(const AVProbeData *p)
static int pfm_probe(const AVProbeData *p)
static int hdr_probe(const AVProbeData *p)
static int photocd_probe(const AVProbeData *p)
static int phm_probe(const AVProbeData *p)
static int xwd_probe(const AVProbeData *p)
static int jpegxl_probe(const AVProbeData *p)
static int xbm_probe(const AVProbeData *p)
static int sgi_probe(const AVProbeData *p)
static int img_read_close(struct AVFormatContext *s1)
static int cri_probe(const AVProbeData *p)
static int exr_probe(const AVProbeData *p)
static int tiff_probe(const AVProbeData *p)
static int ppm_probe(const AVProbeData *p)
static int pnm_probe(const AVProbeData *p)
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.
static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static int xpm_probe(const AVProbeData *p)
static int j2k_probe(const AVProbeData *p)
static int pgx_probe(const AVProbeData *p)
static int psd_probe(const AVProbeData *p)
static int sunrast_probe(const AVProbeData *p)
static int dpx_probe(const AVProbeData *p)
static int rw2_probe(const AVProbeData *p)
static int vbn_probe(const AVProbeData *p)
static int pgm_probe(const AVProbeData *p)
static const int sizes[][2]
static int pcx_probe(const AVProbeData *p)
static int qdraw_probe(const AVProbeData *p)
#define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name)
static int infer_size(int *width_ptr, int *height_ptr, int size)
static const AVOption img2pipe_options[]
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)
static int pgmyuv_probe(const AVProbeData *p)
static int dds_probe(const AVProbeData *p)
static int svg_probe(const AVProbeData *p)
static int qoi_probe(const AVProbeData *p)
int ff_img_read_header(AVFormatContext *s1)
static int pnm_magic_check(const AVProbeData *p, int magic)
static int gif_probe(const AVProbeData *p)
static int webp_probe(const AVProbeData *p)
static int pam_probe(const AVProbeData *p)
static int gem_probe(const AVProbeData *p)
int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
static const AVClass imagepipe_class
static int pgmx_probe(const AVProbeData *p)
static int pictor_probe(const AVProbeData *p)
static int img_read_probe(const AVProbeData *p)
static int jpeg_probe(const AVProbeData *p)
static int png_probe(const AVProbeData *p)
#define FF_JPEGXL_CONTAINER_SIGNATURE_LE
#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE
int ff_jpegxl_parse_codestream_header(const uint8_t *buf, int buflen, FFJXLMetadata *meta, int validate)
Macro definitions for various function/variable attributes.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define MKTAG(a, b, c, d)
#define MKBETAG(a, b, c, d)
Memory handling functions.
MJPEG encoder and decoder.
miscellaneous OS support macros and functions.
static int inc(int num, int period)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
AVPixelFormat
Pixel format.
static const uint8_t header[24]
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
int height
The height of the video frame in pixels.
int width
The width of the video frame in pixels.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
enum AVCodecID audio_codec_id
Forced audio codec_id.
AVIOContext * pb
I/O context.
int flags
Flags modifying the (de)muxer behaviour.
int ctx_flags
Flags signalling stream properties.
char * url
input or output URL.
const struct AVInputFormat * iformat
The input container format.
enum AVCodecID video_codec_id
Forced video codec_id.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
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.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
AVRational avg_frame_rate
Average framerate.
AVRational r_frame_rate
Real base framerate of the stream.
struct AVCodecParserContext * parser
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVStreamParseType need_parsing
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.