From patchwork Mon Oct 26 10:55:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 23229 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 9523C448BD6 for ; Mon, 26 Oct 2020 12:55:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FA4B68A427; Mon, 26 Oct 2020 12:55:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE23868037A for ; Mon, 26 Oct 2020 12:55:43 +0200 (EET) Received: by mail-pj1-f65.google.com with SMTP id p21so3030729pju.0 for ; Mon, 26 Oct 2020 03:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mpr5y4pca8e4YEiidBlNN+UtxNuOBMD+wTzsj39248M=; b=Xut4L2bVXcjwZ2evpuTi+FJmcef6HkmDcq6/Pg/4/r2BkkljTHIu6NgvEs+bBRDaVb PluPpeacaCOZLKUuCRTT59eA5ilnwMACttQmdt/oMquRBt2/mfLjfKXVlkCFkuNkILp3 xLTs5f9foeDMU8bNP9NpSc+5K+ST1rl+BX51QrvHN8kemJdLr9svtvx0ONPw4vTUTykc EuRIWgcGWnjRO+5MDyI9gtAI3La9HfC1Q7U847QgKPq4Zf3ScjM9ZOsV9ZAfffJ9Q7WP F/ow+4tOO+yMyTQSvGW3Q6un1ESHMO5pMCkr45COaVnSHi9cywko3B/UTyLuuJUaYfji Qn3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mpr5y4pca8e4YEiidBlNN+UtxNuOBMD+wTzsj39248M=; b=WLEqGPUhguU+0uiQt0LGIxA1NcYHzbMutgm+gfXeU2Yiy8E05G20pzVeb6TwCst7Ar 2e25Zx3odCq6KU5/nwDVb9WWGbbIvV9aKkB3UvEO+LkBhISJoW7aTaZ/N7B6D7yuV3Ct aVPIfSUC2TIu2t6id7HBwQe0dPdVOwdFjBWVO0bp4VH5kVhyRcil9crFSvT8lTKys5Cq LO9+NyK9gzGCllYY0z3xFUO68JlY48Zn2XMA0brFDmh+sHEUiTpofpPk29rkOb6JTW50 q0uCvh49os6bHNT1iAa1lzJkHUFwv5S4YwgkGvqVIn4pWQd4w9SZb02ah/gI/kEfeuNZ WUPg== X-Gm-Message-State: AOAM531hoI6hnfaCEzQX8hCBe3graja6G9qMHMtvOHE7uxZjO+/16UKt wNcv6HOPzV9vLDCQAqUtiN3L4VysbW0= X-Google-Smtp-Source: ABdhPJyeCSNqIQjEgd1p//Zyaz59JcgoSjfPYDenBBpMzB6wR9VFJZxgplkYsflw3ziSCzId2Q3Eig== X-Received: by 2002:a17:90a:5885:: with SMTP id j5mr20423649pji.117.1603709741592; Mon, 26 Oct 2020 03:55:41 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id 21sm7686569pfw.36.2020.10.26.03.55.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2020 03:55:41 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Oct 2020 18:55:36 +0800 Message-Id: <1603709736-2482-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603379867-6325-2-git-send-email-lance.lmwang@gmail.com> References: <1603379867-6325-2-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v3 2/3] avformat/mpegtsenc: make first_pcr sync with the first valid dts 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 Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang now first_pts assume dts will start from zero, if it's not true(copyts is enable), too many null packet will be inserted for cbr output. Please test with below command, you'll get huge test.ts without the patch: ./ffmpeg -y -copyts -i ../fate-suite/mpegts/loewe.ts -c:v libx264 -x264opts \ nal-hrd=cbr:force-cfr=1 -b:v 3500k -minrate 3500k -maxrate 3500k -bufsize \ 1000k -c:a mp2 -muxrate 4500k -vframes 1000 test.ts Signed-off-by: Limin Wang --- libavformat/mpegtsenc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 5c97d63..29dcaf6 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -81,6 +81,7 @@ typedef struct MpegTSWrite { int64_t pat_period; /* PAT/PMT period in PCR time base */ int nb_services; int64_t first_pcr; + int first_dts_checked; int64_t next_pcr; int mux_rate; ///< set to 1 when VBR int pes_payload_size; @@ -1688,6 +1689,11 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) stream_id = side_data[0]; if (ts->copyts < 1) { + if (!ts->first_dts_checked && dts != AV_NOPTS_VALUE) { + ts->first_pcr += dts * 300; + ts->first_dts_checked = 1; + } + if (pts != AV_NOPTS_VALUE) pts += delay; if (dts != AV_NOPTS_VALUE)