Re: [FFmpeg-devel] [PATCH v2] lavc/libaribcaption: Fix mistake in document decoders.texi

2023-11-02 Thread zheng qian
On Thu, Nov 2, 2023 at 5:40 PM Gyan Doshi  wrote:
>
>
>
> On 2023-11-02 01:21 am, Gyan Doshi wrote:
> >
> >
> > On 2023-11-01 08:54 pm, zheng qian wrote:
> >> Fix the mistake in the description of `-caption_encoding
> >> encoding_scheme` option.
> > Will fix commit message and push.
>
> Pushed as 4dbfb52230c4993e58598386ac79b964589dc00e and
> 80daebdfdff48dc5ad7c1a704d885c215168e214


Thanks.

Regards,
xqq

>
> Regards, Gyan
> >
> >>
> >> Signed-off-by: zheng qian 
> >> ---
> >>   doc/decoders.texi | 5 +
> >>   1 file changed, 1 insertion(+), 4 deletions(-)
> >>
> >> diff --git a/doc/decoders.texi b/doc/decoders.texi
> >> index eb00e2a9e9..f75364166e 100644
> >> --- a/doc/decoders.texi
> >> +++ b/doc/decoders.texi
> >> @@ -391,7 +391,7 @@ Specifies the encoding scheme of input subtitle
> >> text.
> >> @table @samp
> >>   @item auto
> >> -Automatically detect text encoding.
> >> +Automatically detect text encoding (default).
> >>   @item jis
> >>   8bit-char JIS encoding defined in ARIB STD B24.
> >>   This encoding used in Japan for ISDB captions.
> >> @@ -403,9 +403,6 @@ Latin character encoding defined in ABNT NBR
> >> 15606-1.
> >>   This encoding is used in South America for SBTVD / ISDB-Tb captions.
> >>   @end table
> >>   -The default is @dfn{ass} as same as @dfn{libaribb24} decoder.
> >> -Some present players (e.g., @dfn{mpv}) expect ASS format for ARIB
> >> caption.
> >> -
> >>   @item -font @var{font_name[,font_name2,...]}
> >>   Specify comma-separated list of font family names to be used for
> >> @dfn{bitmap}
> >>   or @dfn{ass} type subtitle rendering.
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/libaribcaption: Fix mistake in document decoders.texi

2023-11-01 Thread zheng qian
Fix the mistake in the description of `-caption_encoding encoding_scheme` 
option.

Signed-off-by: zheng qian 
---
 doc/decoders.texi | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index eb00e2a9e9..f75364166e 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -391,7 +391,7 @@ Specifies the encoding scheme of input subtitle text.
 
 @table @samp
 @item auto
-Automatically detect text encoding.
+Automatically detect text encoding (default).
 @item jis
 8bit-char JIS encoding defined in ARIB STD B24.
 This encoding used in Japan for ISDB captions.
@@ -403,9 +403,6 @@ Latin character encoding defined in ABNT NBR 15606-1.
 This encoding is used in South America for SBTVD / ISDB-Tb captions.
 @end table
 
-The default is @dfn{ass} as same as @dfn{libaribb24} decoder.
-Some present players (e.g., @dfn{mpv}) expect ASS format for ARIB caption.
-
 @item -font @var{font_name[,font_name2,...]}
 Specify comma-separated list of font family names to be used for @dfn{bitmap}
 or @dfn{ass} type subtitle rendering.
-- 
2.39.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/1] lavc/libaribcaption: Fix mistake in document decoders.texi

2023-11-01 Thread zheng qian
Fix the mistake in the description of `-caption_encoding encoding_scheme` 
option.

Signed-off-by: zheng qian 
---
 doc/decoders.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index eb00e2a9e9..59279bde24 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -403,8 +403,8 @@ Latin character encoding defined in ABNT NBR 15606-1.
 This encoding is used in South America for SBTVD / ISDB-Tb captions.
 @end table
 
-The default is @dfn{ass} as same as @dfn{libaribb24} decoder.
-Some present players (e.g., @dfn{mpv}) expect ASS format for ARIB caption.
+The default is @dfn{auto} which tries to determine text encoding automatically.
+You can specify a specific encoding scheme if the source of the broadcast is 
known.
 
 @item -font @var{font_name[,font_name2,...]}
 Specify comma-separated list of font family names to be used for @dfn{bitmap}
-- 
2.39.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/1] Fix document mistake for lavc/libaribcaption

2023-11-01 Thread zheng qian
Hi, I'm fixing a mistake contained in the document for lavc/libaribcaption.
This affects the 6.1 release so please also cheery-pick this patch to 6.1.

zheng qian (1):
  lavc/libaribcaption: Fix mistake in document decoders.texi

 doc/decoders.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.39.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 4/4] fftools/ffmpeg: Ignore dts checking for AV_DISPOSITION_URGENT

2021-07-16 Thread zheng qian
Stream with AV_DISPOSITION_URGENT disposition flag could be NOPTS.

Signed-off-by: zheng qian 
---
 fftools/ffmpeg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1ac2e48600..a3b720748b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -824,7 +824,8 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || 
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == 
AVMEDIA_TYPE_SUBTITLE) &&
 pkt->dts != AV_NOPTS_VALUE &&
 !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) &&
-ost->last_mux_dts != AV_NOPTS_VALUE) {
+ost->last_mux_dts != AV_NOPTS_VALUE &&
+!(st->disposition & AV_DISPOSITION_URGENT)) {
 int64_t max = ost->last_mux_dts + !(s->oformat->flags & 
AVFMT_TS_NONSTRICT);
 if (pkt->dts < max) {
 int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type 
== AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 3/4] avformat/mpegtsenc: Add muxing support for ARIB superimpose stream

2021-07-16 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 40 +++-
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 98dac17994..b5d2938c4a 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,26 +287,37 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, 
size_t len)
 *q_ptr += len;
 }
 
-static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
-   AVCodecParameters *codecpar)
+static int put_arib_descriptor(AVFormatContext *s, AVStream* st, uint8_t 
**q_ptr)
 {
 uint8_t stream_identifier;
 uint16_t data_component_id;
 uint8_t *q = *q_ptr;
 
-switch (codecpar->profile) {
+switch (st->codecpar->profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
-stream_identifier = 0x30;
+if (st->disposition & AV_DISPOSITION_URGENT) {
+// ARIB superimpose, with AV_DISPOSITION_URGENT flag
+stream_identifier = 0x38;
+} else {
+// ARIB caption
+stream_identifier = 0x30;
+}
 data_component_id = 0x0008;
 break;
 case FF_PROFILE_ARIB_PROFILE_C:
-stream_identifier = 0x87;
+if (st->disposition & AV_DISPOSITION_URGENT) {
+// ARIB superimpose
+stream_identifier = 0x88;
+} else {
+// ARIB caption
+stream_identifier = 0x87;
+}
 data_component_id = 0x0012;
 break;
 default:
 av_log(s, AV_LOG_ERROR,
"Unset/unknown ARIB caption profile %d utilized!\n",
-   codecpar->profile);
+   st->codecpar->profile);
 return AVERROR_INVALIDDATA;
 }
 
@@ -320,11 +331,17 @@ static int put_arib_caption_descriptor(AVFormatContext 
*s, uint8_t **q_ptr,
 *q++ = 3; // descriptor_length
 put16(, data_component_id);  // data_component_id
 // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 
3, 9.6.1
-// Here we utilize a pre-defined set of values defined in ARIB TR-B14,
+// Here we utilize pre-defined sets of values defined in ARIB TR-B14,
 // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle
 // set to 1 (as that is what every broadcaster seems to be doing in
 // production).
-*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+if (st->disposition & AV_DISPOSITION_URGENT) {
+// ARIB superimpose
+*q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00')
+} else {
+// ARIB caption
+*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+}
 
 *q_ptr = q;
 
@@ -772,7 +789,7 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
 
*len_ptr = q - len_ptr - 1;
 } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
-if (put_arib_caption_descriptor(s, , st->codecpar) < 0)
+if (put_arib_descriptor(s, st, ) < 0)
 break;
 }
 break;
@@ -1444,6 +1461,11 @@ static int get_pes_stream_id(AVFormatContext *s, 
AVStream *st, int stream_id, in
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */
 *async = 1;
 return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+} else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+   st->codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION &&
+   st->disposition & AV_DISPOSITION_URGENT) {  // ARIB superimpose
+// ARIB TR-B14, Fascicle 1 (2/2), Vol.3, 4.2.3
+return STREAM_ID_PRIVATE_STREAM_2;
 } else {
 return STREAM_ID_PRIVATE_STREAM_1;
 }
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/4] avformat/mpegts: Recognize ARIB superimpose stream

2021-07-16 Thread zheng qian
Recognize ARIB superimpose stream through ARIB data coding descriptor,
and re-use AV_CODEC_ID_ARIB_CAPTION codec id with an extra disposition
flag AV_DISPOSITION_URGENT.

Signed-off-by: zheng qian 
---
 libavformat/mpegts.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a02965bacf..44a1841859 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2106,8 +2106,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 }
 break;
 case 0xfd: /* ARIB data coding type descriptor */
-// STD-B24, fascicle 3, chapter 4 defines private_stream_1
-// for captions
+// STD-B24, fascicle 3, chapter 4 defines
+// private_stream_1 for captions, and private_stream_2 for superimpose
 if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
 // This structure is defined in STD-B10, part 1, listing 5.4 and
 // part 2, 6.2.20).
@@ -2115,6 +2115,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 // Component tag limits are documented in TR-B14, fascicle 2,
 // Vol. 3, Section 2, 4.2.8.1
 int actual_component_tag = st->internal->stream_identifier - 1;
+int is_superimpose = 0;
 int picked_profile = FF_PROFILE_UNKNOWN;
 int data_component_id = get16(pp, desc_end);
 if (data_component_id < 0)
@@ -2122,17 +2123,28 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 
 switch (data_component_id) {
 case 0x0008:
-// [0x30..0x37] are component tags utilized for
+// [0x30..0x37] and [0x38..0x3F] are component tags utilized 
for
 // non-mobile captioning service ("profile A").
 if (actual_component_tag >= 0x30 &&
 actual_component_tag <= 0x37) {
+// caption (Profile A)
+picked_profile = FF_PROFILE_ARIB_PROFILE_A;
+} else if (actual_component_tag >= 0x38 &&
+   actual_component_tag <= 0x3F) {
+// superimpose (Profile A)
+is_superimpose = 1;
 picked_profile = FF_PROFILE_ARIB_PROFILE_A;
 }
 break;
 case 0x0012:
-// component tag 0x87 signifies a mobile/partial reception
+// component tag 0x87 and 0x88 signifies a mobile/partial 
reception
 // (1seg) captioning service ("profile C").
 if (actual_component_tag == 0x87) {
+// caption (Profile C)
+picked_profile = FF_PROFILE_ARIB_PROFILE_C;
+} else if (actual_component_tag == 0x88) {
+// superimpose (Profile C)
+is_superimpose = 1;
 picked_profile = FF_PROFILE_ARIB_PROFILE_C;
 }
 break;
@@ -2147,6 +2159,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 st->codecpar->codec_id   = AV_CODEC_ID_ARIB_CAPTION;
 st->codecpar->profile= picked_profile;
 st->internal->request_probe= 0;
+if (is_superimpose) {
+st->disposition |= AV_DISPOSITION_URGENT;
+}
 }
 break;
 case 0xb0: /* DOVI video stream descriptor */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/4] avformat: Introduce AV_DISPOSITION_URGENT disposition flag for emergency alert

2021-07-16 Thread zheng qian
This patchset introduces AV_DISPOSITION_URGENT disposition flag for
marking stuffs which is expected to be shown immediately as received,
and adds recognization/remuxing support for ARIB superimpose stream.

ARIB superimpose is almost same as ARIB caption but is utilized to
transmit emergency alert and newsflash in Japan DTV.

Since superimpose is designed to be displayed immediately as received,
ARIB superimpose utilizes mpegts private_stream_2 rather than the
private_stream_1 that is used by arib_caption, which means superimpose
packet doesn't have PTS/DTS (AV_NOPTS_VALUE).

Purpose of introducing AV_DISPOSITION_URGENT is mainly:

1) To be able to mark stuffs as "show as received", which could be NOPTS

2) Let ffmpeg-based player to be able to recognize these stuffs such as
ARIB superimpose stream, and extract data to render it onto screen

3) Let mpegtsenc to be able to remux ARIB superimpose stream correctly

Signed-off-by: zheng qian 
---
 libavformat/avformat.h | 1 +
 libavformat/dump.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 81d2ac38d0..6c7d3fb3a5 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -831,6 +831,7 @@ typedef struct AVStreamInternal AVStreamInternal;
 #define AV_DISPOSITION_METADATA 0x4
 #define AV_DISPOSITION_DEPENDENT0x8 ///< dependent audio stream 
(mix_type=0 in mpegts)
 #define AV_DISPOSITION_STILL_IMAGE 0x10 ///< still images in video stream 
(still_picture_flag=1 in mpegts)
+#define AV_DISPOSITION_URGENT  0x20 ///< stream which is expected to 
be shown immediately as received (emergency alert)
 
 /**
  * Options for behavior on timestamp wrap detection.
diff --git a/libavformat/dump.c b/libavformat/dump.c
index cf892de107..a987d097dc 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -610,6 +610,8 @@ static void dump_stream_format(const AVFormatContext *ic, 
int i,
 av_log(NULL, AV_LOG_INFO, " (dependent)");
 if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
 av_log(NULL, AV_LOG_INFO, " (still image)");
+if (st->disposition & AV_DISPOSITION_URGENT)
+av_log(NULL, AV_LOG_INFO, " (urgent)");
 av_log(NULL, AV_LOG_INFO, "\n");
 
 dump_metadata(NULL, st->metadata, "");
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 5/5] avcodec/libaribb24: Enable decoding support for arib_superimpose

2021-06-12 Thread zheng qian
ARIB superimpose packet could also be decoded by libaribb24

Signed-off-by: zheng qian 
---
 configure   |  1 +
 libavcodec/allcodecs.c  |  1 +
 libavcodec/libaribb24.c | 14 ++
 3 files changed, 16 insertions(+)

diff --git a/configure b/configure
index 6bfd98b384..00a38b4cdc 100755
--- a/configure
+++ b/configure
@@ -3254,6 +3254,7 @@ libaom_av1_decoder_deps="libaom"
 libaom_av1_encoder_deps="libaom"
 libaom_av1_encoder_select="extract_extradata_bsf"
 libaribb24_decoder_deps="libaribb24"
+libaribb24_superimpose_decoder_deps="libaribb24"
 libcelt_decoder_deps="libcelt"
 libcodec2_decoder_deps="libcodec2"
 libcodec2_encoder_deps="libcodec2"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 623db2a9fa..5d5b536e97 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -722,6 +722,7 @@ extern const AVCodec ff_qdmc_at_decoder;
 extern const AVCodec ff_qdm2_at_decoder;
 extern AVCodec ff_libaom_av1_encoder;
 extern const AVCodec ff_libaribb24_decoder;
+extern const AVCodec ff_libaribb24_superimpose_decoder;
 extern const AVCodec ff_libcelt_decoder;
 extern const AVCodec ff_libcodec2_encoder;
 extern const AVCodec ff_libcodec2_decoder;
diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c
index 0766c0079d..afa43f8f50 100644
--- a/libavcodec/libaribb24.c
+++ b/libavcodec/libaribb24.c
@@ -393,3 +393,17 @@ const AVCodec ff_libaribb24_decoder = {
 .priv_class= _class,
 .wrapper_name = "libaribb24",
 };
+
+const AVCodec ff_libaribb24_superimpose_decoder = {
+.name  = "libaribb24_superimpose",
+.long_name = NULL_IF_CONFIG_SMALL("libaribb24 ARIB STD-B24 superimpose 
decoder"),
+.type  = AVMEDIA_TYPE_SUBTITLE,
+.id= AV_CODEC_ID_ARIB_SUPERIMPOSE,
+.priv_data_size = sizeof(Libaribb24Context),
+.init  = libaribb24_init,
+.close = libaribb24_close,
+.decode= libaribb24_decode,
+.flush = libaribb24_flush,
+.priv_class= _class,
+.wrapper_name = "libaribb24_superimpose",
+};
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 4/5] fftools/ffmpeg: Ignore PTS checking for arib_superimpose

2021-06-12 Thread zheng qian
arib_superimpose codec doesn't has PTS (AV_NOPTS_VALUE)

Signed-off-by: zheng qian 
---
 fftools/ffmpeg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e97d879cb3..d60ab49533 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -824,7 +824,8 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || 
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == 
AVMEDIA_TYPE_SUBTITLE) &&
 pkt->dts != AV_NOPTS_VALUE &&
 !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) &&
-ost->last_mux_dts != AV_NOPTS_VALUE) {
+ost->last_mux_dts != AV_NOPTS_VALUE &&
+st->codecpar->codec_id != AV_CODEC_ID_ARIB_SUPERIMPOSE) {
 int64_t max = ost->last_mux_dts + !(s->oformat->flags & 
AVFMT_TS_NONSTRICT);
 if (pkt->dts < max) {
 int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type 
== AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/5] avformat/mpegtsenc: Add muxing support for arib_superimpose

2021-06-12 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 30 +++---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 98dac17994..68f69d5df8 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,7 +287,7 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, 
size_t len)
 *q_ptr += len;
 }
 
-static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
+static int put_arib_descriptor(AVFormatContext *s, uint8_t **q_ptr,
AVCodecParameters *codecpar)
 {
 uint8_t stream_identifier;
@@ -296,11 +296,19 @@ static int put_arib_caption_descriptor(AVFormatContext 
*s, uint8_t **q_ptr,
 
 switch (codecpar->profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
-stream_identifier = 0x30;
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+stream_identifier = 0x30;
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+stream_identifier = 0x38;
+}
 data_component_id = 0x0008;
 break;
 case FF_PROFILE_ARIB_PROFILE_C:
-stream_identifier = 0x87;
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+stream_identifier = 0x87;
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+stream_identifier = 0x88;
+}
 data_component_id = 0x0012;
 break;
 default:
@@ -320,11 +328,15 @@ static int put_arib_caption_descriptor(AVFormatContext 
*s, uint8_t **q_ptr,
 *q++ = 3; // descriptor_length
 put16(, data_component_id);  // data_component_id
 // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 
3, 9.6.1
-// Here we utilize a pre-defined set of values defined in ARIB TR-B14,
+// Here we utilize pre-defined sets of values defined in ARIB TR-B14,
 // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle
 // set to 1 (as that is what every broadcaster seems to be doing in
 // production).
-*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+*q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00')
+}
 
 *q_ptr = q;
 
@@ -414,6 +426,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
 case AV_CODEC_ID_ARIB_CAPTION:
+case AV_CODEC_ID_ARIB_SUPERIMPOSE:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_SMPTE_KLV:
@@ -771,8 +784,8 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
}
 
*len_ptr = q - len_ptr - 1;
-} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
-if (put_arib_caption_descriptor(s, , st->codecpar) < 0)
+} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION || codec_id == 
AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+if (put_arib_descriptor(s, , st->codecpar) < 0)
 break;
 }
 break;
@@ -1444,6 +1457,9 @@ static int get_pes_stream_id(AVFormatContext *s, AVStream 
*st, int stream_id, in
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */
 *async = 1;
 return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+} else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+   st->codecpar->codec_id == AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+return STREAM_ID_PRIVATE_STREAM_2;
 } else {
 return STREAM_ID_PRIVATE_STREAM_1;
 }
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/5] avformat/mpegts: Recognize arib_superimpose by ARIB data coding descriptor

2021-06-12 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegts.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a02965bacf..6c5fb53c51 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2106,8 +2106,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 }
 break;
 case 0xfd: /* ARIB data coding type descriptor */
-// STD-B24, fascicle 3, chapter 4 defines private_stream_1
-// for captions
+// STD-B24, fascicle 3, chapter 4 defines
+// private_stream_1 for captions, and private_stream_2 for superimpose
 if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
 // This structure is defined in STD-B10, part 1, listing 5.4 and
 // part 2, 6.2.20).
@@ -2115,6 +2115,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 // Component tag limits are documented in TR-B14, fascicle 2,
 // Vol. 3, Section 2, 4.2.8.1
 int actual_component_tag = st->internal->stream_identifier - 1;
+enum AVCodecID arib_codec_id = AV_CODEC_ID_NONE;
 int picked_profile = FF_PROFILE_UNKNOWN;
 int data_component_id = get16(pp, desc_end);
 if (data_component_id < 0)
@@ -2122,17 +2123,30 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 
 switch (data_component_id) {
 case 0x0008:
-// [0x30..0x37] are component tags utilized for
+// [0x30..0x37] and [0x38..0x3F] are component tags utilized 
for
 // non-mobile captioning service ("profile A").
 if (actual_component_tag >= 0x30 &&
 actual_component_tag <= 0x37) {
+// caption (Profile A)
+arib_codec_id = AV_CODEC_ID_ARIB_CAPTION;
+picked_profile = FF_PROFILE_ARIB_PROFILE_A;
+} else if (actual_component_tag >= 0x38 &&
+   actual_component_tag <= 0x3F) {
+// superimpose (Profile A)
+arib_codec_id = AV_CODEC_ID_ARIB_SUPERIMPOSE;
 picked_profile = FF_PROFILE_ARIB_PROFILE_A;
 }
 break;
 case 0x0012:
-// component tag 0x87 signifies a mobile/partial reception
+// component tag 0x87 and 0x88 signifies a mobile/partial 
reception
 // (1seg) captioning service ("profile C").
 if (actual_component_tag == 0x87) {
+// caption (Profile C)
+arib_codec_id = AV_CODEC_ID_ARIB_CAPTION;
+picked_profile = FF_PROFILE_ARIB_PROFILE_C;
+} else if (actual_component_tag == 0x88) {
+// superimpose (Profile C)
+arib_codec_id = AV_CODEC_ID_ARIB_SUPERIMPOSE;
 picked_profile = FF_PROFILE_ARIB_PROFILE_C;
 }
 break;
@@ -2140,11 +2154,11 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 break;
 }
 
-if (picked_profile == FF_PROFILE_UNKNOWN)
+if (arib_codec_id == AV_CODEC_ID_NONE || picked_profile == 
FF_PROFILE_UNKNOWN)
 break;
 
 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
-st->codecpar->codec_id   = AV_CODEC_ID_ARIB_CAPTION;
+st->codecpar->codec_id   = arib_codec_id;
 st->codecpar->profile= picked_profile;
 st->internal->request_probe= 0;
 }
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/5] avcodec/codec: Add arib_superimpose subtitle codec

2021-06-12 Thread zheng qian
This patchset introduces ARIB STD-B24 superimpose support.
ARIB superimpose is almost same as ARIB caption but has a silent difference.

ARIB superimpose is utilized to transmit emergency alert and newsflash in
Japan DTV. Since superimpose is designed to be displayed once received by
the television, ARIB superimpose utilizes mpegts private_stream_2 stream
rather than the private_stream_1 that is used by arib_caption, which means
superimpose packet doesn't have PTS (AV_NOPTS_VALUE).

Purpose of introducing arib_superimpose codec is mainly:

1) Let mpegtsenc to be able to remux ARIB superimpose stream correctly

2) Let ffmpeg-based player to be able to recognize ARIB superimpose stream
then extract binary data and render it onto screen

Signed-off-by: zheng qian 
---
 libavcodec/codec_desc.c | 8 
 libavcodec/codec_id.h   | 1 +
 libavcodec/version.h| 4 ++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 35527dcc37..afb22756a3 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3407,6 +3407,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .props = AV_CODEC_PROP_TEXT_SUB,
 .profiles  = NULL_IF_CONFIG_SMALL(ff_arib_caption_profiles),
 },
+{
+.id= AV_CODEC_ID_ARIB_SUPERIMPOSE,
+.type  = AVMEDIA_TYPE_SUBTITLE,
+.name  = "arib_superimpose",
+.long_name = NULL_IF_CONFIG_SMALL("ARIB STD-B24 superimpose"),
+.props = AV_CODEC_PROP_TEXT_SUB,
+.profiles  = NULL_IF_CONFIG_SMALL(ff_arib_caption_profiles),
+},
 
 /* other kind of codecs and pseudo-codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index d49f9af36c..839ffd3861 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -543,6 +543,7 @@ enum AVCodecID {
 AV_CODEC_ID_HDMV_TEXT_SUBTITLE,
 AV_CODEC_ID_TTML,
 AV_CODEC_ID_ARIB_CAPTION,
+AV_CODEC_ID_ARIB_SUPERIMPOSE,
 
 /* 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.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5b1e9e77f3..1288cecebe 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,8 +28,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR   1
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR   2
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/5] avformat/mpegts: Recognize arib_superimpose by ARIB data coding descriptor

2021-06-12 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegts.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a02965bacf..6c5fb53c51 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2106,8 +2106,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 }
 break;
 case 0xfd: /* ARIB data coding type descriptor */
-// STD-B24, fascicle 3, chapter 4 defines private_stream_1
-// for captions
+// STD-B24, fascicle 3, chapter 4 defines
+// private_stream_1 for captions, and private_stream_2 for superimpose
 if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
 // This structure is defined in STD-B10, part 1, listing 5.4 and
 // part 2, 6.2.20).
@@ -2115,6 +2115,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 // Component tag limits are documented in TR-B14, fascicle 2,
 // Vol. 3, Section 2, 4.2.8.1
 int actual_component_tag = st->internal->stream_identifier - 1;
+enum AVCodecID arib_codec_id = AV_CODEC_ID_NONE;
 int picked_profile = FF_PROFILE_UNKNOWN;
 int data_component_id = get16(pp, desc_end);
 if (data_component_id < 0)
@@ -2122,17 +2123,30 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 
 switch (data_component_id) {
 case 0x0008:
-// [0x30..0x37] are component tags utilized for
+// [0x30..0x37] and [0x38..0x3F] are component tags utilized 
for
 // non-mobile captioning service ("profile A").
 if (actual_component_tag >= 0x30 &&
 actual_component_tag <= 0x37) {
+// caption (Profile A)
+arib_codec_id = AV_CODEC_ID_ARIB_CAPTION;
+picked_profile = FF_PROFILE_ARIB_PROFILE_A;
+} else if (actual_component_tag >= 0x38 &&
+   actual_component_tag <= 0x3F) {
+// superimpose (Profile A)
+arib_codec_id = AV_CODEC_ID_ARIB_SUPERIMPOSE;
 picked_profile = FF_PROFILE_ARIB_PROFILE_A;
 }
 break;
 case 0x0012:
-// component tag 0x87 signifies a mobile/partial reception
+// component tag 0x87 and 0x88 signifies a mobile/partial 
reception
 // (1seg) captioning service ("profile C").
 if (actual_component_tag == 0x87) {
+// caption (Profile C)
+arib_codec_id = AV_CODEC_ID_ARIB_CAPTION;
+picked_profile = FF_PROFILE_ARIB_PROFILE_C;
+} else if (actual_component_tag == 0x88) {
+// superimpose (Profile C)
+arib_codec_id = AV_CODEC_ID_ARIB_SUPERIMPOSE;
 picked_profile = FF_PROFILE_ARIB_PROFILE_C;
 }
 break;
@@ -2140,11 +2154,11 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 break;
 }
 
-if (picked_profile == FF_PROFILE_UNKNOWN)
+if (arib_codec_id == AV_CODEC_ID_NONE || picked_profile == 
FF_PROFILE_UNKNOWN)
 break;
 
 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
-st->codecpar->codec_id   = AV_CODEC_ID_ARIB_CAPTION;
+st->codecpar->codec_id   = arib_codec_id;
 st->codecpar->profile= picked_profile;
 st->internal->request_probe= 0;
 }
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/5] avcodec/codec: Add arib_superimpose subtitle codec

2021-06-12 Thread zheng qian
This patchset introduces ARIB STD-B24 superimpose support.
ARIB superimpose is almost same as ARIB caption but has a silent difference.

ARIB superimpose is utilized to transmit emergency alert and newsflash in
Japan DTV. Since superimpose is designed to be displayed once received by
the television, ARIB superimpose utilizes mpegts private_stream_2 stream
rather than the private_stream_1 that is used by arib_caption, which means
superimpose packet doesn't have PTS (AV_NOPTS_VALUE).

Purpose of introducing arib_superimpose codec is mainly:

1) Let mpegtsenc to be able to remux ARIB superimpose stream correctly

2) Let ffmpeg-based player to be able to recognize ARIB superimpose stream
then extract binary data and render it onto screen

Signed-off-by: zheng qian 
---
 libavcodec/codec_desc.c | 8 
 libavcodec/codec_id.h   | 1 +
 libavcodec/version.h| 4 ++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 35527dcc37..afb22756a3 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3407,6 +3407,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .props = AV_CODEC_PROP_TEXT_SUB,
 .profiles  = NULL_IF_CONFIG_SMALL(ff_arib_caption_profiles),
 },
+{
+.id= AV_CODEC_ID_ARIB_SUPERIMPOSE,
+.type  = AVMEDIA_TYPE_SUBTITLE,
+.name  = "arib_superimpose",
+.long_name = NULL_IF_CONFIG_SMALL("ARIB STD-B24 superimpose"),
+.props = AV_CODEC_PROP_TEXT_SUB,
+.profiles  = NULL_IF_CONFIG_SMALL(ff_arib_caption_profiles),
+},
 
 /* other kind of codecs and pseudo-codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index d49f9af36c..839ffd3861 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -543,6 +543,7 @@ enum AVCodecID {
 AV_CODEC_ID_HDMV_TEXT_SUBTITLE,
 AV_CODEC_ID_TTML,
 AV_CODEC_ID_ARIB_CAPTION,
+AV_CODEC_ID_ARIB_SUPERIMPOSE,
 
 /* 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.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5b1e9e77f3..1288cecebe 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,8 +28,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR   1
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR   2
+#define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/5] avformat/mpegtsenc: Add muxing support for arib_superimpose

2021-06-12 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 30 +++---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 98dac17994..68f69d5df8 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -287,7 +287,7 @@ static void putbuf(uint8_t **q_ptr, const uint8_t *buf, 
size_t len)
 *q_ptr += len;
 }
 
-static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr,
+static int put_arib_descriptor(AVFormatContext *s, uint8_t **q_ptr,
AVCodecParameters *codecpar)
 {
 uint8_t stream_identifier;
@@ -296,11 +296,19 @@ static int put_arib_caption_descriptor(AVFormatContext 
*s, uint8_t **q_ptr,
 
 switch (codecpar->profile) {
 case FF_PROFILE_ARIB_PROFILE_A:
-stream_identifier = 0x30;
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+stream_identifier = 0x30;
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+stream_identifier = 0x38;
+}
 data_component_id = 0x0008;
 break;
 case FF_PROFILE_ARIB_PROFILE_C:
-stream_identifier = 0x87;
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+stream_identifier = 0x87;
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+stream_identifier = 0x88;
+}
 data_component_id = 0x0012;
 break;
 default:
@@ -320,11 +328,15 @@ static int put_arib_caption_descriptor(AVFormatContext 
*s, uint8_t **q_ptr,
 *q++ = 3; // descriptor_length
 put16(, data_component_id);  // data_component_id
 // additional_arib_caption_info: defined in ARIB STD-B24, fascicle 1, Part 
3, 9.6.1
-// Here we utilize a pre-defined set of values defined in ARIB TR-B14,
+// Here we utilize pre-defined sets of values defined in ARIB TR-B14,
 // Fascicle 2, 4.2.8.5 for PMT usage, with the reserved bits in the middle
 // set to 1 (as that is what every broadcaster seems to be doing in
 // production).
-*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+if (codecpar->codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+*q++ = 0x3D; // DMF('0011'), Reserved('11'), Timing('01')
+} else {  // AV_CODEC_ID_ARIB_SUPERIMPOSE
+*q++ = 0x3C; // DMF('0011'), Reserved('11'), Timing('00')
+}
 
 *q_ptr = q;
 
@@ -414,6 +426,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
 case AV_CODEC_ID_ARIB_CAPTION:
+case AV_CODEC_ID_ARIB_SUPERIMPOSE:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_SMPTE_KLV:
@@ -771,8 +784,8 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
}
 
*len_ptr = q - len_ptr - 1;
-} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
-if (put_arib_caption_descriptor(s, , st->codecpar) < 0)
+} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION || codec_id == 
AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+if (put_arib_descriptor(s, , st->codecpar) < 0)
 break;
 }
 break;
@@ -1444,6 +1457,9 @@ static int get_pes_stream_id(AVFormatContext *s, AVStream 
*st, int stream_id, in
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous KLV */
 *async = 1;
 return stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+} else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE &&
+   st->codecpar->codec_id == AV_CODEC_ID_ARIB_SUPERIMPOSE) {
+return STREAM_ID_PRIVATE_STREAM_2;
 } else {
 return STREAM_ID_PRIVATE_STREAM_1;
 }
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/5] avcodec/libaribb24: Enable decoding support for arib_superimpose

2021-06-12 Thread zheng qian
ARIB superimpose packet could also be decoded by libaribb24

Signed-off-by: zheng qian 
---
 libavcodec/allcodecs.c  |  1 +
 libavcodec/libaribb24.c | 14 ++
 2 files changed, 15 insertions(+)

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 623db2a9fa..5d5b536e97 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -722,6 +722,7 @@ extern const AVCodec ff_qdmc_at_decoder;
 extern const AVCodec ff_qdm2_at_decoder;
 extern AVCodec ff_libaom_av1_encoder;
 extern const AVCodec ff_libaribb24_decoder;
+extern const AVCodec ff_libaribb24_superimpose_decoder;
 extern const AVCodec ff_libcelt_decoder;
 extern const AVCodec ff_libcodec2_encoder;
 extern const AVCodec ff_libcodec2_decoder;
diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c
index 0766c0079d..afa43f8f50 100644
--- a/libavcodec/libaribb24.c
+++ b/libavcodec/libaribb24.c
@@ -393,3 +393,17 @@ const AVCodec ff_libaribb24_decoder = {
 .priv_class= _class,
 .wrapper_name = "libaribb24",
 };
+
+const AVCodec ff_libaribb24_superimpose_decoder = {
+.name  = "libaribb24_superimpose",
+.long_name = NULL_IF_CONFIG_SMALL("libaribb24 ARIB STD-B24 superimpose 
decoder"),
+.type  = AVMEDIA_TYPE_SUBTITLE,
+.id= AV_CODEC_ID_ARIB_SUPERIMPOSE,
+.priv_data_size = sizeof(Libaribb24Context),
+.init  = libaribb24_init,
+.close = libaribb24_close,
+.decode= libaribb24_decode,
+.flush = libaribb24_flush,
+.priv_class= _class,
+.wrapper_name = "libaribb24_superimpose",
+};
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/5] fftools/ffmpeg: Ignore PTS checking for arib_superimpose

2021-06-12 Thread zheng qian
arib_superimpose codec doesn't has PTS (AV_NOPTS_VALUE)

Signed-off-by: zheng qian 
---
 fftools/ffmpeg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e97d879cb3..d60ab49533 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -824,7 +824,8 @@ static void write_packet(OutputFile *of, AVPacket *pkt, 
OutputStream *ost, int u
 if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || 
st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == 
AVMEDIA_TYPE_SUBTITLE) &&
 pkt->dts != AV_NOPTS_VALUE &&
 !(st->codecpar->codec_id == AV_CODEC_ID_VP9 && ost->stream_copy) &&
-ost->last_mux_dts != AV_NOPTS_VALUE) {
+ost->last_mux_dts != AV_NOPTS_VALUE &&
+st->codecpar->codec_id != AV_CODEC_ID_ARIB_SUPERIMPOSE) {
 int64_t max = ost->last_mux_dts + !(s->oformat->flags & 
AVFMT_TS_NONSTRICT);
 if (pkt->dts < max) {
 int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type 
== AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v4] avformat/mpegtsenc: enable muxing of ARIB captions

2021-06-07 Thread zheng qian
On Tue, Jun 8, 2021 at 2:28 AM Jan Ekström  wrote:
>
> On Mon, Jun 7, 2021 at 8:09 PM Jan Ekström  wrote:
> >
> > From: zheng qian 
> >
> > Writes a general ARIB stream identifier descriptor, as well
> > as a data component descriptor which also includes a
> > pre-defined additional_arib_caption_info structure.
> >
> > Signed-off-by: zheng qian 
> > ---
>
> For the record, I did and do think that counting and limiting the
> amount of ARIB caption streams per program would be technically more
> correct, but since:
> 1. In most cases you will only have a single stream in your input of a
> given profile (as multi-language subtitles are supposed to be handled
> in the same PID).
> 2. it seems like a pain as mpegtsenc does not have existing
> infrastructure for these sorts of checks as nothing else is limited in
> stream count per-program.
>
> I decided that utilizing the default identifier (0x30, 0x87) for all
> such streams is Good Enough for an initial implementation. For Profile
> A streams values are available until 0x37, but effectively only
> permitted for secondary renditions (multi-view etc). Profile C only
> permits a single identifier - 0x87.
>
> As changes compared to v3:
>
> 1. I have split the descriptor writing into its own function, as
> mpegts_write_pmt is already long enough.
> 2. Checked references and adjusted some comments as well as the commit 
> message.
>
> Jan

LGTM.

Regards,
zheng qian

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-28 Thread zheng qian
On Thu, Apr 29, 2021 at 4:40 AM Marton Balint  wrote:
>
> Thanks, applied the series with slightly modified/extended commit
> message based on your earlier commit message.
>
> Regards,
> Marton

Thank you!

Best regards,
zheng
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-27 Thread zheng qian
On Wed, Apr 21, 2021 at 7:04 AM Jan Ekström  wrote:
>
> I think in general I am preferring the "follow the TR" way since I
> just heard another implementer generally speaking also ignores
> everything else than 0x30/0x87.
>
> Did not yet add the per-program limitation but poked a bit at it with
> https://github.com/jeeb/ffmpeg/commits/mpegts_arib_caption_muxing .
>
> 1. Split the writing of the ARIB caption descriptor as the PMT writing
> function is already way too long. Was not sure if exit or plain break
> would be sufficient, but nothing else around in that function seems to
> return with an error... so break it is.
> 2. Added logging in case an unset/unknown profile was utilized.
> 3. Re-added extraction of additional_arib_caption_info into extradata,
> and writing it out in the muxer if available.
>
> Feel free to note how you like these changes :)
>
> Jan

Any update on this thread?

Please let me know if there is any new information.

Thanks,
zheng
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-24 Thread zheng qian
On Sun, Apr 25, 2021 at 2:13 AM Marton Balint  wrote:
>
> The order of the patches seems wrong. Patch/3 (or similar) should be
> applied first, otherwise you are checking the stream_id provided via side
> data, not the stream id actually used.
>
> Also note that is_dvb_teletext/is_dvb_subtitle might not be set if certain
> stream_id is used, that can also cause issues.
>
> I will send a patch series for these two issues, please check them and if
> they look good then rebase your patchset on top of that.
>
> You should add the relevant stream type constants to mpegts.h and use
> those for the checks, you can spare the comments that way.
>

I have sent a new patchset v4 for these changes.
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=3833

Notice that I re-sent the 3/4 patch file which seems to be lost,
so please pay attention to the order.

Thanks,
zheng
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/4] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-24 Thread zheng qian
Changes since v3:
  Use STREAM_ID_* constants in mpegts.h for stream_id judgement

Current implementation skipped the judgement of stream_id
causing some kind of stream like private_stream_2 to be
incorrectly written with actually a private_stream_1-like
PES header with PTS/DTS field. For example, Japan DTV transmits
news and alerts through ARIB superimpose that utilizes
private_stream_2 still could not be remuxed correctly for now.

This patch set fixes the remuxing for private_stream_2 and
other stream_id types.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d724d646..e6fcecbaca 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1479,6 +1479,16 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 pts = dts = AV_NOPTS_VALUE;
 
 header_len = 0;
+
+if (stream_id != STREAM_ID_PROGRAM_STREAM_MAP &&
+stream_id != STREAM_ID_PADDING_STREAM &&
+stream_id != STREAM_ID_PRIVATE_STREAM_2 &&
+stream_id != STREAM_ID_ECM_STREAM &&
+stream_id != STREAM_ID_EMM_STREAM &&
+stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY &&
+stream_id != STREAM_ID_DSMCC_STREAM &&
+stream_id != STREAM_ID_TYPE_E_STREAM) {
+
 flags  = 0;
 if (pts != AV_NOPTS_VALUE) {
 header_len += 5;
@@ -1572,6 +1582,11 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 memset(q, 0xff, pes_header_stuffing_bytes);
 q += pes_header_stuffing_bytes;
 }
+} else {
+len = payload_size;
+*q++ = len >> 8;
+*q++ = len;
+}
 is_start = 0;
 }
 /* header size */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/4] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-24 Thread zheng qian
Changes since v3:
  Use STREAM_ID_* constants in mpegts.h for stream_id judgement

Current implementation skipped the judgement of stream_id
causing some kind of stream like private_stream_2 to be
incorrectly written with actually a private_stream_1-like
PES header with PTS/DTS field. For example, Japan DTV transmits
news and alerts through ARIB superimpose that utilizes
private_stream_2 still could not be remuxed correctly for now.

This patch set fixes the remuxing for private_stream_2 and
other stream_id types.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d724d646..e6fcecbaca 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1479,6 +1479,16 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 pts = dts = AV_NOPTS_VALUE;
 
 header_len = 0;
+
+if (stream_id != STREAM_ID_PROGRAM_STREAM_MAP &&
+stream_id != STREAM_ID_PADDING_STREAM &&
+stream_id != STREAM_ID_PRIVATE_STREAM_2 &&
+stream_id != STREAM_ID_ECM_STREAM &&
+stream_id != STREAM_ID_EMM_STREAM &&
+stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY &&
+stream_id != STREAM_ID_DSMCC_STREAM &&
+stream_id != STREAM_ID_TYPE_E_STREAM) {
+
 flags  = 0;
 if (pts != AV_NOPTS_VALUE) {
 header_len += 5;
@@ -1572,6 +1582,11 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 memset(q, 0xff, pes_header_stuffing_bytes);
 q += pes_header_stuffing_bytes;
 }
+} else {
+len = payload_size;
+*q++ = len >> 8;
+*q++ = len;
+}
 is_start = 0;
 }
 /* header size */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 1/4] avformat/mpegts: Add missing constants for MPEG-TS stream_id definitions

2021-04-24 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegts.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 04874e0f42..224282b3ed 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -138,11 +138,19 @@
 #define STREAM_TYPE_AUDIO_EAC3  0x87
 
 /* ISO/IEC 13818-1 Table 2-22 */
+#define STREAM_ID_PROGRAM_STREAM_MAP 0xbc
 #define STREAM_ID_PRIVATE_STREAM_1   0xbd
+#define STREAM_ID_PADDING_STREAM 0xbe
+#define STREAM_ID_PRIVATE_STREAM_2   0xbf
 #define STREAM_ID_AUDIO_STREAM_0 0xc0
 #define STREAM_ID_VIDEO_STREAM_0 0xe0
+#define STREAM_ID_ECM_STREAM 0xf0
+#define STREAM_ID_EMM_STREAM 0xf1
+#define STREAM_ID_DSMCC_STREAM   0xf2
+#define STREAM_ID_TYPE_E_STREAM  0xf8
 #define STREAM_ID_METADATA_STREAM0xfc
 #define STREAM_ID_EXTENDED_STREAM_ID 0xfd
+#define STREAM_ID_PROGRAM_STREAM_DIRECTORY  0xff
 
 /* ISO/IEC 13818-1 Table 2-45 */
 #define VIDEO_STREAM_DESCRIPTOR  0x02
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 2/4] avformat/mpegts: Fix indentation for stream_id constants

2021-04-24 Thread zheng qian
Signed-off-by: zheng qian 
---
 libavformat/mpegts.h | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 224282b3ed..c75ba08f29 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -138,18 +138,18 @@
 #define STREAM_TYPE_AUDIO_EAC3  0x87
 
 /* ISO/IEC 13818-1 Table 2-22 */
-#define STREAM_ID_PROGRAM_STREAM_MAP 0xbc
-#define STREAM_ID_PRIVATE_STREAM_1   0xbd
-#define STREAM_ID_PADDING_STREAM 0xbe
-#define STREAM_ID_PRIVATE_STREAM_2   0xbf
-#define STREAM_ID_AUDIO_STREAM_0 0xc0
-#define STREAM_ID_VIDEO_STREAM_0 0xe0
-#define STREAM_ID_ECM_STREAM 0xf0
-#define STREAM_ID_EMM_STREAM 0xf1
-#define STREAM_ID_DSMCC_STREAM   0xf2
-#define STREAM_ID_TYPE_E_STREAM  0xf8
-#define STREAM_ID_METADATA_STREAM0xfc
-#define STREAM_ID_EXTENDED_STREAM_ID 0xfd
+#define STREAM_ID_PROGRAM_STREAM_MAP0xbc
+#define STREAM_ID_PRIVATE_STREAM_1  0xbd
+#define STREAM_ID_PADDING_STREAM0xbe
+#define STREAM_ID_PRIVATE_STREAM_2  0xbf
+#define STREAM_ID_AUDIO_STREAM_00xc0
+#define STREAM_ID_VIDEO_STREAM_00xe0
+#define STREAM_ID_ECM_STREAM0xf0
+#define STREAM_ID_EMM_STREAM0xf1
+#define STREAM_ID_DSMCC_STREAM  0xf2
+#define STREAM_ID_TYPE_E_STREAM 0xf8
+#define STREAM_ID_METADATA_STREAM   0xfc
+#define STREAM_ID_EXTENDED_STREAM_ID0xfd
 #define STREAM_ID_PROGRAM_STREAM_DIRECTORY  0xff
 
 /* ISO/IEC 13818-1 Table 2-45 */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 4/4] avformat/mpegtsenc: Fix indentation inside if-clause in mpegts_write_pes()

2021-04-24 Thread zheng qian
Fix indentation caused by the added stream_id judgement

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 180 
 1 file changed, 90 insertions(+), 90 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index e6fcecbaca..d055e5bc15 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1489,99 +1489,99 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 stream_id != STREAM_ID_DSMCC_STREAM &&
 stream_id != STREAM_ID_TYPE_E_STREAM) {
 
-flags  = 0;
-if (pts != AV_NOPTS_VALUE) {
-header_len += 5;
-flags  |= 0x80;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-header_len += 5;
-flags  |= 0x40;
-}
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
-/* set PES_extension_flag */
-pes_extension = 1;
-flags|= 0x01;
-
-/* One byte for PES2 extension flag +
- * one byte for extension length +
- * one byte for extension id */
-header_len += 3;
-}
-/* for Blu-ray AC3 Audio the PES Extension flag should be as follow
- * otherwise it will not play sound on blu-ray
- */
-if (ts->m2ts_mode &&
-st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
-st->codecpar->codec_id == AV_CODEC_ID_AC3) {
-/* set PES_extension_flag */
-pes_extension = 1;
-flags |= 0x01;
-header_len += 3;
-}
-if (is_dvb_teletext) {
-pes_header_stuffing_bytes = 0x24 - header_len;
-header_len = 0x24;
-}
-len = payload_size + header_len + 3;
-/* 3 extra bytes should be added to DVB subtitle payload: 0x20 
0x00 at the beginning and trailing 0xff */
-if (is_dvb_subtitle) {
-len += 3;
-payload_size++;
-}
-if (len > 0x)
-len = 0;
-if (ts->omit_video_pes_length && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) {
-len = 0;
-}
-*q++ = len >> 8;
-*q++ = len;
-val  = 0x80;
-/* data alignment indicator is required for subtitle and data 
streams */
-if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
-val |= 0x04;
-*q++ = val;
-*q++ = flags;
-*q++ = header_len;
-if (pts != AV_NOPTS_VALUE) {
-write_pts(q, flags >> 6, pts);
-q += 5;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-write_pts(q, 1, dts);
-q += 5;
-}
-if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
-flags = 0x01;  /* set PES_extension_flag_2 */
-*q++  = flags;
-*q++  = 0x80 | 0x01; /* marker bit + extension length */
-/* Set the stream ID extension flag bit to 0 and
- * write the extended stream ID. */
-*q++ = 0x00 | 0x60;
-}
-/* For Blu-ray AC3 Audio Setting extended flags */
-if (ts->m2ts_mode &&
-pes_extension &&
-st->codecpar->codec_id == AV_CODEC_ID_AC3) {
-flags = 0x01; /* set PES_extension_flag_2 */
+flags  = 0;
+if (pts != AV_NOPTS_VALUE) {
+header_len += 5;
+flags  |= 0x80;
+}
+if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != 
pts) {
+header_len += 5;
+flags  |= 0x40;
+}
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
+/* set PES_extension_flag */
+pes_extension = 1;
+flags|= 0x01;
+
+/* One byte for PES2 extension flag +
+ * one byte for extension length +
+ * one byte for extension id */
+header_len += 3;
+}
+/* for Blu-ray AC3 Audio the PES Extension flag should be as 
follow
+  

Re: [FFmpeg-devel] [PATCH v3 3/3] avformat/mpegtsenc: Write stream_id into PES after stream_id decision

2021-04-24 Thread zheng qian
On Sat, Apr 24, 2021 at 5:09 PM Mao Hata  wrote:
>
>
> v3 patch looks good to me.
> Then, since the patch itself is based on ISO_IEC_13818-1, it perhaps has
> some (side) effects for ATSC/DVB as well. If possible, you might want to
> wait for opinions from ATSC/DVB sides.
>
> Mao Hata
>

I will add arib_superimpose codec later once this patchset got merged.

Just waiting for other maintainers to review and merge this, yet.

Regards,
zheng


> P.S.
> I confirmed the effect of your patch with the following command.
> $ ffmpeg -i some_arib_mpeg.ts -c:v libx264 -map 0:v -c:a aac -map 0:a
> -map 0:4 dest.ts
>
> Here "-map 0:4" points to private_stream_2 (ARIB-superimpose).
> The command now properly remuxes "-map 0:4" stream into "dest.ts"
> without any editing.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 3/3] avformat/mpegtsenc: Write stream_id into PES after stream_id decision

2021-04-22 Thread zheng qian
Since stream_id will have effect on the existences of
PES header fields like PTS/DTS, it should be better to
guarantee stream_id variable to be identical with
exact written value.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 967f98931d..525c68ffd1 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1445,28 +1445,28 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 is_dvb_teletext = 0;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC)
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 else
-*q++ = STREAM_ID_VIDEO_STREAM_0;
+stream_id = STREAM_ID_VIDEO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
(st->codecpar->codec_id == AV_CODEC_ID_MP2 ||
 st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
 st->codecpar->codec_id == AV_CODEC_ID_AAC)) {
-*q++ = STREAM_ID_AUDIO_STREAM_0;
+stream_id = STREAM_ID_AUDIO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
 st->codecpar->codec_id == AV_CODEC_ID_AC3 &&
 ts->m2ts_mode) {
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
-*q++ = stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+stream_id = stream_id != -1 ? stream_id : 
STREAM_ID_METADATA_STREAM;
 
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous 
KLV */
 pts = dts = AV_NOPTS_VALUE;
 } else {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
 is_dvb_subtitle = 1;
@@ -1475,6 +1475,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
 }
 }
 }
+*q++ = stream_id;
 header_len = 0;
 
 if (stream_id != 0xBC &&  // program_stream_map
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/3] avformat/mpegtsenc: Fix indentation inside if-clause in mpegts_write_pes()

2021-04-22 Thread zheng qian
Fix indentation caused by the added stream_id judgement

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 180 
 1 file changed, 90 insertions(+), 90 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index b59dab5174..967f98931d 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1486,99 +1486,99 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 stream_id != 0xF2 &&  // DSMCC_stream
 stream_id != 0xF8) {  // ITU-T Rec. H.222.1 type E stream
 
-flags  = 0;
-if (pts != AV_NOPTS_VALUE) {
-header_len += 5;
-flags  |= 0x80;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-header_len += 5;
-flags  |= 0x40;
-}
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
-/* set PES_extension_flag */
-pes_extension = 1;
-flags|= 0x01;
-
-/* One byte for PES2 extension flag +
- * one byte for extension length +
- * one byte for extension id */
-header_len += 3;
-}
-/* for Blu-ray AC3 Audio the PES Extension flag should be as follow
- * otherwise it will not play sound on blu-ray
- */
-if (ts->m2ts_mode &&
-st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
-st->codecpar->codec_id == AV_CODEC_ID_AC3) {
-/* set PES_extension_flag */
-pes_extension = 1;
-flags |= 0x01;
-header_len += 3;
-}
-if (is_dvb_teletext) {
-pes_header_stuffing_bytes = 0x24 - header_len;
-header_len = 0x24;
-}
-len = payload_size + header_len + 3;
-/* 3 extra bytes should be added to DVB subtitle payload: 0x20 
0x00 at the beginning and trailing 0xff */
-if (is_dvb_subtitle) {
-len += 3;
-payload_size++;
-}
-if (len > 0x)
-len = 0;
-if (ts->omit_video_pes_length && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO) {
-len = 0;
-}
-*q++ = len >> 8;
-*q++ = len;
-val  = 0x80;
-/* data alignment indicator is required for subtitle and data 
streams */
-if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
-val |= 0x04;
-*q++ = val;
-*q++ = flags;
-*q++ = header_len;
-if (pts != AV_NOPTS_VALUE) {
-write_pts(q, flags >> 6, pts);
-q += 5;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-write_pts(q, 1, dts);
-q += 5;
-}
-if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
-flags = 0x01;  /* set PES_extension_flag_2 */
-*q++  = flags;
-*q++  = 0x80 | 0x01; /* marker bit + extension length */
-/* Set the stream ID extension flag bit to 0 and
- * write the extended stream ID. */
-*q++ = 0x00 | 0x60;
-}
-/* For Blu-ray AC3 Audio Setting extended flags */
-if (ts->m2ts_mode &&
-pes_extension &&
-st->codecpar->codec_id == AV_CODEC_ID_AC3) {
-flags = 0x01; /* set PES_extension_flag_2 */
+flags  = 0;
+if (pts != AV_NOPTS_VALUE) {
+header_len += 5;
+flags  |= 0x80;
+}
+if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != 
pts) {
+header_len += 5;
+flags  |= 0x40;
+}
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
+/* set PES_extension_flag */
+pes_extension = 1;
+flags|= 0x01;
+
+/* One byte for PES2 extension flag +
+ * one byte for extension length +
+ * one byte for extension id */
+header_len += 3;
+}
+/* for Blu-ray AC3 Audio the PES Extension flag s

[FFmpeg-devel] [PATCH v3 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-22 Thread zheng qian
Changes since v2:
  Fix PES_packet_length mismatch bug

According to the PES packet definition defined in Table 2-17
of ISO_IEC_13818-1 specification, some fields like PTS/DTS or
pes_extension could only appears if the stream_id meets the
condition:

if (stream_id != 0xBC &&  // program_stream_map
stream_id != 0xBE &&  // padding_stream
stream_id != 0xBF &&  // private_stream_2
stream_id != 0xF0 &&  // ECM
stream_id != 0xF1 &&  // EMM
stream_id != 0xFF &&  // program_stream_directory
stream_id != 0xF2 &&  // DSMCC_stream
stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream

And the following stream_id types don't have fields like PTS/DTS:

else if ( stream_id == program_stream_map
|| stream_id == private_stream_2
|| stream_id == ECM
|| stream_id == EMM
|| stream_id == program_stream_directory
|| stream_id == DSMCC_stream
|| stream_id == ITU-T Rec. H.222.1 type E stream ) {
for (i = 0; i < PES_packet_length; i++) {
PES_packet_data_byte
}
}

Current implementation skipped the judgement of stream_id
causing some kind of stream like private_stream_2 to be
incorrectly written with PTS/DTS field. For example,
Japan DTV transmits news and alerts through ARIB superimpose
that utilizes private_stream_2 still could not be remuxed
correctly for now.

This patch set fixes the remuxing for private_stream_2 and
other stream_id types.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index f302af84ff..b59dab5174 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1476,6 +1476,16 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 }
 }
 header_len = 0;
+
+if (stream_id != 0xBC &&  // program_stream_map
+stream_id != 0xBE &&  // padding_stream
+stream_id != 0xBF &&  // private_stream_2
+stream_id != 0xF0 &&  // ECM
+stream_id != 0xF1 &&  // EMM
+stream_id != 0xFF &&  // program_stream_directory
+stream_id != 0xF2 &&  // DSMCC_stream
+stream_id != 0xF8) {  // ITU-T Rec. H.222.1 type E stream
+
 flags  = 0;
 if (pts != AV_NOPTS_VALUE) {
 header_len += 5;
@@ -1569,6 +1579,11 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 memset(q, 0xff, pes_header_stuffing_bytes);
 q += pes_header_stuffing_bytes;
 }
+} else {
+len = payload_size;
+*q++ = len >> 8;
+*q++ = len;
+}
 is_start = 0;
 }
 /* header size */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-21 Thread zheng qian
On Thu, Apr 22, 2021 at 12:11 PM Mao Hata  wrote:
>
> PES_packet_length seems to be inaccurate, because "header_len + 3" has
> already been added to the variable "len".

I'm sorry for that and I'll submit v3 patch set later.
Please tell me if there're any other problems.

Regards,
zheng

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-21 Thread zheng qian
On Wed, Apr 21, 2021 at 10:00 AM zheng qian  wrote:
>
> ARIB superimpose should utilize Timing(00) since superimpose
> uses Asynchronous_PES, but it belongs to another topic.
>
> In other words, addtitional_arib_caption_info can be generated by
> profile information safely and is not necessary to copy by extradata.
>

P.S.: AFAIK the DMF and Timing field actually do not affect ARIB B24
subtitle decoder/renderers' behavior since they always follow the
TMD and DMF field in caption_management_data(), which is
periodically transmitted in arib_caption ES.

In TR-B24, the Timing field for Superimpose could be
'00'(Non-synchronization) or '01'(Time synchronization),
and AFAIK Superimpose used in Japan DTV has never utilized
Timing field rather than '00', since Superimpose is designed to
be displayed immediately once received and usually used for
providing urgent disaster alerts and newsletters (like NHK速報).

Later I'd like to introduce arib_superimpose codec for superimpose
recognition and remuxing, and I believe that for arib_superimpose,
using fixed value 00 for Timing doesn't cause problems in practice.

thus, I'm waiting for your opinion.

Regards,
zheng qian

> Regards,
> zheng
>
> > Feel free to note how you like these changes :)
> >
> > Jan
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-20 Thread zheng qian
On Wed, Apr 21, 2021 at 7:04 AM Jan Ekström  wrote:
>
> I think in general I am preferring the "follow the TR" way since I
> just heard another implementer generally speaking also ignores
> everything else than 0x30/0x87.
>
> Did not yet add the per-program limitation but poked a bit at it with
> https://github.com/jeeb/ffmpeg/commits/mpegts_arib_caption_muxing .
>
> 1. Split the writing of the ARIB caption descriptor as the PMT writing
> function is already way too long. Was not sure if exit or plain break
> would be sufficient, but nothing else around in that function seems to
> return with an error... so break it is.
> 2. Added logging in case an unset/unknown profile was utilized.
> 3. Re-added extraction of additional_arib_caption_info into extradata,
> and writing it out in the muxer if available.
>

I doubt whether it's necessary to extract addtitional_arib_caption_info.
According to ARIB TR-B24, Fascicle 1, 4.2.8.4 - 4.2.8.5:

> Data Encoding Method Descriptor required in PMT:
> DMF is always '0011', aka 0x3
> Timing is always '01' for caption, aka 0x1

Reversed is filled as '11'  aka 0x3 as you know, so for arib_caption,
addtitional_arib_caption_info could be determined as 0x3d.

ARIB superimpose should utilize Timing(00) since superimpose
uses Asynchronous_PES, but it belongs to another topic.

In other words, addtitional_arib_caption_info can be generated by
profile information safely and is not necessary to copy by extradata.

Regards,
zheng

> Feel free to note how you like these changes :)
>
> Jan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-20 Thread zheng qian
On Tue, Apr 20, 2021 at 6:46 AM Jan Ekström  wrote:
>
> On Tue, Apr 20, 2021 at 12:11 AM Marton Balint  wrote:
> >
> >
> >
> > On Mon, 19 Apr 2021, zheng qian wrote:
> >
> > > Is there anyone who could review this patch?
> >
> > Jan was interested in this, so preferably he should also comment, but it
> > looks fine to me.
> >
>
> OK, this explains why I didn't see my response on patchwork.
> Apparently he had CC'd me and thus the "reply" button in gmail sent an
> e-mail directly to him and I was hurrying due to being on a lunch
> break -_- (and thus didn't notice).
>
> In any case, I did some comments and am now waiting for a second
> opinion regarding the usage of stream_identifiers in the ARIB context.
> After all, the specifications do let one utilize 0x30-0x37 for profile
> A/full-seg ARIB captions, so there must be a reason for them to not be
> as limited as profile C/1seg to a single identifier :)
>

I've found related definitions in ARIB TR-B14, Fascicle 1, 4.2.8.1
and you can find it in
http://web.archive.org/web/20160319090430/http://arib.or.jp/english/html/overview/doc/8-TR-B14v2_8-1p3-2-E2.pdf

4.2.8.1 section says:
"However, for component tag values of default ES of caption,
set 0x30 or 0x87, for component tag value of default ES of
superimpose, set 0x38 or 0x88."

That means 0x30 is considered as the default value for
Profile A caption ES. The section didn't describe how to
utilize other values rather than 0x30 in the 0x30~0x37 range,
and due to the second language caption is designed to be
multiplexed in the same ES, seems that it's assumed that
there will be usually only one ARIB caption within a program.

Anyway, I have never seen a TS program that carries 2 or more
arib_caption streams among Japanese TV channels.
Even if we manually try to remux 2 or more arib_caption streams
into a TS program and both use the component tag of 0x30,
it shouldn't cause any playback problems.

Best regards,
zheng qian

> Jan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/3] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-19 Thread zheng qian
Changes since v1:
  Separate if-statement and cosmetic changes into different commits

According to the PES packet definition defined in Table 2-17
of ISO_IEC_13818-1 specification, some fields like PTS/DTS or
pes_extension could only appears if the stream_id meets the
condition:

if (stream_id != 0xBC &&  // program_stream_map
stream_id != 0xBE &&  // padding_stream
stream_id != 0xBF &&  // private_stream_2
stream_id != 0xF0 &&  // ECM
stream_id != 0xF1 &&  // EMM
stream_id != 0xFF &&  // program_stream_directory
stream_id != 0xF2 &&  // DSMCC_stream
stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream

And the following stream_id types don't have fields like PTS/DTS:

else if ( stream_id == program_stream_map
|| stream_id == private_stream_2
|| stream_id == ECM
|| stream_id == EMM
|| stream_id == program_stream_directory
|| stream_id == DSMCC_stream
|| stream_id == ITU-T Rec. H.222.1 type E stream ) {
for (i = 0; i < PES_packet_length; i++) {
PES_packet_data_byte
}
}

Current implementation skipped the judgement of stream_id
causing some kind of stream like private_stream_2 to be
incorrectly written with PTS/DTS field. For example,
Japan DTV transmits news and alerts through ARIB superimpose
that utilizes private_stream_2 still could not be remuxed
correctly for now.

This patch set fixes the remuxing for private_stream_2 and
other stream_id types.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index f302af84ff..0c543c385b 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1524,6 +1524,16 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 }
 *q++ = len >> 8;
 *q++ = len;
+
+if (stream_id != 0xBC &&  // program_stream_map
+stream_id != 0xBE &&  // padding_stream
+stream_id != 0xBF &&  // private_stream_2
+stream_id != 0xF0 &&  // ECM
+stream_id != 0xF1 &&  // EMM
+stream_id != 0xFF &&  // program_stream_directory
+stream_id != 0xF2 &&  // DSMCC_stream
+stream_id != 0xF8) {  // ITU-T Rec. H.222.1 type E stream
+
 val  = 0x80;
 /* data alignment indicator is required for subtitle and data 
streams */
 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
@@ -1569,6 +1579,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
 memset(q, 0xff, pes_header_stuffing_bytes);
 q += pes_header_stuffing_bytes;
 }
+}
 is_start = 0;
 }
 /* header size */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/3] avformat/mpegtsenc: Write stream_id into PES after stream_id decision

2021-04-19 Thread zheng qian
Since stream_id will have effect on the existences of
PES header fields like PTS/DTS, it should be better to
guarantee stream_id variable to be identical with
exact written value.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 4a20775af4..0e9c978d74 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1445,28 +1445,28 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 is_dvb_teletext = 0;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC)
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 else
-*q++ = STREAM_ID_VIDEO_STREAM_0;
+stream_id = STREAM_ID_VIDEO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
(st->codecpar->codec_id == AV_CODEC_ID_MP2 ||
 st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
 st->codecpar->codec_id == AV_CODEC_ID_AAC)) {
-*q++ = STREAM_ID_AUDIO_STREAM_0;
+stream_id = STREAM_ID_AUDIO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
 st->codecpar->codec_id == AV_CODEC_ID_AC3 &&
 ts->m2ts_mode) {
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
-*q++ = stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+stream_id = stream_id != -1 ? stream_id : 
STREAM_ID_METADATA_STREAM;
 
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous 
KLV */
 pts = dts = AV_NOPTS_VALUE;
 } else {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
 is_dvb_subtitle = 1;
@@ -1475,6 +1475,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
 }
 }
 }
+*q++ = stream_id;
 header_len = 0;
 flags  = 0;
 if (pts != AV_NOPTS_VALUE) {
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/3] avformat/mpegtsenc: Fix indentation inside if statement in mpegts_write_pes()

2021-04-19 Thread zheng qian
Fix indentation caused by the added stream_id judgement

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 84 -
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 0c543c385b..4a20775af4 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1534,51 +1534,51 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 stream_id != 0xF2 &&  // DSMCC_stream
 stream_id != 0xF8) {  // ITU-T Rec. H.222.1 type E stream
 
-val  = 0x80;
-/* data alignment indicator is required for subtitle and data 
streams */
-if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
-val |= 0x04;
-*q++ = val;
-*q++ = flags;
-*q++ = header_len;
-if (pts != AV_NOPTS_VALUE) {
-write_pts(q, flags >> 6, pts);
-q += 5;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-write_pts(q, 1, dts);
-q += 5;
-}
-if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) {
-flags = 0x01;  /* set PES_extension_flag_2 */
-*q++  = flags;
-*q++  = 0x80 | 0x01; /* marker bit + extension length */
-/* Set the stream ID extension flag bit to 0 and
- * write the extended stream ID. */
-*q++ = 0x00 | 0x60;
-}
-/* For Blu-ray AC3 Audio Setting extended flags */
-if (ts->m2ts_mode &&
-pes_extension &&
-st->codecpar->codec_id == AV_CODEC_ID_AC3) {
-flags = 0x01; /* set PES_extension_flag_2 */
+val  = 0x80;
+/* data alignment indicator is required for subtitle and data 
streams */
+if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+val |= 0x04;
+*q++ = val;
 *q++ = flags;
-*q++ = 0x80 | 0x01; /* marker bit + extension length */
-*q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on 
blue-rays) */
-}
+*q++ = header_len;
+if (pts != AV_NOPTS_VALUE) {
+write_pts(q, flags >> 6, pts);
+q += 5;
+}
+if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != 
pts) {
+write_pts(q, 1, dts);
+q += 5;
+}
+if (pes_extension && st->codecpar->codec_id == 
AV_CODEC_ID_DIRAC) {
+flags = 0x01;  /* set PES_extension_flag_2 */
+*q++  = flags;
+*q++  = 0x80 | 0x01; /* marker bit + extension length */
+/* Set the stream ID extension flag bit to 0 and
+ * write the extended stream ID. */
+*q++ = 0x00 | 0x60;
+}
+/* For Blu-ray AC3 Audio Setting extended flags */
+if (ts->m2ts_mode &&
+pes_extension &&
+st->codecpar->codec_id == AV_CODEC_ID_AC3) {
+flags = 0x01; /* set PES_extension_flag_2 */
+*q++ = flags;
+*q++ = 0x80 | 0x01; /* marker bit + extension length */
+*q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on 
blue-rays) */
+}
 
 
-if (is_dvb_subtitle) {
-/* First two fields of DVB subtitles PES data:
- * data_identifier: for DVB subtitle streams shall be coded 
with the value 0x20
- * subtitle_stream_id: for DVB subtitle stream shall be 
identified by the value 0x00 */
-*q++ = 0x20;
-*q++ = 0x00;
-}
-if (is_dvb_teletext) {
-memset(q, 0xff, pes_header_stuffing_bytes);
-q += pes_header_stuffing_bytes;
-}
+if (is_dvb_subtitle) {
+/* First two fields of DVB subtitles PES data:
+ * data_identifier: for DVB subtitle streams shall be 
coded with the value 0x20
+ * subtitle_stream_id: for DVB subtitle stream shall be 
identified by the value 0x00 */
+*q++ = 0x20;
+*q++ = 0x00;
+}
+if (is_dvb_teletext) {
+memset(q, 0xff, pes_header_stuffing_bytes);
+q += pes_header_stuffing_bytes;
+ 

[FFmpeg-devel] [PATCH] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

2021-04-19 Thread zheng qian
According to the PES packet definition defined in Table 2-17
of ISO_IEC_13818-1 specification, some fields like PTS/DTS or
pes_extension could only appears if the stream_id meets the
condition:

if (stream_id != 0xBC &&  // program_stream_map
stream_id != 0xBE &&  // padding_stream
stream_id != 0xBF &&  // private_stream_2
stream_id != 0xF0 &&  // ECM
stream_id != 0xF1 &&  // EMM
stream_id != 0xFF &&  // program_stream_directory
stream_id != 0xF2 &&  // DSMCC_stream
stream_id != 0xF8) // ITU-T Rec. H.222.1 type E stream

And the following stream_id types don't have fields like PTS/DTS:

else if ( stream_id == program_stream_map
|| stream_id == private_stream_2
|| stream_id == ECM
|| stream_id == EMM
|| stream_id == program_stream_directory
|| stream_id == DSMCC_stream
|| stream_id == ITU-T Rec. H.222.1 type E stream ) {
for (i = 0; i < PES_packet_length; i++) {
PES_packet_data_byte
}
}

Current implementation skipped the judgement of stream_id
causing some kind of stream like private_stream_2 to be
incorrectly written with PTS/DTS field. For example,
Japan DTV transmits news and alerts through ARIB superimpose
that utilizes private_stream_2 still could not be remuxed
correctly for now.

This patch fixes the remuxing of private_stream_2 and other
stream_id types.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 108 ++--
 1 file changed, 60 insertions(+), 48 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index f302af84ff..da8fb381e5 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1445,28 +1445,28 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 is_dvb_teletext = 0;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC)
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 else
-*q++ = STREAM_ID_VIDEO_STREAM_0;
+stream_id = STREAM_ID_VIDEO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
(st->codecpar->codec_id == AV_CODEC_ID_MP2 ||
 st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
 st->codecpar->codec_id == AV_CODEC_ID_AAC)) {
-*q++ = STREAM_ID_AUDIO_STREAM_0;
+stream_id = STREAM_ID_AUDIO_STREAM_0;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
 st->codecpar->codec_id == AV_CODEC_ID_AC3 &&
 ts->m2ts_mode) {
-*q++ = STREAM_ID_EXTENDED_STREAM_ID;
+stream_id = STREAM_ID_EXTENDED_STREAM_ID;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
st->codecpar->codec_id == AV_CODEC_ID_TIMED_ID3) {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
-*q++ = stream_id != -1 ? stream_id : STREAM_ID_METADATA_STREAM;
+stream_id = stream_id != -1 ? stream_id : 
STREAM_ID_METADATA_STREAM;
 
 if (stream_id == STREAM_ID_PRIVATE_STREAM_1) /* asynchronous 
KLV */
 pts = dts = AV_NOPTS_VALUE;
 } else {
-*q++ = STREAM_ID_PRIVATE_STREAM_1;
+stream_id = STREAM_ID_PRIVATE_STREAM_1;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
 is_dvb_subtitle = 1;
@@ -1475,6 +1475,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream 
*st,
 }
 }
 }
+*q++ = stream_id;
 header_len = 0;
 flags  = 0;
 if (pts != AV_NOPTS_VALUE) {
@@ -1524,50 +1525,61 @@ static void mpegts_write_pes(AVFormatContext *s, 
AVStream *st,
 }
 *q++ = len >> 8;
 *q++ = len;
-val  = 0x80;
-/* data alignment indicator is required for subtitle and data 
streams */
-if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || 
st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
-val |= 0x04;
-*q++ = val;
-*q++ = flags;
-*q++ = header_len;
-if (pts != AV_NOPTS_VALUE) {
-write_pts(q, flags >> 6, pts);
-q += 5;
-}
-if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
-  

Re: [FFmpeg-devel] [PATCH] avformat/mpegtsenc: private_stream_1 is not asynchronous KLV

2021-04-19 Thread zheng qian
On Tue, Apr 20, 2021 at 12:44 AM Mao Hata  wrote:
>
> The reason I created the patch was to fix the problem: when I transcode
> a transport stream based on ARIB-STD-B24, the PTS/DTS is removed from
> private_stream_1 streams, and, conversely, it is added to private_stream_2.
> "ISO/IEC 13818-1 Table 2-17 - PES packet" (sorry, the table number may
> have been shifted) defines the conditions under which PTS/DTS can exist
> as follows:
>
>  >if (stream_id != program_stream_map
>  > && stream_id != padding_stream
>  > && stream_id != private_stream_2
>  > && stream_id != ECM
>  > && stream_id != EMM
>  > && stream_id != program_stream_directory
>  > && stream_id != DSMCC_stream
>  > && stream_id != ITU-T Rec. H.222.1 type E stream) {
>
> So, private_stream_2 can not insert PTS/DTS. In addition, "ARIB-STD-B24,
> VOLUME3, Chapter5" defines private_stream_1 as "Synchronized PES"
> (mainly used for subtitles, with PTS/DTS inserted) and
> private_stream_2 as "Asynchronous PES" (mainly used for superinpose, no
> PTS/DTS inserted).

I'm working on ARIB related patches for mpegtsenc.c and later
I would like to provide a patch to fix the bug of private_stream_2.

In current situation, mpegts_write_pes() incorrectly writes
private_stream_2 with actually a private_stream_1-like PES header
that shouldn't appear according to the ISO/IEC 13818-1 standard.

Regards,
zheng

>  From these things, I misunderstood like that " PTS/DTS is generally
> inserted for private_stream_1, so the `if (stream_id ==
> STREAM_ID_PRIVATE_STREAM_1)` statement (I patched) must be a mistake! " ...
>
> Anyway, as I read the related code, I now understand that the problem
> should be solved specifically for ARIB-based transport stream (at
> "mpegts.c" or so.).
> Thank you again.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-18 Thread zheng qian
Is there anyone who could review this patch?

Best regards,
zheng
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-15 Thread zheng qian
On Fri, Apr 16, 2021 at 12:22 AM zheng qian  wrote:
> +
> +// data_component_descriptor, defined in ARIB STD-B10, part 
> 2, 6.2.20
> +*q++ = 0xFD;  // descriptor_tag: ARIB data coding type 
> descriptor
> +*q++ = 3; // descriptor_length
> +put16(, data_component_id);  // data_component_id
> +// additional_arib_caption_info: defined in ARIB STD-B24, 
> fascicle 1, Part 3, 9.6.1
> +// Use most commonly used value 0x3D: DMF(0x3), 
> Reserved(0x3), Timing(0x1)
> +*q++ = 0x3D;

I have tested lots of TV streams in Japan from terrestrial channels
near Tokyo, and plenty of BS/CS satellite channels. All of them have
a value of 0x3d for the additional_arib_caption_info field so I used it.

Regards,
zheng

>  }
>  break;
>  case AVMEDIA_TYPE_VIDEO:
> --
> 2.29.2
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v3 1/1] avformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption muxing

2021-04-15 Thread zheng qian
Changes since v2:
  Generate stream_identifier and data_component_id from profile

The recognization of ARIB STD-B24 caption has been introduced
in commit a03885b, which is used as closed caption in
Japanese / Brazilian Digital Television.

But arib_caption stream copy is not working correctly caused by
the missing of descriptors in PMT. ARIB caption data inside
remuxed mpegts stream could not be recognized as an arib_caption
subtitle track once again because of the missing of descriptors.

This patch writes stream_identifier_descriptor and
data_component_descriptor by generating stream_identifier and
data_component_id from ARIB profile.

arib_caption remuxing could be worked correctly through this patch.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a357f3a6aa..f302af84ff 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -357,6 +357,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 break;
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
+case AV_CODEC_ID_ARIB_CAPTION:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_SMPTE_KLV:
@@ -714,6 +715,34 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
}
 
*len_ptr = q - len_ptr - 1;
+} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+uint8_t stream_identifier;
+uint16_t data_component_id;
+
+if (st->codecpar->profile == FF_PROFILE_ARIB_PROFILE_A) {
+// non-mobile captioning service ("profile A")
+stream_identifier = 0x30;
+data_component_id = 0x0008;
+} else if (st->codecpar->profile == FF_PROFILE_ARIB_PROFILE_C) 
{
+// (1seg) captioning service ("profile C")
+stream_identifier = 0x87;
+data_component_id = 0x0012;
+} else {
+break;
+}
+
+// stream_identifier_descriptor
+*q++ = 0x52;  // descriptor_tag
+*q++ = 1; // descriptor_length
+*q++ = stream_identifier;  // component_tag: stream_identifier
+
+// data_component_descriptor, defined in ARIB STD-B10, part 2, 
6.2.20
+*q++ = 0xFD;  // descriptor_tag: ARIB data coding type 
descriptor
+*q++ = 3; // descriptor_length
+put16(, data_component_id);  // data_component_id
+// additional_arib_caption_info: defined in ARIB STD-B24, 
fascicle 1, Part 3, 9.6.1
+// Use most commonly used value 0x3D: DMF(0x3), Reserved(0x3), 
Timing(0x1)
+*q++ = 0x3D;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata

2021-04-11 Thread zheng qian
On Mon, Apr 12, 2021 at 1:10 AM Jan Ekström  wrote:
> For context, just checked some random sample I had on hand:
>
> ARIB caption info: DMF: 0xa, reserved: 0x3, timing: 0x1
>
> So "both caption streams are selectable/showable when both received
> and playing back a recording" (0b1010), reserved bits are nonzero,
> timing is PTS based ("program based" seems to mean that).

I have checked several samples dumped from Japanese and
Brazilian TV shows that they all have a value of 0x3d for
additional_arib_caption_info that means they have value 0x3
for DMF field.

Regards,
zheng
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata

2021-04-11 Thread zheng qian
Consider the remuxed stream could be handled by other clients rather
than FFmpeg,
e.g. I'm working on HTML5 playback for ISDB television with ARIB
captions through
mpegts.js + b24.js/aribb24.js. Other ISDB TV clients may also have
possibilities to
check these fields, probably.

It will become more robust to discover whether there's an arib_caption
stream through
the descriptors in PMT. Obviously, the descriptors should match the
ARIB standard.

Best regards,
zheng

On Sun, Apr 11, 2021 at 11:52 PM Jan Ekström  wrote:
>
> On Sun, Apr 11, 2021 at 4:58 PM Jan Ekström  wrote:
> >
> > On Sun, Apr 11, 2021 at 4:25 PM magic xqq  wrote:
> > >
> > > I have already tried to use st->stream_identifier directly in mpegtsenc.c
> > > while handling arib_caption stream in mpegts_write_pmt() function.
> > >
> > > But in mpegtsenc.c, st->stream_identifier always provides
> > > an incorrect value of 0, which should be 0x30 for arib_caption A profile.
> > >
> > > st->stream_identifier seems hasn't been copied correctly while remuxing 
> > > into
> > > another mpegts stream. So I manually copied it.
> > >
> >
> > Yes, AVStream::stream_identifier is not currently handled by ffmpeg.c.
> > Not sure its addition was ever really thought thoroughly, and mostly
> > added so that MPEG-TS reading clients could gain this value when
> > reading data. Not even ffprobe.c is currently poking a stick at it.
> >
> > But quickly looking at things, you can map component_tag and
> > component_id according to the ARIB caption profile, since your
> > possibilities are:
> >
> > FF_PROFILE_ARIB_PROFILE_A => component tag 0x30-0x37, data_component_id = 
> > 0x0008
> > FF_PROFILE_ARIB_PROFILE_C => component_tag 0x87, data_component_id = 0x0012
> >
> > The only issue is if you want to keep the exact same component tag,
> > but that can be improved in ffmpeg.c by just passing it during stream
> > copy into the output AVStream if it's nonzero (that is why it's
> > identifier plus 1). Also probably we need an option to force it to
> > something else if needed. In any case, I consider this somewhat
> > separate from the remux case since I don't think you need to have the
> > exact same id for the remux to be workable? Please note if I am
> > mistaken.
> >
> > Then there's the extra info, I'll have to check the specs later today
> > whether that contains anything dynamic.
> >
> > Best regards,
> > Jan
>
> Alright, so that additional data structure is one byte large and
> contains the following things:
>
> additional_arib_caption_info(){
>   DMF   bslbf(4)
>   Reserved  bslbf(2)
>   Timingbslbf(2)
> }
>
> DMF - (Display mode flag), with b being the most common value "dynamic"
> Timing - async|program sync|real time sync
>
> So I guess at the very least this would make sense to add into the
> extradata. I do find it interesting though that libaribb24 doesn't
> seem to require this data for valid decoding at all :D (although I
> guess mostly the output timing and automated subtitle sub-stream
> selection is affected by these values).
>
> Jan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 2/2] libavformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption

2021-04-09 Thread zheng qian
Stream copy for arib_caption into mpegts is not working correctly for now.

This patch utilizes the data stored in codecpar->extradata to write necessary
stream_identifier_descriptor and data_component_descriptor into PMT table
for arib_caption remuxing.

This patch fixes the copying of arib_caption. After this patch, arib_caption
inside the outputted (remuxed) mpegts stream can be recognized correctly
as an arib_caption subtitle stream.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a357f3a6aa..e26a5d3b51 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -357,6 +357,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 break;
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
+case AV_CODEC_ID_ARIB_CAPTION:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_SMPTE_KLV:
@@ -714,8 +715,21 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
}
 
*len_ptr = q - len_ptr - 1;
+} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+if (st->codecpar->extradata && st->codecpar->extradata_size >= 
4) {
+// stream_identifier_descriptor
+*q++ = 0x52;  // descriptor_tag
+*q++ = 1; // descriptor_length
+*q++ = st->codecpar->extradata[0];  // component_tag: 
stream_identifier
+
+// data_component_descriptor
+*q++ = 0xFD;  // descriptor_tag: ARIB data coding type 
descriptor
+*q++ = 3; // descriptor_length
+memcpy(q, >codecpar->extradata[1], 3);  // 
data_component_id & additional_arib_caption_info
+q += 3;
+}
 }
-break;
+break;
 case AVMEDIA_TYPE_VIDEO:
 if (stream_type == STREAM_TYPE_VIDEO_DIRAC) {
 put_registration_descriptor(, MKTAG('d', 'r', 'a', 'c'));
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata

2021-04-09 Thread zheng qian
Changes since v1:
  If desc_len < 3, break the switch statement instead of return 
AVERROR_INVALIDDATA
  to make it more robust.
  For arib_caption, data_component_descriptor should contains at least 3 bytes:
  data_component_id: uint16, additional_arib_caption_info: uint8.

The recognization of ARIB STD-B24 caption has been introduced in commit a03885b,
which is used as closed caption in Japanese / Brazilian Digital Television.

But whenever copying arib_caption into mpegts output, arib_caption inside the
outputted stream cannot be recgonized as a arib_caption subtitle track once 
again,
which is caused by the missing of descriptors in the PMT table.

These patches are intended to fix broken stream copying of arib_caption 
subtitle.

This patch extracts necessary fields into codecpar->extradata for future 
remuxing,
which describe the stream_identifier, the profile and other additional 
information.

Signed-off-by: zheng qian 
---
 libavformat/mpegts.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 6e0d9d7496..fd7ea1f504 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2107,6 +2107,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 // STD-B24, fascicle 3, chapter 4 defines private_stream_1
 // for captions
 if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
+if (desc_len < 3)
+break;
+
 // This structure is defined in STD-B10, part 1, listing 5.4 and
 // part 2, 6.2.20).
 // Listing of data_component_ids is in STD-B10, part 2, Annex J.
@@ -2145,6 +2148,28 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 st->codecpar->codec_id   = AV_CODEC_ID_ARIB_CAPTION;
 st->codecpar->profile= picked_profile;
 st->internal->request_probe= 0;
+
+// Store stream_identifier and payload of data_component_descriptor
+// (data_component_id & additional_arib_caption_info) as extradata.
+// data_component_descriptor is defined in ARIB STD-B10, part 2, 
6.2.20
+// These will be useful for remuxing arib_caption into mpegts 
output.
+if (!st->codecpar->extradata) {
+st->codecpar->extradata = av_mallocz(4 + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (!st->codecpar->extradata)
+return AVERROR(ENOMEM);
+
+st->codecpar->extradata_size = 4;
+
+// stream_identifier (component_tag of 
stream_identifier_descriptor)
+st->codecpar->extradata[0] = (uint8_t)(st->stream_identifier - 
1);
+
+// payload of data_component_descriptor structure
+// data_component_id
+st->codecpar->extradata[1] = (uint8_t)((data_component_id & 
0xF0) >> 8);
+st->codecpar->extradata[2] = (uint8_t)(data_component_id & 
0x0F);
+// additional_arib_caption_info, defined in ARIB STD-B24, 
fascicle 1, Part 3, 9.6.1
+st->codecpar->extradata[3] = get8(pp, desc_end);
+}
 }
 break;
 case 0xb0: /* DOVI video stream descriptor */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v1 2/2] libavformat/mpegtsenc: Write necessary descriptors into PMT for arib_caption

2021-04-06 Thread zheng qian
Stream copy for arib_caption into mpegts is not working correctly for now.

This patch utilizes the data stored in codecpar->extradata to write necessary
stream_identifier_descriptor and data_component_descriptor into PMT table
for arib_caption remuxing.

This patch fixes the copying of arib_caption. After this patch, arib_caption
inside the outputted (remuxed) mpegts stream can be recognized correctly
as an arib_caption subtitle stream.

Signed-off-by: zheng qian 
---
 libavformat/mpegtsenc.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index a357f3a6aa..e26a5d3b51 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -357,6 +357,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
 break;
 case AV_CODEC_ID_DVB_SUBTITLE:
 case AV_CODEC_ID_DVB_TELETEXT:
+case AV_CODEC_ID_ARIB_CAPTION:
 stream_type = STREAM_TYPE_PRIVATE_DATA;
 break;
 case AV_CODEC_ID_SMPTE_KLV:
@@ -714,8 +715,21 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
}
 
*len_ptr = q - len_ptr - 1;
+} else if (codec_id == AV_CODEC_ID_ARIB_CAPTION) {
+if (st->codecpar->extradata && st->codecpar->extradata_size >= 
4) {
+// stream_identifier_descriptor
+*q++ = 0x52;  // descriptor_tag
+*q++ = 1; // descriptor_length
+*q++ = st->codecpar->extradata[0];  // component_tag: 
stream_identifier
+
+// data_component_descriptor
+*q++ = 0xFD;  // descriptor_tag: ARIB data coding type 
descriptor
+*q++ = 3; // descriptor_length
+memcpy(q, >codecpar->extradata[1], 3);  // 
data_component_id & additional_arib_caption_info
+q += 3;
+}
 }
-break;
+break;
 case AVMEDIA_TYPE_VIDEO:
 if (stream_type == STREAM_TYPE_VIDEO_DIRAC) {
 put_registration_descriptor(, MKTAG('d', 'r', 'a', 'c'));
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v1 1/2] libavformat/mpegts: Extract arib_caption descriptor data into codecpar->extradata

2021-04-06 Thread zheng qian
The recognization of ARIB STD-B24 caption has been introduced in commit a03885b,
which is used as closed caption in Japanese / Brazilian Digital Television.

But whenever copying arib_caption into mpegts output, arib_caption inside the
outputted stream cannot be recgonized as a arib_caption subtitle track once 
again,
which is caused by the missing of descriptors in the PMT table.

These patches are intended to fix broken stream copying of arib_caption 
subtitle.

This patch extracts necessary fields into codecpar->extradata for future 
remuxing,
which describe the stream_identifier, the profile and other additional 
information.

Signed-off-by: zheng qian 
---
 libavformat/mpegts.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 6e0d9d7496..a6a534a277 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2107,6 +2107,9 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 // STD-B24, fascicle 3, chapter 4 defines private_stream_1
 // for captions
 if (stream_type == STREAM_TYPE_PRIVATE_DATA) {
+if (desc_len < 3)
+return AVERROR_INVALIDDATA;
+
 // This structure is defined in STD-B10, part 1, listing 5.4 and
 // part 2, 6.2.20).
 // Listing of data_component_ids is in STD-B10, part 2, Annex J.
@@ -2145,6 +2148,28 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 st->codecpar->codec_id   = AV_CODEC_ID_ARIB_CAPTION;
 st->codecpar->profile= picked_profile;
 st->internal->request_probe= 0;
+
+// Store stream_identifier and payload of data_component_descriptor
+// (data_component_id & additional_arib_caption_info) as extradata.
+// data_component_descriptor is defined in ARIB STD-B10, part 2, 
6.2.20
+// These will be useful for remuxing arib_caption into mpegts 
output.
+if (!st->codecpar->extradata) {
+st->codecpar->extradata = av_mallocz(4 + 
AV_INPUT_BUFFER_PADDING_SIZE);
+if (!st->codecpar->extradata)
+return AVERROR(ENOMEM);
+
+st->codecpar->extradata_size = 4;
+
+// stream_identifier (component_tag of 
stream_identifier_descriptor)
+st->codecpar->extradata[0] = (uint8_t)(st->stream_identifier - 
1);
+
+// payload of data_component_descriptor structure
+// data_component_id
+st->codecpar->extradata[1] = (uint8_t)((data_component_id & 
0xF0) >> 8);
+st->codecpar->extradata[2] = (uint8_t)(data_component_id & 
0x0F);
+// additional_arib_caption_info, defined in ARIB STD-B24, 
fascicle 1, Part 3, 9.6.1
+st->codecpar->extradata[3] = get8(pp, desc_end);
+}
 }
 break;
 case 0xb0: /* DOVI video stream descriptor */
-- 
2.29.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".