Go to the documentation of this file.
37 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
50 AVStream *
const st =
s->streams[stream_index];
52 unsigned int max_entries =
s->max_index_size /
sizeof(
AVIndexEntry);
63 int *nb_index_entries,
64 unsigned int *index_entries_allocated_size,
65 int64_t
pos, int64_t timestamp,
71 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
77 if (size < 0 || size > 0x3FFFFFFF)
84 index_entries_allocated_size,
85 (*nb_index_entries + 1) *
90 *index_entries = entries;
95 index = (*nb_index_entries)++;
105 (*nb_index_entries)++;
106 }
else if (ie->
pos ==
pos && distance < ie->min_distance)
131 int64_t wanted_timestamp,
int flags)
140 if (
b && entries[
b - 1].timestamp < wanted_timestamp)
149 if (m ==
b && entries[m].timestamp >= wanted_timestamp) {
156 if (timestamp >= wanted_timestamp)
158 if (timestamp <= wanted_timestamp)
164 while (m >= 0 && m < nb_entries &&
175 int64_t pos_delta = 0;
185 "Protocol name not provided, cannot determine if input is local or "
186 "a network protocol, buffers and access patterns cannot be configured "
187 "optimally without knowing the protocol\n");
190 if (proto && !(strcmp(proto,
"file") && strcmp(proto,
"pipe") && strcmp(proto,
"cache")))
193 for (
unsigned ist1 = 0; ist1 <
s->nb_streams; ist1++) {
196 for (
unsigned ist2 = 0; ist2 <
s->nb_streams; ist2++) {
211 if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
223 if (
s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) {
232 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, pos_delta/2);
235 if (
skip < (1<<23)) {
244 wanted_timestamp,
flags);
262 int64_t wanted_timestamp,
268 wanted_timestamp,
flags);
280 if (stream_index >= 0)
286 int64_t target_ts,
int flags)
289 int64_t pos_min = 0, pos_max = 0,
pos, pos_limit;
290 int64_t ts_min, ts_max, ts;
296 if (stream_index < 0)
305 st =
s->streams[stream_index];
336 " dts_max=%s\n", pos_max, pos_limit,
av_ts2str(ts_max));
356 int64_t (*read_timestamp_func)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
359 int64_t
limit, ts_max;
366 &pos_max,
limit, read_timestamp_func);
373 int64_t tmp_pos = pos_max + 1;
375 &tmp_pos, INT64_MAX, read_timestamp_func);
394 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
395 int64_t ts_min, int64_t ts_max,
396 int flags, int64_t *ts_ret,
398 int, int64_t *, int64_t))
410 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
415 if (ts_min >= target_ts) {
426 if (ts_max <= target_ts) {
434 while (pos_min < pos_limit) {
436 "pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%s dts_max=%s\n",
440 if (no_change == 0) {
441 int64_t approximate_keyframe_distance = pos_max - pos_limit;
445 pos_min - approximate_keyframe_distance;
446 }
else if (no_change == 1) {
448 pos = (pos_min + pos_limit) >> 1;
456 else if (
pos > pos_limit)
467 " target:%s limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
468 pos_min,
pos, pos_max,
470 pos_limit, start_pos, no_change);
475 if (target_ts <= ts) {
476 pos_limit = start_pos - 1;
480 if (target_ts >= ts) {
490 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
492 ts_max =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
504 int64_t pos_min, pos_max;
511 else if (
pos > pos_max)
516 s->io_repositioned = 1;
522 int64_t timestamp,
int flags)
525 AVStream *
const st =
s->streams[stream_index];
533 if (index < 0 && sti->nb_index_entries &&
534 timestamp < sti->index_entries[0].timestamp)
537 if (index < 0 || index == sti->nb_index_entries - 1) {
546 s->io_repositioned = 1;
551 s->io_repositioned = 1;
558 }
while (read_status ==
AVERROR(EAGAIN));
567 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);
580 if (
s->iformat->read_seek)
581 if (
s->iformat->read_seek(
s, stream_index, timestamp,
flags) >= 0)
586 s->io_repositioned = 1;
593 int64_t timestamp,
int flags)
605 if (stream_index < 0) {
607 if (stream_index < 0)
610 st =
s->streams[stream_index];
617 if (
s->iformat->read_seek) {
619 ret =
s->iformat->read_seek(
s, stream_index, timestamp,
flags);
625 if (
s->iformat->read_timestamp &&
637 int64_t timestamp,
int flags)
641 if (
s->iformat->read_seek2 && !
s->iformat->read_seek) {
642 int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
660 int64_t ts, int64_t max_ts,
int flags)
662 if (min_ts > ts || max_ts < ts)
664 if (stream_index < -1 || stream_index >= (
int)
s->nb_streams)
671 if (
s->iformat->read_seek2) {
675 if (stream_index == -1 &&
s->nb_streams == 1) {
687 ret =
s->iformat->read_seek2(
s, stream_index, min_ts,
695 if (
s->iformat->read_timestamp) {
701 if (
s->iformat->read_seek || 1) {
704 if (
ret < 0 && ts != min_ts && max_ts != ts) {
724 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
759 int64_t *min_ts, int64_t *ts, int64_t *max_ts)
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 inject_global_side_data
Internal data to inject global side data.
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
@ AV_ROUND_UP
Round toward +infinity.
#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.
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).
int inject_global_side_data
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,...
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 AVInputFormat.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.
@ AV_ROUND_DOWN
Round toward -infinity.
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)
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)
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.
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
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))
static av_always_inline int is_relative(int64_t ts)
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.
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.