]> git.sesse.net Git - ffmpeg/commitdiff
lavc/aac_ac3_parser: improve the raw AAC file bit rate calculation
authorJun Zhao <barryjzhao@tencent.com>
Sun, 17 May 2020 04:10:05 +0000 (12:10 +0800)
committerJun Zhao <barryjzhao@tencent.com>
Fri, 26 Jun 2020 01:53:36 +0000 (09:53 +0800)
Now we just use one ADTS raw frame to calculate the bit rate, it's
lead to a larger error when get the duration from bit rate, the
improvement cumulate Nth ADTS frames to get the average bit rate.

e,g used the command get the duration like:
ffprobe -show_entries format=duration -i fate-suite/aac/foo.aac

before this improvement dump the duration=2.173935
after this improvement  dump the duration=1.979267

in fact, the real duration can be get by command like:
ffmpeg -i fate-suite/aac/foo.aac -f null /dev/null with time=00:00:01.97

Also update the fate-adtstoasc_ticket3715.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
libavcodec/aac_ac3_parser.c
libavcodec/aac_ac3_parser.h
tests/ref/fate/adtstoasc_ticket3715

index 54e459844f141c8c176ac64a2be4b360a4c4f56b..0746798dabd86e99b13f217c063631594b2e3863 100644 (file)
@@ -97,8 +97,13 @@ get_next:
             avctx->audio_service_type = s->service_type;
         }
 
-        if (avctx->codec_id != AV_CODEC_ID_EAC3)
-            avctx->bit_rate = s->bit_rate;
+        /* Calculate the average bit rate */
+        s->frame_number++;
+        if (avctx->codec_id != AV_CODEC_ID_EAC3) {
+            avctx->bit_rate =
+                (s->last_bit_rate * (s->frame_number -1) + s->bit_rate)/s->frame_number;
+            s->last_bit_rate = avctx->bit_rate;
+        }
     }
 
     return i;
index c2506a5bfd68f1875164c67031ca885e4d1ee22b..b04041f69d202034135812e45951f82f38d0be9e 100644 (file)
@@ -55,6 +55,8 @@ typedef struct AACAC3ParseContext {
     uint64_t state;
 
     int need_next_header;
+    int frame_number;
+    int last_bit_rate;
     enum AVCodecID codec_id;
 } AACAC3ParseContext;
 
index 49fa3eb8d9fe71b7b572cf1d434b3a05ee39514f..3b473ee99e3451b615218aed687f0bac6e750dbe 100644 (file)
@@ -1,4 +1,4 @@
-4110be924e21846d0e174fac679b062e *tests/data/fate/adtstoasc_ticket3715.mov
+3e63cbb6bb6ec756d79fab2632fef305 *tests/data/fate/adtstoasc_ticket3715.mov
 33324 tests/data/fate/adtstoasc_ticket3715.mov
 #extradata 0:        2, 0x00340022
 #tb 0: 1/44100