AVI audio frame duration

How to calculate audio frame duration:
    The WAVEFORMATEX::nBlockAlign and dwSampleSize, dwScale/dwRate in the audio strh chunk decide the audio frame duration.

    There are two audio type: CBR and VBR.
    The dwSampleSize decide which is CBR or VBR.


        If dwSampleSize is nozero, the audio is CBR:
        The audio frame duration = chunk size / dwSampleSize * dwScale / dwRate.

        but I found some streams must calculate on frame, then the audio chunk include multi-frames(if the dwSampleSize is non-zero, then multiple samples of data can be grouped into a single chunk within file):

        The audio frame duration = (chunk size + dwSampleSize - 1) / dwSampleSize * dwScale / dwRate.


        If dwSampleSize is zero, the audio is VBR:
            There are two definition for dwScale/dwRate:
            Microsoft: duration per sample
            Others(avi format for dshow and some doc on net, some streams are true): duration per frame
           
            Duration per sample:
                dwScale: bytes of one sample.
                dwRate: bytes per second.
                nBlockAlign: the largest size of sample.
                The audio frame duration = roundup(chunk size / nBlockAlign) * dwScale / dwRate.
            So nBlockAlign >= dwScale.
            
            Duration per frame:
                dwScale: the number of samples in one frame.
                dwRate: sample rate.
                nBlockAlign: the largest size of frame.
                The audio frame duration = roundup(chunk size / nBlockAlign) * dwScale / dwRate.
            So nBlockAlign >= dwScale(sample size >=1).

        There are same formula what ever the definition of dwScale / dwRate is duration per sample or duration per frame.
        But there are restriction: nBlockAlign >= dwScale. The nBlockAlign is bad value if nBlockAlign < dwScale.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值