[FFmpeg-devel] [PATCH v3] avformat/movenc: split empty text sample when duration overflow

Jun Li junli1026 at gmail.com
Fri Oct 4 03:28:40 EEST 2019


On Wed, Oct 2, 2019 at 3:42 PM Jun Li <junli1026 at gmail.com> wrote:

>
>
> On Wed, Oct 2, 2019 at 3:22 PM Carl Eugen Hoyos <ceffmpeg at gmail.com>
> wrote:
>
>> Am Mi., 2. Okt. 2019 um 02:21 Uhr schrieb Jun Li <junli1026 at gmail.com>:
>> >
>> > On Tue, Oct 1, 2019 at 4:19 AM Carl Eugen Hoyos <ceffmpeg at gmail.com>
>> wrote:
>> >
>> > > Am Di., 10. Sept. 2019 um 21:12 Uhr schrieb Jun Li <
>> junli1026 at gmail.com>:
>> > > >
>> > > > Fix #7637
>> > > > One empty/end sample is created and inserted between two caption
>> lines
>> > > when there is a gap.
>> > > > This patch is to split the sample into multiple ones when its
>> duration
>> > > is too long (>= INT_MAX).
>> > > > ---
>> > > >  libavformat/movenc.c                          | 24
>> ++++++++++++++-----
>> > > >  tests/fate/subtitles.mak                      |  6 +++++
>> > > >  tests/ref/fate/binsub-movtextenc-long-dur     |  1 +
>> > > >  .../fate/binsub-movtextenc-long-dur-timebase  |  1 +
>> > > >  4 files changed, 26 insertions(+), 6 deletions(-)
>> > > >  create mode 100644 tests/ref/fate/binsub-movtextenc-long-dur
>> > > >  create mode 100644
>> tests/ref/fate/binsub-movtextenc-long-dur-timebase
>> > > >
>> > > > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>> > > > index edddfeeb00..aeb7de351f 100644
>> > > > --- a/libavformat/movenc.c
>> > > > +++ b/libavformat/movenc.c
>> > > > @@ -5746,7 +5746,8 @@ static int mov_write_packet(AVFormatContext
>> *s,
>> > > AVPacket *pkt)
>> > > >           *
>> > > >           * 2) For each subtitle track, check if the current
>> packet's
>> > > >           * dts is past the duration of the last subtitle sample. If
>> > > > -         * so, we now need to write an end sample for that
>> subtitle.
>> > > > +         * so, we now need to write one or multiple end samples for
>> > > > +         * that subtitle.
>> > > >           *
>> > > >           * This must be done conditionally to allow for subtitles
>> that
>> > > >           * immediately replace each other, in which case an end
>> sample
>> > > > @@ -5760,11 +5761,22 @@ static int mov_write_packet(AVFormatContext
>> *s,
>> > > AVPacket *pkt)
>> > > >              int ret;
>> > > >
>> > > >              if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT &&
>> > > > -                trk->track_duration < pkt->dts &&
>> > > > -                (trk->entry == 0 ||
>> !trk->last_sample_is_subtitle_end))
>> > > {
>> > > > -                ret = mov_write_subtitle_end_packet(s, i,
>> > > trk->track_duration);
>> > > > -                if (ret < 0) return ret;
>> > > > -                trk->last_sample_is_subtitle_end = 1;
>> > > > +                trk->track_duration < pkt->dts) {
>> > > > +                int max_duration = INT_MAX - 1;
>> > > > +                if (trk->entry == 0 ||
>> > > !trk->last_sample_is_subtitle_end) {
>> > > > +                    ret = mov_write_subtitle_end_packet(s, i,
>> > > trk->track_duration);
>> > >
>> > > > +                    if (ret < 0) return ret;
>> > >
>> > > > +                    trk->last_sample_is_subtitle_end = 1;
>> > > > +                }
>> > > > +                if (trk->last_sample_is_subtitle_end &&
>> > > > +                    pkt->dts - trk->track_duration > max_duration)
>> {
>> > > > +                    int64_t dts = trk->track_duration;
>> > > > +                    while(pkt->dts - dts > max_duration) {
>> > > > +                        dts += max_duration;
>> > > > +                        ret = mov_write_subtitle_end_packet(s, i,
>> dts);
>> > >
>> > > > +                        if (ret < 0) return ret;
>> > >
>> > > Please add two CRLFs and I am threatening to push this.
>> > >
>> > > Carl Eugen
>> > > _______________________________________________
>> > > ffmpeg-devel mailing list
>> > > ffmpeg-devel at ffmpeg.org
>> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> > >
>> > > To unsubscribe, visit link above, or email
>> > > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>> >
>> >
>> > Thanks Carl for review. Code is updated as follows.
>>
>> git returns an error message ("corrupt line") when I try to
>> commit this patch.
>>
>> Thanks for your time, I rebased the code and re-generated a patch,
> together with the fate test file, in the attachments.
> Could you please help do a re-try ? Thanks.
>

Hi Carl, could you please help to try again ? It should work now. Thanks in
advance!


> -Jun
>
>
>> Carl Eugen
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
>


More information about the ffmpeg-devel mailing list