Go to the documentation of this file.
39 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
52 AVStream *
const st =
s->streams[stream_index];
54 unsigned int max_entries =
s->max_index_size /
sizeof(
AVIndexEntry);
65 int *nb_index_entries,
66 unsigned int *index_entries_allocated_size,
73 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
79 if (size < 0 || size > 0x3FFFFFFF)
86 index_entries_allocated_size,
87 (*nb_index_entries + 1) *
92 *index_entries = entries;
97 index = (*nb_index_entries)++;
101 ie = &entries[
index];
107 (*nb_index_entries)++;
108 }
else if (ie->
pos ==
pos && distance < ie->min_distance)
142 if (
b && entries[
b - 1].timestamp < wanted_timestamp)
151 if (m ==
b && entries[m].timestamp >= wanted_timestamp) {
158 if (timestamp >= wanted_timestamp)
160 if (timestamp <= wanted_timestamp)
166 while (m >= 0 && m < nb_entries &&
187 "Protocol name not provided, cannot determine if input is local or "
188 "a network protocol, buffers and access patterns cannot be configured "
189 "optimally without knowing the protocol\n");
192 if (proto && !(strcmp(proto,
"file") && strcmp(proto,
"pipe") && strcmp(proto,
"cache")))
195 for (
unsigned ist1 = 0; ist1 <
s->nb_streams; ist1++) {
198 for (
unsigned ist2 = 0; ist2 <
s->nb_streams; ist2++) {
209 if (e1->
size < (1 << 23))
216 if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
219 if (cur_delta < (1 << 23))
220 pos_delta =
FFMAX(pos_delta, cur_delta);
230 if (
s->pb->buffer_size < pos_delta) {
239 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, pos_delta/2);
249 wanted_timestamp,
flags);
273 wanted_timestamp,
flags);
285 if (stream_index >= 0)
294 int64_t pos_min = 0, pos_max = 0,
pos, pos_limit;
301 if (stream_index < 0)
310 st =
s->streams[stream_index];
341 " dts_max=%s\n", pos_max, pos_limit,
av_ts2str(ts_max));
371 &pos_max,
limit, read_timestamp_func);
380 &tmp_pos, INT64_MAX, read_timestamp_func);
415 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
420 if (ts_min >= target_ts) {
431 if (ts_max <= target_ts) {
439 while (pos_min < pos_limit) {
441 "pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%s dts_max=%s\n",
445 if (no_change == 0) {
446 int64_t approximate_keyframe_distance = pos_max - pos_limit;
450 pos_min - approximate_keyframe_distance;
451 }
else if (no_change == 1) {
453 pos = (pos_min + pos_limit) >> 1;
461 else if (
pos > pos_limit)
472 " target:%s limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
473 pos_min,
pos, pos_max,
475 pos_limit, start_pos, no_change);
480 if (target_ts <= ts) {
481 pos_limit = start_pos - 1;
485 if (target_ts >= ts) {
495 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
497 ts_max =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
516 else if (
pos > pos_max)
521 s->io_repositioned = 1;
530 AVStream *
const st =
s->streams[stream_index];
538 if (index < 0 && sti->nb_index_entries &&
539 timestamp < sti->index_entries[0].timestamp)
542 if (index < 0 || index == sti->nb_index_entries - 1) {
551 s->io_repositioned = 1;
556 s->io_repositioned = 1;
563 }
while (read_status ==
AVERROR(EAGAIN));
572 av_log(
s,
AV_LOG_ERROR,
"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey);
591 s->io_repositioned = 1;
610 if (stream_index < 0) {
612 if (stream_index < 0)
615 st =
s->streams[stream_index];
647 int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
667 if (min_ts > ts || max_ts < ts)
669 if (stream_index < -1 || stream_index >= (
int)
s->nb_streams)
680 if (stream_index == -1 &&
s->nb_streams == 1) {
709 if (
ret < 0 && ts != min_ts && max_ts != ts) {
729 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
751 if (si->inject_global_side_data)
752 sti->inject_global_side_data = 1;
@ AV_ROUND_UP
Round toward +infinity.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int skip_samples
Number of samples to skip at the start of the frame decoded from the next packet.
int ffio_realloc_buf(AVIOContext *s, int buf_size)
Reallocate a given buffer for AVIOContext.
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
int64_t first_dts
Timestamp corresponding to the last dts sync point.
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
#define AV_LOG_VERBOSE
Detailed information.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int64_t last_dts_for_order_check
Internal data to analyze DTS and detect faulty mpeg streams.
const AVIndexEntry * avformat_index_get_entry_from_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
Get the AVIndexEntry corresponding to the given timestamp.
int64_t avio_size(AVIOContext *s)
Get the filesize.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int avformat_queue_attached_pictures(AVFormatContext *s)
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.
unsigned int index_entries_allocated_size
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int avformat_index_get_entries_count(const AVStream *st)
Get the index entry count for the given AVStream.
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 * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
static int seek_frame_internal(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t data_offset
offset of the first packet
int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, int64_t(*read_timestamp_func)(struct AVFormatContext *, int, int64_t *, int64_t))
int avformat_flush(AVFormatContext *s)
Discard all internally buffered data.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int min_distance
Minimum distance between this and the previous keyframe, used to avoid unneeded searching.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, int64_t wanted_timestamp, int flags)
Internal version of av_index_search_timestamp.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Rational number (pair of numerator and denominator).
void ff_rescale_interval(AVRational tb_in, AVRational tb_out, int64_t *min_ts, int64_t *ts, int64_t *max_ts)
Rescales a timestamp and the endpoints of an interval to which the temstamp belongs,...
@ AV_ROUND_DOWN
Round toward -infinity.
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.
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and FFInputFormat.read_timestamp().
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
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
int flags
A combination of AV_PKT_FLAG values.
static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags)
int probe_packets
Number of packets to buffer for codec probing.
#define AV_LOG_INFO
Standard information.
static int64_t filesize(AVIOContext *pb)
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
const AVIndexEntry * avformat_index_get_entry(AVStream *st, int idx)
Get the AVIndexEntry corresponding to the given index.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int64_t pts_buffer[MAX_REORDER_DELAY+1]
int av_find_default_stream_index(AVFormatContext *s)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static double limit(double x)
void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int ff_add_index_entry(AVIndexEntry **index_entries, int *nb_index_entries, unsigned int *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Internal version of av_add_index_entry.
static int seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
static float distance(float x, float y, int band)
#define flags(name, subs,...)
struct AVCodecParserContext * parser
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int64_t read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t(*read_timestamp_func)(struct AVFormatContext *, int, int64_t *, int64_t))
Perform a binary search using read_timestamp().
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 void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define MAX_REORDER_DELAY
void av_parser_close(AVCodecParserContext *s)
int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
Get the index for a specific timestamp.