[FFmpeg-devel] [PATCH] avcodec/utils: Add case for mp3 to av_get_audio_frame_duration()

Michael Niedermayer michaelni at gmx.at
Fri Jan 1 17:43:01 CET 2016


From: Michael Niedermayer <michael at niedermayer.cc>

This is not guranteed to be correct but only the encoder or the packet headers
can really provide the correct value. And before the first packet there is
no alternative to receiving the value from the encoder by some means

other codecs like AAC are still missing and are left for voluteers

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/utils.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4b4aea0..6ed47ef 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3042,6 +3042,12 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
         if (id == AV_CODEC_ID_TTA)
             return 256 * sr / 245;
 
+        // When frame_bytes is set then the headers can be parsed to find the
+        // frame size
+        if (id == AV_CODEC_ID_MP3 && !frame_bytes) {
+            return sr <= 24000 ? 576 : 1152;
+        }
+
         if (ch > 0) {
             /* calc from sample rate and channels */
             if (id == AV_CODEC_ID_BINKAUDIO_DCT)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list