From patchwork Tue Apr 23 12:03:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_H=C3=A5kon?= X-Patchwork-Id: 12874 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 9664B4493CF for ; Tue, 23 Apr 2019 15:03:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C13B689C3E; Tue, 23 Apr 2019 15:03:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40135.protonmail.ch (mail-40135.protonmail.ch [185.70.40.135]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3177680349 for ; Tue, 23 Apr 2019 15:03:15 +0300 (EEST) Date: Tue, 23 Apr 2019 12:03:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1556020994; bh=YqLfeTz/WNnaS8JJFEu8xrsrqO/GDVD27cs9x2b6EmI=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:Feedback-ID: From; b=BaNAkq46fSF4hjB4fZs879ImpLZU7XARwtDwkAvIDs4Nnw60WZZRzH8mo3A507tKx 6q1h1ZhFvQhxkcmTxzTpTcGPddapHHPpbh0OWO3p8SxVvpZ0IPozZ3InLQEMdAw6eI yRAqv+ofaRqvb536+TBobsMcdbuObxjQNyaTal8s= To: FFmpeg development discussions and patches From: =?UTF-8?Q?Andreas_H=C3=A5kon?= Message-ID: In-Reply-To: <20190423114334.GA27078@sunshine.barsnick.net> References: <2dCt2zqMjOkrr5MeF1qUbesp00k21yI0TKGcTSiSFgFeJuH6g-7pTE0op1bEUjXQGEGH6LzB3fDDrkB8by4sLXTLn_EH2nhjRAhWihVSZNg=@protonmail.com> <20190423114334.GA27078@sunshine.barsnick.net> Feedback-ID: Mx8CaiV20jk_fqXDN0fFpg3vRaGkb9VCTrYRnZNHwEija3aOdqvFspzl6ODkmHrlSKJSx29p-LzkuvS_96L02A==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Subject: Re: [FFmpeg-devel] [PATCH] libavformat: forced PCR pid in mpegts muxer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Tuesday, 23 de April de 2019 13:43, Moritz Barsnick wrote: > On Tue, Apr 23, 2019 at 11:15:40 +0000, Andreas Håkon wrote: > > Nits: > > > Subject: libavformat: forced PCR pid in mpegts muxer > > "libavformat/mpegtsenc: allow to force the PID carrying the PCR" > (or something along those lines) > > > By default FFmpeg selects the first video stream, or the first one in > > the service if no video stream is found. > > This could also go into the documentation, if it doesn't already say so > somewhere. > > > All then the output audio stream (with pid:202) will host the PCR marks. > > "All then the"? > > > +Override the pid for carring the PCR clock. > > ^ > > > Typo: carrying > > Thanks, > Moritz Thank you Moritz! All applied. In addition, one correction regarding the initialization. Sorry, but first version has an error. This is clean! Regards. A.H. --- From af5a92aa00bb159eb2c967ee8764a2a6ffea1abf Mon Sep 17 00:00:00 2001 From: Andreas Hakon Date: Tue, 23 Apr 2019 12:55:04 +0100 Subject: [PATCH] libavformat/mpegtsenc: allow to force the PID carrying the PCR This patch provides a new optional parameter for the mpegtsenc muxer. The parameter "-force_prc_pid" can be used to override the default PCR pid. By default FFmpeg selects the first video stream, or the first one in the service if no video stream is found. With this new parameter any of the pids in the service can be used to carry the PCR clock. This can be handy for many reasons. Example: $ ffmpeg -i input.mpg -c:v libx264 -c:a mp2 \ -f mpegts -mpegts_pmt_start_pid 200 -streamid 0:201 -streamid 1:202 \ -force_pcr_pid 202 output.ts Result: output audio stream (with pid:202) will host the PCR marks. Signed-off-by: Andreas Hakon --- doc/muxers.texi | 5 +++++ libavformat/mpegtsenc.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 83ae017..e5d81ad 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1590,6 +1590,11 @@ is @code{-1}, which results in shifting timestamps so that they start from 0. @item omit_video_pes_length @var{boolean} Omit the PES packet length for video packets. Default is @code{1} (true). +@item force_pcr_pid @var{integer} +Override the pid for carrying the PCR clock. +By default FFmpeg selects the first video stream, or the first one in +the service if no video stream is found. + @item pcr_period @var{integer} Override the default PCR retransmission time in milliseconds. Ignored if variable muxrate is selected. Default is @code{20}. diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index fc0ea22..b741b48 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -96,6 +96,7 @@ typedef struct MpegTSWrite { int pmt_start_pid; int start_pid; + int pcr_forced_pid; int m2ts_mode; int reemit_pat_pmt; // backward compatibility @@ -913,9 +914,9 @@ static int mpegts_init(AVFormatContext *s) ts_st->first_pts_check = 1; ts_st->cc = 15; ts_st->discontinuity = ts->flags & MPEGTS_FLAG_DISCONT; - /* update PCR pid by using the first video stream */ - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - service->pcr_pid == 0x1fff) { + /* update PCR pid by: forced pid or using the first video stream */ + if ((ts->pcr_forced_pid != 0x0010 && ts_st->pid == ts->pcr_forced_pid) || + (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && service->pcr_pid == 0x1fff)) { service->pcr_pid = ts_st->pid; pcr_st = st; } @@ -960,6 +961,7 @@ static int mpegts_init(AVFormatContext *s) service->pcr_pid = ts_st->pid; } else ts_st = pcr_st->priv_data; + av_log(s, AV_LOG_VERBOSE, "PCR in pid %d (%d) \n", service->pcr_pid, st->index); if (ts->mux_rate > 1) { service->pcr_packet_period = (int64_t)ts->mux_rate * ts->pcr_period / @@ -1917,6 +1919,9 @@ static const AVOption options[] = { { "mpegts_start_pid", "Set the first pid.", offsetof(MpegTSWrite, start_pid), AV_OPT_TYPE_INT, { .i64 = 0x0100 }, 0x0010, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM }, + { "force_pcr_pid", "Force the pid carring PCR.", + offsetof(MpegTSWrite, pcr_forced_pid), AV_OPT_TYPE_INT, + { .i64 = 0x0010 }, 0x0010, 0x1ffe, AV_OPT_FLAG_ENCODING_PARAM }, { "mpegts_m2ts_mode", "Enable m2ts mode.", offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, AV_OPT_FLAG_ENCODING_PARAM },