From patchwork Mon Aug 9 14:23:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Weiwen X-Patchwork-Id: 29379 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp2913389ioh; Mon, 9 Aug 2021 07:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLL6bp+VnObFI8Pp4WtV5bFr4sAAdePbY8+o/h+JpX2saWyB6e4MbQOWHO5u12WDk/0MVi X-Received: by 2002:a17:907:2595:: with SMTP id ad21mr22052535ejc.430.1628519067898; Mon, 09 Aug 2021 07:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628519067; cv=none; d=google.com; s=arc-20160816; b=jwsv9MtiKCENKdHV9aprYBNRZzSxjy2bgZFgbwa4rbMvOiw7XVhIWTBc+nL+7OOYOW J4Qx/GpIk7DKzOLlM5wTg65lWh5nQ6Vv+GCMWEHIfRS5o67Y8FGMTnBEXXRB3MQU8/J/ Nwo/rj9Ts03W4dphdisN2foKFICOOGggaxTLeaRiXKkxT/+2FkH0lu3LJbQIQAmFYCbb M98wV8jZ13A/VS+oJZLQ+Os9PvVKSaRF4IzVZDmrFrXHDB3/rY0HsLTRNl64a06OjxYr AgGYJUo2PpfO7E7cJCiJPbcKhm3/whOOO58RBcSY0oHiczkmTdVuXwqYfzc8uWLw2L3z tDAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=AZBlLKMkIicuNugzuf823zSYfBK0nChUmkQDTL3xphM=; b=bMBFVNmhTHqHTMRJ9Azto0KHDIOfiSZYC8N/XhzX7DmIfS/Y6Nim3TKabwjPCW+ZTB 3Yy9cc0IxO44mQSRELuqu95wSMsXURLQLhl8IuHlpKzGtPFVM/+qxp78889gPUWylvN+ 6R9f0gbKe44vK6ADZ59hjyRR4VfOJnP/KspAI7WlA5aPP+J5xQmGZxDIDq2wbR6/04hM ar+eoKlIJvdJ5VufXjfGM+dX0KwDZz0BJPqQah0cRHt0KZiWHls6mz22Cwh3Q2QsrM2y diNndVALwK7hy8MUgM0hzx+aJ81gI+O1snoURlQ29c1Afxh8+EN8PWACZQuqemOY5Lhv Uk3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=scut.edu.cn Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g9si6270047edq.130.2021.08.09.07.24.27; Mon, 09 Aug 2021 07:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=scut.edu.cn Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C9C768A10A; Mon, 9 Aug 2021 17:24:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.scut.edu.cn (stumail1.scut.edu.cn [202.38.213.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 551676806E4 for ; Mon, 9 Aug 2021 17:24:14 +0300 (EEST) Received: from dorm.huww98.cn (unknown [125.216.246.30]) by front (Coremail) with SMTP id AWSowADX30drOhFhFmobAA--.56043S4; Mon, 09 Aug 2021 22:23:40 +0800 (CST) From: Hu Weiwen To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Aug 2021 22:23:42 +0800 Message-Id: <20210809142342.153566-1-sehuww@mail.scut.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805123421.10527-1-martin@martin.st> References: <20210805123421.10527-1-martin@martin.st> MIME-Version: 1.0 X-CM-TRANSID: AWSowADX30drOhFhFmobAA--.56043S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw4ftFyfAry8Cw45Zr4kCrg_yoW8Cry7pw 4I9F1avay7tay8ArWDJrW5JF4kWws5Wr9xAryjvw1FqFsxtF1rJrykKws8uFyrXa45Cayj vFWYva4jya4UAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyK14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r1j 6r4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04 k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY 1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfU5WlkUUUUU X-CM-SenderInfo: qsqrljqqwxllyrt6zt1loo2ulxwovvfxof0/1tbiAQAHBlepTBUJxwAysb Subject: [FFmpeg-devel] [PATCH] avformat/movenc: Don't auto flush fragment if no frame available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: =?utf-8?q?Martin_Storsj=C3=B6?= , Hu Weiwen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: npNT4JTk7vyF Even if FF_MOV_FLAG_FRAG_EVERY_FRAME is set, don't flush if no frame available. This fixes an issue that we overwrite the track duration, causing it to be out-of-sync with the last written packet in previous fragment. Signed-off-by: Hu Weiwen --- Hi Martin, I can confirm your patch "movenc: Don't try to fix the fragment end duration if none will be written"[1] does fix my issue reported in [2]. But I think my current patch would be a better fix. It is more self-explanatory, and more consistent in the case of FF_MOV_FLAG_FRAG_KEYFRAME. Also, I think my original patch [2] still has its value. "frag_start" seems to be redundant, and it is only updated relative to its previous value. This is bad because any potential error updating it will have infinite impact on future packets. [1]: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210805123421.10527-1-martin@martin.st/ [2]: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210718102232.1382376-1-sehuww@mail.scut.edu.cn/ libavformat/movenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 57062f45c57..72fe8df12c2 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -5929,7 +5929,7 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && par->codec_type == AVMEDIA_TYPE_VIDEO && trk->entry && pkt->flags & AV_PKT_FLAG_KEY) || - (mov->flags & FF_MOV_FLAG_FRAG_EVERY_FRAME)) { + (mov->flags & FF_MOV_FLAG_FRAG_EVERY_FRAME && trk->entry)) { if (frag_duration >= mov->min_fragment_duration) { // Set the duration of this track to line up with the next // sample in this track. This avoids relying on AVPacket