From patchwork Sun Apr 12 22:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 18901 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 5E43944B014 for ; Mon, 13 Apr 2020 01:37:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3766868B5A4; Mon, 13 Apr 2020 01:37:58 +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 2932668B472 for ; Mon, 13 Apr 2020 01:37:52 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 12FBAE3E28; Mon, 13 Apr 2020 00:37:52 +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 tHSbUFysw9vg; Mon, 13 Apr 2020 00:37:50 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4C5F2E3E27; Mon, 13 Apr 2020 00:37:50 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Apr 2020 00:37:38 +0200 Message-Id: <20200412223738.22357-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH v2 4/4] avformat/mpegtsenc: use the correct stream_types and write HDMV descriptors for m2ts 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" Fixes ticket #2622. Signed-off-by: Marton Balint --- Changelog | 1 + libavformat/mpegtsenc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 6dfe750d81..4ba44e5e2d 100644 --- a/Changelog +++ b/Changelog @@ -58,6 +58,7 @@ version : - switch from AvxSynth to AviSynth+ on Linux - mv30 decoder - Expanded styling support for 3GPP Timed Text Subtitles (movtext) +- use the correct stream types for m2ts output version 4.2: diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index add35aca89..b154675d60 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -359,6 +359,54 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream *st) return stream_type; } +static int get_m2ts_stream_type(AVFormatContext *s, AVStream *st) +{ + int stream_type; + + switch (st->codecpar->codec_id) { + case AV_CODEC_ID_MPEG2VIDEO: + stream_type = STREAM_TYPE_VIDEO_MPEG2; + break; + case AV_CODEC_ID_H264: + stream_type = STREAM_TYPE_VIDEO_H264; + break; + case AV_CODEC_ID_VC1: + stream_type = STREAM_TYPE_VIDEO_VC1; + break; + case AV_CODEC_ID_HEVC: + stream_type = STREAM_TYPE_VIDEO_HEVC; + break; + case AV_CODEC_ID_PCM_BLURAY: + stream_type = 0x80; + break; + case AV_CODEC_ID_AC3: + stream_type = 0x81; + break; + case AV_CODEC_ID_DTS: + stream_type = (st->codecpar->channels > 6) ? 0x85 : 0x82; + break; + case AV_CODEC_ID_TRUEHD: + stream_type = 0x83; + break; + case AV_CODEC_ID_EAC3: + stream_type = 0x84; + break; + case AV_CODEC_ID_HDMV_PGS_SUBTITLE: + stream_type = 0x90; + break; + case AV_CODEC_ID_HDMV_TEXT_SUBTITLE: + stream_type = 0x92; + break; + default: + av_log(s, AV_LOG_WARNING, "Stream %d, codec %s, is muxed as a private data stream " + "and may not be recognized upon reading.\n", st->index, avcodec_get_name(st->codecpar->codec_id)); + stream_type = STREAM_TYPE_PRIVATE_DATA; + break; + } + + return stream_type; +} + static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) { MpegTSWrite *ts = s->priv_data; @@ -372,6 +420,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) q += 2; /* patched after */ /* put program info here */ + if (ts->m2ts_mode) { + put_registration_descriptor(&q, MKTAG('H', 'D', 'M', 'V')); + *q++ = 0x88; // descriptor_tag - hdmv_copy_control_descriptor + *q++ = 0x04; // descriptor_length + put16(&q, 0x0fff); // CA_System_ID + *q++ = 0xfc; // private_data_byte + *q++ = 0xfc; // private_data_byte + } val = 0xf000 | (q - program_info_length_ptr - 2); program_info_length_ptr[0] = val >> 8; @@ -401,7 +457,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) break; } - stream_type = get_dvb_stream_type(s, st); + stream_type = ts->m2ts_mode ? get_m2ts_stream_type(s, st) : get_dvb_stream_type(s, st); *q++ = stream_type; put16(&q, 0xe000 | ts_st->pid);