[FFmpeg-devel] Patch to WAV to accurately report duration

Justin Ruggles justin.ruggles
Sat Jan 15 17:34:51 CET 2011


On 01/15/2011 05:16 AM, Frank Barchard wrote:

> On Wed, Jan 12, 2011 at 3:21 PM, Michael Niedermayer <michaelni at gmx.at>wrote:
> 
>> On Wed, Jan 12, 2011 at 01:59:09PM -0800, Frank Barchard wrote:
>>> On Wed, Jan 12, 2011 at 8:04 AM, Michael Niedermayer <michaelni at gmx.at
>>> wrote:
>>>
>>>> On Mon, Jan 10, 2011 at 06:51:18PM -0800, Frank Barchard wrote:
>>>>> Patch to accurately report duration of a WAV.
>>>>
>>>> -    } else
>>>>> +    } else {
>>>>>          wav->data_end= url_ftell(pb) + size;
>>>>> +        st->nb_frames = size /
>>>>> +            (st->codec->channels * (st->codec->bits_per_coded_sample
>>>>
>>>> 3));
>>>>> +        st->duration = st->codec->frame_size ?
>>>>> +            st->nb_frames * st->codec->frame_size : st->nb_frames;
>>>>> +    }
>>>>
>>>> this is wrong, iam not even sure its guranteed to work with PCM
>>>>
>>>
>>> The patch has certainly worked for 8-bit, 16-bit, and 24-bit wav files
>> that
>>> we've tested.  With the patch, the number of frames is reported as
>> exactly
>>> right (as compared with the results returned by Apple's 'afinfo' tool).
>>>  Without the patch it is not accurate.
>>
>> try it with any VBR codec
>>
> 
> done.
> 
> This patch corrects VBR codecs, falling back on the estimate if
> bits_per_coded_sample is not set.
> 
> Also tested with mulaw and alaw that are fixed bits per sample.
> The intent of the math is to allow bits per sample that are not multples of
> 8
> 
> diff -wurp -N orig/libavformat/wav.c ffmpeg-mt/libavformat/wav.c
> --- orig/libavformat/wav.c      2011-01-14 12:19:43.446029200 -0800
> +++ ffmpeg-mt/libavformat/wav.c 2011-01-14 12:25:22.181032500 -0800
> @@ -231,8 +231,15 @@ static int wav_read_header(AVFormatConte
>          return -1;
>      if (!size) {
>          wav->data_end = INT64_MAX;
> -    } else
> +    } else {
>          wav->data_end= url_ftell(pb) + size;
> +        if (st->codec->channels * st->codec->bits_per_coded_sample) {
> +            st->nb_frames = (size << 3) /
> +                (st->codec->channels * st->codec->bits_per_coded_sample);
> +            st->duration = st->codec->frame_size ?
> +                st->nb_frames * st->codec->frame_size : st->nb_frames;
> +        }
> +    }





More information about the ffmpeg-devel mailing list