From patchwork Wed Oct 2 00:20:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 15443 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id CAF11447D3C for ; Wed, 2 Oct 2019 03:20:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6F18687FA5; Wed, 2 Oct 2019 03:20:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0CB76687F36 for ; Wed, 2 Oct 2019 03:20:50 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id o18so17469999wrv.13 for ; Tue, 01 Oct 2019 17:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=yAOWDyoaoJphs0nNidENY8X4Cu8y8eiAG7+p3wZPr48=; b=axm6hjKdqKVInfgHUpNe5TuNJ2NnSMKRDPZG5XUPMXpUFPhmcj8XBY/u4zAc9YcnNj Qfdb4U2y5bBJS6p300WQFq/gcU2GRRKx37ThjhgiLvEBs1t8E08W6Vfih3CL+hdrj+HV 1+zgI7C8a3YgmYkD3yQomk+z1IDz0QuBqScS3VqWOA44VUgcwcbeAxlWimaszMOzyftP TGXmmglGOo1FzbpG44tBxrpxqQ/cemEAGOPXsrqjuxdmP0+tf8zn2j/dLJ6o5IEGlCac UQ88N7cFVhRG9J957R3wiKG5EmIxvQof/xBdmvIDeOqCBH8He/zBLYvTCZnoYd1XB3wu nwOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=yAOWDyoaoJphs0nNidENY8X4Cu8y8eiAG7+p3wZPr48=; b=CbswiH90m1+PIvQypBdWWw0EpMjO3aU4M0Tz49lMYJBmCy4M9ysNvt6wEo+Mi2nTGj +Hcyjd/ogmAyi+R6ThBqhRSvwXyhAFAMVNoy7dBtQGnq4V+97J+txhbbH+AJlCMeSs14 EDrd5pZNPGlS8FuUP/3zn7QlcuEOv5HAUwaoJ090/u3kQMc85xGgwaLSwazSWuWYOUux cfIFhZeSYCHTrj+ACx87o7AjUGjjp4tA0wWRxxwLvuH+ME8SOBYXdA5MKgR/yOcYTIXk avexAUJ+r09buyFw/qMi85FCId1CYkuK0qpIHtJ1+Z/TIoCfAATBRXC03bYDEXxAncHZ GaQA== X-Gm-Message-State: APjAAAURXiW10wS0oUZnfLtSy7muIl25SgZkuW/osnSjajXryX9T3Vws 7wtj8k89BMtvo4MgBZiBpcSlfJNS4JQfba/v9fRCH5+uhWo= X-Google-Smtp-Source: APXvYqy2vvpQqLGaKUNOufrUNBx7GKj2ENlyfUXxXVfUcfpzyCVj+/bFfI69C1BQJZgAJ0KBIvv2ewogDfZn5fR8cTA= X-Received: by 2002:a5d:4dd2:: with SMTP id f18mr349321wru.20.1569975649003; Tue, 01 Oct 2019 17:20:49 -0700 (PDT) MIME-Version: 1.0 References: <20190910191232.25575-1-junli1026@gmail.com> In-Reply-To: From: Jun Li Date: Tue, 1 Oct 2019 17:20:37 -0700 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH v3] avformat/movenc: split empty text sample when duration overflow X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Tue, Oct 1, 2019 at 4:19 AM Carl Eugen Hoyos wrote: > Am Di., 10. Sept. 2019 um 21:12 Uhr schrieb Jun Li : > > > > 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@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 Carl for review. Code is updated as follows. 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 | 26 ++++++++++++++----- tests/fate/subtitles.mak | 6 +++++ tests/ref/fate/binsub-movtextenc-long-dur | 1 + .../fate/binsub-movtextenc-long-dur-timebase | 1 + 4 files changed, 28 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..db6f5afefc 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,24 @@ 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; + } + } } } diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak index 0042902161..4c2b34c431 100644 --- a/tests/fate/subtitles.mak +++ b/tests/fate/subtitles.mak @@ -34,6 +34,12 @@ fate-sub-movtext: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/MovText_capabilit FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc fate-binsub-movtextenc: CMD = md5 -i $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc-long-dur +fate-binsub-movtextenc-long-dur: CMD = md5 -i $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov + +FATE_SUBTITLES-$(call ENCDEC, MOVTEXT, MOV) += fate-binsub-movtextenc-long-dur-timebase +fate-binsub-movtextenc-long-dur-timebase: CMD = md5 -i $(TARGET_SAMPLES)/sub/WebVTT_movtext_long_dur.vtt -map 0 -scodec mov_text -time_base 1000 -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov + FATE_SUBTITLES_ASS-$(call DEMDEC, MPL2, MPL2) += fate-sub-mpl2 fate-sub-mpl2: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/MPL2_capability_tester.txt diff --git a/tests/ref/fate/binsub-movtextenc-long-dur b/tests/ref/fate/binsub-movtextenc-long-dur new file mode 100644 index 0000000000..eb8a3f8fc7 --- /dev/null +++ b/tests/ref/fate/binsub-movtextenc-long-dur @@ -0,0 +1 @@ +7f78c11bb4a6b16335540ef31ba10219 diff --git a/tests/ref/fate/binsub-movtextenc-long-dur-timebase b/tests/ref/fate/binsub-movtextenc-long-dur-timebase new file mode 100644 index 0000000000..185dcc0aab --- /dev/null +++ b/tests/ref/fate/binsub-movtextenc-long-dur-timebase @@ -0,0 +1 @@ +349d78698cc1226d33d4e6699dbf46d9