[FFmpeg-devel] [PATCH 1/4] avformat/mpegtsenc: use standard pids for m2ts

Marton Balint cus at passwd.hu
Fri Apr 17 00:42:04 EEST 2020



On Mon, 13 Apr 2020, Petri Hintukainen wrote:

> pe, 2020-04-10 kello 21:44 +0200, Marton Balint kirjoitti:
>> Signed-off-by: Marton Balint <cus at passwd.hu>
>> ---
>>  doc/muxers.texi         |  6 ++++--
>>  libavformat/mpegts.h    | 10 ++++++++++
>>  libavformat/mpegtsenc.c | 44
>> +++++++++++++++++++++++++++++++++++++++++++-
>>  3 files changed, 57 insertions(+), 3 deletions(-)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 4b6ffaaf58..c7caf52ff4 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1630,11 +1630,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{0x0020},
>> -maximum is @code{0x1ffa}.
>> +maximum is @code{0x1ffa}. 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{0x0020}, maximum is @code{0x1ffa}.
>> + at code{0x0020}, maximum is @code{0x1ffa}. This option has no effect
>> in m2ts mode
>> +where the elementary stream 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/mpegts.h b/libavformat/mpegts.h
>> index 86a3eba4e2..f9a7e27564 100644
>> --- a/libavformat/mpegts.h
>> +++ b/libavformat/mpegts.h
>> @@ -65,6 +65,16 @@
>>   * streams and other data tables */
>>  #define NULL_PID        0x1FFF /* Null packet (used for fixed
>> bandwidth padding) */
>> 
>> +/* m2ts pids */
>> +#define M2TS_PMT_PID                      0x0100
>> +#define M2TS_PCR_PID                      0x1001
>> +#define M2TS_VIDEO_PID                    0x1011
>> +#define M2TS_AUDIO_START_PID              0x1100
>> +#define M2TS_PGSSUB_START_PID             0x1200
>> +#define M2TS_TEXTSUB_START_PID            0x1800
>
> M2TS_TEXTSUB_PID ?

Ok.

>
>> +#define M2TS_SECONDARY_AUDIO_START_PID    0x1A00
>> +#define M2TS_SECONDARY_VIDEO_START_PID    0x1B00
>
> These two are not used ?

Yes, these are only here for completeness for now. Maybe some 
AV_DISPOSITION flag can be used in the future to signal secondaries, so 
they can be muxed as secondary streams.

>
>> +/* table ids */
>>  #define PAT_TID         0x00 /* Program Association section */
>>  #define CAT_TID         0x01 /* Conditional Access section */
>> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
>> index ccb631d746..5e71a0b6f8 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_pgssub_pid;
>> +    int m2ts_textsub_pid;
>>
>>      int pcr_period_ms;
>>  #define MPEGTS_FLAG_REEMIT_PAT_PMT  0x01
>> @@ -860,6 +864,14 @@ static int mpegts_init(AVFormatContext *s)
>>          }
>>      }
>> 
>> +    ts->m2ts_video_pid   = M2TS_VIDEO_PID;
>> +    ts->m2ts_audio_pid   = M2TS_AUDIO_START_PID;
>> +    ts->m2ts_pgssub_pid  = M2TS_PGSSUB_START_PID;
>> +    ts->m2ts_textsub_pid = M2TS_TEXTSUB_START_PID;
>> +
>> +    if (ts->m2ts_mode)
>> +        ts->pmt_start_pid = M2TS_PMT_PID;
>> +
>>      if (s->max_delay < 0) /* Not set by the caller */
>>          s->max_delay = 0;
>> 
>> @@ -923,7 +935,37 @@ 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 < 16) {
>> -            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:
>> +                    switch (st->codecpar->codec_id) {
>> +                    case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
>> +                        ts_st->pid = ts->m2ts_pgssub_pid++;
>> +                        break;
>> +                    case AV_CODEC_ID_HDMV_TEXT_SUBTITLE:
>> +                        ts_st->pid = ts->m2ts_textsub_pid++;
>> +                        break;
>> +                    }
>> +                    break;
>> +                }
>> +                if (ts->m2ts_video_pid   > M2TS_VIDEO_PID +
>> 1          ||
>> +                    ts->m2ts_audio_pid   > M2TS_AUDIO_START_PID +
>> 32   ||
>> +                    ts->m2ts_pgssub_pid  > M2TS_PGSSUB_START_PID +
>> 32  ||
>> +                    ts->m2ts_textsub_pid > M2TS_TEXTSUB_START_PID +
>> 32 ||
>
> There can be only one text subtitle stream (pid 0x1800).
>
> In BluRay, text subtitles are stored in separate .m2ts files. There
> shouldn't be any other streams in the same mux.

Indeed, thanks. I'll limit auto PID assignment to 1 streams.

Regards,
Marton

>
>> +                    ts_st->pid < 16) {
>> +                    av_log(s, AV_LOG_ERROR, "Cannot automatically
>> assign PID for stream %d\n", st->index);
>> +                    ret = AVERROR(EINVAL);
>> +                    goto fail;
>> +                }
>> +            } else {
>> +                ts_st->pid = ts->start_pid + i;
>> +            }
>>          } else {
>>              ts_st->pid = st->id;
>>          }
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list