Re: [FFmpeg-devel] [PATCH v3 2/2] avformat/movenc: add support for TTML muxing

2021-08-09 Thread Jan Ekström
On Thu, Aug 5, 2021 at 10:33 PM Andreas Rheinhardt
 wrote:
>
> Jan Ekström:
> > From: Jan Ekström 
> >
> > Includes basic support for both the ISMV ('dfxp') and MP4 ('stpp')
> > methods. This initial version also foregoes fragmentation support
> > in case the built-in sample squashing is to be utilized, as this
> > eases the initial review.
> >
> > Additionally, add basic tests for both muxing modes in MP4.
> >
> > Signed-off-by: Jan Ekström 
> > ---
> >  libavformat/Makefile |   2 +-
> >  libavformat/isom.h   |   3 +
> >  libavformat/movenc.c | 179 ++-
> >  libavformat/movenc.h |   5 +
> >  libavformat/movenc_ttml.c| 178 ++
> >  libavformat/movenc_ttml.h|  31 ++
> >  tests/fate/subtitles.mak |   4 +
> >  tests/ref/fate/sub-ttml-mp4-dfxp |  44 
> >  tests/ref/fate/sub-ttml-mp4-stpp |  44 
> >  9 files changed, 487 insertions(+), 3 deletions(-)
> >  create mode 100644 libavformat/movenc_ttml.c
> >  create mode 100644 libavformat/movenc_ttml.h
> >  create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
> >  create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp
> >
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index 813ddd3c20..7e0f587b41 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -337,7 +337,7 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
> > mov_chan.o mov_esds.o \
> >  qtpalette.o replaygain.o
> >  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o 
> > vpcc.o \
> >  movenchint.o mov_chan.o rtp.o \
> > -movenccenc.o rawutils.o
> > +movenccenc.o movenc_ttml.o 
> > rawutils.o
> >  OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
> >  OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
> >  OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
> > diff --git a/libavformat/isom.h b/libavformat/isom.h
> > index ac1b3f3d56..34a58c79b7 100644
> > --- a/libavformat/isom.h
> > +++ b/libavformat/isom.h
> > @@ -387,4 +387,7 @@ static inline enum AVCodecID 
> > ff_mov_get_lpcm_codec_id(int bps, int flags)
> >  return ff_get_pcm_codec_id(bps, flags & 1, flags & 2, flags & 4 ? -1 : 
> > 0);
> >  }
> >
> > +#define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
> > +#define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
> > +
> >  #endif /* AVFORMAT_ISOM_H */
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index c85efe8748..f3e295ad80 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -56,6 +56,8 @@
> >  #include "hevc.h"
> >  #include "rtpenc.h"
> >  #include "mov_chan.h"
> > +#include "movenc_ttml.h"
> > +#include "ttmlenc.h"
> >  #include "vpcc.h"
> >
> >  static const AVOption options[] = {
> > @@ -119,6 +121,7 @@ static const AVClass mov_isobmff_muxer_class = {
> >  };
> >
> >  static int get_moov_size(AVFormatContext *s);
> > +static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt);
> >
> >  static int utf8len(const uint8_t *b)
> >  {
> > @@ -1787,7 +1790,29 @@ static int mov_write_subtitle_tag(AVIOContext *pb, 
> > MOVTrack *track)
> >
> >  if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE)
> >  mov_write_esds_tag(pb, track);
> > -else if (track->par->extradata_size)
> > +else if (track->par->codec_id == AV_CODEC_ID_TTML) {
> > +switch (track->par->codec_tag) {
> > +case MOV_ISMV_TTML_TAG:
> > +// ISMV dfxp requires no extradata.
> > +break;
> > +case MOV_MP4_TTML_TAG:
> > +// As specified in 14496-30, XMLSubtitleSampleEntry
> > +// Namespace
> > +avio_put_str(pb, "http://www.w3.org/ns/ttml;);
> > +// Empty schema_location
> > +avio_w8(pb, 0);
> > +// Empty auxiliary_mime_types
> > +avio_w8(pb, 0);
> > +break;
> > +default:
> > +av_log(NULL, AV_LOG_ERROR,
> > +   "Unknown codec tag '%s' utilized for TTML stream with "
> > +   "index %d (track id %d)!\n",
> > +   av_fourcc2str(track->par->codec_tag), track->st->index,
> > +   track->track_id);
> > +return AVERROR(EINVAL);
> > +}
> > +} else if (track->par->extradata_size)
> >  avio_write(pb, track->par->extradata, track->par->extradata_size);
> >
> >  if (track->mode == MODE_MP4 &&
> > @@ -2661,6 +2686,14 @@ static int mov_write_nmhd_tag(AVIOContext *pb)
> >  return 12;
> >  }
> >
> > +static int mov_write_sthd_tag(AVIOContext *pb)
> > +{
> > +avio_wb32(pb, 12);
> > +ffio_wfourcc(pb, "sthd");
> > +avio_wb32(pb, 0);
> > +return 12;
> > +}
> > +
> >  static int 

Re: [FFmpeg-devel] [PATCH v3 2/2] avformat/movenc: add support for TTML muxing

2021-08-05 Thread Andreas Rheinhardt
Jan Ekström:
> From: Jan Ekström 
> 
> Includes basic support for both the ISMV ('dfxp') and MP4 ('stpp')
> methods. This initial version also foregoes fragmentation support
> in case the built-in sample squashing is to be utilized, as this
> eases the initial review.
> 
> Additionally, add basic tests for both muxing modes in MP4.
> 
> Signed-off-by: Jan Ekström 
> ---
>  libavformat/Makefile |   2 +-
>  libavformat/isom.h   |   3 +
>  libavformat/movenc.c | 179 ++-
>  libavformat/movenc.h |   5 +
>  libavformat/movenc_ttml.c| 178 ++
>  libavformat/movenc_ttml.h|  31 ++
>  tests/fate/subtitles.mak |   4 +
>  tests/ref/fate/sub-ttml-mp4-dfxp |  44 
>  tests/ref/fate/sub-ttml-mp4-stpp |  44 
>  9 files changed, 487 insertions(+), 3 deletions(-)
>  create mode 100644 libavformat/movenc_ttml.c
>  create mode 100644 libavformat/movenc_ttml.h
>  create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
>  create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 813ddd3c20..7e0f587b41 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -337,7 +337,7 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
> mov_chan.o mov_esds.o \
>  qtpalette.o replaygain.o
>  OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o 
> vpcc.o \
>  movenchint.o mov_chan.o rtp.o \
> -movenccenc.o rawutils.o
> +movenccenc.o movenc_ttml.o 
> rawutils.o
>  OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
>  OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
>  OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index ac1b3f3d56..34a58c79b7 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -387,4 +387,7 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int 
> bps, int flags)
>  return ff_get_pcm_codec_id(bps, flags & 1, flags & 2, flags & 4 ? -1 : 
> 0);
>  }
>  
> +#define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
> +#define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
> +
>  #endif /* AVFORMAT_ISOM_H */
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index c85efe8748..f3e295ad80 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -56,6 +56,8 @@
>  #include "hevc.h"
>  #include "rtpenc.h"
>  #include "mov_chan.h"
> +#include "movenc_ttml.h"
> +#include "ttmlenc.h"
>  #include "vpcc.h"
>  
>  static const AVOption options[] = {
> @@ -119,6 +121,7 @@ static const AVClass mov_isobmff_muxer_class = {
>  };
>  
>  static int get_moov_size(AVFormatContext *s);
> +static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt);
>  
>  static int utf8len(const uint8_t *b)
>  {
> @@ -1787,7 +1790,29 @@ static int mov_write_subtitle_tag(AVIOContext *pb, 
> MOVTrack *track)
>  
>  if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE)
>  mov_write_esds_tag(pb, track);
> -else if (track->par->extradata_size)
> +else if (track->par->codec_id == AV_CODEC_ID_TTML) {
> +switch (track->par->codec_tag) {
> +case MOV_ISMV_TTML_TAG:
> +// ISMV dfxp requires no extradata.
> +break;
> +case MOV_MP4_TTML_TAG:
> +// As specified in 14496-30, XMLSubtitleSampleEntry
> +// Namespace
> +avio_put_str(pb, "http://www.w3.org/ns/ttml;);
> +// Empty schema_location
> +avio_w8(pb, 0);
> +// Empty auxiliary_mime_types
> +avio_w8(pb, 0);
> +break;
> +default:
> +av_log(NULL, AV_LOG_ERROR,
> +   "Unknown codec tag '%s' utilized for TTML stream with "
> +   "index %d (track id %d)!\n",
> +   av_fourcc2str(track->par->codec_tag), track->st->index,
> +   track->track_id);
> +return AVERROR(EINVAL);
> +}
> +} else if (track->par->extradata_size)
>  avio_write(pb, track->par->extradata, track->par->extradata_size);
>  
>  if (track->mode == MODE_MP4 &&
> @@ -2661,6 +2686,14 @@ static int mov_write_nmhd_tag(AVIOContext *pb)
>  return 12;
>  }
>  
> +static int mov_write_sthd_tag(AVIOContext *pb)
> +{
> +avio_wb32(pb, 12);
> +ffio_wfourcc(pb, "sthd");
> +avio_wb32(pb, 0);
> +return 12;
> +}
> +
>  static int mov_write_tcmi_tag(AVIOContext *pb, MOVTrack *track)
>  {
>  int64_t pos = avio_tell(pb);
> @@ -2787,6 +2820,8 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
>  hdlr_type = "sbtl";
>  } else if (track->tag == 

Re: [FFmpeg-devel] [PATCH v3 2/2] avformat/movenc: add support for TTML muxing

2021-08-02 Thread Martin Storsjö

On Mon, 26 Jul 2021, Jan Ekström wrote:


From: Jan Ekström 

Includes basic support for both the ISMV ('dfxp') and MP4 ('stpp')
methods. This initial version also foregoes fragmentation support
in case the built-in sample squashing is to be utilized, as this
eases the initial review.

Additionally, add basic tests for both muxing modes in MP4.

Signed-off-by: Jan Ekström 
---
libavformat/Makefile |   2 +-
libavformat/isom.h   |   3 +
libavformat/movenc.c | 179 ++-
libavformat/movenc.h |   5 +
libavformat/movenc_ttml.c| 178 ++
libavformat/movenc_ttml.h|  31 ++
tests/fate/subtitles.mak |   4 +
tests/ref/fate/sub-ttml-mp4-dfxp |  44 
tests/ref/fate/sub-ttml-mp4-stpp |  44 
9 files changed, 487 insertions(+), 3 deletions(-)
create mode 100644 libavformat/movenc_ttml.c
create mode 100644 libavformat/movenc_ttml.h
create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp


Thanks for addressing my comments. No further comments from me on this, 
but Andreas had more valuable comments on it than me, so I'd let him 
follow up and finish the review of this.


// Martin
___
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/2] avformat/movenc: add support for TTML muxing

2021-07-26 Thread Jan Ekström
From: Jan Ekström 

Includes basic support for both the ISMV ('dfxp') and MP4 ('stpp')
methods. This initial version also foregoes fragmentation support
in case the built-in sample squashing is to be utilized, as this
eases the initial review.

Additionally, add basic tests for both muxing modes in MP4.

Signed-off-by: Jan Ekström 
---
 libavformat/Makefile |   2 +-
 libavformat/isom.h   |   3 +
 libavformat/movenc.c | 179 ++-
 libavformat/movenc.h |   5 +
 libavformat/movenc_ttml.c| 178 ++
 libavformat/movenc_ttml.h|  31 ++
 tests/fate/subtitles.mak |   4 +
 tests/ref/fate/sub-ttml-mp4-dfxp |  44 
 tests/ref/fate/sub-ttml-mp4-stpp |  44 
 9 files changed, 487 insertions(+), 3 deletions(-)
 create mode 100644 libavformat/movenc_ttml.c
 create mode 100644 libavformat/movenc_ttml.h
 create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
 create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 813ddd3c20..7e0f587b41 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -337,7 +337,7 @@ OBJS-$(CONFIG_MOV_DEMUXER)   += mov.o 
mov_chan.o mov_esds.o \
 qtpalette.o replaygain.o
 OBJS-$(CONFIG_MOV_MUXER) += movenc.o av1.o avc.o hevc.o vpcc.o 
\
 movenchint.o mov_chan.o rtp.o \
-movenccenc.o rawutils.o
+movenccenc.o movenc_ttml.o 
rawutils.o
 OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
 OBJS-$(CONFIG_MP3_DEMUXER)   += mp3dec.o replaygain.o
 OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ac1b3f3d56..34a58c79b7 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -387,4 +387,7 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int 
bps, int flags)
 return ff_get_pcm_codec_id(bps, flags & 1, flags & 2, flags & 4 ? -1 : 0);
 }
 
+#define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
+#define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
+
 #endif /* AVFORMAT_ISOM_H */
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index c85efe8748..f3e295ad80 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -56,6 +56,8 @@
 #include "hevc.h"
 #include "rtpenc.h"
 #include "mov_chan.h"
+#include "movenc_ttml.h"
+#include "ttmlenc.h"
 #include "vpcc.h"
 
 static const AVOption options[] = {
@@ -119,6 +121,7 @@ static const AVClass mov_isobmff_muxer_class = {
 };
 
 static int get_moov_size(AVFormatContext *s);
+static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt);
 
 static int utf8len(const uint8_t *b)
 {
@@ -1787,7 +1790,29 @@ static int mov_write_subtitle_tag(AVIOContext *pb, 
MOVTrack *track)
 
 if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE)
 mov_write_esds_tag(pb, track);
-else if (track->par->extradata_size)
+else if (track->par->codec_id == AV_CODEC_ID_TTML) {
+switch (track->par->codec_tag) {
+case MOV_ISMV_TTML_TAG:
+// ISMV dfxp requires no extradata.
+break;
+case MOV_MP4_TTML_TAG:
+// As specified in 14496-30, XMLSubtitleSampleEntry
+// Namespace
+avio_put_str(pb, "http://www.w3.org/ns/ttml;);
+// Empty schema_location
+avio_w8(pb, 0);
+// Empty auxiliary_mime_types
+avio_w8(pb, 0);
+break;
+default:
+av_log(NULL, AV_LOG_ERROR,
+   "Unknown codec tag '%s' utilized for TTML stream with "
+   "index %d (track id %d)!\n",
+   av_fourcc2str(track->par->codec_tag), track->st->index,
+   track->track_id);
+return AVERROR(EINVAL);
+}
+} else if (track->par->extradata_size)
 avio_write(pb, track->par->extradata, track->par->extradata_size);
 
 if (track->mode == MODE_MP4 &&
@@ -2661,6 +2686,14 @@ static int mov_write_nmhd_tag(AVIOContext *pb)
 return 12;
 }
 
+static int mov_write_sthd_tag(AVIOContext *pb)
+{
+avio_wb32(pb, 12);
+ffio_wfourcc(pb, "sthd");
+avio_wb32(pb, 0);
+return 12;
+}
+
 static int mov_write_tcmi_tag(AVIOContext *pb, MOVTrack *track)
 {
 int64_t pos = avio_tell(pb);
@@ -2787,6 +2820,8 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra
 hdlr_type = "sbtl";
 } else if (track->tag == MKTAG('m','p','4','s')) {
 hdlr_type = "subp";
+} else if (track->tag == MOV_MP4_TTML_TAG) {
+hdlr_type = "subt";
 } else {
 hdlr_type = "text";
 }
@@ -2865,6 +2900,8 @@ static int