24#include "config_components.h"
59 timestamp < sti->pts_wrap_reference)
77#if CONFIG_H264_DECODER
106 static const struct {
137 "Probe with size=%d, packets=%d detected %s with score=%d\n",
140 for (
int i = 0; fmt_id_type[
i].name;
i++) {
141 if (!strcmp(fmt->
name, fmt_id_type[
i].name)) {
169 s, 0,
s->format_probesize);
172 "will be ignored with AVFMT_NOFILE format.\n");
186 s, 0,
s->format_probesize);
194 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
202 av_log(
s,
AV_LOG_DEBUG,
"Demuxer context update while decoder is open, closing and trying to re-open\n");
246 av_log(
NULL,
AV_LOG_ERROR,
"Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");
261 if (!(
s->url =
av_strdup(filename ? filename :
""))) {
268 s->probe_score = ret;
270 if (!
s->protocol_whitelist &&
s->pb &&
s->pb->protocol_whitelist) {
271 s->protocol_whitelist =
av_strdup(
s->pb->protocol_whitelist);
272 if (!
s->protocol_whitelist) {
278 if (!
s->protocol_blacklist &&
s->pb &&
s->pb->protocol_blacklist) {
279 s->protocol_blacklist =
av_strdup(
s->pb->protocol_blacklist);
280 if (!
s->protocol_blacklist) {
286 if (
s->format_whitelist &&
av_match_list(
s->iformat->name,
s->format_whitelist,
',') <= 0) {
310 if (
s->iformat->priv_class) {
311 *(
const AVClass **)
s->priv_data =
s->iformat->priv_class;
337 if (id3v2_extra_meta) {
388 if ((
s->iformat && strcmp(
s->iformat->name,
"image2") &&
s->iformat->flags &
AVFMT_NOFILE) ||
406 if (
s->video_codec_id)
410 if (
s->audio_codec_id)
414 if (
s->subtitle_codec_id)
418 if (
s->data_codec_id)
439 "Failed to reallocate probe buffer for stream %d\n",
452 "nothing to probe for stream %d\n", st->
index);
481 int pts_wrap_behavior;
500 if (!first_program) {
504 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
527 program = first_program;
565 if (
s->use_wallclock_as_timestamps)
585 "Invalid stream index.\n");
589 "Packet corrupt (stream = %d, dts = %s)%s.\n",
598 st =
s->streams[
pkt->stream_index];
626 return err < 0 ? err : 0;
634#if FF_API_INIT_PACKET
652 if (
ffstream(st)->request_probe <= 0) {
668 if (!pktl || err ==
AVERROR(EAGAIN))
670 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
712 !codec_framerate.
num &&
719 }
else if (codec_framerate.
den * 1000LL > codec_framerate.
num) {
724 codec_framerate.
num * (
int64_t)ticks_per_frame,
766#if CONFIG_H264_DECODER
802 int64_t best_score = INT64_MAX;
803 for (
int i = 0;
i < delay;
i++) {
806 if (score < best_score) {
813 for (
int i = 0;
i < delay;
i++) {
815#define ABSDIFF(a,b) (((a) < (b)) ? (b) - (uint64_t)(a) : ((a) - (uint64_t)(b)))
847 AVStream *
const st =
s->streams[stream_index];
855 for (; pkt_buffer; pkt_buffer =
get_next_pkt(
s, st, pkt_buffer)) {
860 pts_buffer[0] = pkt_buffer->
pkt.
pts;
874 AVStream *
const st =
s->streams[stream_index];
896 if (pktl_it->pkt.stream_index != stream_index)
899 pktl_it->pkt.pts +=
shift;
902 pktl_it->pkt.dts +=
shift;
947 av_log(
s,
AV_LOG_DEBUG,
"first_dts %s not matching first dts %s (pts %s, duration %"PRId64
") in the queue\n",
990 int num, den, presentation_delayed, delay;
1006 "DTS %"PRIi64
" < %"PRIi64
" out of order\n",
1032 presentation_delayed = 0;
1038 presentation_delayed = 1;
1053 if (delay == 1 &&
pkt->dts ==
pkt->pts &&
1056 if ( strcmp(
s->iformat->name,
"mov,mp4,m4a,3gp,3g2,mj2")
1057 && strcmp(
s->iformat->name,
"flv"))
1062 if (
pkt->duration <= 0) {
1091 presentation_delayed = 1;
1095 "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64
" delay:%d onein_oneout:%d\n",
1097 pkt->stream_index, pc,
pkt->duration, delay, onein_oneout);
1101 if ((delay == 0 || (delay == 1 && pc)) &&
1103 if (presentation_delayed) {
1121 ((uint64_t)sti->
cur_dts - (uint64_t)next_dts + 1) <= 2 &&
1122 next_dts != next_pts &&
1124 pkt->pts = next_dts;
1126 if ((uint64_t)
pkt->duration <= INT32_MAX)
1133 pkt->duration > 0 ) {
1179 int stream_index,
int flush)
1182 AVStream *st =
s->streams[stream_index];
1186 const uint8_t *
data =
pkt->data;
1190 int ret = 0, got_output =
flush, pkt_side_data_consumed = 0;
1205 if (
pkt->side_data_elems)
1215 while (
size > 0 || (
flush && got_output)) {
1231 got_output = !!out_pkt->
size;
1236 if (!pkt_side_data_consumed) {
1237 pkt_side_data_consumed = 1;
1240 }
else for (
int i = 0;
i <
pkt->side_data_elems;
i++) {
1247 memcpy(dst_data, src_sd->
data, src_sd->
size);
1254 if (
pkt->buf && out_pkt->
data ==
pkt->data) {
1260 if (!out_pkt->
buf) {
1323 if (pkt_side_data_consumed) {
1325 pkt->side_data_elems = 0;
1374 sti->
avctx = avctx_new;
1392 int ret, got_packet = 0;
1405 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1416 st =
s->streams[
pkt->stream_index];
1429 av_log(
s,
AV_LOG_DEBUG,
"Demuxer context update while decoder is open, closing and trying to re-open\n");
1468 "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
1476 "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64
", flags=%d\n",
1486 "%s, packets or times may be invalid.\n",
1535 int discard_padding = 0;
1552 AV_WL32(p + 4, discard_padding);
1554 (
unsigned)sti->
skip_samples, (
unsigned)discard_padding);
1573 "read_frame_internal stream=%d, pts=%s, dts=%s, "
1574 "size=%d, duration=%"PRId64
", flags=%d\n",
1612 int wrap_bits =
s->streams[next_pkt->
stream_index]->pts_wrap_bits;
1626 last_dts = pktl->
pkt.
dts;
1653 if (pktl && ret !=
AVERROR(EAGAIN)) {
1669 st =
s->streams[
pkt->stream_index];
1707 int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
1711 start_time_text = INT64_MAX;
1712 end_time = INT64_MIN;
1713 end_time_text = INT64_MIN;
1715 duration_text = INT64_MIN;
1726 start_time_text =
FFMIN(start_time_text, start_time1);
1732 if (end_time1 !=
AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
1733 end_time1 += start_time1;
1735 end_time_text =
FFMAX(end_time_text, end_time1);
1737 end_time =
FFMAX(end_time, end_time1);
1740 if (p->start_time ==
AV_NOPTS_VALUE || p->start_time > start_time1)
1741 p->start_time = start_time1;
1742 if (p->end_time < end_time1)
1743 p->end_time = end_time1;
1750 duration_text =
FFMAX(duration_text, duration1);
1760 if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time <
AV_TIME_BASE))
1761 end_time = end_time_text;
1762 else if (end_time < end_time_text)
1772 if (end_time != INT64_MIN) {
1778 p->end_time > p->start_time &&
1779 p->end_time - (uint64_t)p->start_time <= INT64_MAX)
1819 int show_warning = 0;
1866 "Estimating duration from bitrate, this may be inaccurate\n");
1869#define DURATION_DEFAULT_MAX_READ_SIZE 250000LL
1870#define DURATION_DEFAULT_MAX_RETRY 6
1871#define DURATION_MAX_RETRY 1
1878 int num, den, read_size, ret;
1881 int found_duration = 0;
1897 "start time for stream %d is not set in estimate_timings_from_pts\n",
i);
1906 av_log(ic,
AV_LOG_INFO,
"Skipping duration calculation in estimate_timings_from_pts\n");
1907 goto skip_duration_calc;
1915 is_end = found_duration;
1925 if (read_size >= duration_max_read_size << (
FFMAX(retry - 1, 0)))
1930 }
while (ret ==
AVERROR(EAGAIN));
1933 read_size +=
pkt->size;
1939 if (
pkt->duration == 0) {
1979 ++retry <= duration_max_retry);
2036 file_size =
FFMAX(0, file_size);
2069 "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64
" kb/s\n",
2094#define FAIL(errmsg) do { \
2096 *errmsg_ptr = errmsg; \
2102 FAIL(
"unknown codec");
2106 FAIL(
"unspecified frame size");
2109 FAIL(
"unspecified sample format");
2111 FAIL(
"unspecified sample rate");
2113 FAIL(
"unspecified number of channels");
2115 FAIL(
"no decodable DTS frames");
2119 FAIL(
"unspecified size");
2121 FAIL(
"unspecified pixel format");
2124 FAIL(
"no frame in rv30/40 and no sar");
2128 FAIL(
"unspecified size");
2144 int got_picture = 1, ret = 0;
2147 int do_skip_frame = 0;
2149 int pkt_to_send =
pkt->size > 0;
2174 if (
s->codec_whitelist)
2198 while ((pkt_to_send || (!
pkt->data && got_picture)) &&
2232 if (do_skip_frame) {
2255 if (!
s->nb_chapters)
2258 if (
s->duration > 0 &&
s->start_time < INT64_MAX -
s->duration)
2259 max_time =
s->duration +
2262 timetable =
av_memdup(
s->chapters,
s->nb_chapters *
sizeof(*timetable));
2267 for (
unsigned i = 0;
i <
s->nb_chapters;
i++)
2274 if (
i + 1 <
s->nb_chapters) {
2275 const AVChapter *
const ch1 = timetable[
i + 1];
2278 if (next_start > ch->
start && next_start < end)
2281 ch->
end = (end == INT64_MAX || end < ch->
start) ? ch->
start : end;
2290 return (
i + 1) * 1001;
2294 return (
i + 31) * 1001 * 12;
2298 return ((
const int[]) { 80, 120, 240})[
i] * 1001 * 12;
2302 return ((
const int[]) { 24, 30, 60, 12, 15, 48 })[
i] * 1000 * 12;
2323 if (time_base.
den >= 101LL * time_base.
num ||
2324 time_base.
den < 5LL * time_base.
num ||
2343 && ts - (uint64_t)last < INT64_MAX) {
2358 for (
int j = 0; j < 2; j++) {
2360 double error = sdts - ticks + j*0.5;
2379 if (error0 > 0.04 && error1 > 0.04) {
2414 double best_error = 0.01;
2427 for (
int k = 0; k < 2; k++) {
2441 if (num && (!ref_rate.
num || (
double)num/(12*1001) < 1.01 *
av_q2d(ref_rate)))
2556 side_data->
size = 0;
2609 int count = 0, ret = 0, err;
2617 int64_t max_stream_analyze_duration;
2618 int64_t max_subtitle_analyze_duration;
2620 int eof_reached = 0;
2622 flush_codecs = probesize > 0;
2626 max_stream_analyze_duration = max_analyze_duration;
2627 max_subtitle_analyze_duration = max_analyze_duration;
2628 if (!max_analyze_duration) {
2629 max_stream_analyze_duration =
2640 av_log(ic,
AV_LOG_DEBUG,
"Before avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d nb_streams:%d\n",
2663 "%s, packets or times may be invalid.\n",
2670 goto find_stream_info_err;
2691 if (codec && !avctx->
codec)
2694 "Failed to open codec in %s\n", __func__);
2706 int analyzed_all_streams;
2719 goto unref_then_goto_end;
2725 int fps_analyze_framecount = 20;
2734 fps_analyze_framecount *= 2;
2736 fps_analyze_framecount = 0;
2740 fps_analyze_framecount = 0;
2747 if (count < fps_analyze_framecount)
2765 analyzed_all_streams = 0;
2767 analyzed_all_streams = 1;
2779 if (read_size >= probesize) {
2782 "Probe buffer size limit of %"PRId64
" bytes reached\n", probesize);
2791 "Stream #%d: not enough frames to estimate rate; "
2792 "consider increasing probesize\n",
i);
2813 goto unref_then_goto_end;
2823 read_size +=
pkt->size;
2829 goto unref_then_goto_end;
2838 "Non-increasing DTS in stream %d: packet %d with DTS "
2839 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2855 "DTS discontinuity in stream %d: packet %d with DTS "
2856 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2889 if (analyzed_all_streams)
limit = max_analyze_duration;
2891 else limit = max_stream_analyze_duration;
2894 av_log(ic,
AV_LOG_VERBOSE,
"max_analyze_duration %"PRId64
" reached at %"PRId64
" microseconds st:%d\n",
2896 t,
pkt->stream_index);
2914#if FF_API_R_FRAME_RATE
2923 goto unref_then_goto_end;
2946 for (
unsigned stream_index = 0; stream_index < ic->
nb_streams; stream_index++) {
2951 if (codec && !avctx->
codec) {
2957 "Failed to open codec in %s\n", __func__);
2987 "decoding for stream %d failed\n", st->
index);
3012 double best_error = 0.01;
3030 if (
error < best_error) {
3032 best_fps = std_fps.
num;
3036 codec_frame_rate.
num > 0 && codec_frame_rate.
den > 0) {
3039 if (
error < best_error) {
3041 best_fps = std_fps.
num;
3047 best_fps, 12 * 1001, INT_MAX);
3112 goto find_stream_info_err;
3118 "Could not find codec parameters for stream %d (%s): %s\n"
3119 "Consider increasing the value for the 'analyzeduration' (%"PRId64
") and 'probesize' (%"PRId64
") options\n",
3129 goto find_stream_info_err;
3140 goto find_stream_info_err;
3156 (uint8_t *)props, cpb_size, 0))
3184find_stream_info_err:
3197 if (err < 0 && ret >= 0)
3205 av_log(ic,
AV_LOG_DEBUG,
"After avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d frames:%d\n",
3212 goto find_stream_info_err;
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define PARSER_FLAG_USE_CODEC_TS
#define PARSER_FLAG_COMPLETE_FRAMES
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
#define AVIO_FLAG_READ
read-only
int64_t avio_size(AVIOContext *s)
Get the filesize.
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.
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
AVCodecParameters * avcodec_parameters_alloc(void)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
void avcodec_parameters_free(AVCodecParameters **ppar)
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static __device__ float fabs(float a)
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
@ AV_AUDIO_SERVICE_TYPE_EFFECTS
@ AV_AUDIO_SERVICE_TYPE_KARAOKE
@ AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
@ AV_AUDIO_SERVICE_TYPE_COMMENTARY
@ AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
static int determinable_frame_size(const AVCodecContext *avctx)
static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt)
static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt)
static int has_decode_delay_been_guessed(AVStream *st)
static void fill_all_stream_timings(AVFormatContext *ic)
static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr)
static void force_codec_ids(AVFormatContext *s, AVStream *st)
#define DURATION_DEFAULT_MAX_READ_SIZE
static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts)
static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *pkt, AVDictionary **options)
static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts)
static const char * duration_estimate_name(enum AVDurationEstimationMethod method)
static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration)
void ff_rfps_calculate(AVFormatContext *ic)
static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
static void update_dts_from_pts(AVFormatContext *s, int stream_index, PacketListEntry *pkt_buffer)
Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts of the packets in a wind...
static int compute_chapters_end(AVFormatContext *s)
static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
#define DURATION_DEFAULT_MAX_RETRY
int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)
add frame for rfps calculation.
static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd)
static const char *const duration_name[]
static int64_t ts_to_samples(AVStream *st, int64_t ts)
static int chapter_start_cmp(const void *p1, const void *p2)
static void estimate_timings_from_bit_rate(AVFormatContext *ic)
static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)
static int extract_extradata_init(AVStream *st)
static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt)
static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
static int parameters_from_context(AVFormatContext *ic, AVCodecParameters *par, const AVCodecContext *avctx)
static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough)
Handle a new packet and either return it directly if possible and allow_passthrough is true or queue ...
static int get_std_framerate(int i)
static int has_duration(AVFormatContext *ic)
Return TRUE if the stream has accurate duration in any stream.
static int update_stream_avctx(AVFormatContext *s)
static int tb_unreliable(AVFormatContext *ic, AVStream *st)
int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp)
Wrap a given time stamp, if there is an indication for an overflow.
#define DURATION_MAX_RETRY
static PacketListEntry * get_next_pkt(AVFormatContext *s, AVStream *st, PacketListEntry *pktl)
static void update_stream_timings(AVFormatContext *ic)
Estimate the stream timings from the one of each components.
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush)
Parse a packet, add all split parts to parse_queue.
static int extract_extradata_check(AVStream *st)
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt)
int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
static const AVCodec * find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
static int codec_close(FFStream *sti)
static av_always_inline int is_id3v2_format(const AVInputFormat *fmt)
#define FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
#define FF_INFMT_FLAG_ID3V2_AUTO
Automatically parse ID3v2 metadata.
#define MAX_STD_TIMEBASES
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
void ff_reduce_index(AVFormatContext *s, int stream_index)
Ensure the index uses less memory than the maximum specified in AVFormatContext.max_index_size by dis...
void(* flush)(AVBSFContext *ctx)
static int64_t filesize(AVIOContext *pb)
static int64_t start_time
static const uint8_t frame_size[4]
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int av_codec_is_decoder(const AVCodec *codec)
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_TELETEXT
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
@ AVDISCARD_ALL
discard all
unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt)
Return a value representing the fourCC code associated to the pixel format pix_fmt,...
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
int avcodec_is_open(AVCodecContext *s)
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVCodecParserContext * av_parser_init(enum AVCodecID codec_id)
void av_parser_close(AVCodecParserContext *s)
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int av_probe_input_buffer2(AVIOContext *pb, const AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
Probe a bytestream to determine the input format.
int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
const AVInputFormat * av_probe_input_format2(const AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **ps)
Close an opened input AVFormatContext.
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 avformat_queue_attached_pictures(AVFormatContext *s)
int av_find_default_stream_index(AVFormatContext *s)
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
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_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_EOF
End of file.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)
Add a value to a timestamp.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod)
Compare the remainders of two integer operands divided by a common divisor.
@ AV_ROUND_DOWN
Round toward -infinity.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_NONE
Undefined.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
#define MAX_REORDER_DELAY
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
void ff_id3v2_read_dict(AVFormatContext *s, AVIOContext *pb, AVDictionary **metadata, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag into specified dictionary and retrieve supported extra metadata.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
static int shift(int a, int b)
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
common internal api header.
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
#define FFSWAP(type, a, b)
#define FFDIFFSIGN(x, y)
Comparator.
Memory handling functions.
@ AVCHROMA_LOC_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list, unsigned fourcc)
AVCodecParameters * par_in
Parameters of the input stream.
AVRational time_base_in
The timebase used for the timestamps of the input packets.
This structure describes the bitrate properties of an encoded bitstream.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
int nb_channels
Number of channels in this layout.
int64_t id
unique ID to identify the chapter
int64_t end
chapter start/end time in time_base units
AVRational time_base
time base in which the start/end timestamps are specified
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
enum AVMediaType codec_type
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int has_b_frames
Size of the frame reordering buffer in the decoder.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
int sample_rate
samples per second
int64_t rc_max_rate
maximum bitrate
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int64_t rc_min_rate
minimum bitrate
int frame_size
Number of samples per channel in an audio frame.
enum AVDiscard skip_frame
Skip decoding for selected frames.
This struct describes the properties of a single codec described by an AVCodecID.
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
This struct describes the properties of an encoded stream.
enum AVColorSpace color_space
int frame_size
Audio frame size, if known.
int height
The height of the video frame in pixels.
int nb_coded_side_data
Amount of entries in coded_side_data.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
AVRational framerate
Number of frames per second, for streams with constant frame durations.
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
enum AVColorPrimaries color_primaries
int sample_rate
The number of audio samples per second.
enum AVColorTransferCharacteristic color_trc
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
enum AVChromaLocation chroma_location
enum AVColorRange color_range
Additional colorspace characteristics.
int duration
Duration of the current frame.
int64_t pos
Byte position of currently parsed frame in stream.
int repeat_pict
This field is used for proper frame duration computation in lavf.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
int64_t offset
byte offset from starting packet start
int capabilities
Codec capabilities.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
AVIOContext * pb
I/O context.
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
int flags
Flags modifying the (de)muxer behaviour.
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
int ctx_flags
Flags signalling stream properties.
int fps_probe_size
The number of frames used for determining the framerate in avformat_find_stream_info().
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
const struct AVInputFormat * iformat
The input container format.
enum AVDurationEstimationMethod duration_estimation_method
The duration field can be estimated through various ways, and this field can be used to know how the ...
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
int64_t duration_probesize
Maximum number of bytes read from input in order to determine stream durations when using estimate_ti...
char * codec_whitelist
',' separated list of allowed decoders.
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
AVStream ** streams
A list of all streams in the file.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
int max_ts_probe
Maximum number of packets to read while waiting for the first timestamp.
int skip_estimate_duration_from_pts
Skip duration calculation in estimate_timings_from_pts.
This structure describes decoded (raw) audio or video data.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
enum AVPacketSideDataType type
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
A combination of AV_PKT_FLAG values.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int64_t pos
byte position in stream, -1 if unknown
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
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.
New fields can be added to the end with minor version bumps.
unsigned int nb_stream_indexes
unsigned int * stream_index
int64_t pts_wrap_reference
reference dts for wrap detection
int pts_wrap_behavior
behavior on wrap detection
Rational number (pair of numerator and denominator).
AVStreamGroupLayeredVideo is meant to define the relation between a base layer video stream and a sep...
int height
Height of the final image for presentation.
unsigned int el_index
Index of the enhancement layer stream in AVStreamGroup.
int width
Width of the final stream for presentation.
union AVStreamGroup::@166361102046003066253145020066347265153020354020 params
Group type-specific parameters.
enum AVStreamGroupParamsType type
Group type.
AVStream ** streams
A list of streams in the group.
struct AVStreamGroupLayeredVideo * layered_video
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int64_t duration
Decoding: duration of the stream, in stream time base.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
int pts_wrap_bits
Number of bits in timestamps.
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 time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
AVRational r_frame_rate
Real base framerate of the stream.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
int64_t data_offset
offset of the first packet
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
int64_t codec_info_duration_fields
int found_decoder
0 -> decoder has not been searched for yet.
int64_t fps_first_dts
Those are used for average framerate estimation.
double(* duration_error)[2][MAX_STD_TIMEBASES]
int64_t rfps_duration_sum
int64_t codec_info_duration
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
int probe_packets
Number of packets to buffer for codec probing.
int skip_to_keyframe
Indicates that everything up to the next keyframe should be discarded.
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
int64_t start_skip_samples
If not 0, the number of samples that should be skipped from the start of the stream (the samples are ...
int avctx_inited
1 if avctx has been initialized with the values from the codec parameters
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
struct AVBSFContext * bsf
int64_t first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
int64_t pts_buffer[MAX_REORDER_DELAY+1]
uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]
int64_t last_dts_for_order_check
Internal data to analyze DTS and detect faulty mpeg streams.
int skip_samples
Number of samples to skip at the start of the frame decoded from the next packet.
const struct AVCodecDescriptor * codec_desc
struct AVCodecParserContext * parser
AVStream pub
The public context.
int update_initial_durations_done
Internal data to prevent doing update_initial_durations() twice.
int nb_decoded_frames
Number of internally decoded frames, used internally in libavformat, do not access its lifetime diffe...
int64_t first_dts
Timestamp corresponding to the last dts sync point.
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
AVRational display_aspect_ratio
display aspect ratio (0 if unknown)
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
struct FFStream::@143263315346311247247365102337045232073206113210 extract_extradata
enum AVStreamParseType need_parsing
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
int64_t pts_reorder_error[MAX_REORDER_DELAY+1]
Internal data to generate dts from pts.
PacketList parse_queue
Packets split by the parser get queued here.
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
int metafree
Contexts and child contexts do not contain a metadata option.
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
struct PacketListEntry * next
static void error(const char *err)
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
static AVDictionary * opts
int64_t av_gettime(void)
Get the current time in microseconds.
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
unbuffered private I/O API
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static double limit(double x)
static double a0(void *priv, double x, double y)
static double a1(void *priv, double x, double y)