Commit a293549b authored by Stefano Sabatini's avatar Stefano Sabatini

lavf/utils: extend has_codec_parameters() to make it show what info is missing

Improve feedback.
parent 31a192f3
...@@ -2265,30 +2265,40 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) ...@@ -2265,30 +2265,40 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
} }
} }
static int has_codec_parameters(AVStream *st) static int has_codec_parameters(AVStream *st, const char **errmsg_ptr)
{ {
AVCodecContext *avctx = st->codec; AVCodecContext *avctx = st->codec;
int val;
#define FAIL(errmsg) do { \
if (errmsg_ptr) \
*errmsg_ptr = errmsg; \
return 0; \
} while (0)
switch (avctx->codec_type) { switch (avctx->codec_type) {
case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_AUDIO:
val = avctx->sample_rate && avctx->channels;
if (!avctx->frame_size && determinable_frame_size(avctx)) if (!avctx->frame_size && determinable_frame_size(avctx))
return 0; FAIL("unspecified sample size");
if (st->info->found_decoder >= 0 && avctx->sample_fmt == AV_SAMPLE_FMT_NONE) if (st->info->found_decoder >= 0 && avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
return 0; FAIL("unspecified sample format");
if (!avctx->sample_rate)
FAIL("unspecified sample rate");
if (!avctx->channels)
FAIL("unspecified number of channels");
break; break;
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
val = avctx->width; if (!avctx->width)
FAIL("unspecified size");
if (st->info->found_decoder >= 0 && avctx->pix_fmt == PIX_FMT_NONE) if (st->info->found_decoder >= 0 && avctx->pix_fmt == PIX_FMT_NONE)
return 0; FAIL("unspecified pixel format");
break; break;
case AVMEDIA_TYPE_DATA: case AVMEDIA_TYPE_DATA:
if(avctx->codec_id == CODEC_ID_NONE) return 1; if(avctx->codec_id == CODEC_ID_NONE) return 1;
default:
val = 1;
break;
} }
return avctx->codec_id != CODEC_ID_NONE && val != 0;
if (avctx->codec_id == CODEC_ID_NONE)
FAIL("unknown codec");
return 1;
} }
static int has_decode_delay_been_guessed(AVStream *st) static int has_decode_delay_been_guessed(AVStream *st)
...@@ -2345,7 +2355,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option ...@@ -2345,7 +2355,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option
while ((pkt.size > 0 || (!pkt.data && got_picture)) && while ((pkt.size > 0 || (!pkt.data && got_picture)) &&
ret >= 0 && ret >= 0 &&
(!has_codec_parameters(st) || (!has_codec_parameters(st, NULL) ||
!has_decode_delay_been_guessed(st) || !has_decode_delay_been_guessed(st) ||
(!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF))) { (!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF))) {
got_picture = 0; got_picture = 0;
...@@ -2524,7 +2534,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2524,7 +2534,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
: &thread_opt); : &thread_opt);
//try to just open decoders, in case this is enough to get parameters //try to just open decoders, in case this is enough to get parameters
if (!has_codec_parameters(st)) { if (!has_codec_parameters(st, NULL)) {
if (codec && !st->codec->codec) if (codec && !st->codec->codec)
avcodec_open2(st->codec, codec, options ? &options[i] avcodec_open2(st->codec, codec, options ? &options[i]
: &thread_opt); : &thread_opt);
...@@ -2551,7 +2561,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2551,7 +2561,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
int fps_analyze_framecount = 20; int fps_analyze_framecount = 20;
st = ic->streams[i]; st = ic->streams[i];
if (!has_codec_parameters(st)) if (!has_codec_parameters(st, NULL))
break; break;
/* if the timebase is coarse (like the usual millisecond precision /* if the timebase is coarse (like the usual millisecond precision
of mkv), we need to analyze more frames to reliably arrive at of mkv), we need to analyze more frames to reliably arrive at
...@@ -2689,6 +2699,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2689,6 +2699,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
ret = -1; /* we could not have all the codec parameters before EOF */ ret = -1; /* we could not have all the codec parameters before EOF */
for(i=0;i<ic->nb_streams;i++) { for(i=0;i<ic->nb_streams;i++) {
const char *errmsg;
st = ic->streams[i]; st = ic->streams[i];
/* flush the decoders */ /* flush the decoders */
...@@ -2697,7 +2709,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2697,7 +2709,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
err = try_decode_frame(st, &empty_pkt, err = try_decode_frame(st, &empty_pkt,
(options && i < orig_nb_streams) ? (options && i < orig_nb_streams) ?
&options[i] : NULL); &options[i] : NULL);
} while (err > 0 && !has_codec_parameters(st)); } while (err > 0 && !has_codec_parameters(st, NULL));
if (err < 0) { if (err < 0) {
av_log(ic, AV_LOG_INFO, av_log(ic, AV_LOG_INFO,
...@@ -2705,11 +2717,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -2705,11 +2717,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
} }
} }
if (!has_codec_parameters(st)){ if (!has_codec_parameters(st, &errmsg)) {
char buf[256]; char buf[256];
avcodec_string(buf, sizeof(buf), st->codec, 0); avcodec_string(buf, sizeof(buf), st->codec, 0);
av_log(ic, AV_LOG_WARNING, av_log(ic, AV_LOG_WARNING,
"Could not find codec parameters (%s)\n", buf); "Could not find codec parameters for stream (%s): %s\n",
buf, errmsg);
} else { } else {
ret = 0; ret = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment