55 #include "libavutil/ffversion.h"
71 return FFMPEG_CONFIGURATION;
76 #define LICENSE_PREFIX "libavformat license: "
80 #define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48))
98 timestamp < st->pts_wrap_reference)
111 MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, subtitle_codec)
113 MAKE_ACCESSORS(AVFormatContext, format,
int, metadata_header_padding)
116 #if FF_API_OLD_OPEN_CALLBACKS
155 if ( (src-> codec_whitelist && !dst-> codec_whitelist)
156 || (src-> format_whitelist && !dst-> format_whitelist)
167 #if FF_API_LAVF_AVCTX
169 if (st->codec->codec)
170 return st->codec->codec;
191 const AVCodec *codec;
193 #if CONFIG_H264_DECODER
207 if (probe_codec->
id == codec_id &&
224 #define SANE_CHUNK_SIZE (50000000)
230 if (remaining < size) {
233 s->
maxsize = newsize - !newsize;
235 remaining=
FFMAX(remaining, 0);
238 if (s->
maxsize>= 0 && remaining+1 < size) {
250 int64_t orig_pos = pkt->
pos;
251 int orig_size = pkt->
size;
255 int prev_size = pkt->
size;
273 if (ret != read_size) {
286 return pkt->
size > orig_size ? pkt->
size - orig_size : ret;
316 static const struct {
343 "Probe with size=%d, packets=%d detected %s with score=%d\n",
346 for (i = 0; fmt_id_type[i].name; i++) {
347 if (!strcmp(fmt->
name, fmt_id_type[i].name)) {
357 #if FF_API_LAVF_AVCTX
408 "will be ignored with AVFMT_NOFILE format.\n");
444 (*plast_pktl)->next = pktl;
446 *packet_buffer = pktl;
461 "Attached picture on stream %d has invalid size, "
495 #if FF_API_LAVF_AVCTX
513 AVFormatContext *
s = *ps;
521 av_log(
NULL,
AV_LOG_ERROR,
"Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");
537 if ((ret =
init_input(s, filename, &tmp)) < 0)
605 av_log(s, level,
"Discarding ID3 tags because more suitable tags were found.\n");
611 if (id3v2_extra_meta) {
687 "Failed to reallocate probe buffer for stream %d\n",
700 "nothing to probe for stream %d\n", st->
index);
728 int i, pts_wrap_behavior;
729 int64_t pts_wrap_reference;
747 if (!first_program) {
774 program = first_program;
823 if (!pktl || ret ==
AVERROR(EAGAIN))
846 "Dropped corrupted packet (stream = %d)\n",
916 #if FF_API_LAVF_AVCTX
918 if ((!codec_framerate.den || !codec_framerate.num) && st->codec->time_base.den && st->codec->time_base.num)
925 switch (st->codecpar->codec_type) {
927 if (st->r_frame_rate.num && !pc &&
s->iformat) {
928 *pnum = st->r_frame_rate.den;
929 *pden = st->r_frame_rate.num;
930 }
else if (st->time_base.num * 1000LL > st->time_base.den) {
931 *pnum = st->time_base.num;
932 *pden = st->time_base.den;
933 }
else if (codec_framerate.den * 1000LL > codec_framerate.num) {
934 av_assert0(st->internal->avctx->ticks_per_frame);
937 codec_framerate.num * (int64_t)st->internal->avctx->ticks_per_frame,
940 if (pc && pc->repeat_pict) {
943 (*pnum) * (1LL + pc->repeat_pict),
950 if (st->internal->avctx->ticks_per_frame > 1 && !pc)
955 if (st->internal->avctx_inited) {
957 sample_rate = st->internal->avctx->sample_rate;
960 sample_rate = st->codecpar->sample_rate;
962 if (frame_size <= 0 || sample_rate <= 0)
987 #if CONFIG_H264_DECODER
1018 int64_t best_score = INT64_MAX;
1019 for (i = 0; i<delay; i++) {
1022 if (score < best_score) {
1024 dts = pts_buffer[i];
1029 for (i = 0; i<delay; i++) {
1031 int64_t
diff =
FFABS(pts_buffer[i] - dts)
1046 dts = pts_buffer[0];
1058 AVStream *st = s->
streams[stream_index];
1067 for (; pkt_buffer; pkt_buffer =
get_next_pkt(s, st, pkt_buffer)) {
1072 pts_buffer[0] = pkt_buffer->
pkt.
pts;
1073 for (i = 0; i<delay && pts_buffer[i] > pts_buffer[i + 1]; i++)
1074 FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]);
1084 AVStream *st = s->
streams[stream_index];
1103 for (pktl_it = pktl; pktl_it; pktl_it =
get_next_pkt(s, st, pktl_it)) {
1107 pktl_it->
pkt.
pts += shift;
1110 pktl_it->
pkt.
dts += shift;
1124 st->start_time =
pts;
1126 st->start_time +=
av_rescale_q(st->skip_samples, (
AVRational){1, st->codecpar->sample_rate}, st->time_base);
1151 av_log(s,
AV_LOG_DEBUG,
"first_dts %s not matching first dts %s (pts %s, duration %"PRId64
") in the queue\n",
1188 int64_t next_dts, int64_t next_pts)
1190 int num, den, presentation_delayed, delay, i;
1205 "DTS %"PRIi64
" < %"PRIi64
" out of order\n",
1231 presentation_delayed = 0;
1237 presentation_delayed = 1;
1252 if (delay == 1 && pkt->
dts == pkt->
pts &&
1255 if ( strcmp(s->
iformat->
name,
"mov,mp4,m4a,3gp,3g2,mj2")
1290 presentation_delayed = 1;
1294 "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64
" delay:%d onein_oneout:%d\n",
1300 if ((delay == 0 || (delay == 1 && pc)) &&
1302 if (presentation_delayed) {
1320 ((uint64_t)st->
cur_dts - (uint64_t)next_dts + 1) <= 2 &&
1321 next_dts != next_pts &&
1323 pkt->
pts = next_dts;
1368 #if FF_API_CONVERGENCE_DURATION
1380 *pkt_buf = pktl->
next;
1384 *pkt_buf_end =
NULL;
1395 AVStream *st = s->
streams[stream_index];
1398 int ret = 0, got_output = 0;
1409 while (size > 0 || (pkt == &
flush_pkt && got_output)) {
1411 int64_t next_pts = pkt->
pts;
1412 int64_t next_dts = pkt->
dts;
1416 &out_pkt.
data, &out_pkt.
size, data, size,
1425 got_output = !!out_pkt.
size;
1493 *pkt_buffer = pktl->
next;
1495 *pkt_buffer_end =
NULL;
1507 int ret = 0, i, got_packet = 0;
1537 av_log(s,
AV_LOG_DEBUG,
"Demuxer context update while decoder is open, closing and trying to re-open\n");
1552 #if FF_API_LAVF_AVCTX
1566 cur_pkt.
pts < cur_pkt.
dts) {
1568 "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
1576 "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64
", flags=%d\n",
1586 "%s, packets or times may be invalid.\n",
1637 int discard_padding = 0;
1642 int64_t end_sample = sample +
duration;
1644 sample < st->last_discard_sample)
1653 AV_WL32(p + 4, discard_padding);
1673 memcpy(dst_data, src_sd->
data, src_sd->
size);
1678 #if FF_API_LAVF_MERGE_SD
1680 if (!(s->
flags & AVFMT_FLAG_KEEP_SIDE_DATA))
1694 #if FF_API_LAVF_AVCTX
1700 "read_frame_internal stream=%d, pts=%s, dts=%s, "
1701 "size=%d, duration=%"PRId64
", flags=%d\n",
1738 int64_t last_dts = next_pkt->
dts;
1748 last_dts = pktl->
pkt.
dts;
1776 if (pktl && ret !=
AVERROR(EAGAIN)) {
1825 int best_stream = 0;
1826 int best_score = INT_MIN;
1850 if (score > best_score) {
1910 AVStream *st = s->
streams[stream_index];
1922 int *nb_index_entries,
1923 unsigned int *index_entries_allocated_size,
1924 int64_t pos, int64_t timestamp,
1930 if ((
unsigned) *nb_index_entries + 1 >= UINT_MAX /
sizeof(
AVIndexEntry))
1943 index_entries_allocated_size,
1944 (*nb_index_entries + 1) *
1949 *index_entries = entries;
1955 index = (*nb_index_entries)++;
1956 ie = &entries[
index];
1957 av_assert0(index == 0 || ie[-1].timestamp < timestamp);
1959 ie = &entries[
index];
1963 memmove(entries + index + 1, entries + index,
1965 (*nb_index_entries)++;
1966 }
else if (ie->
pos == pos && distance < ie->min_distance)
1986 timestamp, size, distance, flags);
1990 int64_t wanted_timestamp,
int flags)
1999 if (b && entries[b - 1].timestamp < wanted_timestamp)
2008 if (m == b && entries[m].timestamp >= wanted_timestamp) {
2015 if (timestamp >= wanted_timestamp)
2017 if (timestamp <= wanted_timestamp)
2023 while (m >= 0 && m < nb_entries &&
2027 if (m == nb_entries)
2035 int64_t pos_delta = 0;
2042 "Protocol name not provided, cannot determine if input is local or "
2043 "a network protocol, buffers and access patterns cannot be configured "
2044 "optimally without knowing the protocol\n");
2047 if (proto && !(strcmp(proto,
"file") && strcmp(proto,
"pipe") && strcmp(proto,
"cache")))
2050 for (ist1 = 0; ist1 < s->
nb_streams; ist1++) {
2051 AVStream *st1 = s->
streams[ist1];
2052 for (ist2 = 0; ist2 < s->
nb_streams; ist2++) {
2053 AVStream *st2 = s->
streams[ist2];
2067 if (e2_pts - e1_pts < time_tolerance)
2078 if (s->
pb->
buffer_size < pos_delta && pos_delta < (1<<24)) {
2084 if (skip < (1<<23)) {
2092 wanted_timestamp, flags);
2096 int64_t (*read_timestamp)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
2098 int64_t ts = read_timestamp(s, stream_index, ppos, pos_limit);
2099 if (stream_index >= 0)
2105 int64_t target_ts,
int flags)
2109 int64_t ts_min, ts_max, ts;
2114 if (stream_index < 0)
2123 st = s->
streams[stream_index];
2131 index =
FFMAX(index, 0);
2153 " dts_max=%s\n", pos_max, pos_limit,
av_ts2str(ts_max));
2157 pos =
ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit,
2173 int64_t (*read_timestamp)(
struct AVFormatContext *,
int , int64_t *, int64_t ))
2175 int64_t step = 1024;
2176 int64_t limit, ts_max;
2178 int64_t pos_max = filesize - 1;
2181 pos_max =
FFMAX(0, (pos_max) - step);
2183 &pos_max, limit, read_timestamp);
2190 int64_t tmp_pos = pos_max + 1;
2192 &tmp_pos, INT64_MAX, read_timestamp);
2198 if (tmp_pos >= filesize)
2211 int64_t pos_min, int64_t pos_max, int64_t pos_limit,
2212 int64_t ts_min, int64_t ts_max,
2213 int flags, int64_t *ts_ret,
2214 int64_t (*read_timestamp)(
struct AVFormatContext *,
int,
2215 int64_t *, int64_t))
2226 ts_min =
ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
2231 if (ts_min >= target_ts) {
2237 if ((ret =
ff_find_last_ts(s, stream_index, &ts_max, &pos_max, read_timestamp)) < 0)
2239 pos_limit = pos_max;
2242 if (ts_max <= target_ts) {
2250 while (pos_min < pos_limit) {
2252 "pos_min=0x%"PRIx64
" pos_max=0x%"PRIx64
" dts_min=%s dts_max=%s\n",
2256 if (no_change == 0) {
2257 int64_t approximate_keyframe_distance = pos_max - pos_limit;
2259 pos =
av_rescale(target_ts - ts_min, pos_max - pos_min,
2261 pos_min - approximate_keyframe_distance;
2262 }
else if (no_change == 1) {
2264 pos = (pos_min + pos_limit) >> 1;
2272 else if (pos > pos_limit)
2283 " target:%s limit:%"PRId64
" start:%"PRId64
" noc:%d\n",
2284 pos_min, pos, pos_max,
2286 pos_limit, start_pos, no_change);
2291 if (target_ts <= ts) {
2292 pos_limit = start_pos - 1;
2296 if (target_ts >= ts) {
2306 ts_min =
ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
2308 ts_max =
ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
2317 int64_t pos,
int flags)
2319 int64_t pos_min, pos_max;
2326 else if (pos > pos_max)
2337 int64_t timestamp,
int flags)
2344 st = s->
streams[stream_index];
2348 if (index < 0 && st->nb_index_entries &&
2349 timestamp < st->index_entries[0].timestamp)
2352 if (index < 0 || index == st->nb_index_entries - 1) {
2370 }
while (read_status ==
AVERROR(EAGAIN));
2371 if (read_status < 0)
2379 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);
2404 int64_t timestamp,
int flags)
2416 if (stream_index < 0) {
2418 if (stream_index < 0)
2421 st = s->
streams[stream_index];
2448 int64_t timestamp,
int flags)
2453 int64_t min_ts = INT64_MIN, max_ts = INT64_MAX;
2459 flags & ~AVSEEK_FLAG_BACKWARD);
2471 int64_t ts, int64_t max_ts,
int flags)
2473 if (min_ts > ts || max_ts < ts)
2475 if (stream_index < -1 || stream_index >= (
int)s->
nb_streams)
2486 if (stream_index == -1 && s->
nb_streams == 1) {
2493 time_base.
num * (int64_t)AV_TIME_BASE,
2515 if (ret<0 && ts != min_ts && max_ts != ts) {
2516 ret =
av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir);
2562 int64_t
start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
2563 int64_t
duration, duration1, filesize;
2568 start_time = INT64_MAX;
2569 start_time_text = INT64_MAX;
2570 end_time = INT64_MIN;
2571 end_time_text = INT64_MIN;
2572 duration = INT64_MIN;
2579 if (start_time1 < start_time_text)
2580 start_time_text = start_time1;
2582 start_time =
FFMIN(start_time, start_time1);
2586 if (end_time1 !=
AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
2587 end_time1 += start_time1;
2589 end_time_text =
FFMAX(end_time_text, end_time1);
2591 end_time =
FFMAX(end_time, end_time1);
2603 duration =
FFMAX(duration, duration1);
2606 if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text <
AV_TIME_BASE))
2607 start_time = start_time_text;
2608 else if (start_time > start_time_text)
2611 if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - end_time < AV_TIME_BASE)) {
2612 end_time = end_time_text;
2613 }
else if (end_time < end_time_text) {
2614 av_log(ic,
AV_LOG_VERBOSE,
"Ignoring outlier non primary stream endtime %f\n", end_time_text / (
float)AV_TIME_BASE);
2617 if (start_time != INT64_MAX) {
2619 if (end_time != INT64_MIN) {
2628 }
else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) {
2629 duration =
FFMAX(duration, end_time - start_time);
2638 double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
2640 if (bitrate >= 0 && bitrate <= INT64_MAX)
2667 int i, show_warning = 0;
2672 int64_t bit_rate = 0;
2714 "Estimating duration from bitrate, this may be inaccurate\n");
2717 #define DURATION_MAX_READ_SIZE 250000LL
2718 #define DURATION_MAX_RETRY 6
2725 int num, den, read_size, i, ret;
2726 int found_duration = 0;
2740 "start time for stream %d is not set in estimate_timings_from_pts\n", i);
2753 is_end = found_duration;
2766 }
while (ret ==
AVERROR(EAGAIN));
2769 read_size += pkt->
size;
2826 av_log(ic,
AV_LOG_DEBUG,
"stream %d : no PTS found at end of file, duration not set\n", i);
2828 av_log(ic,
AV_LOG_DEBUG,
"stream %d : no TS found at start of file, duration not set\n", i);
2856 file_size =
FFMAX(0, file_size);
2883 (
double) st->start_time *
av_q2d(st->time_base),
2884 (
double) st->duration *
av_q2d(st->time_base));
2887 "format: start_time: %0.3f duration: %0.3f bitrate=%"PRId64
" kb/s\n",
2898 #define FAIL(errmsg) do { \
2900 *errmsg_ptr = errmsg; \
2906 FAIL(
"unknown codec");
2910 FAIL(
"unspecified frame size");
2913 FAIL(
"unspecified sample format");
2915 FAIL(
"unspecified sample rate");
2917 FAIL(
"unspecified number of channels");
2919 FAIL(
"no decodable DTS frames");
2923 FAIL(
"unspecified size");
2925 FAIL(
"unspecified pixel format");
2928 FAIL(
"no frame in rv30/40 and no sar");
2932 FAIL(
"unspecified size");
2946 const AVCodec *codec;
2947 int got_picture = 1, ret = 0;
2951 int do_skip_frame = 0;
2972 av_dict_set(options ? options : &thread_opt,
"threads",
"1", 0);
2975 ret =
avcodec_open2(avctx, codec, options ? options : &thread_opt);
2997 while ((pkt.
size > 0 || (!pkt.
data && got_picture)) &&
3017 &got_picture, &pkt);
3028 if (!pkt.
data && !got_picture)
3032 if (do_skip_frame) {
3054 if (tag == tags[i].tag)
3064 if (bps <= 0 || bps > 64)
3079 if (sflags & (1 << (bps - 1))) {
3123 for (i = 0; tags && tags[i]; i++) {
3126 if (codec_tags->
id ==
id) {
3127 *tag = codec_tags->
tag;
3139 for (i = 0; tags && tags[i]; i++) {
3150 int64_t max_time = 0;
3167 if (j != i && next_start > ch->
start && next_start < end)
3170 ch->
end = (end == INT64_MAX) ? ch->
start : end;
3177 return (i + 1) * 1001;
3181 return (i + 31) * 1001 * 12;
3185 return ((
const int[]) { 80, 120, 240})[i] * 1001 * 12;
3189 return ((
const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12;
3256 && ts - (uint64_t)last < INT64_MAX) {
3270 double sdts = dts*framerate/(1001*12);
3271 for (j= 0; j<2; j++) {
3272 int64_t ticks =
llrint(sdts+j*0.5);
3273 double error= sdts - ticks + j*0.5;
3290 if (error0 > 0.04 && error1 > 0.04) {
3313 AVStream *st = ic->
streams[i];
3325 double best_error= 0.01;
3340 for (k= 0; k<2; k++) {
3345 if (error < best_error && best_error> 0.000000001) {
3354 if (num && (!ref_rate.
num || (
double)num/(12*1001) < 1.01 *
av_q2d(ref_rate)))
3376 int i,
count = 0, ret = 0, j;
3386 int64_t max_stream_analyze_duration;
3387 int64_t max_subtitle_analyze_duration;
3389 int eof_reached = 0;
3392 flush_codecs = probesize > 0;
3396 max_stream_analyze_duration = max_analyze_duration;
3397 max_subtitle_analyze_duration = max_analyze_duration;
3398 if (!max_analyze_duration) {
3399 max_stream_analyze_duration =
3409 av_log(ic,
AV_LOG_DEBUG,
"Before avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d nb_streams:%d\n",
3413 const AVCodec *codec;
3427 #if FF_API_LAVF_AVCTX
3447 "%s, packets or times may be invalid.\n",
3457 goto find_stream_info_err;
3465 av_dict_set(options ? &options[i] : &thread_opt,
"threads",
"1", 0);
3472 && codec && !avctx->
codec) {
3473 if (
avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
3475 "Failed to open codec in %s\n",__FUNCTION__);
3480 if (codec && !avctx->
codec)
3481 if (
avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
3483 "Failed to open codec in %s\n",__FUNCTION__);
3490 #if FF_API_R_FRAME_RATE
3499 int analyzed_all_streams;
3508 int fps_analyze_framecount = 20;
3517 fps_analyze_framecount *= 2;
3519 fps_analyze_framecount = 0;
3523 fps_analyze_framecount = 0;
3530 if (count < fps_analyze_framecount)
3543 analyzed_all_streams = 0;
3544 if (!missing_streams || !*missing_streams)
3546 analyzed_all_streams = 1;
3558 if (read_size >= probesize) {
3561 "Probe buffer size limit of %"PRId64
" bytes reached\n", probesize);
3568 "Stream #%d: not enough frames to estimate rate; "
3569 "consider increasing probesize\n", i);
3591 goto find_stream_info_err;
3596 read_size += pkt->
size;
3602 goto find_stream_info_err;
3611 "Non-increasing DTS in stream %d: packet %d with DTS "
3612 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
3628 "DTS discontinuity in stream %d: packet %d with DTS "
3629 "%"PRId64
", packet %d with DTS %"PRId64
"\n",
3660 if (analyzed_all_streams) limit = max_analyze_duration;
3662 else limit = max_stream_analyze_duration;
3665 av_log(ic,
AV_LOG_VERBOSE,
"max_analyze_duration %"PRId64
" reached at %"PRId64
" microseconds st:%d\n",
3680 #if FF_API_R_FRAME_RATE
3707 (options && i < orig_nb_streams) ? &options[i] :
NULL);
3718 for (stream_index = 0; stream_index < ic->
nb_streams; stream_index++) {
3719 st = ic->
streams[stream_index];
3723 if (codec && !avctx->
codec) {
3727 if (
avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0)
3729 "Failed to open codec in %s\n",__FUNCTION__);
3755 (options && i < orig_nb_streams)
3756 ? &options[i] :
NULL);
3761 "decoding for stream %d failed\n", st->
index);
3784 double best_error = 0.01;
3801 if (error < best_error) {
3803 best_fps = std_fps.
num;
3808 best_fps, 12 * 1001, INT_MAX);
3870 goto find_stream_info_err;
3876 "Could not find codec parameters for stream %d (%s): %s\n"
3877 "Consider increasing the value for the 'analyzeduration' and 'probesize' options\n",
3895 goto find_stream_info_err;
3903 #if FF_API_LAVF_AVCTX
3907 goto find_stream_info_err;
3917 if (st->codec->codec_tag !=
MKTAG(
't',
'm',
'c',
'd')) {
3925 if (!st->codec->subtitle_header)
3926 goto find_stream_info_err;
3929 st->codec->subtitle_header_size);
3942 find_stream_info_err:
3951 av_log(ic,
AV_LOG_DEBUG,
"After avformat_find_stream_info() pos: %"PRId64
" bytes read:%"PRId64
" seeks:%d frames:%d\n",
3974 int wanted_stream_nb,
int related_stream,
3975 AVCodec **decoder_ret,
int flags)
3979 unsigned *program =
NULL;
3982 if (related_stream >= 0 && wanted_stream_nb < 0) {
3990 int real_stream_index = program ? program[i] : i;
3991 AVStream *st = ic->
streams[real_stream_index];
3995 if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
3997 if (wanted_stream_nb != real_stream_index &&
4014 if ((best_multiframe > multiframe) ||
4015 (best_multiframe == multiframe && best_bitrate > bitrate) ||
4016 (best_multiframe == multiframe && best_bitrate == bitrate && best_count >=
count))
4019 best_bitrate = bitrate;
4020 best_multiframe = multiframe;
4021 ret = real_stream_index;
4023 if (program && i == nb_streams - 1 && ret < 0) {
4031 *decoder_ret = (AVCodec*)best_decoder;
4114 AVStream *st = *pst;
4143 #if FF_API_LAVF_AVCTX
4239 av_log(s,
AV_LOG_ERROR,
"Number of streams exceeds max_streams parameter (%d), see the documentation if you wish to increase it\n", s->
max_streams);
4256 #if FF_API_LAVF_AVCTX
4280 #if FF_API_LAVF_AVCTX
4283 st->codec->bit_rate = 0;
4313 #if FF_API_R_FRAME_RATE
4359 int64_t
start, int64_t
end,
const char *title)
4365 av_log(s,
AV_LOG_ERROR,
"Chapter end time %"PRId64
" before start %"PRId64
"\n", end, start);
4424 char *q, buf1[20],
c;
4425 int nd,
len, percentd_found;
4438 nd = nd * 10 + *p++ -
'0';
4451 snprintf(buf1,
sizeof(buf1),
"%0*d", nd, number);
4453 if ((q - buf + len) > buf_size - 1)
4455 memcpy(q, buf1, len);
4463 if ((q - buf) < buf_size - 1)
4467 if (!percentd_found)
4482 char *authorization,
int authorization_size,
4483 char *hostname,
int hostname_size,
4484 int *port_ptr,
char *path,
int path_size,
const char *url)
4486 const char *p, *ls, *ls2, *at, *at2, *col, *brk;
4492 if (authorization_size > 0)
4493 authorization[0] = 0;
4494 if (hostname_size > 0)
4500 if ((p = strchr(url,
':'))) {
4514 ls = strchr(p,
'/');
4515 ls2 = strchr(p,
'?');
4519 ls =
FFMIN(ls, ls2);
4529 while ((at = strchr(p,
'@')) && at < ls) {
4531 FFMIN(authorization_size, at + 1 - at2));
4535 if (*p ==
'[' && (brk = strchr(p,
']')) && brk < ls) {
4538 FFMIN(hostname_size, brk - p));
4539 if (brk[1] ==
':' && port_ptr)
4540 *port_ptr = atoi(brk + 2);
4541 }
else if ((col = strchr(p,
':')) && col < ls) {
4543 FFMIN(col + 1 - p, hostname_size));
4545 *port_ptr = atoi(col + 1);
4548 FFMIN(ls + 1 - p, hostname_size));
4555 static const char hex_table_uc[16] = {
'0',
'1',
'2',
'3',
4558 'C',
'D',
'E',
'F' };
4559 static const char hex_table_lc[16] = {
'0',
'1',
'2',
'3',
4562 'c',
'd',
'e',
'f' };
4563 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
4565 for (i = 0; i <
s; i++) {
4566 buff[i * 2] = hex_table[src[i] >> 4];
4567 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
4584 if (c >=
'0' && c <=
'9')
4586 else if (c >=
'A' && c <=
'F')
4602 unsigned int pts_num,
unsigned int pts_den)
4606 if (new_tb.
num != pts_num)
4608 "st:%d removing common factor %d from timebase\n",
4612 "st:%d has too large timebase, reducing\n", s->
index);
4614 if (new_tb.
num <= 0 || new_tb.
den <= 0) {
4616 "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
4622 #if FF_API_LAVF_AVCTX
4634 const char *ptr = str;
4639 char *dest =
NULL, *dest_end;
4640 int key_len, dest_len = 0;
4643 while (*ptr && (
av_isspace(*ptr) || *ptr ==
','))
4650 if (!(ptr = strchr(key,
'=')))
4653 key_len = ptr - key;
4655 callback_get_buf(context, key, key_len, &dest, &dest_len);
4656 dest_end = dest + dest_len - 1;
4660 while (*ptr && *ptr !=
'\"') {
4664 if (dest && dest < dest_end)
4668 if (dest && dest < dest_end)
4676 for (; *ptr && !(
av_isspace(*ptr) || *ptr ==
','); ptr++)
4677 if (dest && dest < dest_end)
4698 unsigned int codec_tag;
4700 return ofmt->
query_codec(codec_id, std_compliance);