From patchwork Tue Sep 10 19:12:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 15012 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 897204487BD for ; Tue, 10 Sep 2019 22:12:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6801968804F; Tue, 10 Sep 2019 22:12:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1AB1E687F49 for ; Tue, 10 Sep 2019 22:12:42 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id 4so9029417pld.10 for ; Tue, 10 Sep 2019 12:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Jo0BACUuyIFliC1oNNXJ+YQBc6mh/RLESpaOq+sMMWo=; b=g5GfoJ8Q+dH9lCdubaNRTxWB7kqbmUg6OaLokPXILed4idO/ZyqaeUfSOGpQtbSGgc tm2uWOOg/FfsvNjoWoj+4Ispy7dNoPceiNwY8ISk6Zx+WWzC2NZ/u8nVRd0WvJkA8UpI i7+5Ju+TKfWhVUHA4uRv8DscCC5ra4iWUtWZF/TJUTVfBC+EnBFNP2keN+43T6i9ky7I TG4Z+gF1Shyl9HSNXqZ9W4Luv/sDSv34LZ+0IzI7GEPQi2UThXQQH8lC5mVg3rUAVJoV 0aMcrV88BZ7L7KPKJ2ACqzoy5pduiXfv1UeO/vES8IreTWZSWaF8fDf3QqD8n8fnirfk v+BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Jo0BACUuyIFliC1oNNXJ+YQBc6mh/RLESpaOq+sMMWo=; b=m1gqUci2l2DDg4Fla/5J0ENelAnXgjCm17U8RhScWQ2Be1XcKGTtkanUN2WTKy0NF6 oANr66OJw+JNSHLt9sVKxyqbaEVcktZnfetQVheC1213Le0NZ4tQmrdWhYBZA3cYLZ/7 1tiNE8/nW2GjAV9ZaIzRpQ4lxxVOxOymnz5QdUEgQNow0C3tOe6QDa86IPIulhkhu9TI WnYZuZ1RGpyFCc6gfhFZgjP7h3r5Uy9CJWxOpj64lFDiK/A1bZaNRxfYPX0TZ9t/3vpp dYk7Zj4mekCX9IN4kx5h2ePmuZ4Rbg3+k08POl01GdWAkBRC9QHBfGdFq0rmlmnFe92V 5aGQ== X-Gm-Message-State: APjAAAVlrj2zkvIiApk4GkM4vQ9f4PsDCDhFGwuKNFYoRJGC6ZRNjWoR +AT5IoRZlXmiUU1AByXL36WroEY0 X-Google-Smtp-Source: APXvYqyxj0bvPMn/59CJl5qkp4cW+l6yco80nPY/FJBWmmxXZu2aPiLe/YCOI9lqryS6dDOnjvXSEg== X-Received: by 2002:a17:902:7441:: with SMTP id e1mr33249156plt.332.1568142759541; Tue, 10 Sep 2019 12:12:39 -0700 (PDT) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:f:d8dd:ab4f:4f1e:8499]) by smtp.googlemail.com with ESMTPSA id w189sm8239496pfw.101.2019.09.10.12.12.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 12:12:38 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Sep 2019 12:12:32 -0700 Message-Id: <20190910191232.25575-1-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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; + } + } } } 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