Go to the documentation of this file.
34 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
47 AVStream *
const st =
s->streams[stream_index];
49 unsigned int max_entries =
s->max_index_size /
sizeof(
AVIndexEntry);
60 int *nb_index_entries,
61 unsigned int *index_entries_allocated_size,
62 int64_t
pos, int64_t timestamp,
68 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
74 if (size < 0 || size > 0x3FFFFFFF)
81 index_entries_allocated_size,
82 (*nb_index_entries + 1) *
87 *index_entries = entries;
92 index = (*nb_index_entries)++;
102 (*nb_index_entries)++;
103 }
else if (ie->
pos ==
pos && distance < ie->min_distance)
128 int64_t wanted_timestamp,
int flags)
137 if (
b && entries[
b - 1].timestamp < wanted_timestamp)
146 if (m ==
b && entries[m].timestamp >= wanted_timestamp) {
153 if (timestamp >= wanted_timestamp)
155 if (timestamp <= wanted_timestamp)
161 while (m >= 0 && m < nb_entries &&
172 int64_t pos_delta = 0;
182 "Protocol name not provided, cannot determine if input is local or "
183 "a network protocol, buffers and access patterns cannot be configured "
184 "optimally without knowing the protocol\n");
187 if (proto && !(strcmp(proto,
"file") && strcmp(proto,
"pipe") && strcmp(proto,
"cache")))
190 for (
unsigned ist1 = 0; ist1 <
s->nb_streams; ist1++) {
193 for (
unsigned ist2 = 0; ist2 <
s->nb_streams; ist2++) {
208 if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
220 if (
s->pb->buffer_size < pos_delta && pos_delta < (1<<24)) {
229 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, pos_delta/2);
232 if (skip < (1<<23)) {
233 ctx->short_seek_threshold =
FFMAX(
ctx->short_seek_threshold, skip);
241 wanted_timestamp,
flags);
259 int64_t wanted_timestamp,
265 wanted_timestamp,
flags);
277 if (stream_index >= 0)
283 int64_t target_ts,
int flags)
286 int64_t pos_min = 0, pos_max = 0,
pos, pos_limit;
287 int64_t ts_min, ts_max, ts;
293 if (stream_index < 0)
302 st =
s->streams[stream_index];
333 " dts_max=%s\n", pos_max, pos_limit,
av_ts2str(ts_max));
353 int64_t (*read_timestamp_func)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
356 int64_t
limit, ts_max;
358 int64_t pos_max = filesize - 1;
363 &pos_max,
limit, read_timestamp_func);
370 int64_t tmp_pos = pos_max + 1;
372 &tmp_pos, INT64_MAX, read_timestamp_func);
378 if (tmp_pos >= filesize)
391 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
392 int64_t ts_min, int64_t ts_max,
393 int flags, int64_t *ts_ret,
395 int, int64_t *, int64_t))
407 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
412 if (ts_min >= target_ts) {
423 if (ts_max <= target_ts) {
431 while (pos_min < pos_limit) {
433 "pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%s dts_max=%s\n",
437 if (no_change == 0) {
438 int64_t approximate_keyframe_distance = pos_max - pos_limit;
442 pos_min - approximate_keyframe_distance;
443 }
else if (no_change == 1) {
445 pos = (pos_min + pos_limit) >> 1;
453 else if (
pos > pos_limit)
464 " target:%s limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
465 pos_min,
pos, pos_max,
467 pos_limit, start_pos, no_change);
472 if (target_ts <= ts) {
473 pos_limit = start_pos - 1;
477 if (target_ts >= ts) {
487 ts_min =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
489 ts_max =
read_timestamp(
s, stream_index, &pos_min, INT64_MAX, read_timestamp_func);
501 int64_t pos_min, pos_max;
508 else if (
pos > pos_max)
513 s->io_repositioned = 1;
519 int64_t timestamp,
int flags)
522 AVStream *
const st =
s->streams[stream_index];
530 if (index < 0 && sti->nb_index_entries &&
531 timestamp < sti->index_entries[0].timestamp)
534 if (index < 0 || index == sti->nb_index_entries - 1) {
543 s->io_repositioned = 1;
548 s->io_repositioned = 1;
555 }
while (read_status ==
AVERROR(EAGAIN));
564 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);
577 if (
s->iformat->read_seek)
578 if (
s->iformat->read_seek(
s, stream_index, timestamp,
flags) >= 0)
583 s->io_repositioned = 1;
590 int64_t timestamp,
int flags)
602 if (stream_index < 0) {
604 if (stream_index < 0)
607 st =
s->streams[stream_index];
614 if (
s->iformat->read_seek) {
616 ret =
s->iformat->read_seek(
s, stream_index, timestamp,
flags);
622 if (
s->iformat->read_timestamp &&
634 int64_t timestamp,
int flags)
638 if (
s->iformat->read_seek2 && !
s->iformat->read_seek) {
639 int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
657 int64_t ts, int64_t max_ts,
int flags)
659 if (min_ts > ts || max_ts < ts)
661 if (stream_index < -1 || stream_index >= (
int)
s->nb_streams)
668 if (
s->iformat->read_seek2) {
672 if (stream_index == -1 &&
s->nb_streams == 1) {
684 ret =
s->iformat->read_seek2(
s, stream_index, min_ts,
692 if (
s->iformat->read_timestamp) {
698 if (
s->iformat->read_seek || 1) {
701 if (
ret < 0 && ts != min_ts && max_ts != ts) {
721 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
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
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))
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().
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.