[FFmpeg-cvslog] avformat/movenc: use more fall-back values for average bit rate fields

Jan Ekström git at videolan.org
Tue Sep 22 18:34:40 EEST 2020


ffmpeg | branch: master | Jan Ekström <jeebjp at gmail.com> | Sun Sep 20 18:14:48 2020 +0300| [308882d9f2c6cc7159aba2ca7cdc99d07a9b531e] | committer: Jan Ekström

avformat/movenc: use more fall-back values for average bit rate fields

If the average bit rate cannot be calculated, such as in the case
of streamed fragmented mp4, utilize various available parameters
in priority order.

Tests are updated where the esds or btrt or ISML manifest boxes'
output changes.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=308882d9f2c6cc7159aba2ca7cdc99d07a9b531e
---

 libavformat/movenc.c | 17 +++++++++++++++++
 tests/ref/lavf/ismv  |  6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 76fb251fa8..860e331b19 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -648,6 +648,23 @@ static struct mpeg4_bit_rate_values calculate_mpeg4_bit_rates(MOVTrack *track)
     struct mpeg4_bit_rate_values bit_rates = { 0 };
 
     bit_rates.avg_bit_rate = compute_avg_bitrate(track);
+    if (!bit_rates.avg_bit_rate) {
+        // if the average bit rate cannot be calculated at this point, such as
+        // in the case of fragmented MP4, utilize the following values as
+        // fall-back in priority order:
+        //
+        // 1. average bit rate property
+        // 2. bit rate (usually average over the whole clip)
+        // 3. maximum bit rate property
+
+        if (props && props->avg_bitrate) {
+            bit_rates.avg_bit_rate = props->avg_bitrate;
+        } else if (track->par->bit_rate) {
+            bit_rates.avg_bit_rate = track->par->bit_rate;
+        } else if (props && props->max_bitrate) {
+            bit_rates.avg_bit_rate = props->max_bitrate;
+        }
+    }
 
     // (FIXME should be max rate in any 1 sec window)
     bit_rates.max_bit_rate = FFMAX(track->par->bit_rate,
diff --git a/tests/ref/lavf/ismv b/tests/ref/lavf/ismv
index e7361705fa..ac7f72ba33 100644
--- a/tests/ref/lavf/ismv
+++ b/tests/ref/lavf/ismv
@@ -1,9 +1,9 @@
-4c6bc5ac805a76bbbd886a69d2e61554 *tests/data/lavf/lavf.ismv
+48fb8d7a5d19bd60f3a49ccf4b7d6593 *tests/data/lavf/lavf.ismv
 313169 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0x9d9a638a
-18678627921460328ea3fed238d0d57d *tests/data/lavf/lavf.ismv
+d19cd8e310a2e94fe0a0d11c5dc29217 *tests/data/lavf/lavf.ismv
 322075 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0xe8130120
-b9a858caf55b1eff2273e746e9f72dc4 *tests/data/lavf/lavf.ismv
+3b6023766845b51b075aed474c00f73c *tests/data/lavf/lavf.ismv
 312546 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0x9d9a638a



More information about the ffmpeg-cvslog mailing list