From patchwork Sat Oct 27 20:35:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fix45u+5vw5dhzga3hjs@guerrillamail.com X-Patchwork-Id: 10827 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 B22EA44DEA5 for ; Mon, 29 Oct 2018 03:19:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B2A668A583; Mon, 29 Oct 2018 03:19:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.guerrillamail.com (server9.guerrillamail.com [167.114.101.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B61BA689B6F for ; Sat, 27 Oct 2018 23:34:57 +0300 (EEST) Received: by 167.114.101.158 with HTTP; Sat, 27 Oct 2018 20:35:26 +0000 MIME-Version: 1.0 Message-ID: <4907da416549f55665f564b255368d043984@guerrillamail.com> Date: Sat, 27 Oct 2018 20:35:26 +0000 To: "ffmpeg-devel@ffmpeg.org" From: X-Originating-IP: [95.17.143.252] X-Domain-Signer: PHP mailDomainSigner 0.2-20110415 DKIM-Signature: v=1; a=rsa-sha256; s=highgrade; d=guerrillamail.com; l=4766; t=1540672526; c=relaxed/relaxed; h=to:from:subject; bh=pXb67PKm5muZOR2wIQf2l1VME8I5Z7rBuy6HpYZkyYs=; b=uvsSHfY60aliizSW10WdXyHqx7Azr7rJCiy9Y1FXcBA36iLOOjFDde5P6s1KKvRJ8NDv2iDqPd6F ABGWr6ciHwkJ4tZBG6jKt8Zh8Jnk0O3Mw1XmQyd77Rk4dEje3HzWVVmi1YN9zKo2jS4HS7qppkAH ZbBJzBEisZI2aRpAk/GT8K2LhLnfQhEamKKAq8DVnomybrP05r6LA+kiNPnF4Kc/FUEXLI7nINvz nMEDIGyHCG1ApAvRr3eUs1QShJ1Fa1E+IxTZqazSQpYjYgGSFOrIMfn9y9q83KWrwA99wkWupUei 8YXAteHtTNUA+GkFMO7elzW6T9o7SZgZ8VFkQA== X-Mailman-Approved-At: Mon, 29 Oct 2018 03:19:24 +0200 Subject: [FFmpeg-devel] [PATCH] libavformat: add multiple PCR streams 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" From 44c9f3d96c5969349bd2dc4d63e9a8b8e6b5a0e2 Mon Sep 17 00:00:00 2001 From: M. Sanders Date: Sat, 27 Oct 2018 21:39:44 +0200 Subject: [PATCH] libavformat: add multiple PCR streams in MPEGTS muxer --- This simple patch adds two new options to the MPEG-TS muxer. You can use them to mark PCRs in additional VIDEO and/or AUDIO streams. It's useful when you will remux the output with pid filtering tools. For example, if you put PCR in all audio streams, then you can filter each audio stream to create a radio service. PCR marks do not disturb outgoing stream, but it is not recommended to do so as a regular rule. doc/muxers.texi | 6 ++++++ libavformat/mpegtsenc.c | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index f18543e83d..328707d0ed 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1528,6 +1528,12 @@ 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 pcr_all_video @var{boolean} +Include PCR values in all video streams. Default is @code{0} (false). + +@item pcr_all_audio @var{boolean} +Include PCR values in all audio streams. Default is @code{0} (false). + @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 3339e26d50..caef817a3d 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -113,6 +113,8 @@ typedef struct MpegTSWrite { double sdt_period; int64_t last_pat_ts; int64_t last_sdt_ts; + int pcr_all_video; + int pcr_all_audio; int omit_video_pes_length; } MpegTSWrite; @@ -1178,11 +1180,18 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, int64_t pcr = -1; /* avoid warning */ int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; + int force_pcr = 0; av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO); if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { force_pat = 1; } + if (ts->pcr_all_video && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + force_pcr = 1; + } + if (ts->pcr_all_audio && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + force_pcr = 1; + } is_start = 1; while (payload_size > 0) { @@ -1190,7 +1199,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, force_pat = 0; write_pcr = 0; - if (ts_st->pid == ts_st->service->pcr_pid) { + if (ts_st->pid == ts_st->service->pcr_pid || force_pcr) { if (ts->mux_rate > 1 || is_start) // VBR pcr period is based on frames ts_st->service->pcr_packet_count++; if (ts_st->service->pcr_packet_count >= @@ -1228,7 +1237,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } if (key && is_start && pts != AV_NOPTS_VALUE) { // set Random Access for key frames - if (ts_st->pid == ts_st->service->pcr_pid) + if (ts_st->pid == ts_st->service->pcr_pid || force_pcr) write_pcr = 1; set_af_flag(buf, 0x40); q = get_ts_payload_start(buf); @@ -1951,6 +1960,12 @@ static const AVOption options[] = { { "omit_video_pes_length", "Omit the PES packet length for video packets", offsetof(MpegTSWrite, omit_video_pes_length), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, + { "pcr_all_video", "Include PCR values in all video streams", + offsetof(MpegTSWrite, pcr_all_video), AV_OPT_TYPE_BOOL, + { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, + { "pcr_all_audio", "Include PCR values in all audio streams", + offsetof(MpegTSWrite, pcr_all_audio), AV_OPT_TYPE_BOOL, + { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, { "pcr_period", "PCR retransmission time in milliseconds", offsetof(MpegTSWrite, pcr_period), AV_OPT_TYPE_INT, { .i64 = PCR_RETRANS_TIME }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },