Re: [FFmpeg-devel] [PATCH v4] libavformat/mpegtsenc: Add minimal support for ATSC PSIP tables
It's been a month, no replies. Is this commit going to be committed, or is there something further I need to do to move this along? Should I post a rebased version? Thanks, Phil On Tue, May 21, 2019 at 8:40 AM Phillip Burr wrote: > Minimal support for ATSC PSIP tables. Does not support STT or > EIT tables and so is not compliant with terrestrial ATSC. > ATSC tables are not created by default, and will only be transmitted > if either "atsc_name" or "atsc_channel" metadata is supplied. > > Signed-off-by: Phillip Burr > --- > doc/muxers.texi | 33 ++- > libavformat/mpegts.h| 8 + > libavformat/mpegtsenc.c | 468 > 3 files changed, 415 insertions(+), 94 deletions(-) > > diff --git a/doc/muxers.texi b/doc/muxers.texi > index 83ae017d6c..dd68eec362 100644 > --- a/doc/muxers.texi > +++ b/doc/muxers.texi > @@ -1500,10 +1500,35 @@ MPEG transport stream muxer. > > This muxer implements ISO 13818-1 and part of ETSI EN 300 468. > > -The recognized metadata settings in mpegts muxer are > @code{service_provider} > -and @code{service_name}. If they are not set the default for > -@code{service_provider} is @samp{FFmpeg} and the default for > -@code{service_name} is @samp{Service01}. > +@subsection Metadata > + > +The recognized metadata settings in this muxer are: > + > +@table @option > +@item service_name @var{string} > +Set the @code{service_provider}. Default is @samp{FFmpeg}. > + > +@item service_name @var{string} > +Set the @code{service_name}. Default is @samp{Service01}. > + > +@item atsc_name @var{string} > +Set the @code{atsc_name} for the stream. This is the ATSC short > +channel name for the stream. > + > +@item atsc_channel @var{string} > +Set the @code{atsc_channel} virtual channel for the stream. This > +is parsed as @samp{Channel[.SubChannel]} format where the subchannel > +is optional and defaults to @code{1}. > + > +@end table > + > +ATSC tables will @emph{not} be generated unless either @code{atsc_name} > +or @code{atsc_channel} are provided @emph{and} @code{muxrate} is provided. > +In the event that either @code{atsc_name} or @code{atsc_channel} is > provided > +but not both, the default for @code{atsc_name} is @samp{FFmpeg} > +and the default for @code{atsc_channel} is @samp{1.1}. > +ATSC tables generated include @code{MGT} and @code{TVCT} tables but are > lacking the mandatory > +@code{STT}, @code{EIT0}, @code{EIT1}, @code{EIT2} and @code{EIT3} tables > needed for terrestrial ATC compliance. > > @subsection Options > > diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h > index 272e2be4f7..ca6943b1ba 100644 > --- a/libavformat/mpegts.h > +++ b/libavformat/mpegts.h > @@ -35,12 +35,20 @@ > /* pids */ > #define PAT_PID 0x > #define SDT_PID 0x0011 > +#define ATSC_PID0x1ffb > > /* table ids */ > #define PAT_TID 0x00 > #define PMT_TID 0x02 > #define M4OD_TID 0x05 > #define SDT_TID 0x42 > +#define MGT_TID 0xc7 > +#define TVCT_TID 0xc8 > +#define CVCT_TID 0xc9 > +#define RRT_TID 0xca > +#define EIT_TID 0xcb > +#define ETT_TID 0xcc > +#define STT_TID 0xcd > > #define STREAM_TYPE_VIDEO_MPEG1 0x01 > #define STREAM_TYPE_VIDEO_MPEG2 0x02 > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c > index fc0ea225c6..335ff254d8 100644 > --- a/libavformat/mpegtsenc.c > +++ b/libavformat/mpegtsenc.c > @@ -56,12 +56,40 @@ typedef struct MpegTSService { > int sid; /* service ID */ > uint8_t name[256]; > uint8_t provider_name[256]; > + > +uint16_t atsc_name[7]; /* ATSC VCT fields */ > +int atsc_mj_channel; > +int atsc_mn_channel; > + > int pcr_pid; > int pcr_packet_count; > int pcr_packet_period; > AVProgram *program; > } MpegTSService; > > +/* The section length is 12 bits. The first 2 are set to 0, the remaining > + * 10 bits should not exceed 1021. */ > +#define SECTION_LENGTH 1020 > + > +typedef struct MpegTSAtsc { > +int enabled; > +int regenerate; > + > +MpegTSSection section; /* ATSC tables */ > + > +int mgt_packet_count; > +int mgt_packet_period; > +int tvct_packet_count; > +int tvct_packet_period; > +int64_t last_mgt_ts; > +int64_t last_tvct_ts; > + > +uint32_t tvct_length; > +uint32_t mgt_length; > +uint8_t tvct_data[SECTION_LENGTH]; > +uint8_t mgt_data[SECTION_LENGTH]; > +} MpegTSAtsc; > + > // service_type values as defined in ETSI 300 468 > enum { > MPEGTS_SERVICE_TYPE_DIGITAL_TV = 0x01, > @@ -78,6 +106,7 @@ typedef struct MpegTSWrite { > MpegTSSection pat; /* MPEG-2 PAT table */ > MpegTSSection sdt; /* MPEG-2 SDT table context */ > MpegTSService **services; > +MpegTSAtsc atsc; > int sdt_packet_count; > int sdt_packet_period; > int pat_packet_count; > @@ -121,10 +150,6 @@ typedef struct MpegTSWrite { > #define DEFAULT_PES_HEADER_FREQ 16 > #define DEFAULT_PES_PAYLOAD_SIZE
Re: [FFmpeg-devel] [PATCH v4] libavformat/mpegtsenc: Add minimal support for ATSC PSIP tables
This patch has a bit more restructuring to consolidate the ATSC specific fields. I fixed some bugs where a few fields were set incorrectly. Specifically, the MGT transmits the length of each table it describes and so each table it describes is pre-populated. Testing last night involved taking an OTA ATSC broadcast, remuxing with ffmpeg and transmitting to a TV for two hours. On Tue, May 21, 2019 at 8:40 AM Phillip Burr wrote: > Minimal support for ATSC PSIP tables. Does not support STT or > EIT tables and so is not compliant with terrestrial ATSC. > ATSC tables are not created by default, and will only be transmitted > if either "atsc_name" or "atsc_channel" metadata is supplied. > > Signed-off-by: Phillip Burr > --- > doc/muxers.texi | 33 ++- > libavformat/mpegts.h| 8 + > libavformat/mpegtsenc.c | 468 > 3 files changed, 415 insertions(+), 94 deletions(-) > > diff --git a/doc/muxers.texi b/doc/muxers.texi > index 83ae017d6c..dd68eec362 100644 > --- a/doc/muxers.texi > +++ b/doc/muxers.texi > @@ -1500,10 +1500,35 @@ MPEG transport stream muxer. > > This muxer implements ISO 13818-1 and part of ETSI EN 300 468. > > -The recognized metadata settings in mpegts muxer are > @code{service_provider} > -and @code{service_name}. If they are not set the default for > -@code{service_provider} is @samp{FFmpeg} and the default for > -@code{service_name} is @samp{Service01}. > +@subsection Metadata > + > +The recognized metadata settings in this muxer are: > + > +@table @option > +@item service_name @var{string} > +Set the @code{service_provider}. Default is @samp{FFmpeg}. > + > +@item service_name @var{string} > +Set the @code{service_name}. Default is @samp{Service01}. > + > +@item atsc_name @var{string} > +Set the @code{atsc_name} for the stream. This is the ATSC short > +channel name for the stream. > + > +@item atsc_channel @var{string} > +Set the @code{atsc_channel} virtual channel for the stream. This > +is parsed as @samp{Channel[.SubChannel]} format where the subchannel > +is optional and defaults to @code{1}. > + > +@end table > + > +ATSC tables will @emph{not} be generated unless either @code{atsc_name} > +or @code{atsc_channel} are provided @emph{and} @code{muxrate} is provided. > +In the event that either @code{atsc_name} or @code{atsc_channel} is > provided > +but not both, the default for @code{atsc_name} is @samp{FFmpeg} > +and the default for @code{atsc_channel} is @samp{1.1}. > +ATSC tables generated include @code{MGT} and @code{TVCT} tables but are > lacking the mandatory > +@code{STT}, @code{EIT0}, @code{EIT1}, @code{EIT2} and @code{EIT3} tables > needed for terrestrial ATC compliance. > > @subsection Options > > diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h > index 272e2be4f7..ca6943b1ba 100644 > --- a/libavformat/mpegts.h > +++ b/libavformat/mpegts.h > @@ -35,12 +35,20 @@ > /* pids */ > #define PAT_PID 0x > #define SDT_PID 0x0011 > +#define ATSC_PID0x1ffb > > /* table ids */ > #define PAT_TID 0x00 > #define PMT_TID 0x02 > #define M4OD_TID 0x05 > #define SDT_TID 0x42 > +#define MGT_TID 0xc7 > +#define TVCT_TID 0xc8 > +#define CVCT_TID 0xc9 > +#define RRT_TID 0xca > +#define EIT_TID 0xcb > +#define ETT_TID 0xcc > +#define STT_TID 0xcd > > #define STREAM_TYPE_VIDEO_MPEG1 0x01 > #define STREAM_TYPE_VIDEO_MPEG2 0x02 > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c > index fc0ea225c6..335ff254d8 100644 > --- a/libavformat/mpegtsenc.c > +++ b/libavformat/mpegtsenc.c > @@ -56,12 +56,40 @@ typedef struct MpegTSService { > int sid; /* service ID */ > uint8_t name[256]; > uint8_t provider_name[256]; > + > +uint16_t atsc_name[7]; /* ATSC VCT fields */ > +int atsc_mj_channel; > +int atsc_mn_channel; > + > int pcr_pid; > int pcr_packet_count; > int pcr_packet_period; > AVProgram *program; > } MpegTSService; > > +/* The section length is 12 bits. The first 2 are set to 0, the remaining > + * 10 bits should not exceed 1021. */ > +#define SECTION_LENGTH 1020 > + > +typedef struct MpegTSAtsc { > +int enabled; > +int regenerate; > + > +MpegTSSection section; /* ATSC tables */ > + > +int mgt_packet_count; > +int mgt_packet_period; > +int tvct_packet_count; > +int tvct_packet_period; > +int64_t last_mgt_ts; > +int64_t last_tvct_ts; > + > +uint32_t tvct_length; > +uint32_t mgt_length; > +uint8_t tvct_data[SECTION_LENGTH]; > +uint8_t mgt_data[SECTION_LENGTH]; > +} MpegTSAtsc; > + > // service_type values as defined in ETSI 300 468 > enum { > MPEGTS_SERVICE_TYPE_DIGITAL_TV = 0x01, > @@ -78,6 +106,7 @@ typedef struct MpegTSWrite { > MpegTSSection pat; /* MPEG-2 PAT table */ > MpegTSSection sdt; /* MPEG-2 SDT table context */ > MpegTSService **services; > +MpegTSAtsc atsc; > int sdt_p