end_time1 = av_rescale_q_rnd(st->duration, st->time_base,
AV_TIME_BASE_Q,
AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
- if (end_time1 != AV_NOPTS_VALUE) {
+ if (end_time1 != AV_NOPTS_VALUE && start_time1 <= INT64_MAX - end_time1) {
end_time1 += start_time1;
end_time = FFMAX(end_time, end_time1);
}
AVStream av_unused *st;
for (i = 0; i < ic->nb_streams; i++) {
st = ic->streams[i];
- av_log(ic, AV_LOG_TRACE, "%d: start_time: %0.3f duration: %0.3f\n", i,
- (double) st->start_time / AV_TIME_BASE,
- (double) st->duration / AV_TIME_BASE);
+ av_log(ic, AV_LOG_TRACE, "stream %d: start_time: %0.3f duration: %0.3f\n", i,
+ (double) st->start_time * av_q2d(st->time_base),
+ (double) st->duration * av_q2d(st->time_base));
}
av_log(ic, AV_LOG_TRACE,
- "stream: start_time: %0.3f duration: %0.3f bitrate=%"PRId64" kb/s\n",
+ "format: start_time: %0.3f duration: %0.3f bitrate=%"PRId64" kb/s\n",
(double) ic->start_time / AV_TIME_BASE,
(double) ic->duration / AV_TIME_BASE,
(int64_t)ic->bit_rate / 1000);
unsigned int i, j;
int64_t max_time = 0;
- if (s->duration > 0)
+ if (s->duration > 0 && s->start_time < INT64_MAX - s->duration)
max_time = s->duration +
((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time);
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
{
- int i, count, ret = 0, j;
+ int i, count = 0, ret = 0, j;
int64_t read_size;
AVStream *st;
AVCodecContext *avctx;
}
if (ic->pb)
- av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d\n",
- avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count);
+ av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n",
+ avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, ic->nb_streams);
for (i = 0; i < ic->nb_streams; i++) {
const AVCodec *codec;
ic->streams[i]->info->fps_last_dts = AV_NOPTS_VALUE;
}
- count = 0;
read_size = 0;
for (;;) {
int analyzed_all_streams;
count++;
}
- if (eof_reached && ic->internal->packet_buffer) {
+ if (eof_reached) {
int stream_index;
for (stream_index = 0; stream_index < ic->nb_streams; stream_index++) {
+ st = ic->streams[stream_index];
+ avctx = st->internal->avctx;
+ if (!has_codec_parameters(st, NULL)) {
+ AVCodec *codec = find_decoder(ic, st, st->codecpar->codec_id);
+ if (codec && !avctx->codec) {
+ if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : NULL) < 0)
+ av_log(ic, AV_LOG_WARNING,
+ "Failed to open codec in av_find_stream_info\n");
+ }
+ }
+
// EOF already reached while reading the stream above.
// So continue with reoordering DTS with whatever delay we have.
- if (!has_decode_delay_been_guessed(st)) {
+ if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) {
update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer);
}
}
/* if no packet was ever seen, update context now for has_codec_parameters */
if (!st->internal->avctx_inited) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ st->codecpar->format == AV_SAMPLE_FMT_NONE)
+ st->codecpar->format = st->internal->avctx->sample_fmt;
ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
if (ret < 0)
goto find_stream_info_err;
av_codec_set_lowres(st->codec, av_codec_get_lowres(st->internal->avctx));
st->codec->width = st->internal->avctx->width;
st->codec->height = st->internal->avctx->height;
- st->codec->coded_width = st->internal->avctx->coded_width;
- st->codec->coded_height = st->internal->avctx->coded_height;
}
if (st->codec->codec_tag != MKTAG('t','m','c','d'))
memcpy(st->codec->subtitle_header, st->internal->avctx->subtitle_header,
st->codec->subtitle_header_size);
}
+
+ // Fields unavailable in AVCodecParameters
+ st->codec->coded_width = st->internal->avctx->coded_width;
+ st->codec->coded_height = st->internal->avctx->coded_height;
+ st->codec->properties = st->internal->avctx->properties;
FF_ENABLE_DEPRECATION_WARNINGS
#endif