diff mbox

[FFmpeg-devel,1/7] dashenc: fix bitrate estimation with correct scaling

Message ID 20171026155840.16816-2-pegro@friiks.de
State Accepted
Commit 4723c6226aa1ece4099338cc9b38a9cef4fa4846
Headers show

Commit Message

Peter Große Oct. 26, 2017, 3:58 p.m. UTC
From: Anton Schubert <ischluff@mailbox.org>

Signed-off-by: Anton Schubert <ischluff@mailbox.org>
---
 libavformat/dashenc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Oct. 28, 2017, 12:46 a.m. UTC | #1
On Thu, Oct 26, 2017 at 05:58:34PM +0200, Peter Große wrote:
> From: Anton Schubert <ischluff@mailbox.org>
> 
> Signed-off-by: Anton Schubert <ischluff@mailbox.org>
> ---
>  libavformat/dashenc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 240ff41380..a4b37403d6 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -953,6 +953,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
>  
>      for (i = 0; i < s->nb_streams; i++) {
>          OutputStream *os = &c->streams[i];
> +        AVStream *st = s->streams[i];
>          char filename[1024] = "", full_path[1024], temp_path[1024];
>          int range_length, index_length = 0;
>  
> @@ -1007,7 +1008,9 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
>  
>          if (!os->bit_rate) {
>              // calculate average bitrate of first segment
> -            int64_t bitrate = (int64_t) range_length * 8 * AV_TIME_BASE / (os->max_pts - os->start_pts);
> +            int64_t bitrate = (int64_t) range_length * 8 * AV_TIME_BASE / av_rescale_q(os->max_pts - os->start_pts,
> +                                                                                       st->time_base,
> +                                                                                       AV_TIME_BASE_Q);

this looks like it does scaling twice (AV_TIME_BASE)

is that intended ?

[...]
diff mbox

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 240ff41380..a4b37403d6 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -953,6 +953,7 @@  static int dash_flush(AVFormatContext *s, int final, int stream)
 
     for (i = 0; i < s->nb_streams; i++) {
         OutputStream *os = &c->streams[i];
+        AVStream *st = s->streams[i];
         char filename[1024] = "", full_path[1024], temp_path[1024];
         int range_length, index_length = 0;
 
@@ -1007,7 +1008,9 @@  static int dash_flush(AVFormatContext *s, int final, int stream)
 
         if (!os->bit_rate) {
             // calculate average bitrate of first segment
-            int64_t bitrate = (int64_t) range_length * 8 * AV_TIME_BASE / (os->max_pts - os->start_pts);
+            int64_t bitrate = (int64_t) range_length * 8 * AV_TIME_BASE / av_rescale_q(os->max_pts - os->start_pts,
+                                                                                       st->time_base,
+                                                                                       AV_TIME_BASE_Q);
             if (bitrate >= 0) {
                 os->bit_rate = bitrate;
                 snprintf(os->bandwidth_str, sizeof(os->bandwidth_str),