Go to the documentation of this file.
24 #include "config_components.h"
57 timestamp < sti->pts_wrap_reference)
75 #if CONFIG_H264_DECODER
104 static const struct {
134 "Probe with size=%d, packets=%d detected %s with score=%d\n",
137 for (
int i = 0; fmt_id_type[
i].name;
i++) {
138 if (!strcmp(fmt->
name, fmt_id_type[
i].name)) {
166 s, 0,
s->format_probesize);
169 "will be ignored with AVFMT_NOFILE format.\n");
183 s, 0,
s->format_probesize);
189 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
227 av_log(
NULL,
AV_LOG_ERROR,
"Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");
242 if (!(
s->url =
av_strdup(filename ? filename :
""))) {
249 s->probe_score =
ret;
251 if (!
s->protocol_whitelist &&
s->pb &&
s->pb->protocol_whitelist) {
252 s->protocol_whitelist =
av_strdup(
s->pb->protocol_whitelist);
253 if (!
s->protocol_whitelist) {
259 if (!
s->protocol_blacklist &&
s->pb &&
s->pb->protocol_blacklist) {
260 s->protocol_blacklist =
av_strdup(
s->pb->protocol_blacklist);
261 if (!
s->protocol_blacklist) {
267 if (
s->format_whitelist &&
av_match_list(
s->iformat->name,
s->format_whitelist,
',') <= 0) {
291 if (
s->iformat->priv_class) {
292 *(
const AVClass **)
s->priv_data =
s->iformat->priv_class;
318 if (id3v2_extra_meta) {
319 if (!strcmp(
s->iformat->name,
"mp3") || !strcmp(
s->iformat->name,
"aac") ||
320 !strcmp(
s->iformat->name,
"tta") || !strcmp(
s->iformat->name,
"wav")) {
373 if ((
s->iformat && strcmp(
s->iformat->name,
"image2") &&
s->iformat->flags &
AVFMT_NOFILE) ||
392 if (
s->video_codec_id)
396 if (
s->audio_codec_id)
400 if (
s->subtitle_codec_id)
404 if (
s->data_codec_id)
425 "Failed to reallocate probe buffer for stream %d\n",
438 "nothing to probe for stream %d\n", st->
index);
467 int pts_wrap_behavior;
486 if (!first_program) {
490 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
505 pts_wrap_reference =
program->pts_wrap_reference;
506 pts_wrap_behavior =
program->pts_wrap_behavior;
515 if (
program->pts_wrap_reference != pts_wrap_reference) {
516 for (
unsigned i = 0;
i <
program->nb_stream_indexes;
i++) {
522 program->pts_wrap_reference = pts_wrap_reference;
523 program->pts_wrap_behavior = pts_wrap_behavior;
551 if (
s->use_wallclock_as_timestamps)
571 "Invalid stream index.\n");
575 "Packet corrupt (stream = %d, dts = %s)%s.\n",
612 return err < 0 ? err : 0;
620 #if FF_API_INIT_PACKET
638 if (
ffstream(st)->request_probe <= 0) {
654 if (!pktl || err ==
AVERROR(EAGAIN))
656 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
698 !codec_framerate.
num &&
705 }
else if (codec_framerate.
den * 1000LL > codec_framerate.
num) {
710 codec_framerate.
num * (
int64_t)ticks_per_frame,
751 #if CONFIG_H264_DECODER
786 int64_t best_score = INT64_MAX;
787 for (
int i = 0;
i < delay;
i++) {
790 if (score < best_score) {
797 for (
int i = 0;
i < delay;
i++) {
826 AVStream *
const st =
s->streams[stream_index];
834 for (; pkt_buffer; pkt_buffer =
get_next_pkt(
s, st, pkt_buffer)) {
839 pts_buffer[0] = pkt_buffer->
pkt.
pts;
840 for (
int i = 0; i < delay && pts_buffer[i] > pts_buffer[
i + 1];
i++)
852 AVStream *
const st =
s->streams[stream_index];
874 if (pktl_it->pkt.stream_index != stream_index)
877 pktl_it->pkt.pts +=
shift;
880 pktl_it->pkt.dts +=
shift;
924 av_log(
s,
AV_LOG_DEBUG,
"first_dts %s not matching first dts %s (pts %s, duration %"PRId64
") in the queue\n",
966 int num, den, presentation_delayed, delay;
982 "DTS %"PRIi64
" < %"PRIi64
" out of order\n",
1008 presentation_delayed = 0;
1014 presentation_delayed = 1;
1032 if ( strcmp(
s->iformat->name,
"mov,mp4,m4a,3gp,3g2,mj2")
1033 && strcmp(
s->iformat->name,
"flv"))
1067 presentation_delayed = 1;
1071 "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64
" delay:%d onein_oneout:%d\n",
1077 if ((delay == 0 || (delay == 1 && pc)) &&
1079 if (presentation_delayed) {
1097 ((uint64_t)sti->
cur_dts - (uint64_t)next_dts + 1) <= 2 &&
1098 next_dts != next_pts &&
1155 int stream_index,
int flush)
1159 AVStream *st =
s->streams[stream_index];
1170 while (
size > 0 || (
flush && got_output)) {
1186 got_output = !!out_pkt->
size;
1197 if (!out_pkt->
buf) {
1302 #if FF_API_TICKS_PER_FRAME
1309 sti->
avctx = avctx_new;
1324 int ret, got_packet = 0;
1337 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
1356 av_log(
s,
AV_LOG_DEBUG,
"Demuxer context update while decoder is open, closing and trying to re-open\n");
1384 "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
1392 "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64
", flags=%d\n",
1402 "%s, packets or times may be invalid.\n",
1451 int discard_padding = 0;
1458 sample < sti->last_discard_sample)
1468 AV_WL32(p + 4, discard_padding);
1470 (
unsigned)sti->
skip_samples, (
unsigned)discard_padding);
1475 #if FF_API_AVSTREAM_SIDE_DATA
1476 if (sti->inject_global_side_data) {
1490 memcpy(dst_data, src_sd->
data, src_sd->
size);
1492 sti->inject_global_side_data = 0;
1510 "read_frame_internal stream=%d, pts=%s, dts=%s, "
1511 "size=%d, duration=%"PRId64
", flags=%d\n",
1549 int wrap_bits =
s->streams[next_pkt->
stream_index]->pts_wrap_bits;
1563 last_dts = pktl->
pkt.
dts;
1644 int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
1648 start_time_text = INT64_MAX;
1649 end_time = INT64_MIN;
1650 end_time_text = INT64_MIN;
1652 duration_text = INT64_MIN;
1663 start_time_text =
FFMIN(start_time_text, start_time1);
1669 if (end_time1 !=
AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
1670 end_time1 += start_time1;
1672 end_time_text =
FFMAX(end_time_text, end_time1);
1674 end_time =
FFMAX(end_time, end_time1);
1677 if (p->start_time ==
AV_NOPTS_VALUE || p->start_time > start_time1)
1678 p->start_time = start_time1;
1679 if (p->end_time < end_time1)
1680 p->end_time = end_time1;
1687 duration_text =
FFMAX(duration_text, duration1);
1697 if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time <
AV_TIME_BASE))
1698 end_time = end_time_text;
1699 else if (end_time < end_time_text)
1709 if (end_time != INT64_MIN) {
1756 int show_warning = 0;
1803 "Estimating duration from bitrate, this may be inaccurate\n");
1806 #define DURATION_MAX_READ_SIZE 250000LL
1807 #define DURATION_MAX_RETRY 6
1814 int num, den, read_size,
ret;
1815 int found_duration = 0;
1831 "start time for stream %d is not set in estimate_timings_from_pts\n",
i);
1840 av_log(ic,
AV_LOG_INFO,
"Skipping duration calculation in estimate_timings_from_pts\n");
1841 goto skip_duration_calc;
1849 is_end = found_duration;
1970 file_size =
FFMAX(0, file_size);
2003 "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64
" kb/s\n",
2028 #define FAIL(errmsg) do { \
2030 *errmsg_ptr = errmsg; \
2036 FAIL(
"unknown codec");
2040 FAIL(
"unspecified frame size");
2043 FAIL(
"unspecified sample format");
2045 FAIL(
"unspecified sample rate");
2047 FAIL(
"unspecified number of channels");
2049 FAIL(
"no decodable DTS frames");
2053 FAIL(
"unspecified size");
2055 FAIL(
"unspecified pixel format");
2058 FAIL(
"no frame in rv30/40 and no sar");
2062 FAIL(
"unspecified size");
2078 int got_picture = 1,
ret = 0;
2081 int do_skip_frame = 0;
2083 int pkt_to_send =
pkt->
size > 0;
2108 if (
s->codec_whitelist)
2132 while ((pkt_to_send || (!
pkt->
data && got_picture)) &&
2166 if (do_skip_frame) {
2189 if (!
s->nb_chapters)
2192 if (
s->duration > 0 &&
s->start_time < INT64_MAX -
s->duration)
2193 max_time =
s->duration +
2196 timetable =
av_memdup(
s->chapters,
s->nb_chapters *
sizeof(*timetable));
2201 for (
unsigned i = 0;
i <
s->nb_chapters;
i++)
2208 if (
i + 1 <
s->nb_chapters) {
2209 const AVChapter *
const ch1 = timetable[
i + 1];
2212 if (next_start > ch->
start && next_start < end)
2215 ch->
end = (end == INT64_MAX || end < ch->
start) ? ch->
start : end;
2224 return (
i + 1) * 1001;
2228 return (
i + 31) * 1001 * 12;
2232 return ((
const int[]) { 80, 120, 240})[
i] * 1001 * 12;
2236 return ((
const int[]) { 24, 30, 60, 12, 15, 48 })[
i] * 1000 * 12;
2257 if (time_base.
den >= 101LL * time_base.
num ||
2258 time_base.
den < 5LL * time_base.
num ||
2277 && ts - (uint64_t)last < INT64_MAX) {
2281 if (!
info->duration_error)
2283 if (!
info->duration_error)
2289 if (
info->duration_error[0][1][
i] < 1e10) {
2292 for (
int j = 0; j < 2; j++) {
2294 double error = sdts - ticks + j*0.5;
2301 info->duration_count++;
2305 if (
info->duration_count % 10 == 0) {
2306 int n =
info->duration_count;
2308 if (
info->duration_error[0][1][
i] < 1e10) {
2309 double a0 =
info->duration_error[0][0][
i] / n;
2310 double error0 =
info->duration_error[0][1][
i] / n -
a0*
a0;
2311 double a1 =
info->duration_error[1][0][
i] / n;
2312 double error1 =
info->duration_error[1][1][
i] / n -
a1*
a1;
2313 if (error0 > 0.04 && error1 > 0.04) {
2314 info->duration_error[0][1][
i] = 2e10;
2315 info->duration_error[1][1][
i] = 2e10;
2326 info->last_dts = ts;
2348 double best_error = 0.01;
2361 for (
int k = 0; k < 2; k++) {
2366 if (error < best_error && best_error> 0.000000001) {
2375 if (num && (!ref_rate.
num || (
double)num/(12*1001) < 1.01 *
av_q2d(ref_rate)))
2489 side_data->
size = 0;
2502 int count = 0,
ret = 0, err;
2510 int64_t max_stream_analyze_duration;
2511 int64_t max_subtitle_analyze_duration;
2513 int eof_reached = 0;
2516 flush_codecs = probesize > 0;
2520 max_stream_analyze_duration = max_analyze_duration;
2521 max_subtitle_analyze_duration = max_analyze_duration;
2522 if (!max_analyze_duration) {
2523 max_stream_analyze_duration =
2534 av_log(ic,
AV_LOG_DEBUG,
"Before avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d nb_streams:%d\n",
2557 "%s, packets or times may be invalid.\n",
2564 goto find_stream_info_err;
2585 if (codec && !avctx->
codec)
2588 "Failed to open codec in %s\n", __func__);
2600 int analyzed_all_streams;
2612 int fps_analyze_framecount = 20;
2621 fps_analyze_framecount *= 2;
2623 fps_analyze_framecount = 0;
2627 fps_analyze_framecount = 0;
2634 if (count < fps_analyze_framecount)
2652 analyzed_all_streams = 0;
2653 if (!missing_streams || !*missing_streams)
2655 analyzed_all_streams = 1;
2667 if (read_size >= probesize) {
2670 "Probe buffer size limit of %"PRId64
" bytes reached\n", probesize);
2679 "Stream #%d: not enough frames to estimate rate; "
2680 "consider increasing probesize\n",
i);
2701 goto unref_then_goto_end;
2717 goto unref_then_goto_end;
2726 "Non-increasing DTS in stream %d: packet %d with DTS "
2727 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2743 "DTS discontinuity in stream %d: packet %d with DTS "
2744 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
2777 if (analyzed_all_streams)
limit = max_analyze_duration;
2779 else limit = max_stream_analyze_duration;
2782 av_log(ic,
AV_LOG_VERBOSE,
"max_analyze_duration %"PRId64
" reached at %"PRId64
" microseconds st:%d\n",
2802 #if FF_API_R_FRAME_RATE
2811 goto unref_then_goto_end;
2834 for (
unsigned stream_index = 0; stream_index < ic->
nb_streams; stream_index++) {
2839 if (codec && !avctx->
codec) {
2845 "Failed to open codec in %s\n", __func__);
2875 "decoding for stream %d failed\n", st->
index);
2900 double best_error = 0.01;
2918 if (
error < best_error) {
2920 best_fps = std_fps.
num;
2926 if (
error < best_error) {
2928 best_fps = std_fps.
num;
2934 best_fps, 12 * 1001, INT_MAX);
2999 goto find_stream_info_err;
3005 "Could not find codec parameters for stream %d (%s): %s\n"
3006 "Consider increasing the value for the 'analyzeduration' (%"PRId64
") and 'probesize' (%"PRId64
") options\n",
3016 goto find_stream_info_err;
3027 goto find_stream_info_err;
3043 (uint8_t *)props, cpb_size, 0))
3050 #if FF_API_AVSTREAM_SIDE_DATA
3053 av_assert0(!st->side_data && !st->nb_side_data);
3055 if (!st->side_data) {
3057 goto find_stream_info_err;
3065 goto find_stream_info_err;
3069 st->side_data[j].data =
data;
3077 find_stream_info_err:
3089 if (err < 0 && ret >= 0)
3095 av_log(ic,
AV_LOG_DEBUG,
"After avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d frames:%d\n",
3100 unref_then_goto_end:
3102 goto find_stream_info_err;
static void error(const char *err)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int frame_size
Number of samples per channel in an audio frame.
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)
add frame for rfps calculation.
#define FF_ENABLE_DEPRECATION_WARNINGS
AVCodecParameters * par_in
Parameters of the input stream.
#define AV_LOG_WARNING
Something somehow does not look correct.
int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
int skip_samples
Number of samples to skip at the start of the frame decoded from the next packet.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
int avpriv_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
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
int prefer_codec_framerate
enum AVMediaType codec_type
General type of the encoded data.
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.
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
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_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)
Add a value to a timestamp.
int64_t first_dts
Timestamp corresponding to the last dts sync point.
int sample_rate
samples per second
int64_t rc_min_rate
minimum bitrate
This struct describes the properties of an encoded stream.
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
struct AVBSFContext * bsf
@ 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 AVERROR_EOF
End of file.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
int duration
Duration of the current frame.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
struct FFStream::@318 extract_extradata
int64_t first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
This structure describes decoded (raw) audio or video data.
AVStream ** streams
A list of all streams in the file.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
int capabilities
Codec capabilities.
@ AV_CODEC_ID_DVB_TELETEXT
static int extract_extradata_check(AVStream *st)
AVRational avg_frame_rate
Average framerate.
static int has_duration(AVFormatContext *ic)
Return TRUE if the stream has accurate duration in any stream.
enum AVDurationEstimationMethod duration_estimation_method
The duration field can be estimated through various ways, and this field can be used to know how the ...
AVRational framerate
Video only.
#define AV_LOG_VERBOSE
Detailed information.
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 ...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int64_t ts_to_samples(AVStream *st, int64_t ts)
int buf_size
Size of buf except extra allocated bytes.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avcodec_is_open(AVCodecContext *s)
int nb_channels
Number of channels in this layout.
static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)
int64_t last_dts_for_order_check
Internal data to analyze DTS and detect faulty mpeg streams.
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int64_t avio_size(AVIOContext *s)
Get the filesize.
static void update_stream_timings(AVFormatContext *ic)
Estimate the stream timings from the one of each components.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define DURATION_MAX_READ_SIZE
static int codec_close(FFStream *sti)
const struct AVCodecDescriptor * codec_desc
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,...
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int avformat_queue_attached_pictures(AVFormatContext *s)
void avformat_close_input(AVFormatContext **ps)
Close an opened input AVFormatContext.
int64_t offset
byte offset from starting packet start
#define MAX_STD_TIMEBASES
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
static void force_codec_ids(AVFormatContext *s, AVStream *st)
const struct AVCodec * codec
AVChannelLayout ch_layout
Audio channel layout.
static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt)
enum AVDiscard skip_frame
Skip decoding for selected frames.
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.
int64_t fps_first_dts
Those are used for average framerate estimation.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
AVCodecParserContext * av_parser_init(int codec_id)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
int64_t duration
Decoding: duration of the stream, in stream time base.
int metafree
Contexts and child contexts do not contain a metadata option.
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int extract_extradata_init(AVStream *st)
#define FFDIFFSIGN(x, y)
Comparator.
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_CODEC_ID_DVB_SUBTITLE
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
int max_ts_probe
Maximum number of packets to read while waiting for the first timestamp.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
static int chapter_start_cmp(const void *p1, const void *p2)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
int ctx_flags
Flags signalling stream properties.
int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int has_b_frames
Size of the frame reordering buffer in the decoder.
PacketList parse_queue
Packets split by the parser get queued here.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int64_t end
chapter start/end time in time_base units
This struct describes the properties of a single codec described by an AVCodecID.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
int flags
Flags modifying the (de)muxer behaviour.
AVRational sample_aspect_ratio
Video only.
static const char *const duration_name[]
const struct AVInputFormat * iformat
The input container format.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int nb_decoded_frames
Number of internally decoded frames, used internally in libavformat, do not access its lifetime diffe...
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t data_offset
offset of the first packet
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
AVRational time_base_in
The timebase used for the timestamps of the input packets.
uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVRational display_aspect_ratio
display aspect ratio (0 if unknown)
@ AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
#define DURATION_MAX_RETRY
int64_t rc_max_rate
maximum bitrate
int nb_coded_side_data
Amount of entries in coded_side_data.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
int64_t pts_reorder_error[MAX_REORDER_DELAY+1]
Internal data to generate dts from pts.
static int determinable_frame_size(const AVCodecContext *avctx)
This structure describes the bitrate properties of an encoded bitstream.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
int found_decoder
0 -> decoder has not been searched for yet.
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const AVInputFormat * av_probe_input_format2(const AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
static int get_std_framerate(int i)
static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr)
#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...
int repeat_pict
This field is used for proper frame duration computation in lavf.
enum AVStreamParseType need_parsing
int rc_buffer_size
decoder bitstream buffer size
@ AVDISCARD_ALL
discard all
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int avctx_inited
1 if avctx has been initialized with the values from the codec parameters
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int64_t codec_info_duration
int fps_probe_size
The number of frames used for determining the framerate in avformat_find_stream_info().
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Rational number (pair of numerator and denominator).
int64_t bit_rate
the average bitrate
enum AVPacketSideDataType type
static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration)
@ AV_PICTURE_TYPE_I
Intra.
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
AVIOContext * pb
I/O context.
static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
This structure contains the data a format has to probe a file.
void(* flush)(AVBSFContext *ctx)
static PacketListEntry * get_next_pkt(AVFormatContext *s, AVStream *st, PacketListEntry *pktl)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int skip_estimate_duration_from_pts
Skip duration calcuation in estimate_timings_from_pts.
int64_t codec_info_duration_fields
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVChannelLayout ch_layout
Audio only.
struct PacketListEntry * next
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
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
int sample_rate
Audio only.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static const char * duration_estimate_name(enum AVDurationEstimationMethod method)
AVCodecID
Identify the syntax and semantics of the bitstream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
@ AV_ROUND_DOWN
Round toward -infinity.
int av_codec_is_decoder(const AVCodec *codec)
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.
const OptionDef options[]
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list, unsigned fourcc)
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
static int shift(int a, int b)
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
static int64_t start_time
enum AVSampleFormat sample_fmt
audio sample format
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt)
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
@ AV_PICTURE_TYPE_NONE
Undefined.
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
static int update_stream_avctx(AVFormatContext *s)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
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.
int64_t rfps_duration_sum
int update_initial_durations_done
Internal data to prevent doing update_initial_durations() twice.
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 ...
static void estimate_timings_from_bit_rate(AVFormatContext *ic)
int probe_packets
Number of packets to buffer for codec probing.
void ff_rfps_calculate(AVFormatContext *ic)
#define AV_LOG_INFO
Standard information.
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
void * av_opt_ptr(const AVClass *class, void *obj, const char *name)
Gets a pointer to the requested field in a struct.
static int64_t filesize(AVIOContext *pb)
int skip_to_keyframe
Indicates that everything up to the next keyframe should be discarded.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
double(* duration_error)[2][MAX_STD_TIMEBASES]
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
int64_t pos
Byte position of currently parsed frame in stream.
#define PARSER_FLAG_COMPLETE_FRAMES
#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...
int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
int64_t id
unique ID to identify the chapter
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
static const AVCodec * find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
#define AV_TIME_BASE
Internal time base represented as integer.
void ff_id3v2_read_dict(AVIOContext *pb, AVDictionary **metadata, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag into specified dictionary and retrieve supported extra metadata.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
char * codec_whitelist
',' separated list of allowed decoders.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp)
Wrap a given time stamp, if there is an indication for an overflow.
int64_t pts_buffer[MAX_REORDER_DELAY+1]
int av_find_default_stream_index(AVFormatContext *s)
@ AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
New fields can be added to the end with minor version bumps.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt)
void * av_calloc(size_t nmemb, size_t size)
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *pkt, AVDictionary **options)
static double limit(double x)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
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.
int id
Format-specific stream ID.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define FFSWAP(type, a, b)
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
static int tb_unreliable(AVFormatContext *ic, AVStream *st)
@ AV_AUDIO_SERVICE_TYPE_KARAOKE
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
main external API structure.
int index
stream index in AVFormatContext
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
@ AV_AUDIO_SERVICE_TYPE_COMMENTARY
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
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...
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
#define PARSER_FLAG_USE_CODEC_TS
static int ref[MAX_W *MAX_W]
AVRational r_frame_rate
Real base framerate of the stream.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts)
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush)
Parse a packet, add all split parts to parse_queue.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int64_t av_gettime(void)
Get the current time in microseconds.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define AVIO_FLAG_READ
read-only
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate a string.
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.
static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt)
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
@ AV_AUDIO_SERVICE_TYPE_EFFECTS
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
static void fill_all_stream_timings(AVFormatContext *ic)
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts)
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int64_t pos
byte position in stream, -1 if unknown
int width
picture width / height.
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
struct AVCodecParserContext * parser
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
static int has_decode_delay_been_guessed(AVStream *st)
static av_always_inline int is_relative(int64_t ts)
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
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...
int pts_wrap_bits
Number of bits in timestamps.
AVRational time_base
time base in which the start/end timestamps are specified
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void * priv_data
Format private data.
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
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.
static int compute_chapters_end(AVFormatContext *s)
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
void av_parser_close(AVCodecParserContext *s)
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)