[FFmpeg-devel] [PATCH 06/10] avformat/mpegtsenc: use standard pids for m2ts
Marton Balint
cus at passwd.hu
Tue Nov 12 23:29:02 EET 2019
Signed-off-by: Marton Balint <cus at passwd.hu>
---
doc/muxers.texi | 6 ++++--
libavformat/mpegtsenc.c | 31 ++++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index c36ae60f19..b2fae01995 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1583,11 +1583,13 @@ Advanced Codec Digital HDTV service.
@item mpegts_pmt_start_pid @var{integer}
Set the first PID for PMTs. Default is @code{0x1000}, minimum is @code{0x0010},
-maximum is @code{0x1ffe}.
+maximum is @code{0x1ffe}. This option has no effect in m2ts mode where the PMT
+PID is fixed @code{0x0100}.
@item mpegts_start_pid @var{integer}
Set the first PID for elementary streams. Default is @code{0x0100}, minimum is
- at code{0x0010}, maximum is @code{0x1ffe}.
+ at code{0x0010}, maximum is @code{0x1ffe}. This option has no effect in m2ts mode
+where the elementary PIDs are fixed.
@item mpegts_m2ts_mode @var{boolean}
Enable m2ts mode if set to @code{1}. Default value is @code{-1} which
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 726e4786ad..be41311bf7 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -94,6 +94,10 @@ typedef struct MpegTSWrite {
int pmt_start_pid;
int start_pid;
int m2ts_mode;
+ int m2ts_video_pid;
+ int m2ts_audio_pid;
+ int m2ts_subtitle_pid;
+ int m2ts_other_pid;
int pcr_period_ms;
#define MPEGTS_FLAG_REEMIT_PAT_PMT 0x01
@@ -858,6 +862,14 @@ static int mpegts_init(AVFormatContext *s)
}
}
+ ts->m2ts_video_pid = 0x1011;
+ ts->m2ts_audio_pid = 0x1100;
+ ts->m2ts_subtitle_pid = 0x1200;
+ ts->m2ts_other_pid = 0x1300; // should not be needed
+
+ if (ts->m2ts_mode)
+ ts->pmt_start_pid = 0x0100;
+
if (s->max_delay < 0) /* Not set by the caller */
s->max_delay = 0;
@@ -921,7 +933,24 @@ static int mpegts_init(AVFormatContext *s)
/* MPEG pid values < 16 are reserved. Applications which set st->id in
* this range are assigned a calculated pid. */
if (st->id < FIRST_OTHER_PID) {
- ts_st->pid = ts->start_pid + i;
+ if (ts->m2ts_mode) {
+ switch (st->codecpar->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ ts_st->pid = ts->m2ts_video_pid++;
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ ts_st->pid = ts->m2ts_audio_pid++;
+ break;
+ case AVMEDIA_TYPE_SUBTITLE:
+ ts_st->pid = ts->m2ts_subtitle_pid++;
+ break;
+ default:
+ ts_st->pid = ts->m2ts_other_pid++;
+ break;
+ }
+ } else {
+ ts_st->pid = ts->start_pid + i;
+ }
} else {
ts_st->pid = st->id;
}
--
2.16.4
More information about the ffmpeg-devel
mailing list