diff mbox series

[FFmpeg-devel] lavf/matroska: add support for ARIB captions

Message ID 20230113172640.52901-1-rcombs@rcombs.me
State Accepted
Commit f758d4fcb93b77115b6d971859f5bee56f8070b8
Headers show
Series [FFmpeg-devel] lavf/matroska: add support for ARIB captions | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

rcombs Jan. 13, 2023, 5:26 p.m. UTC
Not yet ready for merge, pending finalization of the standard proposal for this mapping:
https://github.com/ietf-wg-cellar/matroska-specification/pull/724
---
 libavformat/matroska.c    |  1 +
 libavformat/matroskadec.c | 30 ++++++++++++++++++++++++++++++
 libavformat/matroskaenc.c | 23 +++++++++++++++++++++++
 3 files changed, 54 insertions(+)

Comments

Pierre-Anthony Lemieux Jan. 13, 2023, 7:06 p.m. UTC | #1
On Fri, Jan 13, 2023 at 9:27 AM rcombs <rcombs@rcombs.me> wrote:
>
> Not yet ready for merge, pending finalization of the standard proposal for this mapping:
> https://github.com/ietf-wg-cellar/matroska-specification/pull/724

Is sample ARIB caption available?

> ---
>  libavformat/matroska.c    |  1 +
>  libavformat/matroskadec.c | 30 ++++++++++++++++++++++++++++++
>  libavformat/matroskaenc.c | 23 +++++++++++++++++++++++
>  3 files changed, 54 insertions(+)
>
> diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> index 90d94b65bf..79b2d09984 100644
> --- a/libavformat/matroska.c
> +++ b/libavformat/matroska.c
> @@ -76,6 +76,7 @@ const CodecTags ff_mkv_codec_tags[]={
>      {"S_DVBSUB"         , AV_CODEC_ID_DVB_SUBTITLE},
>      {"S_HDMV/PGS"       , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
>      {"S_HDMV/TEXTST"    , AV_CODEC_ID_HDMV_TEXT_SUBTITLE},
> +    {"S_ARIBSUB"        , AV_CODEC_ID_ARIB_CAPTION},
>
>      {"V_AV1"            , AV_CODEC_ID_AV1},
>      {"V_AVS2"           , AV_CODEC_ID_AVS2},
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index d582f566a2..3a888e3ada 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -50,6 +50,7 @@
>  #include "libavutil/time_internal.h"
>  #include "libavutil/spherical.h"
>
> +#include "libavcodec/avcodec.h"
>  #include "libavcodec/bytestream.h"
>  #include "libavcodec/flac.h"
>  #include "libavcodec/mpeg4audio.h"
> @@ -2813,6 +2814,35 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              /* we don't need any value stored in CodecPrivate.
>                 make sure that it's not exported as extradata. */
>              track->codec_priv.size = 0;
> +        } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION && track->codec_priv.size == 3) {
> +            int component_tag = track->codec_priv.data[0];
> +            int data_component_id = AV_RB16(track->codec_priv.data + 1);
> +
> +            switch (data_component_id) {
> +            case 0x0008:
> +                // [0x30..0x37] are component tags utilized for
> +                // non-mobile captioning service ("profile A").
> +                if (component_tag >= 0x30 && component_tag <= 0x37) {
> +                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_A;
> +                }
> +                break;
> +            case 0x0012:
> +                // component tag 0x87 signifies a mobile/partial reception
> +                // (1seg) captioning service ("profile C").
> +                if (component_tag == 0x87) {
> +                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_C;
> +                }
> +                break;
> +            default:
> +                break;
> +            }
> +
> +            if (st->codecpar->profile == FF_PROFILE_UNKNOWN)
> +                av_log(matroska->ctx, AV_LOG_WARNING,
> +                       "Unknown ARIB caption profile utilized: %02x / %04x\n",
> +                       component_tag, data_component_id);
> +
> +            track->codec_priv.size = 0;
>          }
>          track->codec_priv.size -= extradata_offset;
>
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 2deb4284e8..67cfec761a 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -58,6 +58,7 @@
>  #include "libavutil/stereo3d.h"
>
>  #include "libavcodec/av1.h"
> +#include "libavcodec/avcodec.h"
>  #include "libavcodec/codec_desc.h"
>  #include "libavcodec/xiph.h"
>  #include "libavcodec/mpeg4audio.h"
> @@ -1142,6 +1143,27 @@ static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn
>          else
>              *size_to_reserve = MAX_PCE_SIZE;
>          break;
> +    case AV_CODEC_ID_ARIB_CAPTION: {
> +        unsigned stream_identifier, data_component_id;
> +        switch (par->profile) {
> +        case FF_PROFILE_ARIB_PROFILE_A:
> +            stream_identifier = 0x30;
> +            data_component_id = 0x0008;
> +            break;
> +        case FF_PROFILE_ARIB_PROFILE_C:
> +            stream_identifier = 0x87;
> +            data_component_id = 0x0012;
> +            break;
> +        default:
> +            av_log(s, AV_LOG_ERROR,
> +                   "Unset/unknown ARIB caption profile %d utilized!\n",
> +                   par->profile);
> +            return AVERROR_INVALIDDATA;
> +        }
> +        avio_w8(dyn_cp, stream_identifier);
> +        avio_wb16(dyn_cp, data_component_id);
> +        break;
> +    }
>  #endif
>      default:
>          if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES &&
> @@ -3274,6 +3296,7 @@ static const AVCodecTag additional_subtitle_tags[] = {
>      { AV_CODEC_ID_DVB_SUBTITLE,      0xFFFFFFFF },
>      { AV_CODEC_ID_DVD_SUBTITLE,      0xFFFFFFFF },
>      { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
> +    { AV_CODEC_ID_ARIB_CAPTION,      0xFFFFFFFF },
>      { AV_CODEC_ID_NONE,              0xFFFFFFFF }
>  };
>
> --
> 2.38.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Andreas Rheinhardt Jan. 29, 2023, 11:06 p.m. UTC | #2
rcombs:
> Not yet ready for merge, pending finalization of the standard proposal for this mapping:
> https://github.com/ietf-wg-cellar/matroska-specification/pull/724
> ---
>  libavformat/matroska.c    |  1 +
>  libavformat/matroskadec.c | 30 ++++++++++++++++++++++++++++++
>  libavformat/matroskaenc.c | 23 +++++++++++++++++++++++
>  3 files changed, 54 insertions(+)
> 
> diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> index 90d94b65bf..79b2d09984 100644
> --- a/libavformat/matroska.c
> +++ b/libavformat/matroska.c
> @@ -76,6 +76,7 @@ const CodecTags ff_mkv_codec_tags[]={
>      {"S_DVBSUB"         , AV_CODEC_ID_DVB_SUBTITLE},
>      {"S_HDMV/PGS"       , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
>      {"S_HDMV/TEXTST"    , AV_CODEC_ID_HDMV_TEXT_SUBTITLE},
> +    {"S_ARIBSUB"        , AV_CODEC_ID_ARIB_CAPTION},
>  
>      {"V_AV1"            , AV_CODEC_ID_AV1},
>      {"V_AVS2"           , AV_CODEC_ID_AVS2},
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index d582f566a2..3a888e3ada 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -50,6 +50,7 @@
>  #include "libavutil/time_internal.h"
>  #include "libavutil/spherical.h"
>  
> +#include "libavcodec/avcodec.h"
>  #include "libavcodec/bytestream.h"
>  #include "libavcodec/flac.h"
>  #include "libavcodec/mpeg4audio.h"
> @@ -2813,6 +2814,35 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              /* we don't need any value stored in CodecPrivate.
>                 make sure that it's not exported as extradata. */
>              track->codec_priv.size = 0;
> +        } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION && track->codec_priv.size == 3) {
> +            int component_tag = track->codec_priv.data[0];
> +            int data_component_id = AV_RB16(track->codec_priv.data + 1);
> +
> +            switch (data_component_id) {
> +            case 0x0008:
> +                // [0x30..0x37] are component tags utilized for
> +                // non-mobile captioning service ("profile A").
> +                if (component_tag >= 0x30 && component_tag <= 0x37) {
> +                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_A;
> +                }
> +                break;
> +            case 0x0012:
> +                // component tag 0x87 signifies a mobile/partial reception
> +                // (1seg) captioning service ("profile C").
> +                if (component_tag == 0x87) {
> +                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_C;
> +                }
> +                break;
> +            default:
> +                break;
> +            }
> +
> +            if (st->codecpar->profile == FF_PROFILE_UNKNOWN)
> +                av_log(matroska->ctx, AV_LOG_WARNING,
> +                       "Unknown ARIB caption profile utilized: %02x / %04x\n",
> +                       component_tag, data_component_id);
> +
> +            track->codec_priv.size = 0;
>          }
>          track->codec_priv.size -= extradata_offset;
>  
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 2deb4284e8..67cfec761a 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -58,6 +58,7 @@
>  #include "libavutil/stereo3d.h"
>  
>  #include "libavcodec/av1.h"
> +#include "libavcodec/avcodec.h"

Why are these FF_PROFILE_* defines in avcodec.h and not either in a
header of their own or in defs.h?

>  #include "libavcodec/codec_desc.h"
>  #include "libavcodec/xiph.h"
>  #include "libavcodec/mpeg4audio.h"
> @@ -1142,6 +1143,27 @@ static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn
>          else
>              *size_to_reserve = MAX_PCE_SIZE;
>          break;
> +    case AV_CODEC_ID_ARIB_CAPTION: {
> +        unsigned stream_identifier, data_component_id;
> +        switch (par->profile) {
> +        case FF_PROFILE_ARIB_PROFILE_A:
> +            stream_identifier = 0x30;
> +            data_component_id = 0x0008;
> +            break;
> +        case FF_PROFILE_ARIB_PROFILE_C:
> +            stream_identifier = 0x87;
> +            data_component_id = 0x0012;
> +            break;
> +        default:
> +            av_log(s, AV_LOG_ERROR,
> +                   "Unset/unknown ARIB caption profile %d utilized!\n",
> +                   par->profile);
> +            return AVERROR_INVALIDDATA;
> +        }
> +        avio_w8(dyn_cp, stream_identifier);
> +        avio_wb16(dyn_cp, data_component_id);
> +        break;
> +    }
>  #endif
>      default:
>          if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES &&
> @@ -3274,6 +3296,7 @@ static const AVCodecTag additional_subtitle_tags[] = {
>      { AV_CODEC_ID_DVB_SUBTITLE,      0xFFFFFFFF },
>      { AV_CODEC_ID_DVD_SUBTITLE,      0xFFFFFFFF },
>      { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
> +    { AV_CODEC_ID_ARIB_CAPTION,      0xFFFFFFFF },
>      { AV_CODEC_ID_NONE,              0xFFFFFFFF }
>  };
>
diff mbox series

Patch

diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index 90d94b65bf..79b2d09984 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -76,6 +76,7 @@  const CodecTags ff_mkv_codec_tags[]={
     {"S_DVBSUB"         , AV_CODEC_ID_DVB_SUBTITLE},
     {"S_HDMV/PGS"       , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
     {"S_HDMV/TEXTST"    , AV_CODEC_ID_HDMV_TEXT_SUBTITLE},
+    {"S_ARIBSUB"        , AV_CODEC_ID_ARIB_CAPTION},
 
     {"V_AV1"            , AV_CODEC_ID_AV1},
     {"V_AVS2"           , AV_CODEC_ID_AVS2},
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..3a888e3ada 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -50,6 +50,7 @@ 
 #include "libavutil/time_internal.h"
 #include "libavutil/spherical.h"
 
+#include "libavcodec/avcodec.h"
 #include "libavcodec/bytestream.h"
 #include "libavcodec/flac.h"
 #include "libavcodec/mpeg4audio.h"
@@ -2813,6 +2814,35 @@  static int matroska_parse_tracks(AVFormatContext *s)
             /* we don't need any value stored in CodecPrivate.
                make sure that it's not exported as extradata. */
             track->codec_priv.size = 0;
+        } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION && track->codec_priv.size == 3) {
+            int component_tag = track->codec_priv.data[0];
+            int data_component_id = AV_RB16(track->codec_priv.data + 1);
+
+            switch (data_component_id) {
+            case 0x0008:
+                // [0x30..0x37] are component tags utilized for
+                // non-mobile captioning service ("profile A").
+                if (component_tag >= 0x30 && component_tag <= 0x37) {
+                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_A;
+                }
+                break;
+            case 0x0012:
+                // component tag 0x87 signifies a mobile/partial reception
+                // (1seg) captioning service ("profile C").
+                if (component_tag == 0x87) {
+                    st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_C;
+                }
+                break;
+            default:
+                break;
+            }
+
+            if (st->codecpar->profile == FF_PROFILE_UNKNOWN)
+                av_log(matroska->ctx, AV_LOG_WARNING,
+                       "Unknown ARIB caption profile utilized: %02x / %04x\n",
+                       component_tag, data_component_id);
+
+            track->codec_priv.size = 0;
         }
         track->codec_priv.size -= extradata_offset;
 
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 2deb4284e8..67cfec761a 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -58,6 +58,7 @@ 
 #include "libavutil/stereo3d.h"
 
 #include "libavcodec/av1.h"
+#include "libavcodec/avcodec.h"
 #include "libavcodec/codec_desc.h"
 #include "libavcodec/xiph.h"
 #include "libavcodec/mpeg4audio.h"
@@ -1142,6 +1143,27 @@  static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn
         else
             *size_to_reserve = MAX_PCE_SIZE;
         break;
+    case AV_CODEC_ID_ARIB_CAPTION: {
+        unsigned stream_identifier, data_component_id;
+        switch (par->profile) {
+        case FF_PROFILE_ARIB_PROFILE_A:
+            stream_identifier = 0x30;
+            data_component_id = 0x0008;
+            break;
+        case FF_PROFILE_ARIB_PROFILE_C:
+            stream_identifier = 0x87;
+            data_component_id = 0x0012;
+            break;
+        default:
+            av_log(s, AV_LOG_ERROR,
+                   "Unset/unknown ARIB caption profile %d utilized!\n",
+                   par->profile);
+            return AVERROR_INVALIDDATA;
+        }
+        avio_w8(dyn_cp, stream_identifier);
+        avio_wb16(dyn_cp, data_component_id);
+        break;
+    }
 #endif
     default:
         if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES &&
@@ -3274,6 +3296,7 @@  static const AVCodecTag additional_subtitle_tags[] = {
     { AV_CODEC_ID_DVB_SUBTITLE,      0xFFFFFFFF },
     { AV_CODEC_ID_DVD_SUBTITLE,      0xFFFFFFFF },
     { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
+    { AV_CODEC_ID_ARIB_CAPTION,      0xFFFFFFFF },
     { AV_CODEC_ID_NONE,              0xFFFFFFFF }
 };