From d65b697e12f10b29c4b8e147f64ea78cd027aa64 Mon Sep 17 00:00:00 2001 From: pstatic Date: Wed, 21 May 2008 20:03:39 +0000 Subject: [PATCH] Add workaround for what looks like a ffmpeg bug Originally committed to SVN as r2194. --- aegisub/audio_provider_lavc.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aegisub/audio_provider_lavc.cpp b/aegisub/audio_provider_lavc.cpp index 2b0745063..b302553a0 100644 --- a/aegisub/audio_provider_lavc.cpp +++ b/aegisub/audio_provider_lavc.cpp @@ -122,8 +122,15 @@ LAVCAudioProvider::LAVCAudioProvider(Aegisub::String _filename) resample_ratio = (float)sample_rate / (float)codecContext->sample_rate; } - - double length = (double)stream->duration * av_q2d(stream->time_base); + + /* libavcodec seems to give back invalid stream length values for Matroska files. + * As a workaround, we can use the overall file length. + */ + double length; + if(stream->duration == AV_NOPTS_VALUE) + length = (double)lavcfile->fctx->duration / AV_TIME_BASE; + else + length = (double)stream->duration * av_q2d(stream->time_base); num_samples = (int64_t)(length * sample_rate); buffer = (int16_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);