diff mbox

[FFmpeg-devel] avformat/hlsenc: fix duration wrong when no pkt duration

Message ID 20170313091247.19031-1-lq@chinaffmpeg.org
State Accepted
Commit e90ad882819cc46add0ea5ad2cef81490cef96c4
Headers show

Commit Message

Steven Liu March 13, 2017, 9:12 a.m. UTC
when cannot get pkt duration, hlsenc segments duration will
be set to 0, this patch can fix it.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Steven Liu March 14, 2017, 11:38 p.m. UTC | #1
2017-03-13 17:12 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:

> when cannot get pkt duration, hlsenc segments duration will
> be set to 0, this patch can fix it.
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 5df2514..d6f0631 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1354,7 +1354,12 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>                                         * st->time_base.num /
> st->time_base.den;
>              hls->dpp = (double)(pkt->duration) * st->time_base.num /
> st->time_base.den;
>          } else {
> -            hls->duration += (double)(pkt->duration) * st->time_base.num
> / st->time_base.den;
> +            if (pkt->duration) {
> +                hls->duration += (double)(pkt->duration) *
> st->time_base.num / st->time_base.den;
> +            } else {
> +                av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the
> hls segment duration will not precise\n");
> +                hls->duration = (double)(pkt->pts - hls->end_pts) *
> st->time_base.num / st->time_base.den;
> +            }
>          }
>
>      }
> --
> 2.10.1.382.ga23ca1b.dirty
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

applied!
Alexander Strasser March 15, 2017, 10:24 p.m. UTC | #2
Hi!

On 2017-03-13 17:12 +0800, Steven Liu wrote:
> when cannot get pkt duration, hlsenc segments duration will
> be set to 0, this patch can fix it.
> 
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 5df2514..d6f0631 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1354,7 +1354,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>                                         * st->time_base.num / st->time_base.den;
>              hls->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;
>          } else {
> -            hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
> +            if (pkt->duration) {
> +                hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
> +            } else {
> +                av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");
                                                                                                        ^

There is a word missing in the log message: "be"

For a warning it might have been better to use more natural language and to convey a bit more information:

  "Packet duration is 0. Trying to compensate. Segment duration may not be accurate.\n"



> +                hls->duration = (double)(pkt->pts - hls->end_pts) * st->time_base.num / st->time_base.den;
> +            }
>          }
>  
>      }


  I am sorry to comment after you pushed already. Anyway my remarks are only 
cosmetics and not so important. I did not investigate the issue at all.


Thank you,
  Alexander
Steven Liu March 16, 2017, 2:49 a.m. UTC | #3
2017-03-16 6:24 GMT+08:00 Alexander Strasser <eclipse7@gmx.net>:

> Hi!
>
> On 2017-03-13 17:12 +0800, Steven Liu wrote:
> > when cannot get pkt duration, hlsenc segments duration will
> > be set to 0, this patch can fix it.
> >
> > Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> > ---
> >  libavformat/hlsenc.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index 5df2514..d6f0631 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -1354,7 +1354,12 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >                                         * st->time_base.num /
> st->time_base.den;
> >              hls->dpp = (double)(pkt->duration) * st->time_base.num /
> st->time_base.den;
> >          } else {
> > -            hls->duration += (double)(pkt->duration) *
> st->time_base.num / st->time_base.den;
> > +            if (pkt->duration) {
> > +                hls->duration += (double)(pkt->duration) *
> st->time_base.num / st->time_base.den;
> > +            } else {
> > +                av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the
> hls segment duration will not precise\n");
>
>                               ^
>
> There is a word missing in the log message: "be"
>
> For a warning it might have been better to use more natural language and
> to convey a bit more information:
>
>   "Packet duration is 0. Trying to compensate. Segment duration may not be
> accurate.\n"
>
>
>
> > +                hls->duration = (double)(pkt->pts - hls->end_pts) *
> st->time_base.num / st->time_base.den;
> > +            }
> >          }
> >
> >      }
>
>
>   I am sorry to comment after you pushed already. Anyway my remarks are
> only
> cosmetics and not so important. I did not investigate the issue at all.
>
>
> Thank you,
>   Alexander
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


Hi Alexander,

      Your suggestion is right, i will merge it in next commit.



Thanks

Steven
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 5df2514..d6f0631 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1354,7 +1354,12 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
                                        * st->time_base.num / st->time_base.den;
             hls->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den;
         } else {
-            hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
+            if (pkt->duration) {
+                hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den;
+            } else {
+                av_log(s, AV_LOG_WARNING, "pkt->duration = 0, maybe the hls segment duration will not precise\n");
+                hls->duration = (double)(pkt->pts - hls->end_pts) * st->time_base.num / st->time_base.den;
+            }
         }
 
     }