From patchwork Fri Sep 6 23:10:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 14963 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 DE18D44784E for ; Sat, 7 Sep 2019 02:16:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B1416687F89; Sat, 7 Sep 2019 02:16:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 164DF687F89 for ; Sat, 7 Sep 2019 02:16:17 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id k1so3867921pls.11 for ; Fri, 06 Sep 2019 16:16:16 -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=ykgrYKxVlOuaAMhZnQ4ajE0FP3KRp/kT4CT/hSA6NzU=; b=M0tOBxj9K9Blx0kA6nC+UOjhqQr0eDMC1duEtifuTOBAqp87EOm0LJZyZXsj7wktm1 uYZzMz+429Jfa3rcS/XBS92ARcy8/j/w43ULZaqvhsDV2BbKsH/ztwL9XcWGpZpenWod GEWmbuPtu7wrcDCRZ33pxoRK09h/IJVY4dV8MzRMKcag+w9RcZCZVL0f/C7bsCNqUL9f IrOhWS+9zdSvAwRL0H0hf1TClFZY1Sx4fzGk8VFZQ67kncHBHkY4YS+71omHXKMdHplC Fv17f/yYPpaMke0KgXLPRFY4vSpsvGWatr50G4XKlrmUkT9tO89PrgHxbWPX8W2e5Gf4 nPcg== 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=ykgrYKxVlOuaAMhZnQ4ajE0FP3KRp/kT4CT/hSA6NzU=; b=DDSdmQn05GNesR19YVdpeWHEwWPebFT+q8j4BjAhCp7GPiZ6RwVVAEGjrygGfdDToX LkAl/PLTj46hHWWgdI/TxjtWHV7NP/lwOuzFp73g3eK39YSGQ1uKnaISmTPDAuH/0qHn Si0u9PLhBsosSmFothMw+DIUvIFQP2YD6afr4Qu0iiZ1yQsaPtclr70UAxzZ559ccK7Y 2zipAN7MOb4sw+KPI6wa7fa4bOw8mJJoWVxzzSgkw+hbxNoum4oXDMhWdjNE1G7da8JU 3PLSu9AwxrF2znHFseRqbwHXpdoWpJniiM69I6TJJfZY6pqE/V0fBFB/irFggkIAEPTA 5O8w== X-Gm-Message-State: APjAAAV3B4q2tuLW3rqzETfbhLFDw9q6VtgkWFvKe0NO8bHIZBHMcfFY Zn8L0U89mgy7DoUtFhv8aiNAIVb6 X-Google-Smtp-Source: APXvYqwlC2nlxGT6gXomFzP3E/AGtI/MQ/a5UmhwTq53RvbOAglkESeYaw+JkWDGdjWhQgWnjK7ptQ== X-Received: by 2002:a17:902:b20c:: with SMTP id t12mr11748848plr.205.1567811442009; Fri, 06 Sep 2019 16:10:42 -0700 (PDT) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:9:63c7:82cd:aa6e:a9bc]) by smtp.googlemail.com with ESMTPSA id p20sm10963890pgi.81.2019.09.06.16.10.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2019 16:10:41 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Sep 2019 16:10:35 -0700 Message-Id: <20190906231035.23139-1-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH v1] 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 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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; + } + } } }