[FFmpeg-devel] Calculating audio frame rate

Anton Khirnov anton at khirnov.net
Tue Mar 3 13:11:04 EET 2020


Quoting Eran Kornblau (2020-03-03 10:48:31)
> > 
> > 
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Hendrik Leppkes
> > Sent: Tuesday, March 3, 2020 11:08 AM
> > To: FFmpeg development discussions and patches <ffmpeg-devel at ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] Calculating audio frame rate
> > 
> > On Tue, Mar 3, 2020 at 8:22 AM Eran Kornblau <eran.kornblau at kaltura.com> wrote:
> > >
> > > Hi all,
> > >
> > > First, I apologize for asking a question not directly related to ffmpeg development, but hope you can still help me...
> > >
> > > I'm looking for some code to calculate the frame rate of audio, based 
> > > on parameters such as the codec id, sampling rate, channels, codec private data etc.
> > > For example, if the codec is AAC and the sampling rate is 44.1KHz, the 
> > > frame rate would be 44100/1024= ~43 fps (assuming each frame has 1024 
> > > samples, not 960)
> > >
> > > Has anyone ever written/bumped into something that implements this across multiple codecs?
> > >
> > 
> > The frame size of audio codecs is pretty much only dependent on the codec itself, which means you would need to basically hard-code this for every codec you care about.
> > Ultimately I wonder however, when does this information really matter?
> 
> Thanks Hendrik. 
> 
> What I'm trying to do is to estimate the final bitrate of the stream, that includes the muxing overhead.
> I'm generating an HLS stream, and would like to output the right 'bandwidth' attribute for the master m3u8.
> For example, when using MPEG-TS container I may need to add up to 10% to the original bitrate, in order to get 
> the 'real' bitrate of the segments, when using fMP4 it's much less.
> 
> I don't have the audio/video frames at hand, and would like to calculate this estimate based on the media info.
> For example, with video, I'm assuming on average a padding of 1/2 MPEG-TS packet per frame, to that I'm adding 
> the size of the PES header and multiplying everything by 188/184 to account for the MPEG-TS header.
> So, I wrote some formula that depends on - net bitrate, frame rate and segment duration.
> The audio frame rate probably has a tiny effect here, but if there is an easy solution for it, I rather add it.
> 

There is av_get_audio_frame_duration[2]() in libavcodec, but it only
handles some codecs. Not AAC for example, probably because it can have a
bunch of different frame sizes depending on bitstream parameters.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list