diff mbox series

[FFmpeg-devel,v1] avfilter/src_movie: Fix the loop function of dynamic logo

Message ID 20200317105501.2847-1-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v1] avfilter/src_movie: Fix the loop function of dynamic logo | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Lance Wang March 17, 2020, 10:55 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

The following command will attempt to create the input and overlay test sequence for you.
./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv

Please try with below command and compare the final output.
./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
 enable='between(t,0,25)" test.mkv

 Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/src_movie.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Lance Wang April 8, 2020, 1:58 p.m. UTC | #1
ping this patch for review.

On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> The following command will attempt to create the input and overlay test sequence for you.
> ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> 
> Please try with below command and compare the final output.
> ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>  enable='between(t,0,25)" test.mkv
> 
>  Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/src_movie.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> index 79423a8..2327046 100644
> --- a/libavfilter/src_movie.c
> +++ b/libavfilter/src_movie.c
> @@ -68,6 +68,8 @@ typedef struct MovieContext {
>      int loop_count;
>      int64_t discontinuity_threshold;
>      int64_t ts_offset;
> +    int64_t last_pts;
> +    int64_t last_loop_pts;
>  
>      AVFormatContext *format_ctx;
>      int eof;
> @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>          movie->st[i].done = 0;
>      }
>      movie->eof = 0;
> +    movie->last_loop_pts = movie->last_pts;
>      return 0;
>  }
>  
> @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>      if (frame->pts != AV_NOPTS_VALUE) {
>          if (movie->ts_offset)
>              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
> +        if (movie->last_loop_pts)
> +            frame->pts += movie->last_loop_pts;
>          if (st->discontinuity_threshold) {
>              if (st->last_pts != AV_NOPTS_VALUE) {
>                  int64_t diff = frame->pts - st->last_pts;
> @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>                  }
>              }
>          }
> +        movie->last_pts =
>          st->last_pts = frame->pts;
>      }
>      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> -- 
> 2.9.5
>
Lance Wang May 3, 2020, 12:55 p.m. UTC | #2
On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> The following command will attempt to create the input and overlay test sequence for you.
> ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> 
> Please try with below command and compare the final output.
> ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>  enable='between(t,0,25)" test.mkv
> 
>  Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/src_movie.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> index 79423a8..2327046 100644
> --- a/libavfilter/src_movie.c
> +++ b/libavfilter/src_movie.c
> @@ -68,6 +68,8 @@ typedef struct MovieContext {
>      int loop_count;
>      int64_t discontinuity_threshold;
>      int64_t ts_offset;
> +    int64_t last_pts;
> +    int64_t last_loop_pts;
>  
>      AVFormatContext *format_ctx;
>      int eof;
> @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>          movie->st[i].done = 0;
>      }
>      movie->eof = 0;
> +    movie->last_loop_pts = movie->last_pts;
>      return 0;
>  }
>  
> @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>      if (frame->pts != AV_NOPTS_VALUE) {
>          if (movie->ts_offset)
>              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
> +        if (movie->last_loop_pts)
> +            frame->pts += movie->last_loop_pts;
>          if (st->discontinuity_threshold) {
>              if (st->last_pts != AV_NOPTS_VALUE) {
>                  int64_t diff = frame->pts - st->last_pts;
> @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>                  }
>              }
>          }
> +        movie->last_pts =
>          st->last_pts = frame->pts;
>      }
>      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> -- 
> 2.9.5
> 

ping
Marton Balint May 3, 2020, 5:10 p.m. UTC | #3
On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:

> On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
>> From: Limin Wang <lance.lmwang@gmail.com>
>> 
>> The following command will attempt to create the input and overlay test sequence for you.
>> ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
>> ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
>> 
>> Please try with below command and compare the final output.
>> ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>>  enable='between(t,0,25)" test.mkv
>>
>>  Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.

Why?

Thanks,
Marton

>> 
>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> ---
>>  libavfilter/src_movie.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>> 
>> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
>> index 79423a8..2327046 100644
>> --- a/libavfilter/src_movie.c
>> +++ b/libavfilter/src_movie.c
>> @@ -68,6 +68,8 @@ typedef struct MovieContext {
>>      int loop_count;
>>      int64_t discontinuity_threshold;
>>      int64_t ts_offset;
>> +    int64_t last_pts;
>> +    int64_t last_loop_pts;
>>
>>      AVFormatContext *format_ctx;
>>      int eof;
>> @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>>          movie->st[i].done = 0;
>>      }
>>      movie->eof = 0;
>> +    movie->last_loop_pts = movie->last_pts;
>>      return 0;
>>  }
>> 
>> @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>>      if (frame->pts != AV_NOPTS_VALUE) {
>>          if (movie->ts_offset)
>>              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
>> +        if (movie->last_loop_pts)
>> +            frame->pts += movie->last_loop_pts;
>>          if (st->discontinuity_threshold) {
>>              if (st->last_pts != AV_NOPTS_VALUE) {
>>                  int64_t diff = frame->pts - st->last_pts;
>> @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>>                  }
>>              }
>>          }
>> +        movie->last_pts =
>>          st->last_pts = frame->pts;
>>      }
>>      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
>> -- 
>> 2.9.5
>> 
>
> ping
>
> -- 
> Thanks,
> Limin Wang
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lance Wang May 4, 2020, 1:23 p.m. UTC | #4
On Sun, May 03, 2020 at 07:10:07PM +0200, Marton Balint wrote:
> 
> 
> On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:
> 
> > On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
> > > From: Limin Wang <lance.lmwang@gmail.com>
> > > 
> > > The following command will attempt to create the input and overlay test sequence for you.
> > > ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> > > ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> > > 
> > > Please try with below command and compare the final output.
> > > ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
> > >  enable='between(t,0,25)" test.mkv
> > > 
> > >  Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.
> 
> Why?

I haven't clear about the question yet, if you try to insert a dynamic logo
repeatly, without the patch, the dynamic logo will not overlay repeatly.


> 
> Thanks,
> Marton
> 
> > > 
> > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > > ---
> > >  libavfilter/src_movie.c | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > > 
> > > diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> > > index 79423a8..2327046 100644
> > > --- a/libavfilter/src_movie.c
> > > +++ b/libavfilter/src_movie.c
> > > @@ -68,6 +68,8 @@ typedef struct MovieContext {
> > >      int loop_count;
> > >      int64_t discontinuity_threshold;
> > >      int64_t ts_offset;
> > > +    int64_t last_pts;
> > > +    int64_t last_loop_pts;
> > > 
> > >      AVFormatContext *format_ctx;
> > >      int eof;
> > > @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
> > >          movie->st[i].done = 0;
> > >      }
> > >      movie->eof = 0;
> > > +    movie->last_loop_pts = movie->last_pts;
> > >      return 0;
> > >  }
> > > 
> > > @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > >      if (frame->pts != AV_NOPTS_VALUE) {
> > >          if (movie->ts_offset)
> > >              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
> > > +        if (movie->last_loop_pts)
> > > +            frame->pts += movie->last_loop_pts;
> > >          if (st->discontinuity_threshold) {
> > >              if (st->last_pts != AV_NOPTS_VALUE) {
> > >                  int64_t diff = frame->pts - st->last_pts;
> > > @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > >                  }
> > >              }
> > >          }
> > > +        movie->last_pts =
> > >          st->last_pts = frame->pts;
> > >      }
> > >      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> > > -- 
> > > 2.9.5
> > > 
> > 
> > ping
> > 
> > -- 
> > Thanks,
> > Limin Wang
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Marton Balint May 4, 2020, 7:34 p.m. UTC | #5
On Mon, 4 May 2020, lance.lmwang@gmail.com wrote:

> On Sun, May 03, 2020 at 07:10:07PM +0200, Marton Balint wrote:
>> 
>> 
>> On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:
>> 
>> > On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
>> > > From: Limin Wang <lance.lmwang@gmail.com>
>> > > 
>> > > The following command will attempt to create the input and overlay test sequence for you.
>> > > ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
>> > > ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
>> > > 
>> > > Please try with below command and compare the final output.
>> > > ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>> > >  enable='between(t,0,25)" test.mkv
>> > > 
>> > >  Without the patch applied, the overlay will repeat the last frame in overlay.mkv after the first loop.
>> 
>> Why?
>
> I haven't clear about the question yet, if you try to insert a dynamic logo
> repeatly, without the patch, the dynamic logo will not overlay repeatly.

But why is that? You explained what this patch fixes. But you have not 
explained why the error is happening and what goes wrong in the current 
code. I am asking, because there is some timestamp discontinuity handling 
in src_movie, shouldn't that handle the timestamp discontinuity caused by 
looping?

Thanks,
Marton

  > >
>> 
>> Thanks,
>> Marton
>> 
>> > > 
>> > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> > > ---
>> > >  libavfilter/src_movie.c | 6 ++++++
>> > >  1 file changed, 6 insertions(+)
>> > > 
>> > > diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
>> > > index 79423a8..2327046 100644
>> > > --- a/libavfilter/src_movie.c
>> > > +++ b/libavfilter/src_movie.c
>> > > @@ -68,6 +68,8 @@ typedef struct MovieContext {
>> > >      int loop_count;
>> > >      int64_t discontinuity_threshold;
>> > >      int64_t ts_offset;
>> > > +    int64_t last_pts;
>> > > +    int64_t last_loop_pts;
>> > > 
>> > >      AVFormatContext *format_ctx;
>> > >      int eof;
>> > > @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>> > >          movie->st[i].done = 0;
>> > >      }
>> > >      movie->eof = 0;
>> > > +    movie->last_loop_pts = movie->last_pts;
>> > >      return 0;
>> > >  }
>> > > 
>> > > @@ -565,6 +568,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>> > >      if (frame->pts != AV_NOPTS_VALUE) {
>> > >          if (movie->ts_offset)
>> > >              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
>> > > +        if (movie->last_loop_pts)
>> > > +            frame->pts += movie->last_loop_pts;
>> > >          if (st->discontinuity_threshold) {
>> > >              if (st->last_pts != AV_NOPTS_VALUE) {
>> > >                  int64_t diff = frame->pts - st->last_pts;
>> > > @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>> > >                  }
>> > >              }
>> > >          }
>> > > +        movie->last_pts =
>> > >          st->last_pts = frame->pts;
>> > >      }
>> > >      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
>> > > -- 
>> > > 2.9.5
>> > > 
>> > 
>> > ping
>> > 
>> > -- 
>> > Thanks,
>> > Limin Wang
>> > _______________________________________________
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel@ffmpeg.org
>> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > 
>> > To unsubscribe, visit link above, or email
>> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
> -- 
> Thanks,
> Limin Wang
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lance Wang May 5, 2020, 12:29 a.m. UTC | #6
On Mon, May 04, 2020 at 09:34:02PM +0200, Marton Balint wrote:
> 
> 
> On Mon, 4 May 2020, lance.lmwang@gmail.com wrote:
> 
> > On Sun, May 03, 2020 at 07:10:07PM +0200, Marton Balint wrote:
> > > 
> > > 
> > > On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:
> > > 
> > > > On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
> > > > > From: Limin Wang <lance.lmwang@gmail.com>
> > > > > > > The following command will attempt to create the input and
> > > overlay test sequence for you.
> > > > > ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> > > > > ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> > > > > > > Please try with below command and compare the final output.
> > > > > ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
> > > > >  enable='between(t,0,25)" test.mkv
> > > > > > >  Without the patch applied, the overlay will repeat the last
> > > frame in overlay.mkv after the first loop.
> > > 
> > > Why?
> > 
> > I haven't clear about the question yet, if you try to insert a dynamic logo
> > repeatly, without the patch, the dynamic logo will not overlay repeatly.
> 
> But why is that? You explained what this patch fixes. But you have not
> explained why the error is happening and what goes wrong in the current
> code. I am asking, because there is some timestamp discontinuity handling in
> src_movie, shouldn't that handle the timestamp discontinuity caused by
> looping?

When the dynamic logo is end for reading, the pts will not accumulate with the
first loop, so it'll failed to overlay.

> 
> Thanks,
> Marton
> 
>  > >
> > > 
> > > Thanks,
> > > Marton
> > > 
> > > > > > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > > > > ---
> > > > >  libavfilter/src_movie.c | 6 ++++++
> > > > >  1 file changed, 6 insertions(+)
> > > > > > > diff --git a/libavfilter/src_movie.c
> > > b/libavfilter/src_movie.c
> > > > > index 79423a8..2327046 100644
> > > > > --- a/libavfilter/src_movie.c
> > > > > +++ b/libavfilter/src_movie.c
> > > > > @@ -68,6 +68,8 @@ typedef struct MovieContext {
> > > > >      int loop_count;
> > > > >      int64_t discontinuity_threshold;
> > > > >      int64_t ts_offset;
> > > > > +    int64_t last_pts;
> > > > > +    int64_t last_loop_pts;
> > > > > > >      AVFormatContext *format_ctx;
> > > > >      int eof;
> > > > > @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
> > > > >          movie->st[i].done = 0;
> > > > >      }
> > > > >      movie->eof = 0;
> > > > > +    movie->last_loop_pts = movie->last_pts;
> > > > >      return 0;
> > > > >  }
> > > > > > > @@ -565,6 +568,8 @@ static int
> > > movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > > > >      if (frame->pts != AV_NOPTS_VALUE) {
> > > > >          if (movie->ts_offset)
> > > > >              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
> > > > > +        if (movie->last_loop_pts)
> > > > > +            frame->pts += movie->last_loop_pts;
> > > > >          if (st->discontinuity_threshold) {
> > > > >              if (st->last_pts != AV_NOPTS_VALUE) {
> > > > >                  int64_t diff = frame->pts - st->last_pts;
> > > > > @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > > > >                  }
> > > > >              }
> > > > >          }
> > > > > +        movie->last_pts =
> > > > >          st->last_pts = frame->pts;
> > > > >      }
> > > > >      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> > > > > -- > > 2.9.5
> > > > > > > ping
> > > > > -- > Thanks,
> > > > Limin Wang
> > > > _______________________________________________
> > > > ffmpeg-devel mailing list
> > > > ffmpeg-devel@ffmpeg.org
> > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > > > To unsubscribe, visit link above, or email
> > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > 
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > 
> > -- 
> > Thanks,
> > Limin Wang
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Marton Balint May 6, 2020, 7:43 p.m. UTC | #7
On Tue, 5 May 2020, lance.lmwang@gmail.com wrote:

> On Mon, May 04, 2020 at 09:34:02PM +0200, Marton Balint wrote:
>> 
>> 
>> On Mon, 4 May 2020, lance.lmwang@gmail.com wrote:
>> 
>> > On Sun, May 03, 2020 at 07:10:07PM +0200, Marton Balint wrote:
>> > > 
>> > > 
>> > > On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:
>> > > 
>> > > > On Tue, Mar 17, 2020 at 06:55:00PM +0800, lance.lmwang@gmail.com wrote:
>> > > > > From: Limin Wang <lance.lmwang@gmail.com>
>> > > > > > > The following command will attempt to create the input and
>> > > overlay test sequence for you.
>> > > > > ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
>> > > > > ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
>> > > > > > > Please try with below command and compare the final output.
>> > > > > ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
>> > > > >  enable='between(t,0,25)" test.mkv
>> > > > > > >  Without the patch applied, the overlay will repeat the last
>> > > frame in overlay.mkv after the first loop.
>> > > 
>> > > Why?
>> > 
>> > I haven't clear about the question yet, if you try to insert a dynamic logo
>> > repeatly, without the patch, the dynamic logo will not overlay repeatly.
>> 
>> But why is that? You explained what this patch fixes. But you have not
>> explained why the error is happening and what goes wrong in the current
>> code. I am asking, because there is some timestamp discontinuity handling in
>> src_movie, shouldn't that handle the timestamp discontinuity caused by
>> looping?
>
> When the dynamic logo is end for reading, the pts will not accumulate with the
> first loop, so it'll failed to overlay.

That is intentional, that is how the src_movie works. It passes on source 
pts values by default. If you want discontinuty handling to kick in either 
for seeking or looping, you should use the discontinuity option.

E.g:

./ffmpeg -y -filter_complex 
"movie=./input.mkv[main];movie=./overlay.mkv:loop=5:discontinuity=0.04[overlay];[main][overlay]overlay=10:10:enable='between(t,0,25)" 
test.mkv

So this patch is wrong I am afraid.

Regards,
Marton


>
>> 
>> Thanks,
>> Marton
>>
>>  > >
>> > > 
>> > > Thanks,
>> > > Marton
>> > > 
>> > > > > > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> > > > > ---
>> > > > >  libavfilter/src_movie.c | 6 ++++++
>> > > > >  1 file changed, 6 insertions(+)
>> > > > > > > diff --git a/libavfilter/src_movie.c
>> > > b/libavfilter/src_movie.c
>> > > > > index 79423a8..2327046 100644
>> > > > > --- a/libavfilter/src_movie.c
>> > > > > +++ b/libavfilter/src_movie.c
>> > > > > @@ -68,6 +68,8 @@ typedef struct MovieContext {
>> > > > >      int loop_count;
>> > > > >      int64_t discontinuity_threshold;
>> > > > >      int64_t ts_offset;
>> > > > > +    int64_t last_pts;
>> > > > > +    int64_t last_loop_pts;
>> > > > > > >      AVFormatContext *format_ctx;
>> > > > >      int eof;
>> > > > > @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
>> > > > >          movie->st[i].done = 0;
>> > > > >      }
>> > > > >      movie->eof = 0;
>> > > > > +    movie->last_loop_pts = movie->last_pts;
>> > > > >      return 0;
>> > > > >  }
>> > > > > > > @@ -565,6 +568,8 @@ static int
>> > > movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>> > > > >      if (frame->pts != AV_NOPTS_VALUE) {
>> > > > >          if (movie->ts_offset)
>> > > > >              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
>> > > > > +        if (movie->last_loop_pts)
>> > > > > +            frame->pts += movie->last_loop_pts;
>> > > > >          if (st->discontinuity_threshold) {
>> > > > >              if (st->last_pts != AV_NOPTS_VALUE) {
>> > > > >                  int64_t diff = frame->pts - st->last_pts;
>> > > > > @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
>> > > > >                  }
>> > > > >              }
>> > > > >          }
>> > > > > +        movie->last_pts =
>> > > > >          st->last_pts = frame->pts;
>> > > > >      }
>> > > > >      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
>> > > > > -- > > 2.9.5
>> > > > > > > ping
>> > > > > -- > Thanks,
>> > > > Limin Wang
>> > > > _______________________________________________
>> > > > ffmpeg-devel mailing list
>> > > > ffmpeg-devel@ffmpeg.org
>> > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > > > > To unsubscribe, visit link above, or email
>> > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> > > _______________________________________________
>> > > ffmpeg-devel mailing list
>> > > ffmpeg-devel@ffmpeg.org
>> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > > 
>> > > To unsubscribe, visit link above, or email
>> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> > 
>> > -- 
>> > Thanks,
>> > Limin Wang
>> > _______________________________________________
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel@ffmpeg.org
>> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > 
>> > To unsubscribe, visit link above, or email
>> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
> -- 
> Thanks,
> Limin Wang
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lance Wang May 6, 2020, 11:08 p.m. UTC | #8
On Wed, May 06, 2020 at 09:43:32PM +0200, Marton Balint wrote:
> 
> 
> On Tue, 5 May 2020, lance.lmwang@gmail.com wrote:
> 
> > On Mon, May 04, 2020 at 09:34:02PM +0200, Marton Balint wrote:
> > > 
> > > 
> > > On Mon, 4 May 2020, lance.lmwang@gmail.com wrote:
> > > 
> > > > On Sun, May 03, 2020 at 07:10:07PM +0200, Marton Balint wrote:
> > > > > > > > > On Sun, 3 May 2020, lance.lmwang@gmail.com wrote:
> > > > > > > > On Tue, Mar 17, 2020 at 06:55:00PM +0800,
> > > lance.lmwang@gmail.com wrote:
> > > > > > > From: Limin Wang <lance.lmwang@gmail.com>
> > > > > > > > > The following command will attempt to create the input and
> > > > > overlay test sequence for you.
> > > > > > > ./ffmpeg -f lavfi  -i color=white:duration=100:r=25:size=1280x720  input.mkv
> > > > > > > ./ffmpeg -f lavfi -i "testsrc=duration=5:size=320x240:rate=25" overlay.mkv
> > > > > > > > > Please try with below command and compare the final output.
> > > > > > > ./ffmpeg -y -filter_complex "movie=./input.mkv,setpts=PTS-STARTPTS[main];movie=./overlay.mkv:loop=5,setpts=PTS-STARTPTS[overlay];[main][overlay]overlay=10:10:
> > > > > > >  enable='between(t,0,25)" test.mkv
> > > > > > > > >  Without the patch applied, the overlay will repeat the last
> > > > > frame in overlay.mkv after the first loop.
> > > > > > > Why?
> > > > > I haven't clear about the question yet, if you try to insert a
> > > dynamic logo
> > > > repeatly, without the patch, the dynamic logo will not overlay repeatly.
> > > 
> > > But why is that? You explained what this patch fixes. But you have not
> > > explained why the error is happening and what goes wrong in the current
> > > code. I am asking, because there is some timestamp discontinuity handling in
> > > src_movie, shouldn't that handle the timestamp discontinuity caused by
> > > looping?
> > 
> > When the dynamic logo is end for reading, the pts will not accumulate with the
> > first loop, so it'll failed to overlay.
> 
> That is intentional, that is how the src_movie works. It passes on source
> pts values by default. If you want discontinuty handling to kick in either
> for seeking or looping, you should use the discontinuity option.
> 
> E.g:
> 
> ./ffmpeg -y -filter_complex "movie=./input.mkv[main];movie=./overlay.mkv:loop=5:discontinuity=0.04[overlay];[main][overlay]overlay=10:10:enable='between(t,0,25)"
> test.mkv
> 
> So this patch is wrong I am afraid.

Thanks for the comments, I'm clear for the discontinuity flag now. Please ignore 
the patch. 


> 
> Regards,
> Marton
> 
> 
> > 
> > > 
> > > Thanks,
> > > Marton
> > > 
> > >  > >
> > > > > > > Thanks,
> > > > > Marton
> > > > > > > > > > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > > > > > > ---
> > > > > > >  libavfilter/src_movie.c | 6 ++++++
> > > > > > >  1 file changed, 6 insertions(+)
> > > > > > > > > diff --git a/libavfilter/src_movie.c
> > > > > b/libavfilter/src_movie.c
> > > > > > > index 79423a8..2327046 100644
> > > > > > > --- a/libavfilter/src_movie.c
> > > > > > > +++ b/libavfilter/src_movie.c
> > > > > > > @@ -68,6 +68,8 @@ typedef struct MovieContext {
> > > > > > >      int loop_count;
> > > > > > >      int64_t discontinuity_threshold;
> > > > > > >      int64_t ts_offset;
> > > > > > > +    int64_t last_pts;
> > > > > > > +    int64_t last_loop_pts;
> > > > > > > > >      AVFormatContext *format_ctx;
> > > > > > >      int eof;
> > > > > > > @@ -455,6 +457,7 @@ static int rewind_file(AVFilterContext *ctx)
> > > > > > >          movie->st[i].done = 0;
> > > > > > >      }
> > > > > > >      movie->eof = 0;
> > > > > > > +    movie->last_loop_pts = movie->last_pts;
> > > > > > >      return 0;
> > > > > > >  }
> > > > > > > > > @@ -565,6 +568,8 @@ static int
> > > > > movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > > > > > >      if (frame->pts != AV_NOPTS_VALUE) {
> > > > > > >          if (movie->ts_offset)
> > > > > > >              frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
> > > > > > > +        if (movie->last_loop_pts)
> > > > > > > +            frame->pts += movie->last_loop_pts;
> > > > > > >          if (st->discontinuity_threshold) {
> > > > > > >              if (st->last_pts != AV_NOPTS_VALUE) {
> > > > > > >                  int64_t diff = frame->pts - st->last_pts;
> > > > > > > @@ -575,6 +580,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
> > > > > > >                  }
> > > > > > >              }
> > > > > > >          }
> > > > > > > +        movie->last_pts =
> > > > > > >          st->last_pts = frame->pts;
> > > > > > >      }
> > > > > > >      ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
> > > > > > > -- > > 2.9.5
> > > > > > > > > ping
> > > > > > > -- > Thanks,
> > > > > > Limin Wang
> > > > > > _______________________________________________
> > > > > > ffmpeg-devel mailing list
> > > > > > ffmpeg-devel@ffmpeg.org
> > > > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > > > > > To unsubscribe, visit link above, or email
> > > > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > > > > _______________________________________________
> > > > > ffmpeg-devel mailing list
> > > > > ffmpeg-devel@ffmpeg.org
> > > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > > > > > To unsubscribe, visit link above, or email
> > > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > > > > -- > Thanks,
> > > > Limin Wang
> > > > _______________________________________________
> > > > ffmpeg-devel mailing list
> > > > ffmpeg-devel@ffmpeg.org
> > > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > > > To unsubscribe, visit link above, or email
> > > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > 
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > 
> > -- 
> > Thanks,
> > Limin Wang
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 79423a8..2327046 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -68,6 +68,8 @@  typedef struct MovieContext {
     int loop_count;
     int64_t discontinuity_threshold;
     int64_t ts_offset;
+    int64_t last_pts;
+    int64_t last_loop_pts;
 
     AVFormatContext *format_ctx;
     int eof;
@@ -455,6 +457,7 @@  static int rewind_file(AVFilterContext *ctx)
         movie->st[i].done = 0;
     }
     movie->eof = 0;
+    movie->last_loop_pts = movie->last_pts;
     return 0;
 }
 
@@ -565,6 +568,8 @@  static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
     if (frame->pts != AV_NOPTS_VALUE) {
         if (movie->ts_offset)
             frame->pts += av_rescale_q_rnd(movie->ts_offset, AV_TIME_BASE_Q, outlink->time_base, AV_ROUND_UP);
+        if (movie->last_loop_pts)
+            frame->pts += movie->last_loop_pts;
         if (st->discontinuity_threshold) {
             if (st->last_pts != AV_NOPTS_VALUE) {
                 int64_t diff = frame->pts - st->last_pts;
@@ -575,6 +580,7 @@  static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
                 }
             }
         }
+        movie->last_pts =
         st->last_pts = frame->pts;
     }
     ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,