From 34c61ad383eeb4cf1f90f8928cc3c8fd59b84081 Mon Sep 17 00:00:00 2001 From: Alexander Kojevnikov Date: Wed, 7 Sep 2011 21:29:03 +0800 Subject: [PATCH] Fix duration for certain video files --- src/spek-audio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spek-audio.c b/src/spek-audio.c index 06deb42..b782e0f 100644 --- a/src/spek-audio.c +++ b/src/spek-audio.c @@ -83,7 +83,14 @@ SpekAudioContext * spek_audio_open (const gchar *file_name) { cx->bits_per_sample = cx->codec_context->bits_per_coded_sample; } cx->channels = cx->codec_context->channels; - cx->duration = cx->stream->duration * av_q2d (cx->stream->time_base); + if (cx->stream->duration != AV_NOPTS_VALUE) { + cx->duration = cx->stream->duration * av_q2d (cx->stream->time_base); + } else if (cx->format_context->duration != AV_NOPTS_VALUE) { + cx->duration = cx->format_context->duration / (double) AV_TIME_BASE; + } else { + cx->error = _("Unknown duration"); + return cx; + } if (cx->channels <= 0) { cx->error = _("No audio channels"); return cx;