Go to the documentation of this file.
35 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
48 AVStream *
const st =
s->streams[stream_index];
50 unsigned int max_entries =
s->max_index_size /
sizeof(
AVIndexEntry);
61 int *nb_index_entries,
62 unsigned int *index_entries_allocated_size,
63 int64_t
pos, int64_t timestamp,
69 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
75 if (size < 0 || size > 0x3FFFFFFF)
82 index_entries_allocated_size,
83 (*nb_index_entries + 1) *
88 *index_entries = entries;
93 index = (*nb_index_entries)++;
103 (*nb_index_entries)++;
104 }
else if (ie->
pos ==
pos && distance < ie->min_distance)
129 int64_t wanted_timestamp,
int flags)
138 if (
b && entries[
b - 1].timestamp < wanted_timestamp)
147 if (m ==
b && entries[m].timestamp >= wanted_timestamp) {
154 if (timestamp >= wanted_timestamp)
156 if (timestamp <= wanted_timestamp)
162 while (m >= 0 && m < nb_entries &&
173 int64_t pos_delta = 0;
183 "Protocol name not provided, cannot determine if input is local or "
184 "a network protocol, buffers and access patterns cannot be configured "
185 "optimally without knowing the protocol\n");
188 if (proto && !(strcmp(proto,
"file") && strcmp(proto,
"pipe") && strcmp(proto,
"cache")))
191 for (
unsigned ist1 = 0; ist1 <
s->nb_streams; ist1++) {
194 for (
unsigned ist2 = 0; ist2 <
s->nb_streams; ist2++) {
209 if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
221 if (
s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) {
230 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, pos_delta/2);
233 if (skip < (1<<23)) {
234 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, skip);
242 wanted_timestamp,
flags);
260 int64_t wanted_timestamp,
266 wanted_timestamp,
flags);
278 if (stream_index >= 0)
284 int64_t target_ts,
int flags)
287 int64_t pos_min = 0, pos_max = 0,
pos, pos_limit;
288 int64_t ts_min, ts_max, ts;
294 if (stream_index < 0)
303 st =
s->streams[stream_index];
334 " dts_max=%s\n", pos_max, pos_limit,
av_ts2str(ts_max));
354 int64_t (*read_timestamp_func)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
357 int64_t
limit, ts_max;
359 int64_t pos_max = filesize - 1;
364 &pos_max,
limit, read_timestamp_func);
371 int64_t tmp_pos = pos_max + 1;
373 &tmp_pos, INT64_MAX, read_timestamp_func);
379 if (tmp_pos >= filesize)
392 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
393 int64_t ts_min, int64_t ts_max,
394 int flags, int64_t *ts_ret,
396 int, int64_t *, int64_t))
408 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
413 if (ts_min >= target_ts) {
424 if (ts_max <= target_ts) {
432 while (pos_min < pos_limit) {
434 "pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%s dts_max=%s\n",
438 if (no_change == 0) {
439 int64_t approximate_keyframe_distance = pos_max - pos_limit;
443 pos_min - approximate_keyframe_distance;
444 }
else if (no_change == 1) {
446 pos = (pos_min + pos_limit) >> 1;
454 else if (
pos > pos_limit)
465 " target:%s limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
466 pos_min,
pos, pos_max,
468 pos_limit, start_pos, no_change);
473 if (target_ts <= ts) {
474 pos_limit = start_pos - 1;
478 if (target_ts >= ts) {
488 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
490 ts_max =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
502 int64_t pos_min, pos_max;
509 else if (
pos > pos_max)
514 s->io_repositioned = 1;
520 int64_t timestamp,
int flags)
523 AVStream *
const st =
s->streams[stream_index];
531 if (index < 0 && sti->nb_index_entries &&
532 timestamp < sti->index_entries[0].timestamp)
535 if (index < 0 || index == sti->nb_index_entries - 1) {
544 s->io_repositioned = 1;
549 s->io_repositioned = 1;
556 }
while (read_status ==
AVERROR(EAGAIN));
565 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);
578 if (
s->iformat->read_seek)
579 if (
s->iformat->read_seek(
s, stream_index, timestamp,
flags) >= 0)
584 s->io_repositioned = 1;
591 int64_t timestamp,
int flags)
603 if (stream_index < 0) {
605 if (stream_index < 0)
608 st =
s->streams[stream_index];
615 if (
s->iformat->read_seek) {
617 ret =
s->iformat->read_seek(
s, stream_index, timestamp,
flags);
623 if (
s->iformat->read_timestamp &&
635 int64_t timestamp,
int flags)
639 if (
s->iformat->read_seek2 && !
s->iformat->read_seek) {
640 int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
658 int64_t ts, int64_t max_ts,
int flags)
660 if (min_ts > ts || max_ts < ts)
662 if (stream_index < -1 || stream_index >= (
int)
s->nb_streams)
669 if (
s->iformat->read_seek2) {
673 if (stream_index == -1 &&
s->nb_streams == 1) {
685 ret =
s->iformat->read_seek2(
s, stream_index, min_ts,
693 if (
s->iformat->read_timestamp) {
699 if (
s->iformat->read_seek || 1) {
702 if (
ret < 0 && ts != min_ts && max_ts != ts) {
722 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
757 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.
#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.
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.