[FFmpeg-devel] [PATCH] added synchronous KLV codec ID and mpegts PAT and PMT descriptors as specified in stanag4609 annex C

Peter Ross pross at xvid.org
Sat Aug 30 16:23:45 CEST 2014


On Fri, Aug 29, 2014 at 02:24:21PM +0200, paolovergori wrote:
> ---
>  libavcodec/avcodec.h    | 17 +++++++++--------
>  libavcodec/codec_desc.c |  6 ++++++
>  libavformat/mpegts.c    |  2 ++
>  libavformat/mpegts.h    |  1 +
>  libavformat/mpegtsenc.c | 27 +++++++++++++++++++++++++++
>  5 files changed, 45 insertions(+), 8 deletions(-)

The changes to the mpegts muxer and demuxer really should be done in separate patches.

> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index fb1c9ca..99eba82 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -526,14 +526,15 @@ enum AVCodecID {
>      /* other specific kind of codecs (generally used for attachments) */
>      AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
>      AV_CODEC_ID_TTF = 0x18000,
> -    AV_CODEC_ID_BINTEXT    = MKBETAG('B','T','X','T'),
> -    AV_CODEC_ID_XBIN       = MKBETAG('X','B','I','N'),
> -    AV_CODEC_ID_IDF        = MKBETAG( 0 ,'I','D','F'),
> -    AV_CODEC_ID_OTF        = MKBETAG( 0 ,'O','T','F'),
> -    AV_CODEC_ID_SMPTE_KLV  = MKBETAG('K','L','V','A'),
> -    AV_CODEC_ID_DVD_NAV    = MKBETAG('D','N','A','V'),
> -    AV_CODEC_ID_TIMED_ID3  = MKBETAG('T','I','D','3'),
> -    AV_CODEC_ID_BIN_DATA   = MKBETAG('D','A','T','A'),
> +    AV_CODEC_ID_BINTEXT         = MKBETAG('B','T','X','T'),
> +    AV_CODEC_ID_XBIN            = MKBETAG('X','B','I','N'),
> +    AV_CODEC_ID_IDF             = MKBETAG( 0 ,'I','D','F'),
> +    AV_CODEC_ID_OTF             = MKBETAG( 0 ,'O','T','F'),
> +    AV_CODEC_ID_SMPTE_KLV       = MKBETAG('K','L','V','A'),
> +    AV_CODEC_ID_SMPTE_KLV_SYNC  = MKBETAG('K','L','V','S'),
> +    AV_CODEC_ID_DVD_NAV         = MKBETAG('D','N','A','V'),
> +    AV_CODEC_ID_TIMED_ID3       = MKBETAG('T','I','D','3'),
> +    AV_CODEC_ID_BIN_DATA        = MKBETAG('D','A','T','A'),
>  
>  
>      AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 9e9728b..5cad936 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -2706,6 +2706,12 @@ static const AVCodecDescriptor codec_descriptors[] = {
>          .long_name = NULL_IF_CONFIG_SMALL("SMPTE 336M Key-Length-Value (KLV) metadata"),
>      },
>      {
> +        .id        = AV_CODEC_ID_SMPTE_KLV_SYNC,
> +        .type      = AVMEDIA_TYPE_DATA,
> +        .name      = "klvSync",
> +        .long_name = NULL_IF_CONFIG_SMALL("SMPTE 336M Key-Length-Value (KLV) synchronous metadata"),
> +    },

Is a new CODEC_ID really neccessary here? 
The SMPTE 336M KLV data structures are the same regardless of how it is muxed.

> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index a118689..6633801 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -694,12 +694,14 @@ static const StreamType REGD_types[] = {
>      { MKTAG('D', 'T', 'S', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS   },
>      { MKTAG('H', 'E', 'V', 'C'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC  },
>      { MKTAG('K', 'L', 'V', 'A'), AVMEDIA_TYPE_DATA,  AV_CODEC_ID_SMPTE_KLV },
> +    { MKTAG('K', 'L', 'V', 'S'), AVMEDIA_TYPE_DATA,  AV_CODEC_ID_SMPTE_KLV_SYNC },

What is 'KLVS'? This is not in STANAG 4609.

>      { MKTAG('V', 'C', '-', '1'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1   },
>      { 0 },
>  };



> +            if (st->codec->codec_id == AV_CODEC_ID_SMPTE_KLV_SYNC) {

Hmm. It looks like you are using the CODEC_ID to decide if the KLV packets should be muxed synchronously.
IMHO, this should be controlled by an AVOption


add comment here like 'Begin metadata_descriptor'
> +                *q++ = 0x26;
> +                *q++ = 0x09;

> +                *q++ = 0x01;  
> +                *q++ = 0x00;
this is a 16-bit field. use AV_WB16. Add comment 'metadata_application_format'

> +                *q++ = 0xFF;
> +                *q++ = 'K';
> +                *q++ = 'L';
> +                *q++ = 'V';
> +                *q++ = 'A';
> +                *q++ = 0x00;
> +                *q++ = 0x0f;

add comment here 'Begin metadata_std_descriptor'
> +                *q++ = 0x27;
> +                *q++ = 0x09;
> +                *q++ = 0xC0;

> +                *q++ = 0x00;
> +                *q++ = 0x00;//0x04;
// add comment. what do those 0x00's mean

> +                *q++ = 0xC0;

> +                *q++ = 0x00;
> +                *q++ = 0x00;//0x01;
// add comment

> +                *q++ = 0xC0;

> +                *q++ = 0x00;
> +                *q++ = 0x00;
// add comment


-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140831/af3d4549/attachment.asc>


More information about the ffmpeg-devel mailing list