diff mbox series

[FFmpeg-devel,4/5] avformat/movenc: use more fall-back values for average bit rate fields

Message ID 20200920170629.26504-5-jeebjp@gmail.com
State Accepted
Headers show
Series avformat/movenc: btrt box support | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Jan Ekström Sept. 20, 2020, 5:06 p.m. UTC
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.
---
 libavformat/movenc.c | 17 +++++++++++++++++
 tests/ref/lavf/ismv  |  6 +++---
 2 files changed, 20 insertions(+), 3 deletions(-)

Comments

Martin Storsjö Sept. 21, 2020, 10:13 a.m. UTC | #1
On Sun, 20 Sep 2020, Jan Ekström wrote:

> 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.
> ---
> 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 9bff2c89ca..0f14e255e9 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -647,6 +647,23 @@ static struct mpeg4_bit_rate_values calculate_mpeg4_bit_rates(MOVTrack *track)
>                                                   NULL);
>     unsigned avg_bit_rate = compute_avg_bitrate(track);
> 
> +    if (!avg_bit_rate) {
> +        // if there is no calculate'able average bit rate, such as

Nit: calculatable?

> +        // in the case of fragmented MP4, utilize the following values
> +        // 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) {
> +            avg_bit_rate = props->avg_bitrate;
> +        } else if (track->par->bit_rate) {
> +            avg_bit_rate = track->par->bit_rate;
> +        } else if (props && props->max_bitrate) {
> +            avg_bit_rate = props->max_bitrate;
> +        }
> +    }

Code looks sensible though, I guess.

// Martin
diff mbox series

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 9bff2c89ca..0f14e255e9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -647,6 +647,23 @@  static struct mpeg4_bit_rate_values calculate_mpeg4_bit_rates(MOVTrack *track)
                                                   NULL);
     unsigned avg_bit_rate = compute_avg_bitrate(track);
 
+    if (!avg_bit_rate) {
+        // if there is no calculate'able average bit rate, such as
+        // in the case of fragmented MP4, utilize the following values
+        // 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) {
+            avg_bit_rate = props->avg_bitrate;
+        } else if (track->par->bit_rate) {
+            avg_bit_rate = track->par->bit_rate;
+        } else if (props && props->max_bitrate) {
+            avg_bit_rate = props->max_bitrate;
+        }
+    }
 
     return (struct mpeg4_bit_rate_values){
         .buffer_size = props ? props->buffer_size / 8 : 0,
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