From patchwork Wed Aug 14 23:51:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 14510 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 87D8544A105 for ; Thu, 15 Aug 2019 02:51:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 71EB468AB2F; Thu, 15 Aug 2019 02:51:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5480168A35D for ; Thu, 15 Aug 2019 02:51:40 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 40AAAE383F; Thu, 15 Aug 2019 01:51:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XKi3iFtoUnF8; Thu, 15 Aug 2019 01:51:38 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4269BE3840; Thu, 15 Aug 2019 01:51:38 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Aug 2019 01:51:28 +0200 Message-Id: <20190814235130.5973-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190814235130.5973-1-cus@passwd.hu> References: <20190814235130.5973-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/4] avformat/mpegtsenc: add support for setting PCR interval for VBR streams 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also document the algorithm for the default PCR interval. Fixes ticket #8061. Signed-off-by: Marton Balint --- doc/muxers.texi | 6 ++++-- libavformat/mpegtsenc.c | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 019eee6145..c27bfee4f5 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1619,8 +1619,10 @@ is @code{-1}, which results in shifting timestamps so that they start from 0. Omit the PES packet length for video packets. Default is @code{1} (true). @item pcr_period @var{integer} -Override the default PCR retransmission time in milliseconds. Ignored if -variable muxrate is selected. Default is @code{20}. +Override the default PCR retransmission time in milliseconds. Default is +@code{-1} which means that the PCR interval will be determined automatically: +20 ms is used for CBR streams, the highest multiple of the frame duration which +is less than 100 ms is used for VBR streams. @item pat_period @var{double} Maximum time in seconds between PAT/PMT tables. diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 5cdd9d3313..9dee5fa1d0 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -790,8 +790,9 @@ static void enable_pcr_generation_for_stream(AVFormatContext *s, AVStream *pcr_s MpegTSWrite *ts = s->priv_data; MpegTSWriteStream *ts_st = pcr_st->priv_data; - if (ts->mux_rate > 1) { - ts_st->pcr_period = av_rescale(ts->pcr_period_ms, PCR_TIME_BASE, 1000); + if (ts->mux_rate > 1 || ts->pcr_period_ms >= 0) { + int pcr_period_ms = ts->pcr_period_ms == -1 ? PCR_RETRANS_TIME : ts->pcr_period_ms; + ts_st->pcr_period = av_rescale(pcr_period_ms, PCR_TIME_BASE, 1000); } else { /* For VBR we select the highest multiple of frame duration which is less than 100 ms. */ int64_t frame_period = 0; @@ -1964,7 +1965,7 @@ static const AVOption options[] = { { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, { "pcr_period", "PCR retransmission time in milliseconds", offsetof(MpegTSWrite, pcr_period_ms), AV_OPT_TYPE_INT, - { .i64 = PCR_RETRANS_TIME }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, { "pat_period", "PAT/PMT retransmission time limit in seconds", offsetof(MpegTSWrite, pat_period), AV_OPT_TYPE_DOUBLE, { .dbl = INT_MAX }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },