diff mbox

[FFmpeg-devel,1/2] hlsenc: use stream's maximum bit rate as fall-back advertised rate

Message ID 20180323224251.29626-1-jeebjp@gmail.com
State New
Headers show

Commit Message

Jan Ekström March 23, 2018, 10:42 p.m. UTC
From: Jan Ekström <jan.ekstrom@aminocom.com>

Enables having proper bit rate values being written into the master
playlist in case of hard-constrained VBR where the maximum bit
rate utilized is known before hand.

Does the same thing as movenc.c, for example.

Signed-off-by: Jan Ekström <jan.ekstrom@aminocom.com>
---
 libavformat/hlsenc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Steven Liu March 24, 2018, 5:26 a.m. UTC | #1
2018-03-24 6:42 GMT+08:00 Jan Ekström <jeebjp@gmail.com>:
> From: Jan Ekström <jan.ekstrom@aminocom.com>
>
> Enables having proper bit rate values being written into the master
> playlist in case of hard-constrained VBR where the maximum bit
> rate utilized is known before hand.
>
> Does the same thing as movenc.c, for example.
>
> Signed-off-by: Jan Ekström <jan.ekstrom@aminocom.com>
> ---
>  libavformat/hlsenc.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index b7c6fbde6a..07569dbff1 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1174,6 +1174,17 @@ static int get_relative_url(const char *master_url, const char *media_url,
>      return 0;
>  }
>
> +static int64_t get_stream_bit_rate(AVStream *stream) {
> +    AVCPBProperties *props = (AVCPBProperties*)av_stream_get_side_data(stream, AV_PKT_DATA_CPB_PROPERTIES, NULL);
> +
> +    if (stream->codecpar->bit_rate)
> +        return stream->codecpar->bit_rate;
> +    else if (props)
> +        return props->max_bitrate;
> +
> +    return 0;
> +}
> +
>  static int create_master_playlist(AVFormatContext *s,
>                                    VariantStream * const input_vs)
>  {
> @@ -1300,9 +1311,9 @@ static int create_master_playlist(AVFormatContext *s,
>
>          bandwidth = 0;
>          if (vid_st)
> -            bandwidth += vid_st->codecpar->bit_rate;
> +            bandwidth += get_stream_bit_rate(vid_st);
>          if (aud_st)
> -            bandwidth += aud_st->codecpar->bit_rate;
> +            bandwidth += get_stream_bit_rate(aud_st);
>          bandwidth += bandwidth / 10;
>
>          ccgroup = NULL;
> --
> 2.14.3
>


LGTM

Thanks
Steven
Jan Ekström March 24, 2018, 11:17 p.m. UTC | #2
On Sat, Mar 24, 2018 at 7:26 AM, Steven Liu <lingjiujianke@gmail.com> wrote:
>
> LGTM
>
> Thanks
> Steven

Cheers,

Pushed with the prefix changed to avformat/hlsenc and made the
av_stream_get_side_data call fit into 80 columns.

Jan
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index b7c6fbde6a..07569dbff1 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1174,6 +1174,17 @@  static int get_relative_url(const char *master_url, const char *media_url,
     return 0;
 }
 
+static int64_t get_stream_bit_rate(AVStream *stream) {
+    AVCPBProperties *props = (AVCPBProperties*)av_stream_get_side_data(stream, AV_PKT_DATA_CPB_PROPERTIES, NULL);
+
+    if (stream->codecpar->bit_rate)
+        return stream->codecpar->bit_rate;
+    else if (props)
+        return props->max_bitrate;
+
+    return 0;
+}
+
 static int create_master_playlist(AVFormatContext *s,
                                   VariantStream * const input_vs)
 {
@@ -1300,9 +1311,9 @@  static int create_master_playlist(AVFormatContext *s,
 
         bandwidth = 0;
         if (vid_st)
-            bandwidth += vid_st->codecpar->bit_rate;
+            bandwidth += get_stream_bit_rate(vid_st);
         if (aud_st)
-            bandwidth += aud_st->codecpar->bit_rate;
+            bandwidth += get_stream_bit_rate(aud_st);
         bandwidth += bandwidth / 10;
 
         ccgroup = NULL;