Re: [FFmpeg-devel] [PATCH v3] avformat/concatdec: add support for setting input options

2021-02-10 Thread Jan Ekström
On Wed, Feb 10, 2021 at 8:33 PM Nicolas George  wrote:
>
> Jan Ekström (12021-02-08):
> > This way protocol or format related options can be set for all
> > of the files opened during concatenation both globally as well
> > as per-file.
> > ---
> >
> > Changes from v2:
> >
> > 1. Added an example, although I had issues figuring out something useful
> >that is not a hack for something. Ended up doing a disablement of
> >advanced edit list functionality, since that can sometimes lead to
> >unwanted behavior.
> >
>
> >* First idea was to override the input format for a file without an
> >  extension. For that, we have no AVOption it seems.
>
> Indeed, lavf does not accept it as an option. It needs to be added
> separately. Or we can make it an option.
>
> >* Then came the idea of utilizing the framerate option in the raw
> >  h264 demuxer. That didn't work because apparently if there is a header
> >  in there that probed/parsed frame rate field gets utilized.
>
> You could set the frame rate for a raw video stream.
>

Sure.

> >* Third idea was either the one I picked, or analyzeduration/probesize
> >  for MPEG-TS. I opted for the mp4 case.
> >
> > 2. Quoted the : in documentation with @code{:}.
> > 3. Fixed a duplicate space in a log message.
> > ---
> >
> >  doc/demuxers.texi   | 24 ++
> >  libavformat/concatdec.c | 69 -
> >  2 files changed, 92 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> > index 3c15ab9eee..20601f9575 100644
> > --- a/doc/demuxers.texi
> > +++ b/doc/demuxers.texi
> > @@ -149,6 +149,14 @@ Metadata of the packets of the file. The specified 
> > metadata will be set for
> >  each file packet. You can specify this directive multiple times to add 
> > multiple
> >  metadata entries.
> >
> > +@item @code{input_options @var{key=value:key2=value2}}
>
> > +Input options passed on when reading a specific file, using a 
> > @code{:}-separated
> > +list of key=value pairs.
>
> No! Why would you do that? It adds one level of escaping, we already
> have way too much of them.

Because:
1. we have the functionality for it
2. it matches the AVOption.

Please do not take it as if I did not have any logic behind my actions
whatsoever, which is what the exclamation mark looks like.

>
> input option key=value
>
> singular, and can be set as many times as necessary.
>
> > Requires @code{safe} to be non-positive.
>
> Zero would be safer.
>
> > Global options
> > +for all files can be set with the @code{input_options} demuxer option. 
> > When using
> > +both options on the list of files as well as globally via the demuxer 
> > option,
> > +the global ones get applied first and the file-specific options are then 
> > applied
> > +on top of them.
>
> I am not sure it is the right order. Options added on the fly should
> take precedence over options written in a file, in general. But the
> global / specific distinction makes it less clear-cut.
>

You set the AVOption for option(s) to be applied for all files, and if
you want to only set some option for specific files you set them in
the list.

*You* requested the latter capability, I added it.

> Other opinions?
>
> > +
> >  @item @code{stream}
> >  Introduce a stream in the virtual file.
> >  All subsequent stream-related directives apply to the last introduced
> > @@ -204,6 +212,10 @@ expressed in microseconds. The duration metadata is 
> > only set if it is known
> >  based on the concat file.
> >  The default is 0.
> >
> > +@item input_options
> > +Input options to be passed on for all opened inputs using
>
> > a :-separated list of
>
> It should say "a dictionary", with a link to where the syntax of
> dictionaries is documented, but whoever added AV_OPT_TYPE_DICT neglected
> to add the corresponding documentation paragraph :(
>

Yes. This just matches the rest of the documentation strings etc for
such things.

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".

Re: [FFmpeg-devel] [PATCH] avformat/movenc: remove unnecessary HDR metadata log messages

2021-02-10 Thread Jan Ekström
On Wed, Feb 10, 2021 at 12:43 PM Paul B Mahol  wrote:
>
> lgtm

Cheers, applied as 752f14ff942576dd8697320fb6ba055593a2de9d .

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] [PATCH v2] avfilter/vf_zscale: add support for setting scaling filter parameters

2021-02-11 Thread Jan Ekström
param_a/b are utilized for this.
---
Changes from v1:

* Documentation was added.
* The author of the zimg library noted that the bicubic parameters technically
  can go negative. Thus the range is -DBL_MAX to DBL_MAX.

---
 doc/filters.texi| 7 +++
 libavfilter/vf_zscale.c | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 50aa0eb305..152e806fdd 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22393,6 +22393,13 @@ Possible values are:
 
 @item npl
 Set the nominal peak luminance.
+
+@item param_a
+Parameter A for scaling filters. Parameter "b" for bicubic, and the number of
+filter taps for lanczos.
+
+@item param_b
+Parameter B for scaling filters. Parameter "c" for bicubic.
 @end table
 
 The values of the @option{w} and @option{h} options are expressions
diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 57199a0878..c18a161ab4 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -101,6 +101,8 @@ typedef struct ZScaleContext {
 char *size_str;
 double nominal_peak_luminance;
 int approximate_gamma;
+double param_a;
+double param_b;
 
 char *w_expr;   ///< width  expression string
 char *h_expr;   ///< height expression string
@@ -601,6 +603,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
 s->params.resample_filter_uv = s->filter;
 s->params.nominal_peak_luminance = s->nominal_peak_luminance;
 s->params.allow_approximate_gamma = s->approximate_gamma;
+s->params.filter_param_a = s->params.filter_param_a_uv = s->param_a;
+s->params.filter_param_b = s->params.filter_param_b_uv = s->param_b;
 
 format_init(>src_format, in, desc, s->colorspace_in,
 s->primaries_in, s->trc_in, s->range_in, s->chromal_in);
@@ -897,6 +901,9 @@ static const AVOption zscale_options[] = {
 { "cin","set input chroma location", OFFSET(chromal_in), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
 { "npl",   "set nominal peak luminance", 
OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, 
FLAGS },
 { "agamma",   "allow approximate gamma", OFFSET(approximate_gamma),
  AV_OPT_TYPE_BOOL,   {.i64 = 1},   0, 1,   FLAGS },
+{ "param_a", "parameter A, which is parameter \"b\" for bicubic, "
+ "and the number of filter taps for lanczos", OFFSET(param_a), 
AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
+{ "param_b", "parameter B, which is parameter \"c\" for bicubic", 
OFFSET(param_b), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
 { NULL }
 };
 
-- 
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] avfilter/vf_zscale: add support for setting scaling filter parameters

2021-02-11 Thread Jan Ekström
On Thu, Feb 11, 2021 at 8:31 PM Paul B Mahol  wrote:
>
> lgtm

Thanks, applied as 58e59396f5fe93f0606dc458d84c609b5d23ea1c .

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".

Re: [FFmpeg-devel] [PATCH] Increase MOV_TIMESCALE for higher precision

2021-03-24 Thread Jan Ekström
On Wed, Mar 24, 2021 at 7:30 AM Gyan Doshi  wrote:
>
>
>
> On 2021-03-24 03:38, Andrey Rikunov wrote:
> > ---
> >   libavformat/movenc.h | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavformat/movenc.h b/libavformat/movenc.h
> > index cdbc407..8a152c0 100644
> > --- a/libavformat/movenc.h
> > +++ b/libavformat/movenc.h
> > @@ -29,7 +29,7 @@
> >
> >   #define MOV_FRAG_INFO_ALLOC_INCREMENT 64
> >   #define MOV_INDEX_CLUSTER_SIZE 1024
> > -#define MOV_TIMESCALE 1000
> > +#define MOV_TIMESCALE 6
>
> Instead of hardcoding it, add an option to allow the user to set it.

I think if the "Mov requires timescale 1000" assumption is no longer
correct, it should be removed and the generic time base based
timescale generation utilized instead, which is utilized for
MP4-likes. That way by setting time base one can affect it with the
standard option.

For the general logic (for MP4- likes), I am planning on getting rid
of the video time scale option in the following steps:
1. Figure out what the historical reasons for having a video time
scale of over 10k are (I think it was mostly to adjust A/V sync with
more granularity than frame rate - but we have edit lists for that
now?).
2. If those still hold, make a "auto_adjust_timescale" boolean, which
would first be on by default.
3. Make video_timescale disable the auto-adjustment of video
timescale, and set the time base earlier in the muxer logic (since
muxers are allowed to override the AVStreams' time base).
4. Deprecate video_timescale and point people towards
-auto_adjust_timescale false/0 -time_base:v "1:NUMBER"

I have seen people add various timescale related options to movenc in
their trees for audio/subtitles just because it's not clear that we
already have time_base :s . Thus this just needs to be cleaned up. And
if MOV still needs its timescale override of 1:1000 for some
compatibility reasons (?) then "auto_adjust_timescale" can also poke
at that.

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] [PATCH 4/4] avcodec/ttmlenc: add support for region positioning and sizing

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

The ASS margins are utilized to generate percentual values, as
the usage of cell-based sizing and offsetting seems to be not too
well supported by renderers.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 41 --
 tests/ref/fate/sub-ttmlenc |  2 ++
 2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index 7e6add62e1..a08b1ada2e 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -254,6 +254,26 @@ static const char *ttml_get_text_alignment(int alignment)
 }
 }
 
+static void ttml_get_origin(ASSScriptInfo script_info, ASSStyle *style,
+   int *origin_left, int *origin_top)
+{
+*origin_left = av_rescale(style->margin_l, 100, script_info.play_res_x);
+*origin_top  =
+av_rescale((style->alignment >= 7) ? style->margin_v : 0,
+   100, script_info.play_res_x);
+}
+
+static void ttml_get_extent(ASSScriptInfo script_info, ASSStyle *style,
+   int *width, int *height)
+{
+*width  = av_rescale(script_info.play_res_x - style->margin_r,
+ 100, script_info.play_res_x);
+*height = av_rescale((style->alignment <= 3) ?
+ script_info.play_res_y - style->margin_v :
+ script_info.play_res_y,
+ 100, script_info.play_res_y);
+}
+
 // if we set cell resolution to our script reference resolution,
 // then a single line is a single "point" on our canvas. Thus, by setting our
 // font size to font size in cells, we should gain a similar enough scale
@@ -261,6 +281,8 @@ static const char *ttml_get_text_alignment(int alignment)
 // upon in the TTML community.
 static const char ttml_region_base[] =
 "  \n";
 
 static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf,
- ASSStyle *style)
+ ASSScriptInfo script_info, ASSStyle *style)
 {
 if (!style)
 return AVERROR_INVALIDDATA;
@@ -288,11 +310,22 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+if (style->margin_l < 0 || style->margin_r < 0 || style->margin_v < 0) {
+av_log(avctx, AV_LOG_ERROR,
+   "One or more negative margin values in subtitle style: "
+   "left: %d, right: %d, vertical: %d!\n",
+   style->margin_l, style->margin_r, style->margin_v);
+}
+
 {
 const char *display_alignment =
 ttml_get_display_alignment(style->alignment);
 const char *text_alignment =
 ttml_get_text_alignment(style->alignment);
+int origin_left = 0;
+int origin_top  = 0;
+int width = 0;
+int height = 0;
 char *style_name = NULL;
 char *font_name = NULL;
 AVBPrint local_bprint = { 0 };
@@ -307,6 +340,9 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+ttml_get_origin(script_info, style, _left, _top);
+ttml_get_extent(script_info, style, , );
+
 av_bprint_init(_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
 av_bprint_escape(_bprint, style->name, NULL,
  AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
@@ -318,6 +354,7 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return ret;
 
 av_bprintf(buf, ttml_region_base, style_name,
+   origin_left, origin_top, width, height,
display_alignment, text_alignment, style->font_size);
 
 if (style->font_name) {
@@ -383,7 +420,7 @@ static int ttml_write_header_content(AVCodecContext *avctx)
 int ret = AVERROR_BUG;
 style = >styles[i];
 
-if ((ret = ttml_write_region(avctx, >buffer, style)) < 0)
+if ((ret = ttml_write_region(avctx, >buffer, script_info, style)) < 
0)
 return ret;
 }
 
diff --git a/tests/ref/fate/sub-ttmlenc b/tests/ref/fate/sub-ttmlenc
index 6d0a8067fc..4df8f8796f 100644
--- a/tests/ref/fate/sub-ttmlenc
+++ b/tests/ref/fate/sub-ttmlenc
@@ -9,6 +9,8 @@
   
 
   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/4] avformat/ttmlenc: enable writing out additional header values

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

This way the encoder may pass on the following values to the muxer:
1) Additional root "tt" element attributes, such as the subtitle
   canvas reference size.
2) Anything before the body element of the document, such as regions
   in the head element, which can configure styles.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.h  |  5 +++
 libavformat/ttmlenc.c | 78 ---
 2 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ttmlenc.h b/libavcodec/ttmlenc.h
index c1dd5ec990..c3bb11478d 100644
--- a/libavcodec/ttmlenc.h
+++ b/libavcodec/ttmlenc.h
@@ -25,4 +25,9 @@
 #define TTMLENC_EXTRADATA_SIGNATURE "lavc-ttmlenc"
 #define TTMLENC_EXTRADATA_SIGNATURE_SIZE (sizeof(TTMLENC_EXTRADATA_SIGNATURE) 
- 1)
 
+static const char ttml_default_namespacing[] =
+"  xmlns=\"http://www.w3.org/ns/ttml\"\n;
+"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
+"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;;
+
 #endif /* AVCODEC_TTMLENC_H */
diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
index 940f8bbd4e..5d9ad6b756 100644
--- a/libavformat/ttmlenc.c
+++ b/libavformat/ttmlenc.c
@@ -37,18 +37,23 @@ enum TTMLPacketType {
 PACKET_TYPE_DOCUMENT,
 };
 
+struct TTMLHeaderParameters {
+char *tt_element_params;
+char *pre_body_elements;
+};
+
 typedef struct TTMLMuxContext {
 enum TTMLPacketType input_type;
 unsigned int document_written;
+struct TTMLHeaderParameters header_params;
 } TTMLMuxContext;
 
 static const char ttml_header_text[] =
 "\n"
 "http://www.w3.org/ns/ttml\"\n;
-"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
-"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;
+"%s"
 "  xml:lang=\"%s\">\n"
+"%s"
 "  \n"
 "\n";
 
@@ -72,6 +77,47 @@ static void ttml_write_time(AVIOContext *pb, const char 
tag[],
 tag, hour, min, sec, millisec);
 }
 
+static int ttml_set_header_values_from_extradata(
+AVCodecParameters *par, struct TTMLHeaderParameters *header_params)
+{
+size_t additional_data_size =
+par->extradata_size - TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+
+if (!additional_data_size) {
+header_params->tt_element_params =
+av_strndup(ttml_default_namespacing,
+   sizeof(ttml_default_namespacing) - 1);
+header_params->pre_body_elements = av_strndup("", 1);
+
+if (!header_params->tt_element_params ||
+!header_params->pre_body_elements)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+{
+char *value =
+(char *)par->extradata + TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+size_t value_size = av_strnlen(value, additional_data_size);
+
+if (!(header_params->tt_element_params = av_strndup(value, 
value_size)))
+return AVERROR(ENOMEM);
+
+additional_data_size -= value_size + 1;
+value += value_size + 1;
+if (additional_data_size <= 0)
+return AVERROR_INVALIDDATA;
+
+value_size = av_strnlen(value, additional_data_size);
+
+if (!(header_params->pre_body_elements = av_strndup(value, 
value_size)))
+return AVERROR(ENOMEM);
+
+return 0;
+}
+}
+
 static int ttml_write_header(AVFormatContext *ctx)
 {
 TTMLMuxContext *ttml_ctx = ctx->priv_data;
@@ -103,8 +149,21 @@ static int ttml_write_header(AVFormatContext *ctx)
 
 avpriv_set_pts_info(st, 64, 1, 1000);
 
-if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH)
-avio_printf(pb, ttml_header_text, printed_lang);
+if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH) {
+int ret = ttml_set_header_values_from_extradata(
+st->codecpar, _ctx->header_params);
+if (ret < 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Failed to parse TTML header values from extradata: "
+   "%s!\n", av_err2str(ret));
+return ret;
+}
+
+avio_printf(pb, ttml_header_text,
+ttml_ctx->header_params.tt_element_params,
+printed_lang,
+ttml_ctx->header_params.pre_body_elements);
+}
 }
 
 return 0;
@@ -159,6 +218,14 @@ static int ttml_write_trailer(AVFormatContext *ctx)
 return 0;
 }
 
+static void ttml_free(AVFormatContext *ctx)
+{
+TTMLMuxContext *ttml_ctx = ctx->priv_data;
+
+av_freep(&(ttml_ctx->header_params.tt_element_params));
+av_freep(&(ttml_ctx->header_params.pre_body_elements));
+}
+
 AVOutputFormat ff_ttml_muxer = {
 .name  = "ttml",
 .long_name

Re: [FFmpeg-devel] [PATCH 4/4] avcodec/ttmlenc: add support for region positioning and sizing

2021-03-30 Thread Jan Ekström
On Tue, Mar 30, 2021 at 11:23 AM Jan Ekström  wrote:
>
> +if (style->margin_l < 0 || style->margin_r < 0 || style->margin_v < 0) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "One or more negative margin values in subtitle style: "
> +   "left: %d, right: %d, vertical: %d!\n",
> +   style->margin_l, style->margin_r, style->margin_v);
> +}

Just as I was sending this patch set, I noticed that this missed a
return. Fixed locally.

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] [PATCH 3/4] avcodec/ttmlenc: add initial support for regions and styles

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

Attempts to utilize the TTML cell resolution as a mapping to the
reference resolution, and maps font size to cell size. Additionally
sets the display and text alignment according to the ASS alignment
number.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 257 +++--
 libavcodec/ttmlenc.h   |   3 +-
 tests/ref/fate/sub-ttmlenc |  86 +++--
 3 files changed, 294 insertions(+), 52 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index e3c155fdd1..7e6add62e1 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -82,6 +82,7 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
*buf,
 {
 TTMLContext *s = avctx->priv_data;
 ASSDialog *dialog;
+AVBPrint local_bprint = { 0 };
 int i;
 
 av_bprint_clear(>buffer);
@@ -100,20 +101,41 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, );
 
 for (; dialog && num--; dialog++) {
-int ret = ff_ass_split_override_codes(_callbacks, s,
-  dialog->text);
-int log_level = (ret != AVERROR_INVALIDDATA ||
- avctx->err_recognition & AV_EF_EXPLODE) ?
-AV_LOG_ERROR : AV_LOG_WARNING;
+if (dialog->style) {
+av_bprint_init(_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_escape(_bprint, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+if (!av_bprint_is_complete(_bprint)) {
+ return AVERROR(ENOMEM);
+}
 
-if (ret < 0) {
-av_log(avctx, log_level,
-   "Splitting received ASS dialog failed: %s\n",
-   av_err2str(ret));
+av_bprintf(>buffer, "",
+   local_bprint.str);
 
-if (log_level == AV_LOG_ERROR)
-return ret;
+av_bprint_finalize(_bprint, NULL);
 }
+
+{
+int ret = ff_ass_split_override_codes(_callbacks, s,
+  dialog->text);
+int log_level = (ret != AVERROR_INVALIDDATA ||
+ avctx->err_recognition & AV_EF_EXPLODE) ?
+AV_LOG_ERROR : AV_LOG_WARNING;
+
+if (ret < 0) {
+av_log(avctx, log_level,
+   "Splitting received ASS dialog failed: %s\n",
+   av_err2str(ret));
+
+if (log_level == AV_LOG_ERROR)
+return ret;
+}
+}
+
+if (dialog->style)
+av_bprintf(>buffer, "");
 }
 } else {
 #endif
@@ -121,6 +143,22 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 if (!dialog)
 return AVERROR(ENOMEM);
 
+if (dialog->style) {
+av_bprint_init(_bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_escape(_bprint, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+if (!av_bprint_is_complete(_bprint)) {
+ return AVERROR(ENOMEM);
+}
+
+av_bprintf(>buffer, "",
+   local_bprint.str);
+
+av_bprint_finalize(_bprint, NULL);
+}
+
 {
 int ret = ff_ass_split_override_codes(_callbacks, s,
   dialog->text);
@@ -140,6 +178,9 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
*buf,
 }
 }
 
+if (dialog->style)
+av_bprintf(>buffer, "");
+
 ff_ass_free_dialog();
 }
 #if FF_API_ASS_TIMING
@@ -173,17 +214,205 @@ static av_cold int ttml_encode_close(AVCodecContext 
*avctx)
 return 0;
 }
 
+static const char *ttml_get_display_alignment(int alignment)
+{
+switch (alignment) {
+case 1:
+case 2:
+case 3:
+return "after";
+case 4:
+case 5:
+case 6:
+return "center";
+case 7:
+case 8:
+case 9:
+return "before";
+default:
+return NULL;
+}
+}
+
+static const char *tt

[FFmpeg-devel] [PATCH 1/4] avcodec/ttmlenc: split header writing into its own function

2021-03-30 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index 3972b4368c..e3c155fdd1 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -173,16 +173,8 @@ static av_cold int ttml_encode_close(AVCodecContext *avctx)
 return 0;
 }
 
-static av_cold int ttml_encode_init(AVCodecContext *avctx)
+static int ttml_write_header_content(AVCodecContext *avctx)
 {
-TTMLContext *s = avctx->priv_data;
-
-s->avctx   = avctx;
-
-if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
-return AVERROR_INVALIDDATA;
-}
-
 if (!(avctx->extradata = av_mallocz(TTMLENC_EXTRADATA_SIGNATURE_SIZE +
 1 + AV_INPUT_BUFFER_PADDING_SIZE))) {
 return AVERROR(ENOMEM);
@@ -192,8 +184,25 @@ static av_cold int ttml_encode_init(AVCodecContext *avctx)
 memcpy(avctx->extradata, TTMLENC_EXTRADATA_SIGNATURE,
TTMLENC_EXTRADATA_SIGNATURE_SIZE);
 
+return 0;
+}
+
+static av_cold int ttml_encode_init(AVCodecContext *avctx)
+{
+TTMLContext *s = avctx->priv_data;
+int ret = AVERROR_BUG;
+s->avctx   = avctx;
+
 av_bprint_init(>buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
 
+if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
+return AVERROR_INVALIDDATA;
+}
+
+if ((ret = ttml_write_header_content(avctx)) < 0) {
+return ret;
+}
+
 return 0;
 }
 
-- 
2.30.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 0/4] Initial region (styling) support for TTML

2021-03-30 Thread Jan Ekström
Now sets alignment, font size, font family and the region's position
and size according to the ASS styles passed to the encoder. Regions are
relatively important in TTML, since the spec-defined default region is in
raster location (similar to the default with HTML) - it starts from the
top left corner and covers the whole screen.

Mapping of the ASS script resolution to the cell resolution and using cells as
sizing metric is not perfect, but while TTML does have a pixel based reference
sizing by means of setting an extent to the root tt element, it is specifically
disallowed in the EBU-TT profile, as well as apparently generally frowned upon
as opposed to defining the cell resolution. In general, mapping to cell 
resolution
seems to give "close enough" results, though.

FATE test output still passes https://github.com/skynav/ttt/ validation,
and visually the result can be verified against such renderers as
http://sandflow.com/imsc1_1/index.html .

Jan

Jan Ekström (4):
  avcodec/ttmlenc: split header writing into its own function
  avformat/ttmlenc: enable writing out additional header values
  avcodec/ttmlenc: add initial support for regions and styles
  avcodec/ttmlenc: add support for region positioning and sizing

 libavcodec/ttmlenc.c   | 311 ++---
 libavcodec/ttmlenc.h   |   6 +
 libavformat/ttmlenc.c  |  78 +-
 tests/ref/fate/sub-ttmlenc |  88 ++-
 4 files changed, 423 insertions(+), 60 deletions(-)

-- 
2.30.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 2/4] avformat/ttmlenc: enable writing out additional header values

2021-03-31 Thread Jan Ekström
On Tue, Mar 30, 2021 at 12:19 PM Andreas Rheinhardt
 wrote:
>
> Jan Ekström:
> > From: Jan Ekström 
> >
> > This way the encoder may pass on the following values to the muxer:
> > 1) Additional root "tt" element attributes, such as the subtitle
> >canvas reference size.
> > 2) Anything before the body element of the document, such as regions
> >in the head element, which can configure styles.
> >
> > Signed-off-by: Jan Ekström 
> > ---
> >  libavcodec/ttmlenc.h  |  5 +++
> >  libavformat/ttmlenc.c | 78 ---
> >  2 files changed, 78 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavcodec/ttmlenc.h b/libavcodec/ttmlenc.h
> > index c1dd5ec990..c3bb11478d 100644
> > --- a/libavcodec/ttmlenc.h
> > +++ b/libavcodec/ttmlenc.h
> > @@ -25,4 +25,9 @@
> >  #define TTMLENC_EXTRADATA_SIGNATURE "lavc-ttmlenc"
> >  #define TTMLENC_EXTRADATA_SIGNATURE_SIZE 
> > (sizeof(TTMLENC_EXTRADATA_SIGNATURE) - 1)
> >
> > +static const char ttml_default_namespacing[] =
> > +"  xmlns=\"http://www.w3.org/ns/ttml\"\n;
> > +"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
> > +"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;;
> > +
> >  #endif /* AVCODEC_TTMLENC_H */
> > diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
> > index 940f8bbd4e..5d9ad6b756 100644
> > --- a/libavformat/ttmlenc.c
> > +++ b/libavformat/ttmlenc.c
> > @@ -37,18 +37,23 @@ enum TTMLPacketType {
> >  PACKET_TYPE_DOCUMENT,
> >  };
> >
> > +struct TTMLHeaderParameters {
> > +char *tt_element_params;
> > +char *pre_body_elements;
> > +};
> > +
> >  typedef struct TTMLMuxContext {
> >  enum TTMLPacketType input_type;
> >  unsigned int document_written;
> > +struct TTMLHeaderParameters header_params;
> >  } TTMLMuxContext;
> >
> >  static const char ttml_header_text[] =
> >  "\n"
> >  " > -"  xmlns=\"http://www.w3.org/ns/ttml\"\n;
> > -"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
> > -"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;
> > +"%s"
> >  "  xml:lang=\"%s\">\n"
> > +"%s"
> >  "  \n"
> >  "\n";
> >
> > @@ -72,6 +77,47 @@ static void ttml_write_time(AVIOContext *pb, const char 
> > tag[],
> >  tag, hour, min, sec, millisec);
> >  }
> >
> > +static int ttml_set_header_values_from_extradata(
> > +AVCodecParameters *par, struct TTMLHeaderParameters *header_params)
> > +{
> > +size_t additional_data_size =
> > +par->extradata_size - TTMLENC_EXTRADATA_SIGNATURE_SIZE;
> > +
>
> Missing check that extradata_size is >= TTMLENC_EXTRADATA_SIGNATURE_SIZE.

This function is only called if `ttml_ctx->input_type ==
PACKET_TYPE_PARAGRAPH`, which is only set if `extradata_size >=
TTMLENC_EXTRADATA_SIGNATURE_SIZE` (and if the , thus I thought that
checking it again would be unnecessary. Of course, if you think a
check is still needed, the following `!additional_data_size` check
`additional_data_size <= 0`.

>
> > +if (!additional_data_size) {
> > +header_params->tt_element_params =
> > +av_strndup(ttml_default_namespacing,
> > +   sizeof(ttml_default_namespacing) - 1);
> > +header_params->pre_body_elements = av_strndup("", 1);
>
> Why are you using av_strndup and not the ordinary av_strdup here?

True, just got used to using the function with the max size defined.

> Anyway, these allocations and the ones below are unnecessary as you only
> need all of this when writing the header.

Yes, I could either utilize a struct, or pass a pointer to
values/struct. Just tried to be careful and not to re-utilize buffers
too easily from the extradata as-is.

>
> > +
> > +if (!header_params->tt_element_params ||
> > +!header_params->pre_body_elements)
> > +return AVERROR(ENOMEM);
> > +
> > +return 0;
> > +}
> > +
> > +{
> > +char *value =
> > +(char *)par->extradata + TTMLENC_EXTRADATA_SIGNATURE_SIZE;
> > +size_t value_size = av_strnlen(value, additional_data_size);
> > +
> > +if (!(header_params->tt_element_params = av_strndup(value, 
> > value_size)))
> > +return AVERROR(ENOMEM);
> > +
> 

Re: [FFmpeg-devel] 4.4 Release Name

2021-04-03 Thread Jan Ekström
On Fri, Apr 2, 2021 at 12:59 PM Michael Niedermayer
 wrote:
>
> Hi all
>
> We still need to choose the name for 4.4
> previous unused suggestions where:
> Von Neumann, Lorentz, Poincaré, Desitter, De Broglie, Gauss, Galois, Viterbi, 
> Darwin
>
> Feel free to reply with name suggestions
> If theres a tie then i will randomly pick amongth the tied, i assume all 
> previous
> suggestions where suggested exactly once already.
>
> I plan to make the release today or tomorrow unless major bugfixes are
> still pending. I probably wont have time sunday / monday for making the
> release
>
> Thanks
>

K. R. Rao +1

I would refrain from direct references to the recent (and in some
places still ongoing) pandemic.

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".

Re: [FFmpeg-devel] [PATCH v2] libsvtav1: Add logical_processors option

2021-03-30 Thread Jan Ekström
On Sat, Feb 20, 2021 at 3:20 AM Christopher Degawa  wrote:
>
> From: Christopher Degawa 
>
> Used for limiting the size of memory buffers and threads for a target
> logical processor count, but does not set thread affinity or limit the
> amount of threads used, although thread affinities can be controlled
> with an additional parameters, it is prefered to add them until
> a svtav1-params option or similar is added
>
> Signed-off-by: Christopher Degawa 
> ---
>  doc/encoders.texi  | 5 +
>  libavcodec/libsvtav1.c | 7 +++
>  2 files changed, 12 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 8fb573c416..28c1a11a6c 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1757,6 +1757,11 @@ Set log2 of the number of rows of tiles to use (0-6).
>  @item tile_columns
>  Set log2 of the number of columns of tiles to use (0-4).
>
> +@item logical_processors
> +Number of logical processors to run the encoder on, threads are managed by 
> the OS scheduler.
> +Used for limiting the size of memory buffers and threads for a target 
> logical processor count.
> +Does not set thread affinity or limit threads.
> +

Hi, and sorry for getting to this patch so slowly. Thank you for your
discussion on IRC, I think that cleared up what this option does a
bit.

I think it might be more clear to call this just a "thread count
multiplier override to limit the amount of threads utilized" in the
docs and the help string, since that's what it essentially seems to
boil to. According to what I grasped from your explanation, the
encoder spawns XYZ threads per logical processor (core) by default,
and this is a way to limit that calculation to a specific number. As
SVT-AV1 does not have a separate switch to just plain set the amount
of threads in general, it is also the only way right now to limit the
thread count at the moment.

ref:
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/05ed7cb78620c2ebbc948b20f26dd9a9c1756fa5/Source/Lib/Encoder/Globals/EbEncHandle.c#L254-257

>  @end table
>
>  @section libkvazaar
> diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
> index eb6043bcac..2296735f25 100644
> --- a/libavcodec/libsvtav1.c
> +++ b/libavcodec/libsvtav1.c
> @@ -71,6 +71,8 @@ typedef struct SvtContext {
>
>  int tile_columns;
>  int tile_rows;
> +
> +unsigned logical_processors;
>  } SvtContext;
>
>  static const struct {
> @@ -218,6 +220,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
> *param,
>  param->tile_columns = svt_enc->tile_columns;
>  param->tile_rows= svt_enc->tile_rows;
>
> +param->logical_processors = svt_enc->logical_processors;
> +

Do we already require a new enough SVT-AV1 to always have this option?
If yes, great. If not, it might be OK to just bump the requirement
then (to keep unnecessary ifdefs at bay for a relatively new and
actively developed library)?

>  return 0;
>  }
>
> @@ -533,6 +537,9 @@ static const AVOption options[] = {
>  { "tile_columns", "Log2 of number of tile columns to use", 
> OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
>  { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), 
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},
>
> +{ "logical_processors", "Number of logical processors to run the encoder 
> on, threads are managed by the OS scheduler", OFFSET(logical_processors),
> +  AV_OPT_TYPE_INT, { .i64 = 0 }, 0,  INT_MAX, VE },
> +

I think this could just be made to mention that it's a thread count
multiplier override to limit the amount of threads utilized.

There is an int/unsigned mismatch, but I think that should be OK since
you limit the value to 0-INT_MAX in the AVOption itself?

Otherwise LGTM, and once again sorry for taking the time to get to this.

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".

Re: [FFmpeg-devel] Hardware purchase request

2021-03-29 Thread Jan Ekström
On Tue, Mar 23, 2021 at 12:47 AM Lynne  wrote:
>
> As discussed during the last developer meeting, I am in need of new hardware 
> to
> work on Vulkan filtering, hwcontext, AV1 VAAPI decoding, new assembly and
> general development on FFmpeg and projects involving the FFmpeg libraries.
>
> I was requested to post what I'd like on the mailing list for discussion, as 
> well
> as to talk about their purchase, since I currently lack the spare funds to buy
> everything and then be refunded, which is the standard way we have handled
> hardware and expenses in the past.
>

Hi, and first of all - thank you for posting this.

Just to start with my position:
1. I have no control over whether someone receives money or not, I am
just part of the community.
2. IMHO we should be utilizing the money for things we find useful for
the project, the most recent of which were the two M1 Mac Minis.
Hardware required for development clearly fits that bill. So as such I
am not opposed to

> As we have literally hundreds of thousands of dollars in our SPI fund
> (121 716.03 USD as of the end of 2019), I have spared no expense in
> my selection.

Personally, while I know that thinking about the big picture in money
is not our hobby nor a thing that we like to keep in our minds, but I
think we should not make such statements unless one has an
understanding of the growth rate of that fund. I do not have such
understanding, and I would not like to start making the calculations
in my head to get an understanding of the yearly fluctuations of the
fund, and thus I would not have utilized such wording.

Depending on such knowledge, it could be seen whether utilizing
roughly 1:20 of that amount on a single entry can be seen as either
something that can be handled within the yearly growth, or not. And if
not, whether we have a reason to be OK with it (the single entry being
of such importance that it cannot be ignored, other sources of income
for the project, etc)

Let's just say that I'm happy to not be an accountant for anyone else
than myself, having to look at whether something is sustainable or
not.

> The price listed on each component is the lowest I could
> find from all the stores I searched.
>
> PCPartPicker Part List: https://pcpartpicker.com/list/HJwhLP 
> 
>
> CPU: AMD Ryzen 9 5950X 3.4 GHz 16-Core Processor  (€949.00 @ Topchat.com)
> CPU Cooler: Fractal Design Celsius+ S36 Dynamic X2 PWM 87.6 CFM Liquid CPU 
> Cooler  (€145.66 @ Amazon)
> Motherboard: Asus ROG Crosshair VIII Dark Hero ATX AM4 Motherboard  (€574.98 
> @ Amazon)
> Memory: 2x G.Skill Trident Z RGB 32 GB (2 x 16 GB) F4-4000C16D-32GTZR 
> DDR4-4000 CL16 Memory  (€470.95 @ Amazon)
> Storage: 2x Samsung 980 Pro 1 TB M.2-2280 NVME Solid State Drive  (€216.38 @ 
> Amazon)
> Video Card: XFX Radeon RX 6900 XT 16 GB Speedster MERC 319 Ultra Video Card 
> (€1925.89 @ Amazon)
> Case: Fractal Design Define 7 Compact ATX Mid Tower Case  (€132.78 @ Amazon)
> Power Supply: Fractal Design Ion+ 860 W 80+ Platinum Certified Fully Modular 
> ATX Power Supply  (€185.50 @ Amazon)
> Case Fan: 3x Noctua A14 PWM 82.5 CFM 140 mm Fan  (€21.90 @ Amazon)
> Monitor: LG 27GN950-B 27.0" 3840x2160 144 Hz Monitor  (€742.49 @ Amazon)
>
> Total: €6096.66

A lot of these components sound quite alright, and reasonable for a
development workstation. Then there are various things which
unfortunately make it hit my uncomfortability level, mostly due to not
knowing how the context of the fund.

The most recent purchase I recall was for two pieces of shared
hardware going for about 1500eur (1,299 gbp) which together would be
around 3000eur. Personally, without knowing the state or growth rate
of the fund I would be much more comfortable with something along
those lines.

Best regards,
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".

Re: [FFmpeg-devel] [PATCH] added parameter to dash encoder for start available time

2021-03-18 Thread Jan Ekström
On Thu, Mar 18, 2021, 17:01 Gyan Doshi  wrote:

>
>
> On 2021-03-18 20:12, Jan Ekström wrote:
> > So right now we do have an option in ffmpeg.c called itsoffset. It
> > lets you configure the input offset in time (seconds - such as
> > "1337.123" or time format - such as "00:00:01.123"). The only problem
> > with it right now is that unless you set -copyts it will not get
> > applied for anything else than subtitles, as the offset gets applied
> > before and is not taken into account in the "start from PTS 0"
> > calculation for video/audio streams.
>
> Not the case.
>
>  ffmpeg -f lavfi -itsoffset 3 -i nullsrc=r=1:d=3 -vf showinfo -f null -
>
> gives
>
> [Parsed_showinfo_0 @ 019cc1b88540] n:   0 pts:  3 pts_time:3   ...
> [Parsed_showinfo_0 @ 019cc1b88540] n:   1 pts:  4 pts_time:4   ...
> [Parsed_showinfo_0 @ 019cc1b88540] n:   2 pts:  5 pts_time:5   ...
>
> I've used it many times to adjust sync among streams.
>
> Regards,
> Gyan
>

Very interesting!

I will have to retest, I just recall that the last time I tried it got
applied when there were multiple streams in an input when the start_time
based adjustment was done.

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".

Re: [FFmpeg-devel] [PATCH] added parameter to dash encoder for start available time

2021-03-18 Thread Jan Ekström
On Thu, Mar 18, 2021 at 3:49 AM Jerome Berclaz  wrote:
>
> ---
>  libavformat/dashenc.c | 28 
>  1 file changed, 20 insertions(+), 8 deletions(-)

So right now we do have an option in ffmpeg.c called itsoffset. It
lets you configure the input offset in time (seconds - such as
"1337.123" or time format - such as "00:00:01.123"). The only problem
with it right now is that unless you set -copyts it will not get
applied for anything else than subtitles, as the offset gets applied
before and is not taken into account in the "start from PTS 0"
calculation for video/audio streams. I have been meaning to do some
git blaming and asking the people still around who added that logic,
if that was really meant - since as far as I can tell even people such
as Martin actually recommended me this option - probably expecting for
it to work.

If we just make itsoffset usable without copyts (just take it into
mention in the zero'ification process), I think all these options in
the output modules would effectively become unnecessary, since your
DTS/PTS will start from nonzero positive value depending on the
itsoffset.

Best regards,
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".

Re: [FFmpeg-devel] [PATCH] added parameter to dash encoder for start available time

2021-03-18 Thread Jan Ekström
On Thu, Mar 18, 2021 at 5:07 PM Jan Ekström  wrote:
>
> On Thu, Mar 18, 2021, 17:01 Gyan Doshi  wrote:
>>
>>
>>
>> On 2021-03-18 20:12, Jan Ekström wrote:
>> > So right now we do have an option in ffmpeg.c called itsoffset. It
>> > lets you configure the input offset in time (seconds - such as
>> > "1337.123" or time format - such as "00:00:01.123"). The only problem
>> > with it right now is that unless you set -copyts it will not get
>> > applied for anything else than subtitles, as the offset gets applied
>> > before and is not taken into account in the "start from PTS 0"
>> > calculation for video/audio streams.
>>
>> Not the case.
>>
>>  ffmpeg -f lavfi -itsoffset 3 -i nullsrc=r=1:d=3 -vf showinfo -f null -
>>
>> gives
>>
>> [Parsed_showinfo_0 @ 019cc1b88540] n:   0 pts:  3 pts_time:3   ...
>> [Parsed_showinfo_0 @ 019cc1b88540] n:   1 pts:  4 pts_time:4   ...
>> [Parsed_showinfo_0 @ 019cc1b88540] n:   2 pts:  5 pts_time:5   ...
>>
>> I've used it many times to adjust sync among streams.
>>
>> Regards,
>> Gyan
>
>
> Very interesting!
>
> I will have to retest, I just recall that the last time I tried it got 
> applied when there were multiple streams in an input when the start_time 
> based adjustment was done.

Right, so taking in a Matroska file it works fine, but when taking in
an MPEG-TS file with a start_time it not only transforms (start_time +
input_ts_offset) to (input_ts_offset), but just to 0 :) .

Example:
ffmpeg -v verbose -debug_ts -itsoffset "1616090389" -i
'https://megumin.fushizen.eu/samples/switchingaudio.ts' -c copy -bsf:a
aac_adtstoasc -movflags dash+frag_discont+delay_moov -vframes 5 -f mp4
- > test.mp4

Probed start_time:
  Duration: 00:00:15.25, start: 19516.478644, bitrate: 23823 kb/s

And how ffmpeg.c then adjusted it:
demuxer -> ist_index:2 type:audio next_dts:NOPTS next_dts_time:NOPTS
next_pts:NOPTS next_pts_time:NOPTS pkt_pts:1756483078
pkt_pts_time:19516.5 pkt_dts:1756483078 pkt_dts_time:19516.5
off:1616070872521356 off_time:1.61607e+09
demuxer+ffmpeg -> ist_index:2 type:audio pkt_pts:0 pkt_pts_time:0
pkt_dts:0 pkt_dts_time:0 off:-19516478644 off_time:-19516.5

Thus, ffmpeg.c is not only adjusting the timestamp to start at zero
with the start_time, but also takes the itsoffset off as well.

Best regards,
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".

Re: [FFmpeg-devel] [PATCH v6 0/4] Initial implementation of TTML encoding/muxing

2021-03-03 Thread Jan Ekström
On Tue, Mar 2, 2021 at 11:00 AM Jan Ekström  wrote:
>
> I've intentionally kept this initial version simple (no styling etc) to focus
> on the basics. As this goes through review, additional features can be added
> (I had initial PoC for styling implemented some time around previous VDD), and
> there is another patch set in my queue which would then add support for muxing
> TTML into MP4.
>
> Changes from the fifth version:
>   - Fixed a stupid mistake in tools/ffescape.
>   - Reworked the err_recognition commit based on comments from James and 
> Anton.
>
> Jan
>
> Jan Ekström (3):
>   ffprobe: switch to av_bprint_escape for XML escaping
>   avcodec: enable usage of err_recognition for encoders
>   {avcodec,avformat}: add TTML encoder and muxer
>
> Stefano Sabatini (1):
>   avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil
>

So:

1. the XML escaping stuff has been OK'd. (Nicolas, Anton)
2. The err_recognition change has been OK'd (Anton, James on IRC)
3. Multiple nice review passes have been had with the actual encoder
and muxer, and the requests have been applied.
4. The document generated in the FATE test actually passes validation
in https://github.com/skynav/ttt .

Thus, I will be pulling this set in Soon (probably tomorrow). Thus if
anyone still wishes to have a say, I recommend doing it earlier than
later. Then I will be moving onto the TTML-in-MP4 work, which I have
been able to refactor onto relatively working state earlier this week
:) .

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".

Re: [FFmpeg-devel] [PATCH v5 3/4] avcodec: enable usage of AV_EF_EXPLODE for subtitle encoders

2021-02-28 Thread Jan Ekström
On Mon, Feb 22, 2021 at 3:19 PM Jan Ekström  wrote:
>
> From: Jan Ekström 
>
> As currently it is the responsibility of the following subtitle
> encoder to validate the correctness of the incoming ASS dialog line.
>
> Signed-off-by: Jan Ekström 

Requesting comments on this bit of the change set, since apparently
the actual implementation bits have been reviewed.

This way of doing it was recommended by Anton, and as noted in the
opening mail for the patch set I am open to just an AVOption if
someone feels like this is a bad idea.

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] [PATCH v6 1/4] avutil/{avstring, bprint}: add XML escaping from ffprobe to avutil

2021-03-02 Thread Jan Ekström
From: Stefano Sabatini 

Base escaping only escapes values required for base character data
according to part 2.4 of XML, and if additional flags are added
single and double quotes can additionally be escaped in order
to handle single and double quoted attributes.

Co-Authored-By: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavutil/avstring.h | 14 ++
 libavutil/bprint.c   | 29 +
 libavutil/version.h  |  2 +-
 tools/ffescape.c |  7 +--
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index ee225585b3..fae446c302 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -324,6 +324,7 @@ enum AVEscapeMode {
 AV_ESCAPE_MODE_AUTO,  ///< Use auto-selected escaping mode.
 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
+AV_ESCAPE_MODE_XML,   ///< Use XML non-markup character data escaping.
 };
 
 /**
@@ -343,6 +344,19 @@ enum AVEscapeMode {
  */
 #define AV_ESCAPE_FLAG_STRICT (1 << 1)
 
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES (1 << 2)
+
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES (1 << 3)
+
+
 /**
  * Escape string in src, and put the escaped string in an allocated
  * string in *dst, which must be freed with av_free().
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 2f059c5ba6..e12fb263fe 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -283,6 +283,35 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 av_bprint_chars(dstbuf, '\'', 1);
 break;
 
+case AV_ESCAPE_MODE_XML:
+/* escape XML non-markup character data as per 2.4 by default: */
+/*  [^<&]* - ([^<&]* ']]>' [^<&]*) */
+
+/* additionally, given one of the AV_ESCAPE_FLAG_XML_* flags, */
+/* escape those specific characters as required. */
+for (; *src; src++) {
+switch (*src) {
+case '&' : av_bprintf(dstbuf, "%s", "");  break;
+case '<' : av_bprintf(dstbuf, "%s", "");   break;
+case '>' : av_bprintf(dstbuf, "%s", "");   break;
+case '\'':
+if (!(flags & AV_ESCAPE_FLAG_XML_SINGLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+case '"' :
+if (!(flags & AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+XML_DEFAULT_HANDLING:
+default: av_bprint_chars(dstbuf, *src, 1);
+}
+}
+break;
+
 /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
 default:
 /* \-escape characters */
diff --git a/libavutil/version.h b/libavutil/version.h
index b7c5892a37..356c54d633 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  66
+#define LIBAVUTIL_VERSION_MINOR  67
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tools/ffescape.c b/tools/ffescape.c
index 0530d28c6d..1ed8daa801 100644
--- a/tools/ffescape.c
+++ b/tools/ffescape.c
@@ -78,8 +78,10 @@ int main(int argc, char **argv)
 infilename = optarg;
 break;
 case 'f':
-if  (!strcmp(optarg, "whitespace")) escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
-else if (!strcmp(optarg, "strict")) escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+if  (!strcmp(optarg, "whitespace"))escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
+else if (!strcmp(optarg, "strict"))escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+else if (!strcmp(optarg, "xml_single_quotes")) escape_flags |= 
AV_ESCAPE_FLAG_XML_SINGLE_QUOTES;
+else if (!strcmp(optarg, "xml_double_quotes")) escape_flags |= 
AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES;
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -f, "
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
 if  (!strcmp(optarg, "auto"))  escape_mode = 
AV_ESCAPE_MODE_AUTO;
 else if (!strcmp(optarg, "backslash")) escape_mode = 
AV_ESCAPE_MODE_BACKSLASH;
 else if (!strcmp(optarg, "

[FFmpeg-devel] [PATCH v6 4/4] {avcodec, avformat}: add TTML encoder and muxer

2021-03-02 Thread Jan Ekström
From: Jan Ekström 

Enables encoding of other subtitle formats into TTML and writing
them out as such documents.

Signed-off-by: Jan Ekström 
---
 Changelog  |   1 +
 doc/general_contents.texi  |   1 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/ttmlenc.c   | 210 +
 libavcodec/ttmlenc.h   |  28 +
 libavcodec/version.h   |   4 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 ++
 libavformat/version.h  |   2 +-
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/sub-ttmlenc | 122 +
 13 files changed, 546 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

diff --git a/Changelog b/Changelog
index 9e7f67cc19..f0b2995444 100644
--- a/Changelog
+++ b/Changelog
@@ -78,6 +78,7 @@ version :
 - Simbiosis IMX decoder
 - Simbiosis IMX demuxer
 - Digital Pictures SGA demuxer and decoders
+- TTML subtitle encoder and muxer
 
 
 version 4.3:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 6acdf441d6..58c9bcf747 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1352,6 +1352,7 @@ performance on systems without hardware floating point 
support).
 @item SubViewer v1 @tab   @tab X @tab   @tab X
 @item SubViewer@tab   @tab X @tab   @tab X
 @item TED Talks captions @tab @tab X @tab   @tab X
+@item TTML @tab X @tab   @tab X @tab
 @item VobSub (IDX+SUB) @tab   @tab X @tab   @tab X
 @item VPlayer  @tab   @tab X @tab   @tab X
 @item WebVTT   @tab X @tab X @tab X @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b7e456b59f..d1b1125a30 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -672,6 +672,7 @@ OBJS-$(CONFIG_TSCC_DECODER)+= tscc.o msrledec.o
 OBJS-$(CONFIG_TSCC2_DECODER)   += tscc2.o
 OBJS-$(CONFIG_TTA_DECODER) += tta.o ttadata.o ttadsp.o
 OBJS-$(CONFIG_TTA_ENCODER) += ttaenc.o ttaencdsp.o ttadata.o
+OBJS-$(CONFIG_TTML_ENCODER)+= ttmlenc.o ass_split.o
 OBJS-$(CONFIG_TWINVQ_DECODER)  += twinvqdec.o twinvq.o metasound_data.o
 OBJS-$(CONFIG_TXD_DECODER) += txd.o
 OBJS-$(CONFIG_ULTI_DECODER)+= ulti.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a04faead16..2e9a3581de 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -691,6 +691,7 @@ extern AVCodec ff_subviewer_decoder;
 extern AVCodec ff_subviewer1_decoder;
 extern AVCodec ff_text_encoder;
 extern AVCodec ff_text_decoder;
+extern AVCodec ff_ttml_encoder;
 extern AVCodec ff_vplayer_decoder;
 extern AVCodec ff_webvtt_encoder;
 extern AVCodec ff_webvtt_decoder;
diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
new file mode 100644
index 00..3972b4368c
--- /dev/null
+++ b/libavcodec/ttmlenc.c
@@ -0,0 +1,210 @@
+/*
+ * TTML subtitle encoder
+ * Copyright (c) 2020 24i
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * TTML subtitle encoder
+ * @see https://www.w3.org/TR/ttml1/
+ * @see https://www.w3.org/TR/ttml2/
+ * @see https://www.w3.org/TR/ttml-imsc/rec
+ */
+
+#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/internal.h"
+#include "ass_split.h"
+#include "ass.h"
+#include "ttmlenc.h"
+
+typedef struct {
+AVCodecContext *avctx;
+ASSSplitContext *ass_ctx;
+AVBPrint buffer;
+} TTMLContext;
+
+static void ttml_text_cb(void *priv, const char *text, int len)
+{
+TTMLContext *s = priv;
+AVBPrint cur_line = { 0 };
+AVBPrint *buffer = >buffer;
+
+av_bprint_init(_line, len, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_append_data(_line, text, len);
+if (!av_bprint_is_complete(_line)) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Failed to move the current subtitle dialog to AVBPrint!\n");
+av_bprint_fin

[FFmpeg-devel] [PATCH v6 2/4] ffprobe: switch to av_bprint_escape for XML escaping

2021-03-02 Thread Jan Ekström
From: Jan Ekström 

Additionally update the result of the ffprobe XML writing test.

Signed-off-by: Jan Ekström 
---
 fftools/ffprobe.c  | 32 +++-
 tests/ref/fate/ffprobe_xml |  2 +-
 2 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 740e759958..1eb9d88b5e 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -1672,24 +1672,6 @@ static av_cold int xml_init(WriterContext *wctx)
 return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void 
*log_ctx)
-{
-const char *p;
-
-for (p = src; *p; p++) {
-switch (*p) {
-case '&' : av_bprintf(dst, "%s", "");  break;
-case '<' : av_bprintf(dst, "%s", "");   break;
-case '>' : av_bprintf(dst, "%s", "");   break;
-case '"' : av_bprintf(dst, "%s", ""); break;
-case '\'': av_bprintf(dst, "%s", ""); break;
-default: av_bprint_chars(dst, *p, 1);
-}
-}
-
-return dst->str;
-}
-
 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
 
 static void xml_print_section_header(WriterContext *wctx)
@@ -1761,14 +1743,22 @@ static void xml_print_str(WriterContext *wctx, const 
char *key, const char *valu
 
 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
 XML_INDENT();
+av_bprint_escape(, key, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
 printf("<%s key=\"%s\"",
-   section->element_name, xml_escape_str(, key, wctx));
+   section->element_name, buf.str);
 av_bprint_clear();
-printf(" value=\"%s\"/>\n", xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf(" value=\"%s\"/>\n", buf.str);
 } else {
 if (wctx->nb_item[wctx->level])
 printf(" ");
-printf("%s=\"%s\"", key, xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf("%s=\"%s\"", key, buf.str);
 }
 
 av_bprint_finalize(, NULL);
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index 1e99158021..04261ed693 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -51,7 +51,7 @@
 
 
 
-
+
 
 
 
-- 
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 v6 3/4] avcodec: enable usage of err_recognition for encoders

2021-03-02 Thread Jan Ekström
From: Jan Ekström 

Enables the usage of such values as AV_EF_EXPLODE in encoders, which
can be useful in cases such as subtitle encoders where they have the
responsibility to validate the correctness of an incoming ASS dialog line.

Signed-off-by: Jan Ekström 
---
 doc/APIchanges |  3 +++
 libavcodec/avcodec.h   |  2 +-
 libavcodec/options_table.h | 18 +-
 libavcodec/version.h   |  2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a49e181c13..a4cb3a5d63 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2021-03-02 - xx - lavc 58.128.101 - avcodec.h
+  Enable err_recognition to be set for encoders.
+
 2021-02-27 - xx - lavc 58.126.100 - avcodec.h
   Deprecated avcodec_get_frame_class().
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index cd6e6d19bc..ecc665677a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1634,7 +1634,7 @@ typedef struct AVCodecContext {
 
 /**
  * Error recognition; may misdetect some more or less valid parts as 
errors.
- * - encoding: unused
+ * - encoding: Set by user.
  * - decoding: Set by user.
  */
 int err_recognition;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index ded9de4d67..e12159f734 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -140,15 +140,15 @@ static const AVOption avcodec_options[] = {
 {"unofficial", "allow unofficial extensions", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
 {"experimental", "allow non-standardized experimental things", 0, 
AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, 
A|V|D|E, "strict"},
 {"b_qoffset", "QP offset between P- and B-frames", OFFSET(b_quant_offset), 
AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
-{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"bitstream", "detect bitstream specification deviations", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|D, 
"err_detect"},
-{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"ignore_err", "ignore errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_IGNORE_ERR 
}, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"careful","consider things that violate the spec, are fast to check and 
have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"compliant",  "consider all spec non compliancies as errors", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_COMPLIANT | AV_EF_CAREFUL }, INT_MIN, INT_MAX, 
A|V|D, "err_detect"},
-{"aggressive", "consider things that a sane encoder should not do as an 
error", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_AGGRESSIVE | AV_EF_COMPLIANT | 
AV_EF_CAREFUL}, INT_MIN, INT_MAX, A|V|D, "err_detect"},
+{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"bitstream", "detect bitstream specification deviations", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|S|D|E, 
"err_detect"},
+{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"ignore_err", "ignore errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_IGNORE_ERR 
}, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"careful","consider things that violate the spec, are fast to check and 
have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CAREFUL }, INT_MIN, INT_MAX

[FFmpeg-devel] [PATCH v6 0/4] Initial implementation of TTML encoding/muxing

2021-03-02 Thread Jan Ekström
I've intentionally kept this initial version simple (no styling etc) to focus
on the basics. As this goes through review, additional features can be added
(I had initial PoC for styling implemented some time around previous VDD), and
there is another patch set in my queue which would then add support for muxing
TTML into MP4.

Changes from the fifth version:
  - Fixed a stupid mistake in tools/ffescape.
  - Reworked the err_recognition commit based on comments from James and Anton.

Jan

Jan Ekström (3):
  ffprobe: switch to av_bprint_escape for XML escaping
  avcodec: enable usage of err_recognition for encoders
  {avcodec,avformat}: add TTML encoder and muxer

Stefano Sabatini (1):
  avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil

 Changelog  |   1 +
 doc/APIchanges |   3 +
 doc/general_contents.texi  |   1 +
 fftools/ffprobe.c  |  32 ++
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/avcodec.h   |   2 +-
 libavcodec/options_table.h |  18 ++--
 libavcodec/ttmlenc.c   | 210 +
 libavcodec/ttmlenc.h   |  28 +
 libavcodec/version.h   |   2 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 ++
 libavformat/version.h  |   2 +-
 libavutil/avstring.h   |  14 +++
 libavutil/bprint.c |  29 +
 libavutil/version.h|   2 +-
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/ffprobe_xml |   2 +-
 tests/ref/fate/sub-ttmlenc | 122 +
 tools/ffescape.c   |   7 +-
 22 files changed, 619 insertions(+), 37 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

-- 
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 v5 0/4] Initial implementation of TTML encoding/muxing

2021-02-25 Thread Jan Ekström
On Mon, Feb 22, 2021, 15:32 Jan Ekström  wrote:

> On Mon, Feb 22, 2021 at 3:19 PM Jan Ekström  wrote:
> >
> > I've intentionally kept this initial version simple (no styling etc) to
> focus
> > on the basics. As this goes through review, additional features can be
> added
> > (I had initial PoC for styling implemented some time around previous
> VDD), and
> > there is another patch set in my queue which would then add support for
> muxing
> > TTML into MP4.
> >
> > Changes from the fourth version:
> >   - Switched from separate escaping modes back to a single
> AV_ESCAPE_MODE_XML,
> > with additional flags for single and double quote escaping for
> attributes
> > (Anton noted that the AV_ESCAPE_FLAG_XML prefix makes it all long
> enough,
> > so ATTR was left away from these).
> >   - Added the libavutil minor bump, which was forgotten so far.
> >   - ff_ass_split_override_codes calls are now checked for errors and a
> warning
> > or error is logged depending on whether it was an invalid input
> error,
> > and if AV_EF_EXPLODE was set. In case of invalid input and
> AV_EF_EXPLODE,
> > a malformed ASS dialog will cause the encoder to fail. By default it
> will
> > not, which matches the current behavior of all other subtitle
> encoders,
> > which do not test the return value of ff_ass_split_override_codes at
> all,
> > and thus just skip malformed parts of an ASS dialog.
> >
> > Thank you to Anton for giving the idea of the AV_EF_EXPLODE usage.
> >   - Documented that AV_EF_EXPLODE is now usable for subtitle encoders.
>
> For the record, if this seems unacceptable I can switch it to a
> specifically named AVOption in the subtitle encoder.
>
> Either way is fine by me, the explode flag was just what was noted as
> an alternative first.
>
> Jan
>


Ping for this set.

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".

Re: [FFmpeg-devel] [PATCH] mov.c log qt ref extenal essence metadata

2021-03-06 Thread Jan Ekström
On Sat, Mar 6, 2021 at 10:38 AM emcodem  wrote:
>
> ---
>  libavformat/mov.c | 8 
>  1 file changed, 8 insertions(+)
>
> In quicktime reference files, exposing the parsed info for external essences 
> location can be very handy for users
>

Unfortunately, as per the discussion we had yesterday on #ffmpeg, Data
References are not as simple as mov.c might make it feel like.

So, if we think that a single MOV/MP4 Track is:
1. A set of decode'able packets of a certain media type (as far as I
can tell that has been the limitation, while other things can change
during a Track the media type is one that doesn't).
2. Which is then presented according to a virtual time line (edit
lists, which we will in this case ignore since they get applied on top
of the decoded result on the presentation layer, and data references
are on the packet set level).

Thus if we go through the layers:
1. We have samples (packets in FFmpeg parliance more or less, stsz
defines the sizes of them and so forth).
2. Samples get put into chunks, which are basically tuple of
(sample_description_index, data offset) - see stsc, stco, co64.
3. Sample Description can thought of as a tuple of (AVCodec, the
extradata (if any) required, data reference index), there is a list of
them in the Track's stsd box.
4. Then finally we get to the data reference list in the dref box of the track.

Currently as far as I can tell from reading mov_read_stsd /
ff_mov_read_stsd_entries, it does generate extradata buffer for each
sample description, but effectively only keeps a single data reference
around in the MOVStreamContext, skipping the whole chunk matching etc
part of things :) (if I am reading the code correctly, which I might
not be).

So yea, there's two questions:
1. Should this be exposed?
2. If it should be exposed, how? A set of metadata this should not be,
as this at the very least would end up being a weird set/list of byte
offsets/sizes and references :)

So yea, sorry for things not actually being as simple as they look by
the code in mov.c.

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".

Re: [FFmpeg-devel] [PATCH v6 0/4] Initial implementation of TTML encoding/muxing

2021-03-04 Thread Jan Ekström
On Thu, Mar 4, 2021 at 11:57 AM Moritz Barsnick  wrote:
>
> On Wed, Mar 03, 2021 at 22:09:12 +0200, Jan Ekström wrote:
> > Thus, I will be pulling this set in Soon (probably tomorrow). Thus if
> > anyone still wishes to have a say, I recommend doing it earlier than
> > later.
>
> > + * Copyright (c) 2020 24i
>
> Is 24i a company? Just wondering.
>

Yes. In the case of this patch set this is the case.

> Also, I'm not sure whether it's usually advised to split libavformat
> and libavcodec changes into two separate commits.

Yes, in general if the feature is usable by itself it could be split.
In this case the tests can only be run after both parts are there, and
thus there is only limited usefulness, as currently reading a TTML
document from MXF is supported, and I have not seen such samples out
in the wild.

That said, if we really want to go in pedantic we could split this as follows:

1. Add the muxer, only for the remux use case (from MXF, which we
cannot test since there is no samples).
2. Add the encoder and modify the muxer to be able to handle the
paragraph-based packets.

Alternatively, we can pull in the encoder first, then the muxer. But
the encoder by itself can only be tested through the API or so.

I... just am not so sure in this case splitting the TTML writer and
the TTML encoder from each other makes sense.

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".

Re: [FFmpeg-devel] [PATCH v6 0/4] Initial implementation of TTML encoding/muxing

2021-03-04 Thread Jan Ekström
On Thu, Mar 4, 2021, 16:43 Moritz Barsnick  wrote:

> On Thu, Mar 04, 2021 at 15:52:13 +0200, Jan Ekström wrote:
> > I... just am not so sure in this case splitting the TTML writer and
> > the TTML encoder from each other makes sense.
>
> I agree. In very many cases, muxer and encoder, or demuxer and decoder
> are only useful together.
>
> Yet I have observed that commits to libavformat and libavcodec are
> usually separated. Check the addition of many other such combinations.
> (I think usually the codec comes first, because the muxer/demuxer uses
> the codec definition.
>

Yes, I have looked at things, and I after I go for a walk will specifically
check previous subtitle additions. Meanwhile, please take a look at the
alternatives that I've raised and please tell me of either of those makes
a) sense b) it easier to revert things in case that is wanted.

The codec definition is there already, as demuxing of ttml packets from mxf
was already implemented. That - as I did note in my previous message would
be why if you really wanted the muxer could be brought in first as well.

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".

Re: [FFmpeg-devel] [PATCH v6 0/4] Initial implementation of TTML encoding/muxing

2021-03-04 Thread Jan Ekström
On Thu, Mar 4, 2021 at 4:52 PM Jan Ekström  wrote:
>
> On Thu, Mar 4, 2021, 16:43 Moritz Barsnick  wrote:
>>
>> On Thu, Mar 04, 2021 at 15:52:13 +0200, Jan Ekström wrote:
>> > I... just am not so sure in this case splitting the TTML writer and
>> > the TTML encoder from each other makes sense.
>>
>> I agree. In very many cases, muxer and encoder, or demuxer and decoder
>> are only useful together.
>>
>> Yet I have observed that commits to libavformat and libavcodec are
>> usually separated. Check the addition of many other such combinations.
>> (I think usually the codec comes first, because the muxer/demuxer uses
>> the codec definition.
>
>
> Yes, I have looked at things, and I after I go for a walk will specifically 
> check previous subtitle additions. Meanwhile, please take a look at the 
> alternatives that I've raised and please tell me of either of those makes a) 
> sense b) it easier to revert things in case that is wanted.
>
> The codec definition is there already, as demuxing of ttml packets from mxf 
> was already implemented. That - as I did note in my previous message would be 
> why if you really wanted the muxer could be brought in first as well.

I have asked Anton for an opinion on this because my first reaction
might have been a bit "asdf unclear comments from someone after the
patch set has been in review for months and it's something that's been
part of the patch set from the beginning.", and thus might have
required a bit of re-calibration.

And it was a combo of:

1. ENOCARE (as in, either would be acceptable)
2. If I really wanted an opinion on this, split.

Thus I will split it, encoder first, then muxer. Since the muxer
utilizes a helper from the encoder's header and I'm too lazy at this
point to rewrite things into multiple bits. I do not find it required
in this case, but if it gets things forward...

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] [PATCH v7 4/5] avcodec: add TTML encoder

2021-03-04 Thread Jan Ekström
From: Jan Ekström 

Enables encoding of other subtitle formats into TTML paragraphs.

Signed-off-by: Jan Ekström 
---
 Changelog |   1 +
 doc/general_contents.texi |   1 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/ttmlenc.c  | 210 ++
 libavcodec/ttmlenc.h  |  28 +
 libavcodec/version.h  |   4 +-
 7 files changed, 244 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h

diff --git a/Changelog b/Changelog
index 9e7f67cc19..43b6abb82b 100644
--- a/Changelog
+++ b/Changelog
@@ -78,6 +78,7 @@ version :
 - Simbiosis IMX decoder
 - Simbiosis IMX demuxer
 - Digital Pictures SGA demuxer and decoders
+- TTML subtitle encoder
 
 
 version 4.3:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 6acdf441d6..ac02f33c6f 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1352,6 +1352,7 @@ performance on systems without hardware floating point 
support).
 @item SubViewer v1 @tab   @tab X @tab   @tab X
 @item SubViewer@tab   @tab X @tab   @tab X
 @item TED Talks captions @tab @tab X @tab   @tab X
+@item TTML @tab   @tab   @tab X @tab
 @item VobSub (IDX+SUB) @tab   @tab X @tab   @tab X
 @item VPlayer  @tab   @tab X @tab   @tab X
 @item WebVTT   @tab X @tab X @tab X @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b7e456b59f..d1b1125a30 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -672,6 +672,7 @@ OBJS-$(CONFIG_TSCC_DECODER)+= tscc.o msrledec.o
 OBJS-$(CONFIG_TSCC2_DECODER)   += tscc2.o
 OBJS-$(CONFIG_TTA_DECODER) += tta.o ttadata.o ttadsp.o
 OBJS-$(CONFIG_TTA_ENCODER) += ttaenc.o ttaencdsp.o ttadata.o
+OBJS-$(CONFIG_TTML_ENCODER)+= ttmlenc.o ass_split.o
 OBJS-$(CONFIG_TWINVQ_DECODER)  += twinvqdec.o twinvq.o metasound_data.o
 OBJS-$(CONFIG_TXD_DECODER) += txd.o
 OBJS-$(CONFIG_ULTI_DECODER)+= ulti.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a04faead16..2e9a3581de 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -691,6 +691,7 @@ extern AVCodec ff_subviewer_decoder;
 extern AVCodec ff_subviewer1_decoder;
 extern AVCodec ff_text_encoder;
 extern AVCodec ff_text_decoder;
+extern AVCodec ff_ttml_encoder;
 extern AVCodec ff_vplayer_decoder;
 extern AVCodec ff_webvtt_encoder;
 extern AVCodec ff_webvtt_decoder;
diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
new file mode 100644
index 00..3972b4368c
--- /dev/null
+++ b/libavcodec/ttmlenc.c
@@ -0,0 +1,210 @@
+/*
+ * TTML subtitle encoder
+ * Copyright (c) 2020 24i
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * TTML subtitle encoder
+ * @see https://www.w3.org/TR/ttml1/
+ * @see https://www.w3.org/TR/ttml2/
+ * @see https://www.w3.org/TR/ttml-imsc/rec
+ */
+
+#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/internal.h"
+#include "ass_split.h"
+#include "ass.h"
+#include "ttmlenc.h"
+
+typedef struct {
+AVCodecContext *avctx;
+ASSSplitContext *ass_ctx;
+AVBPrint buffer;
+} TTMLContext;
+
+static void ttml_text_cb(void *priv, const char *text, int len)
+{
+TTMLContext *s = priv;
+AVBPrint cur_line = { 0 };
+AVBPrint *buffer = >buffer;
+
+av_bprint_init(_line, len, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_append_data(_line, text, len);
+if (!av_bprint_is_complete(_line)) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Failed to move the current subtitle dialog to AVBPrint!\n");
+av_bprint_finalize(_line, NULL);
+return;
+}
+
+
+av_bprint_escape(buffer, cur_line.str, NULL, AV_ESCAPE_MODE_XML,
+ 0);
+
+av_bprint_finalize(_line, NULL);
+}
+
+static void ttml_new_line_cb(void *priv, int forced)
+{
+TTMLContext *s = priv;
+
+av_bprintf(>buffer, "");
+}
+
+static const ASSCodesCallbacks ttml_callbacks = {
+.text = ttml_

[FFmpeg-devel] [PATCH v7 3/5] avcodec: enable usage of err_recognition for encoders

2021-03-04 Thread Jan Ekström
From: Jan Ekström 

Enables the usage of such values as AV_EF_EXPLODE in encoders, which
can be useful in cases such as subtitle encoders where they have the
responsibility to validate the correctness of an incoming ASS dialog line.

Signed-off-by: Jan Ekström 
---
 doc/APIchanges |  3 +++
 libavcodec/avcodec.h   |  2 +-
 libavcodec/options_table.h | 18 +-
 libavcodec/version.h   |  2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a003abf7ca..4027d599e7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2021-03-04 - xx - lavc 58.128.101 - avcodec.h
+  Enable err_recognition to be set for encoders.
+
 2021-03-03 - xx - lavf 58.70.100 - avformat.h
   Deprecate AVFMT_FLAG_PRIV_OPT. It will do nothing
   as soon as av_demuxer_open() is removed.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index cd6e6d19bc..ecc665677a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1634,7 +1634,7 @@ typedef struct AVCodecContext {
 
 /**
  * Error recognition; may misdetect some more or less valid parts as 
errors.
- * - encoding: unused
+ * - encoding: Set by user.
  * - decoding: Set by user.
  */
 int err_recognition;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index ded9de4d67..e12159f734 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -140,15 +140,15 @@ static const AVOption avcodec_options[] = {
 {"unofficial", "allow unofficial extensions", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
 {"experimental", "allow non-standardized experimental things", 0, 
AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, 
A|V|D|E, "strict"},
 {"b_qoffset", "QP offset between P- and B-frames", OFFSET(b_quant_offset), 
AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
-{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"bitstream", "detect bitstream specification deviations", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|D, 
"err_detect"},
-{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"ignore_err", "ignore errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_IGNORE_ERR 
}, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"careful","consider things that violate the spec, are fast to check and 
have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"compliant",  "consider all spec non compliancies as errors", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_COMPLIANT | AV_EF_CAREFUL }, INT_MIN, INT_MAX, 
A|V|D, "err_detect"},
-{"aggressive", "consider things that a sane encoder should not do as an 
error", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_AGGRESSIVE | AV_EF_COMPLIANT | 
AV_EF_CAREFUL}, INT_MIN, INT_MAX, A|V|D, "err_detect"},
+{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"bitstream", "detect bitstream specification deviations", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|S|D|E, 
"err_detect"},
+{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"ignore_err", "ignore errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_IGNORE_ERR 
}, INT_MIN, INT_MAX, A|V|S|D|E, "err_detect"},
+{"careful","consider things that violate the spec, are fast to check and 
have not been seen in the wild as errors", 0, AV_OPT_T

[FFmpeg-devel] [PATCH v7 2/5] ffprobe: switch to av_bprint_escape for XML escaping

2021-03-04 Thread Jan Ekström
From: Jan Ekström 

Additionally update the result of the ffprobe XML writing test.

Signed-off-by: Jan Ekström 
---
 fftools/ffprobe.c  | 32 +++-
 tests/ref/fate/ffprobe_xml |  2 +-
 2 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 740e759958..1eb9d88b5e 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -1672,24 +1672,6 @@ static av_cold int xml_init(WriterContext *wctx)
 return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void 
*log_ctx)
-{
-const char *p;
-
-for (p = src; *p; p++) {
-switch (*p) {
-case '&' : av_bprintf(dst, "%s", "");  break;
-case '<' : av_bprintf(dst, "%s", "");   break;
-case '>' : av_bprintf(dst, "%s", "");   break;
-case '"' : av_bprintf(dst, "%s", ""); break;
-case '\'': av_bprintf(dst, "%s", ""); break;
-default: av_bprint_chars(dst, *p, 1);
-}
-}
-
-return dst->str;
-}
-
 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
 
 static void xml_print_section_header(WriterContext *wctx)
@@ -1761,14 +1743,22 @@ static void xml_print_str(WriterContext *wctx, const 
char *key, const char *valu
 
 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
 XML_INDENT();
+av_bprint_escape(, key, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
 printf("<%s key=\"%s\"",
-   section->element_name, xml_escape_str(, key, wctx));
+   section->element_name, buf.str);
 av_bprint_clear();
-printf(" value=\"%s\"/>\n", xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf(" value=\"%s\"/>\n", buf.str);
 } else {
 if (wctx->nb_item[wctx->level])
 printf(" ");
-printf("%s=\"%s\"", key, xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf("%s=\"%s\"", key, buf.str);
 }
 
 av_bprint_finalize(, NULL);
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index 1e99158021..04261ed693 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -51,7 +51,7 @@
 
 
 
-
+
 
 
 
-- 
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 v7 0/5] Initial implementation of TTML encoding/muxing

2021-03-04 Thread Jan Ekström
I've intentionally kept this initial version simple (no styling etc) to focus
on the basics. As this goes through review, additional features can be added
(I had initial PoC for styling implemented some time around previous VDD), and
there is another patch set in my queue which would then add support for muxing
TTML into MP4.

Changes from the sixth version:
  - Split the lavc and lavf bits.

Jan

Jan Ekström (4):
  ffprobe: switch to av_bprint_escape for XML escaping
  avcodec: enable usage of err_recognition for encoders
  avcodec: add TTML encoder
  avformat: add TTML muxer

Stefano Sabatini (1):
  avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil

 Changelog  |   1 +
 doc/APIchanges |   3 +
 doc/general_contents.texi  |   1 +
 fftools/ffprobe.c  |  32 ++
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/avcodec.h   |   2 +-
 libavcodec/options_table.h |  18 ++--
 libavcodec/ttmlenc.c   | 210 +
 libavcodec/ttmlenc.h   |  28 +
 libavcodec/version.h   |   2 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 ++
 libavformat/version.h  |   2 +-
 libavutil/avstring.h   |  14 +++
 libavutil/bprint.c |  29 +
 libavutil/version.h|   2 +-
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/ffprobe_xml |   2 +-
 tests/ref/fate/sub-ttmlenc | 122 +
 tools/ffescape.c   |   7 +-
 22 files changed, 619 insertions(+), 37 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

-- 
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 v7 1/5] avutil/{avstring, bprint}: add XML escaping from ffprobe to avutil

2021-03-04 Thread Jan Ekström
From: Stefano Sabatini 

Base escaping only escapes values required for base character data
according to part 2.4 of XML, and if additional flags are added
single and double quotes can additionally be escaped in order
to handle single and double quoted attributes.

Co-authored-by: Jan Ekström 
Signed-off-by: Jan Ekström 
---
 libavutil/avstring.h | 14 ++
 libavutil/bprint.c   | 29 +
 libavutil/version.h  |  2 +-
 tools/ffescape.c |  7 +--
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index ee225585b3..fae446c302 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -324,6 +324,7 @@ enum AVEscapeMode {
 AV_ESCAPE_MODE_AUTO,  ///< Use auto-selected escaping mode.
 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
+AV_ESCAPE_MODE_XML,   ///< Use XML non-markup character data escaping.
 };
 
 /**
@@ -343,6 +344,19 @@ enum AVEscapeMode {
  */
 #define AV_ESCAPE_FLAG_STRICT (1 << 1)
 
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES (1 << 2)
+
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES (1 << 3)
+
+
 /**
  * Escape string in src, and put the escaped string in an allocated
  * string in *dst, which must be freed with av_free().
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 2f059c5ba6..e12fb263fe 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -283,6 +283,35 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 av_bprint_chars(dstbuf, '\'', 1);
 break;
 
+case AV_ESCAPE_MODE_XML:
+/* escape XML non-markup character data as per 2.4 by default: */
+/*  [^<&]* - ([^<&]* ']]>' [^<&]*) */
+
+/* additionally, given one of the AV_ESCAPE_FLAG_XML_* flags, */
+/* escape those specific characters as required. */
+for (; *src; src++) {
+switch (*src) {
+case '&' : av_bprintf(dstbuf, "%s", "");  break;
+case '<' : av_bprintf(dstbuf, "%s", "");   break;
+case '>' : av_bprintf(dstbuf, "%s", "");   break;
+case '\'':
+if (!(flags & AV_ESCAPE_FLAG_XML_SINGLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+case '"' :
+if (!(flags & AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+XML_DEFAULT_HANDLING:
+default: av_bprint_chars(dstbuf, *src, 1);
+}
+}
+break;
+
 /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
 default:
 /* \-escape characters */
diff --git a/libavutil/version.h b/libavutil/version.h
index b7c5892a37..356c54d633 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  66
+#define LIBAVUTIL_VERSION_MINOR  67
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tools/ffescape.c b/tools/ffescape.c
index 0530d28c6d..1ed8daa801 100644
--- a/tools/ffescape.c
+++ b/tools/ffescape.c
@@ -78,8 +78,10 @@ int main(int argc, char **argv)
 infilename = optarg;
 break;
 case 'f':
-if  (!strcmp(optarg, "whitespace")) escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
-else if (!strcmp(optarg, "strict")) escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+if  (!strcmp(optarg, "whitespace"))escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
+else if (!strcmp(optarg, "strict"))escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+else if (!strcmp(optarg, "xml_single_quotes")) escape_flags |= 
AV_ESCAPE_FLAG_XML_SINGLE_QUOTES;
+else if (!strcmp(optarg, "xml_double_quotes")) escape_flags |= 
AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES;
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -f, "
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
 if  (!strcmp(optarg, "auto"))  escape_mode = 
AV_ESCAPE_MODE_AUTO;
 else if (!strcmp(optarg, "backslash")) escape_mode = 
AV_ESCAPE_MODE_BACKSLASH;
 else if (!strcmp(optarg, "

[FFmpeg-devel] [PATCH v7 5/5] avformat: add TTML muxer

2021-03-04 Thread Jan Ekström
From: Jan Ekström 

Enables writing TTML documents or encoded TTML paragraphs as such
documents.

Additionally, a test for the combined TTML encoder and muxer has
been added to validate that the components still work.

Signed-off-by: Jan Ekström 
---
 Changelog  |   2 +-
 doc/general_contents.texi  |   2 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 +
 libavformat/version.h  |   2 +-
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/sub-ttmlenc | 122 ++
 8 files changed, 304 insertions(+), 3 deletions(-)
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

diff --git a/Changelog b/Changelog
index 43b6abb82b..f0b2995444 100644
--- a/Changelog
+++ b/Changelog
@@ -78,7 +78,7 @@ version :
 - Simbiosis IMX decoder
 - Simbiosis IMX demuxer
 - Digital Pictures SGA demuxer and decoders
-- TTML subtitle encoder
+- TTML subtitle encoder and muxer
 
 
 version 4.3:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index ac02f33c6f..58c9bcf747 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1352,7 +1352,7 @@ performance on systems without hardware floating point 
support).
 @item SubViewer v1 @tab   @tab X @tab   @tab X
 @item SubViewer@tab   @tab X @tab   @tab X
 @item TED Talks captions @tab @tab X @tab   @tab X
-@item TTML @tab   @tab   @tab X @tab
+@item TTML @tab X @tab   @tab X @tab
 @item VobSub (IDX+SUB) @tab   @tab X @tab   @tab X
 @item VPlayer  @tab   @tab X @tab   @tab X
 @item WebVTT   @tab X @tab X @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 48b91ea4d0..0504f47f88 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -546,6 +546,7 @@ OBJS-$(CONFIG_TRUEHD_DEMUXER)+= rawdec.o 
mlpdec.o
 OBJS-$(CONFIG_TRUEHD_MUXER)  += rawenc.o
 OBJS-$(CONFIG_TTA_DEMUXER)   += tta.o apetag.o img2.o
 OBJS-$(CONFIG_TTA_MUXER) += ttaenc.o apetag.o img2.o
+OBJS-$(CONFIG_TTML_MUXER)+= ttmlenc.o
 OBJS-$(CONFIG_TTY_DEMUXER)   += tty.o sauce.o
 OBJS-$(CONFIG_TY_DEMUXER)+= ty.o
 OBJS-$(CONFIG_TXD_DEMUXER)   += txd.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index ade247640c..a38fd1f583 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -445,6 +445,7 @@ extern AVInputFormat  ff_truehd_demuxer;
 extern AVOutputFormat ff_truehd_muxer;
 extern AVInputFormat  ff_tta_demuxer;
 extern AVOutputFormat ff_tta_muxer;
+extern AVOutputFormat ff_ttml_muxer;
 extern AVInputFormat  ff_txd_demuxer;
 extern AVInputFormat  ff_tty_demuxer;
 extern AVInputFormat  ff_ty_demuxer;
diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
new file mode 100644
index 00..940f8bbd4e
--- /dev/null
+++ b/libavformat/ttmlenc.c
@@ -0,0 +1,174 @@
+/*
+ * TTML subtitle muxer
+ * Copyright (c) 2020 24i
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * TTML subtitle muxer
+ * @see https://www.w3.org/TR/ttml1/
+ * @see https://www.w3.org/TR/ttml2/
+ * @see https://www.w3.org/TR/ttml-imsc/rec
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "libavcodec/ttmlenc.h"
+#include "libavutil/internal.h"
+
+enum TTMLPacketType {
+PACKET_TYPE_PARAGRAPH,
+PACKET_TYPE_DOCUMENT,
+};
+
+typedef struct TTMLMuxContext {
+enum TTMLPacketType input_type;
+unsigned int document_written;
+} TTMLMuxContext;
+
+static const char ttml_header_text[] =
+"\n"
+"http://www.w3.org/ns/ttml\"\n;
+"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
+"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;
+"  xml:lang=\"%s\">\n"
+"  \n"
+"\n";
+
+static const char ttml_footer_text[] =
+"\n"
+"  \n"
+"\n";
+
+static void ttml_write_time(AVIOContext *pb, const char tag[],
+int64_t millisec)
+{
+int64_t sec, min, hour;
+sec = millisec / 1000;
+millisec -= 

Re: [FFmpeg-devel] [PATCH v7 0/5] Initial implementation of TTML encoding/muxing

2021-03-05 Thread Jan Ekström
On Thu, Mar 4, 2021 at 7:48 PM Jan Ekström  wrote:
>
> I've intentionally kept this initial version simple (no styling etc) to focus
> on the basics. As this goes through review, additional features can be added
> (I had initial PoC for styling implemented some time around previous VDD), and
> there is another patch set in my queue which would then add support for muxing
> TTML into MP4.
>
> Changes from the sixth version:
>   - Split the lavc and lavf bits.
>
> Jan

As there were no further comments, applied the set as:

0f6bf94eb71c2d5e996c89c290f1a53660c46c2e
c8c6c9f5d96789001ea628f44cc5602bdc41d5f3
a0eec776b6212b0126f04bbac6bd6af0f6530b76
18713d22a2001321f9917fa4c7735f62563ec0a1
64af14555be2c9e522109e55160e0cb3f65c4690

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".

Re: [FFmpeg-devel] [PATCH v5 1/4] avutil/{avstring, bprint}: add XML escaping from ffprobe to avutil

2021-02-26 Thread Jan Ekström
On Fri, Feb 26, 2021 at 7:54 PM Michael Niedermayer
 wrote:
>
> On Mon, Feb 22, 2021 at 03:19:11PM +0200, Jan Ekström wrote:
> > From: Stefano Sabatini 
> >
> > Base escaping only escapes values required for base character data
> > according to part 2.4 of XML, and if additional flags are added
> > single and double quotes can additionally be escaped in order
> > to handle single and double quoted attributes.
> > ---
> >  libavutil/avstring.h | 14 ++
> >  libavutil/bprint.c   | 29 +
> >  libavutil/version.h  |  2 +-
> >  tools/ffescape.c |  7 +--
> >  4 files changed, 49 insertions(+), 3 deletions(-)
>
> breaks: tools/ffescape.o
>
> CC  tools/ffescape.o
> tools/ffescape.c: In function ‘main’:
> tools/ffescape.c:83:59: error: expected ‘)’ before ‘escape_flags’
>  else if (!strcmp(optarg, "xml_single_quotes") escape_flags |= 
> AV_ESCAPE_FLAG_XML_SINGLE_QUOTES);
>^~~~
> tools/ffescape.c:84:59: error: expected ‘)’ before ‘escape_flags’
>  else if (!strcmp(optarg, "xml_double_quotes") escape_flags |= 
> AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
>^~~~
> ffbuild/common.mak:67: recipe for target 'tools/ffescape.o' failed
> make: *** [tools/ffescape.o] Error 1

OK, sorry. That is a clear mistake yet I somehow thought that was
built by default and thus it was OK :/

Will fix.

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".

Re: [FFmpeg-devel] [PATCH v5 1/4] avutil/{avstring, bprint}: add XML escaping from ffprobe to avutil

2021-02-26 Thread Jan Ekström
On Fri, Feb 26, 2021 at 9:00 PM Jan Ekström  wrote:
>
> On Fri, Feb 26, 2021 at 7:54 PM Michael Niedermayer
>  wrote:
> >
> > On Mon, Feb 22, 2021 at 03:19:11PM +0200, Jan Ekström wrote:
> > > From: Stefano Sabatini 
> > >
> > > Base escaping only escapes values required for base character data
> > > according to part 2.4 of XML, and if additional flags are added
> > > single and double quotes can additionally be escaped in order
> > > to handle single and double quoted attributes.
> > > ---
> > >  libavutil/avstring.h | 14 ++
> > >  libavutil/bprint.c   | 29 +
> > >  libavutil/version.h  |  2 +-
> > >  tools/ffescape.c |  7 +--
> > >  4 files changed, 49 insertions(+), 3 deletions(-)
> >
> > breaks: tools/ffescape.o
> >
> > CC  tools/ffescape.o
> > tools/ffescape.c: In function ‘main’:
> > tools/ffescape.c:83:59: error: expected ‘)’ before ‘escape_flags’
> >  else if (!strcmp(optarg, "xml_single_quotes") escape_flags |= 
> > AV_ESCAPE_FLAG_XML_SINGLE_QUOTES);
> >^~~~
> > tools/ffescape.c:84:59: error: expected ‘)’ before ‘escape_flags’
> >  else if (!strcmp(optarg, "xml_double_quotes") escape_flags |= 
> > AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
> >^~~~
> > ffbuild/common.mak:67: recipe for target 'tools/ffescape.o' failed
> > make: *** [tools/ffescape.o] Error 1
>
> OK, sorry. That is a clear mistake yet I somehow thought that was
> built by default and thus it was OK :/
>
> Will fix.
>

Is now fixed as:

diff --git a/tools/ffescape.c b/tools/ffescape.c
index 0530d28c6d..1ed8daa801 100644
--- a/tools/ffescape.c
+++ b/tools/ffescape.c
@@ -78,8 +78,10 @@ int main(int argc, char **argv)
 infilename = optarg;
 break;
 case 'f':
-if  (!strcmp(optarg, "whitespace")) escape_flags |=
AV_ESCAPE_FLAG_WHITESPACE;
-else if (!strcmp(optarg, "strict")) escape_flags |=
AV_ESCAPE_FLAG_STRICT;
+if  (!strcmp(optarg, "whitespace"))
escape_flags |= AV_ESCAPE_FLAG_WHITESPACE;
+else if (!strcmp(optarg, "strict"))
escape_flags |= AV_ESCAPE_FLAG_STRICT;
+else if (!strcmp(optarg, "xml_single_quotes"))
escape_flags |= AV_ESCAPE_FLAG_XML_SINGLE_QUOTES;
+else if (!strcmp(optarg, "xml_double_quotes"))
escape_flags |= AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES;
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -f, "
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
 if  (!strcmp(optarg, "auto"))  escape_mode =
AV_ESCAPE_MODE_AUTO;
 else if (!strcmp(optarg, "backslash")) escape_mode =
AV_ESCAPE_MODE_BACKSLASH;
 else if (!strcmp(optarg, "quote")) escape_mode =
AV_ESCAPE_MODE_QUOTE;
+else if (!strcmp(optarg, "xml"))   escape_mode =
AV_ESCAPE_MODE_XML;
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -m, "
___
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] avformat/img2dec: set r_frame_rate in addition to avg_frame_rate

2021-04-07 Thread Jan Ekström
Apparently for various image sequences libavformat/utils.c can
calculate rather fancy r_frame_rate values, such as `186/1921`,
and since ffmpeg.c utilizes r_frame_rate for the filter chain
time base, this can quite deteriorate the output frame timing - even
though the user has requested the image sequence to be interpreted
at a specific, constant frame rate.
---
 libavformat/img2dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index be7149bb2f..7b03cb2af1 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -222,7 +222,7 @@ int ff_img_read_header(AVFormatContext *s1)
 avpriv_set_pts_info(st, 64, 1, 1);
 else {
 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
-st->avg_frame_rate = s->framerate;
+st->avg_frame_rate = st->r_frame_rate = s->framerate;
 }
 
 if (s->width && s->height) {
-- 
2.30.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] libavdevice/gdigrab: fix capture window title contain non-ASCII chars

2021-04-12 Thread Jan Ekström
On Sat, Mar 20, 2021 at 5:34 PM <1160386...@qq.com> wrote:
>
> From: He Yang <1160386...@qq.com>
>
> Signed-off-by: He Yang <1160386...@qq.com>

Sorry for taking a while to respond, and thank you for the
contribution. I have verified that this conversion and FindWindowW
usage indeed fixes issues with non-ASCII window titles.

Before:
[gdigrab @ 01d1f24b2cc0] Can't find window 'ジャンキーナイトタウンオーケストラ _
すりぃ feat.鏡音レン-sm36109943.mp4 - mpv', aborting.
title=ジャンキーナイトタウンオーケストラ _ すりぃ feat.鏡音レン-sm36109943.mp4 - mpv: I/O error

After:
[gdigrab @ 017d298b2cc0] Found window ジャンキーナイトタウンオーケストラ _  すりぃ
feat.鏡音レン-sm36109943.mp4 - mpv, capturing 1920x1080x32 at (0,0)
Input #0, gdigrab, from 'title=ジャンキーナイトタウンオーケストラ _ すりぃ
feat.鏡音レン-sm36109943.mp4 - mpv':

Now, taking things step-by-step, first from the most clear things:
1. FFmpeg utilizes C99 features, but follows the rule that no
declarations should happen after non-declaring code within a
scope/context.
src/libavdevice/gdigrab.c: In function 'gdigrab_read_header':
src/libavdevice/gdigrab.c:249:9: warning: ISO C90 forbids mixed
declarations and code [-Wdeclaration-after-statement]
  249 | const wchar_t *name_w = NULL;
  | ^

-> Basically fixed by moving the new wchar_t as the first thing in the
scope of that if branch.

2. Mismatch between function and the calling code in `const`ness.
Const things are nice, but in this case the function takes in a
non-const pointer.

src/libavdevice/gdigrab.c:250:30: warning: passing argument 2 of
'utf8towchar' from incompatible pointer type
[-Wincompatible-pointer-types]
  250 | if(utf8towchar(name, _w)) {
  |  ^~~
  |  |
  |  const wchar_t ** {aka const short
unsigned int **}
In file included from src/libavformat/os_support.h:148,
 from src/libavformat/internal.h:28,
 from src/libavdevice/gdigrab.c:32:
src/libavutil/wchar_filename.h:27:68: note: expected 'wchar_t **' {aka
'short unsigned int **'} but argument is of type 'const wchar_t **'
{aka 'const short unsigned int **'}
   27 | static inline int utf8towchar(const char *filename_utf8,
wchar_t **filename_w)
  |
~~^~

-> Fixed by removing the const from the wchar_t pointer.

Thus we move to actual review:

1. The libavutil header should be explicitly #included. That way users
of headers should be more easily find'able.
2. When utf8towchar returns nonzero, ret should probably be set to
AVERROR(errno). That way we are not re-guessing implementation
specifics of the function. (noticed by Martin)
3. Some whitespace would be good between the variable
declarations/setting, doing the conversion and finally the actual
window finding.

As I had to go through these points for the review process, I
basically posted a version with these changes @
https://github.com/jeeb/ffmpeg/commits/gdigrab_unicode_fix . I also
took the liberty of rewording the commit message somewhat. If you
think these changes are acceptable, then unless something new is
noticed, I consider this LGTM.

Best regards,
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".

Re: [FFmpeg-devel] [PATCH v2 0/4] Initial region (styling) support for TTML

2021-04-19 Thread Jan Ekström
On Wed, Apr 14, 2021 at 9:57 AM Jan Ekström  wrote:
>
> Now sets alignment, font size, font family and the region's position
> and size according to the ASS styles passed to the encoder. Regions are
> relatively important in TTML, since the spec-defined default region is in
> raster location (similar to the default with HTML) - it starts from the
> top left corner and covers the whole screen.
>
> Mapping of the ASS script resolution to the cell resolution and using cells as
> sizing metric is not perfect, but while TTML does have a pixel based reference
> sizing by means of setting an extent to the root tt element, it is 
> specifically
> disallowed in the EBU-TT profile, as well as apparently generally frowned upon
> as opposed to defining the cell resolution. In general, mapping to cell 
> resolution
> seems to give "close enough" results, though.
>
> FATE test output still passes https://github.com/skynav/ttt/ validation,
> and visually the result can be verified against such renderers as
> http://sandflow.com/imsc1_1/index.html .
>
> Changes from v1:
> * Removal of unnecessary intermediate AVBprints by printing elements in three
>   steps instead of attempting to do a single one. A bit less pretty, but lets
>   us write straight into the actual output buffer.
> * Removal of some local scopes. Seems like I'd been utilizing them as a
>   convenient way of having variable definitions after initial sanity checks.
> * Merging of script play X/Y resolution being zero or smaller checks into just
>   <= 0 checks.
> * Utilization of extradata buffers as-is after verifying that the buffer ends
>   with a null. Removes the requirement to copy strings out of the extradata 
> into
>   the lavf context, and thus the deinit/free function was no longer necessary.
>
> The diff can be checked as follows on my git repository:
> https://github.com/jeeb/ffmpeg/compare/ttml_add_default_region_v1..ttml_add_default_region_v2
> (more easily readable due to file limiting with the following command:
> git diff ttml_add_default_region_v1..ttml_add_default_region_v2 -- 
> libavcodec/ttmlenc.* libavformat/ttmlenc.*
> )
>
> Jan
>
> Jan Ekström (4):
>   avcodec/ttmlenc: split header writing into its own function
>   avformat/ttmlenc: enable writing out additional header values
>   avcodec/ttmlenc: add initial support for regions and styles
>   avcodec/ttmlenc: add support for region positioning and sizing
>
>  libavcodec/ttmlenc.c   | 267 ++---
>  libavcodec/ttmlenc.h   |   6 +
>  libavformat/ttmlenc.c  |  70 +-
>  tests/ref/fate/sub-ttmlenc |  88 +++-
>  4 files changed, 371 insertions(+), 60 deletions(-)
>
> --
> 2.30.2
>

If there is no further interest, I will start applying this set in a
day or two, as this actually makes subtitles look like you'd expect
them to look like :)  (due to the TTML default region starting from
the top left corner).

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".


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

2021-04-19 Thread Jan Ekström
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 :)

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".


Re: [FFmpeg-devel] [PATCH] libavdevice/gdigrab: fix capture window title contain non-ASCII chars

2021-04-13 Thread Jan Ekström
On Tue, Apr 13, 2021 at 12:35 AM Jan Ekström  wrote:
>
> On Sat, Mar 20, 2021 at 5:34 PM <1160386...@qq.com> wrote:
> >
> > From: He Yang <1160386...@qq.com>
> >
> > Signed-off-by: He Yang <1160386...@qq.com>
>
> Sorry for taking a while to respond, and thank you for the
> contribution. I have verified that this conversion and FindWindowW
> usage indeed fixes issues with non-ASCII window titles.
>
> Before:
> [gdigrab @ 01d1f24b2cc0] Can't find window 'ジャンキーナイトタウンオーケストラ _
> すりぃ feat.鏡音レン-sm36109943.mp4 - mpv', aborting.
> title=ジャンキーナイトタウンオーケストラ _ すりぃ feat.鏡音レン-sm36109943.mp4 - mpv: I/O error
>
> After:
> [gdigrab @ 017d298b2cc0] Found window ジャンキーナイトタウンオーケストラ _  すりぃ
> feat.鏡音レン-sm36109943.mp4 - mpv, capturing 1920x1080x32 at (0,0)
> Input #0, gdigrab, from 'title=ジャンキーナイトタウンオーケストラ _ すりぃ
> feat.鏡音レン-sm36109943.mp4 - mpv':
>
> Now, taking things step-by-step, first from the most clear things:
> 1. FFmpeg utilizes C99 features, but follows the rule that no
> declarations should happen after non-declaring code within a
> scope/context.
> src/libavdevice/gdigrab.c: In function 'gdigrab_read_header':
> src/libavdevice/gdigrab.c:249:9: warning: ISO C90 forbids mixed
> declarations and code [-Wdeclaration-after-statement]
>   249 | const wchar_t *name_w = NULL;
>   | ^
>
> -> Basically fixed by moving the new wchar_t as the first thing in the
> scope of that if branch.
>
> 2. Mismatch between function and the calling code in `const`ness.
> Const things are nice, but in this case the function takes in a
> non-const pointer.
>
> src/libavdevice/gdigrab.c:250:30: warning: passing argument 2 of
> 'utf8towchar' from incompatible pointer type
> [-Wincompatible-pointer-types]
>   250 | if(utf8towchar(name, _w)) {
>   |  ^~~
>   |  |
>   |  const wchar_t ** {aka const short
> unsigned int **}
> In file included from src/libavformat/os_support.h:148,
>  from src/libavformat/internal.h:28,
>  from src/libavdevice/gdigrab.c:32:
> src/libavutil/wchar_filename.h:27:68: note: expected 'wchar_t **' {aka
> 'short unsigned int **'} but argument is of type 'const wchar_t **'
> {aka 'const short unsigned int **'}
>27 | static inline int utf8towchar(const char *filename_utf8,
> wchar_t **filename_w)
>   |
> ~~^~
>
> -> Fixed by removing the const from the wchar_t pointer.
>
> Thus we move to actual review:
>
> 1. The libavutil header should be explicitly #included. That way users
> of headers should be more easily find'able.
> 2. When utf8towchar returns nonzero, ret should probably be set to
> AVERROR(errno). That way we are not re-guessing implementation
> specifics of the function. (noticed by Martin)
> 3. Some whitespace would be good between the variable
> declarations/setting, doing the conversion and finally the actual
> window finding.
>
> As I had to go through these points for the review process, I
> basically posted a version with these changes @
> https://github.com/jeeb/ffmpeg/commits/gdigrab_unicode_fix . I also
> took the liberty of rewording the commit message somewhat. If you
> think these changes are acceptable, then unless something new is
> noticed, I consider this LGTM.
>
> Best regards,
> Jan

Got an ack for these changes on both IRC and Github, thus applied as
707f9c9f475f612e196876708cdb5ead31f63525 .

Thank you once again for the contribution.

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".

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

2021-04-20 Thread Jan Ekström
On Tue, Apr 20, 2021 at 3:03 PM zheng qian  wrote:
>
> 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.
>

Alright, so I took another look as well throughout these Technical
Recommendations:

TR B14 fascicle 4
- http://www.arib.or.jp/english/html/overview/doc/8-TR-B14v6_5-4p5-E1.pdf

See:
14  Use of “component_tag”

> Table 14-1   Assignment of “component_tag” Values
> Others
> 0x30 to 0x7F
> Please note that 0x40 is assigned to the default ES for data
> broadcasting. 0x30, 0x31 to 0x37, 0x38 and 0x39 to 0x3F are assigned to 
> subtitle
> main, subtitle sub, teletext main and teletext sub respectively.

Then in TR B14 fascicle 2:
- http://www.arib.or.jp/english/html/overview/doc/8-TR-B14v6_5-2p5-E1.pdf

> 4.2.1  Specification for composition and transmission
> (3) Number of ES
> The maximum number of ESs that can be transmitted simultaneously for the same 
> service is
> 1  for  captions  and  1  for  superimpositions  when  the  component  group  
> descriptor  is  not
> transmitted. When the component group descriptor is transmitted, the maximum 
> number of ESs
> for captions is 1 and the maximum number of ESs for superimpositions is 1 for 
> each component
> group.

So to recap my understanding:
1. STD side (specs): It seems like these values have to be unique at
least at the level of a PMT (thus, per-program) - discussed this with
a person working on ARIB area of operations :) .
2. STD side: We can indeed have multiple caption/subtitle ES in a
single program (PMT) for Profile A. Profile C is always limited to one
ES per program since only one content_tag is possible.
3. TR side (tech. rec.): 0x30/0x87 should be the default for Profile A/C
4. TR side: If we do not code Component Group Descriptor (0xD9 in the
EIT), we should stick to a single ES (the default one) on both Profile
A and C.
5. TR side: If we code a Component Group Descriptor in the EIT, we can
have one ES for each composition group.

So basically:
1. STD side lets us go for it
2. TR side says "nope, you stick to one - unless you're defining
composition groups". Which is why you do not see multi-subtitle
streams in the wild, since almost nobody utilizes Content Group
Descriptors.

We don't and not sure if we will ever support component groups, so the
alternatives are:
1. Follow TR side, and be more strict than the specification. Limit in
`mpegts_init` each program to a single ARIB caption stream (be it
Profile A or Profile C). Set component_tag in descriptor to the
default one (0x30 or 0x87 respectively).
2. Follow STD side, and utilize what the specification enables. Limit
in `mpegts_init` each program to either 8 Profile A ARIB caption
streams, or 1 Profile C ARIB caption stream. Set component_tag
iteratively in order.

In both cases during counting the profile should be checked, since we
require the profile info to be there for writing of the descriptor.

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".


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

2021-04-20 Thread Jan Ekström
On Tue, Apr 20, 2021 at 8:16 PM Jan Ekström  wrote:
>
> On Tue, Apr 20, 2021 at 3:03 PM zheng qian  wrote:
> >
> > 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.
> >
>
> Alright, so I took another look as well throughout these Technical
> Recommendations:
>
> TR B14 fascicle 4
> - http://www.arib.or.jp/english/html/overview/doc/8-TR-B14v6_5-4p5-E1.pdf
>
> See:
> 14  Use of “component_tag”
>
> > Table 14-1   Assignment of “component_tag” Values
> > Others
> > 0x30 to 0x7F
> > Please note that 0x40 is assigned to the default ES for data
> > broadcasting. 0x30, 0x31 to 0x37, 0x38 and 0x39 to 0x3F are assigned to 
> > subtitle
> > main, subtitle sub, teletext main and teletext sub respectively.
>
> Then in TR B14 fascicle 2:
> - http://www.arib.or.jp/english/html/overview/doc/8-TR-B14v6_5-2p5-E1.pdf
>
> > 4.2.1  Specification for composition and transmission
> > (3) Number of ES
> > The maximum number of ESs that can be transmitted simultaneously for the 
> > same service is
> > 1  for  captions  and  1  for  superimpositions  when  the  component  
> > group  descriptor  is  not
> > transmitted. When the component group descriptor is transmitted, the 
> > maximum number of ESs
> > for captions is 1 and the maximum number of ESs for superimpositions is 1 
> > for each component
> > group.
>
> So to recap my understanding:
> 1. STD side (specs): It seems like these values have to be unique at
> least at the level of a PMT (thus, per-program) - discussed this with
> a person working on ARIB area of operations :) .
> 2. STD side: We can indeed have multiple caption/subtitle ES in a
> single program (PMT) for Profile A. Profile C is always limited to one
> ES per program since only one content_tag is possible.
> 3. TR side (tech. rec.): 0x30/0x87 should be the default for Profile A/C
> 4. TR side: If we do not code Component Group Descriptor (0xD9 in the
> EIT), we should stick to a single ES (the default one) on both Profile
> A and C.
> 5. TR side: If we code a Component Group Descriptor in the EIT, we can
> have one ES for each composition group.
>
> So basically:
> 1. STD side lets us go for it
> 2. TR side says "nope, you stick to one - unless you're defining
> composition groups". Which is why you do not see multi-subtitle
> streams in the wild, since almost nobody utilizes Content Group
> Descriptors.
>
> We don't and not sure if we will ever support component groups, so the
> alternatives are:
> 1. Follow TR side, and be more strict than the specification. Limit in
> `mpegts_init` each program to a single ARIB caption stream (be it
> Profile A or Profile C). Set c

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

2021-04-11 Thread Jan Ekström
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
___
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 Jan Ekström
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".

Re: [FFmpeg-devel] [PATCH] avformat/img2dec: set r_frame_rate in addition to avg_frame_rate

2021-04-11 Thread Jan Ekström
On Sun, Apr 11, 2021 at 1:16 PM Anton Khirnov  wrote:
>
> Quoting Jan Ekström (2021-04-07 20:25:03)
> > Apparently for various image sequences libavformat/utils.c can
> > calculate rather fancy r_frame_rate values, such as `186/1921`,
> > and since ffmpeg.c utilizes r_frame_rate for the filter chain
> > time base, this can quite deteriorate the output frame timing - even
> > though the user has requested the image sequence to be interpreted
> > at a specific, constant frame rate.
> > ---
> >  libavformat/img2dec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> > index be7149bb2f..7b03cb2af1 100644
> > --- a/libavformat/img2dec.c
> > +++ b/libavformat/img2dec.c
> > @@ -222,7 +222,7 @@ int ff_img_read_header(AVFormatContext *s1)
> >  avpriv_set_pts_info(st, 64, 1, 1);
> >  else {
> >  avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
> > -st->avg_frame_rate = s->framerate;
> > +st->avg_frame_rate = st->r_frame_rate = s->framerate;
> >  }
> >
> >  if (s->width && s->height) {
> > --
> > 2.30.2
>
> acceptable
>

Thanks.

Applied as 5945288818b98682884888e3800893b2f2ac7507 .

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".

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

2021-04-11 Thread Jan Ekström
On Sun, Apr 11, 2021 at 6:17 PM zheng qian  wrote:
>
> 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.
>

I don't think anything I have noted so far has made the remuxed
streams any more invalid than what your patch ideas have been? I mean,
that is the base idea - to make sure what we are generating is valid.
Just that you can already grasp the component tag and
data_component_id ranges/values from the ARIB caption profile already,
without having to copy the structure wholesale. component tag happens
to be what is exposed by AVStream::stream_identifier already at this
point, so if re-use of this value is wanted, that can be attained
through other purposes.

That is, unless there are other structures in the stream which have
references to the component_tag bit (which as far as I can tell is the
only changing bit in addition to additional_arib_caption_info, which I
went through). That said, if there are references to this value in
other streams or data structures, we are *not* copying those around,
so those would have to be implemented if that is so.

In other words, at this point the only thing explicitly required by
the muxer (albeit dummy values can be inserted if really needed) seems
to be the stuff within additional_arib_caption_info.

Jan

P.S.
Please do not top-post on this mailing list.
___
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 Jan Ekström
On Sun, Apr 11, 2021 at 5:51 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).

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).

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] [PATCH v2 4/4] avcodec/ttmlenc: add support for region positioning and sizing

2021-04-14 Thread Jan Ekström
From: Jan Ekström 

The ASS margins are utilized to generate percentual values, as
the usage of cell-based sizing and offsetting seems to be not too
well supported by renderers.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 44 --
 tests/ref/fate/sub-ttmlenc |  2 ++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index c190356683..eab6240a75 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -237,11 +237,35 @@ static const char *ttml_get_text_alignment(int alignment)
 }
 }
 
+static void ttml_get_origin(ASSScriptInfo script_info, ASSStyle *style,
+   int *origin_left, int *origin_top)
+{
+*origin_left = av_rescale(style->margin_l, 100, script_info.play_res_x);
+*origin_top  =
+av_rescale((style->alignment >= 7) ? style->margin_v : 0,
+   100, script_info.play_res_y);
+}
+
+static void ttml_get_extent(ASSScriptInfo script_info, ASSStyle *style,
+   int *width, int *height)
+{
+*width  = av_rescale(script_info.play_res_x - style->margin_r,
+ 100, script_info.play_res_x);
+*height = av_rescale((style->alignment <= 3) ?
+ script_info.play_res_y - style->margin_v :
+ script_info.play_res_y,
+ 100, script_info.play_res_y);
+}
+
 static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf,
- ASSStyle *style)
+ ASSScriptInfo script_info, ASSStyle *style)
 {
 const char *display_alignment = NULL;
 const char *text_alignment = NULL;
+int origin_left = 0;
+int origin_top  = 0;
+int width = 0;
+int height = 0;
 
 if (!style)
 return AVERROR_INVALIDDATA;
@@ -257,6 +281,14 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+if (style->margin_l < 0 || style->margin_r < 0 || style->margin_v < 0) {
+av_log(avctx, AV_LOG_ERROR,
+   "One or more negative margin values in subtitle style: "
+   "left: %d, right: %d, vertical: %d!\n",
+   style->margin_l, style->margin_r, style->margin_v);
+return AVERROR_INVALIDDATA;
+}
+
 display_alignment = ttml_get_display_alignment(style->alignment);
 text_alignment = ttml_get_text_alignment(style->alignment);
 if (!display_alignment || !text_alignment) {
@@ -268,11 +300,19 @@ static int ttml_write_region(AVCodecContext *avctx, 
AVBPrint *buf,
 return AVERROR_INVALIDDATA;
 }
 
+ttml_get_origin(script_info, style, _left, _top);
+ttml_get_extent(script_info, style, , );
+
 av_bprintf(buf, "  name, NULL, AV_ESCAPE_MODE_XML,
  AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
 av_bprintf(buf, "\"\n");
 
+av_bprintf(buf, "tts:origin=\"%d%% %d%%\"\n",
+   origin_left, origin_top);
+av_bprintf(buf, "tts:extent=\"%d%% %d%%\"\n",
+   width, height);
+
 av_bprintf(buf, "tts:displayAlign=\"");
 av_bprint_escape(buf, display_alignment, NULL, AV_ESCAPE_MODE_XML,
  AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
@@ -335,7 +375,7 @@ static int ttml_write_header_content(AVCodecContext *avctx)
 
 for (int i = 0; i < ass->styles_count; i++) {
 ASSStyle *style = >styles[i];
-int ret = ttml_write_region(avctx, >buffer, style);
+int ret = ttml_write_region(avctx, >buffer, script_info, style);
 if (ret < 0)
 return ret;
 }
diff --git a/tests/ref/fate/sub-ttmlenc b/tests/ref/fate/sub-ttmlenc
index 6d0a8067fc..4df8f8796f 100644
--- a/tests/ref/fate/sub-ttmlenc
+++ b/tests/ref/fate/sub-ttmlenc
@@ -9,6 +9,8 @@
   
 
   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/4] avcodec/ttmlenc: split header writing into its own function

2021-04-14 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index 3972b4368c..e3c155fdd1 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -173,16 +173,8 @@ static av_cold int ttml_encode_close(AVCodecContext *avctx)
 return 0;
 }
 
-static av_cold int ttml_encode_init(AVCodecContext *avctx)
+static int ttml_write_header_content(AVCodecContext *avctx)
 {
-TTMLContext *s = avctx->priv_data;
-
-s->avctx   = avctx;
-
-if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
-return AVERROR_INVALIDDATA;
-}
-
 if (!(avctx->extradata = av_mallocz(TTMLENC_EXTRADATA_SIGNATURE_SIZE +
 1 + AV_INPUT_BUFFER_PADDING_SIZE))) {
 return AVERROR(ENOMEM);
@@ -192,8 +184,25 @@ static av_cold int ttml_encode_init(AVCodecContext *avctx)
 memcpy(avctx->extradata, TTMLENC_EXTRADATA_SIGNATURE,
TTMLENC_EXTRADATA_SIGNATURE_SIZE);
 
+return 0;
+}
+
+static av_cold int ttml_encode_init(AVCodecContext *avctx)
+{
+TTMLContext *s = avctx->priv_data;
+int ret = AVERROR_BUG;
+s->avctx   = avctx;
+
 av_bprint_init(>buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
 
+if (!(s->ass_ctx = ff_ass_split(avctx->subtitle_header))) {
+return AVERROR_INVALIDDATA;
+}
+
+if ((ret = ttml_write_header_content(avctx)) < 0) {
+return ret;
+}
+
 return 0;
 }
 
-- 
2.30.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/4] avcodec/ttmlenc: add initial support for regions and styles

2021-04-14 Thread Jan Ekström
From: Jan Ekström 

Attempts to utilize the TTML cell resolution as a mapping to the
reference resolution, and maps font size to cell size. Additionally
sets the display and text alignment according to the ASS alignment
number.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.c   | 210 ++---
 libavcodec/ttmlenc.h   |   3 +-
 tests/ref/fate/sub-ttmlenc |  86 ---
 3 files changed, 247 insertions(+), 52 deletions(-)

diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index e3c155fdd1..c190356683 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -100,20 +100,33 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, );
 
 for (; dialog && num--; dialog++) {
-int ret = ff_ass_split_override_codes(_callbacks, s,
-  dialog->text);
-int log_level = (ret != AVERROR_INVALIDDATA ||
- avctx->err_recognition & AV_EF_EXPLODE) ?
-AV_LOG_ERROR : AV_LOG_WARNING;
+if (dialog->style) {
+av_bprintf(>buffer, "buffer, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+av_bprintf(>buffer, "\">");
+}
 
-if (ret < 0) {
-av_log(avctx, log_level,
-   "Splitting received ASS dialog failed: %s\n",
-   av_err2str(ret));
+{
+int ret = ff_ass_split_override_codes(_callbacks, s,
+  dialog->text);
+int log_level = (ret != AVERROR_INVALIDDATA ||
+ avctx->err_recognition & AV_EF_EXPLODE) ?
+AV_LOG_ERROR : AV_LOG_WARNING;
 
-if (log_level == AV_LOG_ERROR)
-return ret;
+if (ret < 0) {
+av_log(avctx, log_level,
+   "Splitting received ASS dialog failed: %s\n",
+   av_err2str(ret));
+
+if (log_level == AV_LOG_ERROR)
+return ret;
+}
 }
+
+if (dialog->style)
+av_bprintf(>buffer, "");
 }
 } else {
 #endif
@@ -121,6 +134,14 @@ static int ttml_encode_frame(AVCodecContext *avctx, 
uint8_t *buf,
 if (!dialog)
 return AVERROR(ENOMEM);
 
+if (dialog->style) {
+av_bprintf(>buffer, "buffer, dialog->style, NULL,
+ AV_ESCAPE_MODE_XML,
+ AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+av_bprintf(>buffer, "\">");
+}
+
 {
 int ret = ff_ass_split_override_codes(_callbacks, s,
   dialog->text);
@@ -140,6 +161,9 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t 
*buf,
 }
 }
 
+if (dialog->style)
+av_bprintf(>buffer, "");
+
 ff_ass_free_dialog();
 }
 #if FF_API_ASS_TIMING
@@ -173,17 +197,175 @@ static av_cold int ttml_encode_close(AVCodecContext 
*avctx)
 return 0;
 }
 
+static const char *ttml_get_display_alignment(int alignment)
+{
+switch (alignment) {
+case 1:
+case 2:
+case 3:
+return "after";
+case 4:
+case 5:
+case 6:
+return "center";
+case 7:
+case 8:
+case 9:
+return "before";
+default:
+return NULL;
+}
+}
+
+static const char *ttml_get_text_alignment(int alignment)
+{
+switch (alignment) {
+case 1:
+case 4:
+case 7:
+return "left";
+case 2:
+case 5:
+case 8:
+return "center";
+case 3:
+case 6:
+case 9:
+return "right";
+default:
+return NULL;
+}
+}
+
+static int ttml_write_region(AVCodecContext *avctx, AVBPrint *buf,
+ ASSStyle *style)
+{
+const char *display_alignment = NULL;
+const char *text_alignment = NULL;
+
+if (!style)
+return AVERROR_INVALIDDATA;
+
+if (!style->name) {
+av_log(avctx, AV_LOG_ERROR, "Subtitle style name not set!\n");
+return AVERROR_INVALIDDATA;
+}
+
+if (style->font_size < 0) {
+av_log(avctx, AV_LOG_

[FFmpeg-devel] [PATCH v2 0/4] Initial region (styling) support for TTML

2021-04-14 Thread Jan Ekström
Now sets alignment, font size, font family and the region's position
and size according to the ASS styles passed to the encoder. Regions are
relatively important in TTML, since the spec-defined default region is in
raster location (similar to the default with HTML) - it starts from the
top left corner and covers the whole screen.

Mapping of the ASS script resolution to the cell resolution and using cells as
sizing metric is not perfect, but while TTML does have a pixel based reference
sizing by means of setting an extent to the root tt element, it is specifically
disallowed in the EBU-TT profile, as well as apparently generally frowned upon
as opposed to defining the cell resolution. In general, mapping to cell 
resolution
seems to give "close enough" results, though.

FATE test output still passes https://github.com/skynav/ttt/ validation,
and visually the result can be verified against such renderers as
http://sandflow.com/imsc1_1/index.html .

Changes from v1:
* Removal of unnecessary intermediate AVBprints by printing elements in three
  steps instead of attempting to do a single one. A bit less pretty, but lets
  us write straight into the actual output buffer.
* Removal of some local scopes. Seems like I'd been utilizing them as a
  convenient way of having variable definitions after initial sanity checks.
* Merging of script play X/Y resolution being zero or smaller checks into just
  <= 0 checks.
* Utilization of extradata buffers as-is after verifying that the buffer ends
  with a null. Removes the requirement to copy strings out of the extradata into
  the lavf context, and thus the deinit/free function was no longer necessary.

The diff can be checked as follows on my git repository:
https://github.com/jeeb/ffmpeg/compare/ttml_add_default_region_v1..ttml_add_default_region_v2
(more easily readable due to file limiting with the following command:
git diff ttml_add_default_region_v1..ttml_add_default_region_v2 -- 
libavcodec/ttmlenc.* libavformat/ttmlenc.*
)

Jan

Jan Ekström (4):
  avcodec/ttmlenc: split header writing into its own function
  avformat/ttmlenc: enable writing out additional header values
  avcodec/ttmlenc: add initial support for regions and styles
  avcodec/ttmlenc: add support for region positioning and sizing

 libavcodec/ttmlenc.c   | 267 ++---
 libavcodec/ttmlenc.h   |   6 +
 libavformat/ttmlenc.c  |  70 +-
 tests/ref/fate/sub-ttmlenc |  88 +++-
 4 files changed, 371 insertions(+), 60 deletions(-)

-- 
2.30.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/4] avformat/ttmlenc: enable writing out additional header values

2021-04-14 Thread Jan Ekström
From: Jan Ekström 

This way the encoder may pass on the following values to the muxer:
1) Additional root "tt" element attributes, such as the subtitle
   canvas reference size.
2) Anything before the body element of the document, such as regions
   in the head element, which can configure styles.

Signed-off-by: Jan Ekström 
---
 libavcodec/ttmlenc.h  |  5 
 libavformat/ttmlenc.c | 70 +++
 2 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ttmlenc.h b/libavcodec/ttmlenc.h
index c1dd5ec990..c3bb11478d 100644
--- a/libavcodec/ttmlenc.h
+++ b/libavcodec/ttmlenc.h
@@ -25,4 +25,9 @@
 #define TTMLENC_EXTRADATA_SIGNATURE "lavc-ttmlenc"
 #define TTMLENC_EXTRADATA_SIGNATURE_SIZE (sizeof(TTMLENC_EXTRADATA_SIGNATURE) 
- 1)
 
+static const char ttml_default_namespacing[] =
+"  xmlns=\"http://www.w3.org/ns/ttml\"\n;
+"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
+"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;;
+
 #endif /* AVCODEC_TTMLENC_H */
diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
index 940f8bbd4e..34a0107a14 100644
--- a/libavformat/ttmlenc.c
+++ b/libavformat/ttmlenc.c
@@ -37,6 +37,11 @@ enum TTMLPacketType {
 PACKET_TYPE_DOCUMENT,
 };
 
+struct TTMLHeaderParameters {
+const char *tt_element_params;
+const char *pre_body_elements;
+};
+
 typedef struct TTMLMuxContext {
 enum TTMLPacketType input_type;
 unsigned int document_written;
@@ -45,10 +50,9 @@ typedef struct TTMLMuxContext {
 static const char ttml_header_text[] =
 "\n"
 "http://www.w3.org/ns/ttml\"\n;
-"  xmlns:ttm=\"http://www.w3.org/ns/ttml#metadata\"\n;
-"  xmlns:tts=\"http://www.w3.org/ns/ttml#styling\"\n;
+"%s"
 "  xml:lang=\"%s\">\n"
+"%s"
 "  \n"
 "\n";
 
@@ -72,6 +76,48 @@ static void ttml_write_time(AVIOContext *pb, const char 
tag[],
 tag, hour, min, sec, millisec);
 }
 
+static int ttml_set_header_values_from_extradata(
+AVCodecParameters *par, struct TTMLHeaderParameters *header_params)
+{
+size_t additional_data_size =
+par->extradata_size - TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+char *value =
+(char *)par->extradata + TTMLENC_EXTRADATA_SIGNATURE_SIZE;
+size_t value_size = av_strnlen(value, additional_data_size);
+struct TTMLHeaderParameters local_params = { 0 };
+
+if (!additional_data_size) {
+// simple case, we don't have to go through local_params and just
+// set default fall-back values (for old extradata format).
+header_params->tt_element_params = ttml_default_namespacing;
+header_params->pre_body_elements = "";
+
+return 0;
+}
+
+if (value_size == additional_data_size ||
+value[value_size] != '\0')
+return AVERROR_INVALIDDATA;
+
+local_params.tt_element_params = value;
+
+additional_data_size -= value_size + 1;
+value += value_size + 1;
+if (!additional_data_size)
+return AVERROR_INVALIDDATA;
+
+value_size = av_strnlen(value, additional_data_size);
+if (value_size == additional_data_size ||
+value[value_size] != '\0')
+return AVERROR_INVALIDDATA;
+
+local_params.pre_body_elements = value;
+
+*header_params = local_params;
+
+return 0;
+}
+
 static int ttml_write_header(AVFormatContext *ctx)
 {
 TTMLMuxContext *ttml_ctx = ctx->priv_data;
@@ -103,8 +149,22 @@ static int ttml_write_header(AVFormatContext *ctx)
 
 avpriv_set_pts_info(st, 64, 1, 1000);
 
-if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH)
-avio_printf(pb, ttml_header_text, printed_lang);
+if (ttml_ctx->input_type == PACKET_TYPE_PARAGRAPH) {
+struct TTMLHeaderParameters header_params;
+int ret = ttml_set_header_values_from_extradata(
+st->codecpar, _params);
+if (ret < 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Failed to parse TTML header values from extradata: "
+   "%s!\n", av_err2str(ret));
+return ret;
+}
+
+avio_printf(pb, ttml_header_text,
+header_params.tt_element_params,
+printed_lang,
+header_params.pre_body_elements);
+}
 }
 
 return 0;
-- 
2.30.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] avcodec/mediacodecdec: Do not abort when H264/HEVC extradata extraction fails

2021-02-12 Thread Jan Ekström
On Fri, Feb 12, 2021 at 12:36 PM Matthieu Bouron
 wrote:
>
> On Mon, Jan 25, 2021 at 06:38:36PM +0100, sfan5 wrote:
> > Although rare, extradata can be present but empty and extraction will fail.
> > However Android also supports passing codec-specific data inline and
> > will likely play such a stream anyway. So there's no reason to abort
> > initialization before we know for sure.
> > ---
> >  libavcodec/mediacodecdec.c | 8 
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > index ac1725e466..67adefb530 100644
> > --- a/libavcodec/mediacodecdec.c
> > +++ b/libavcodec/mediacodecdec.c
> > @@ -167,8 +167,8 @@ static int h264_set_extradata(AVCodecContext *avctx,
> > FFAMediaFormat *format)
> >  ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
> >  av_freep();
> >  } else {
> > -av_log(avctx, AV_LOG_ERROR, "Could not extract PPS/SPS from
> > extradata");
> > -ret = AVERROR_INVALIDDATA;
> > +av_log(avctx, AV_LOG_WARNING, "Could not extract PPS/SPS from
> > extradata\n");
> > +ret = 0;
> >  }
> >   done:
> > @@ -254,8 +254,8 @@ static int hevc_set_extradata(AVCodecContext *avctx,
> > FFAMediaFormat *format)
> >   av_freep();
> >  } else {
> > -av_log(avctx, AV_LOG_ERROR, "Could not extract VPS/PPS/SPS from
> > extradata");
> > -ret = AVERROR_INVALIDDATA;
> > +av_log(avctx, AV_LOG_WARNING, "Could not extract VPS/PPS/SPS from
> > extradata\n");
> > +ret = 0;
> >  }
> >   done:
>
> Hello,
>
> First of all, sorry for the late reply. The original intent with this
> restriction was to make sure that MediaCodec could error out early (at the
> configuration stage) so an implementation on top of libavcodec can decide
> to fall back to a software decoder (without trying to decode anything).
>
> I am fine with removing this restriction (if everyone is OK with that) for
> the following reasons:
> - there are chances that the h264/hevc software decoders have not been
>   enabled (to avoid licensing issues) so the fallback mechanism is not
>   available
> - as you said extradata are not always available (mpegts) and we want to
>   give MediaCodec a chance to decode the stream

I just had a discussion with sfan5 on IRC yesterday when I was looking
at the related code, and yea - I think this is acceptable since to get
to this point ff_h264_decode_extradata / ff_hevc_decode_extradata
would have to return success. They just didn't get anything. This can
happen with f.ex. completely valid MP4 files, since certain
identifiers (which are visible through the codec_tag identifier) do
not required all of the required parameter sets to be within the
extradata (and thus having 0 pps and 0 sps is technically valid with
those).

My idea was thus to make the log message either WARNING or DEBUG
depending on (is_avc || is_nalff) && codec_tag in (list, of, tags) (in
pseudocode). How matroska should be handled depends on how the codec
stuff is currently defined in there.

>
> So LGTM.
>
> If everyone is OK with that, I'll also submit a patch that removes the
> requirements on having the avctx->extradata set (I use such patch at work
> to allow playback of certain hls/mpegts streams).
>
> [...]
> --
> Matthieu B.
> ___
> 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] avcodec/mediacodecdec: Do not abort when H264/HEVC extradata extraction fails

2021-02-14 Thread Jan Ekström
On Sat, Feb 13, 2021 at 4:31 PM Jan Ekström  wrote:
>
> On Sat, Feb 13, 2021 at 12:48 AM sfan5  wrote:
> >
> > 12.02.21 - 21:43 - Andreas Rheinhardt:
> > > sfan5:
> > >> Hi,
> > >>
> > >>
> > >> attached v2 patch after discussion on IRC with JEEB (as he already
> > >> mentioned).
> > >>
> > >> Only change is that the log level turns to debug when missing parameter
> > >> sets are within spec (cf. 14496-15).
> > >>
> > >>
> > >> -av_log(avctx, AV_LOG_ERROR, "Could not extract PPS/SPS from 
> > >> extradata");
> > >> -ret = AVERROR_INVALIDDATA;
> > >> +const int warn = is_avc && avctx->codec_tag != 
> > >> MKTAG('a','v','c','1') &&
> > >> +avctx->codec_tag != MKTAG('a','v','c','2');
> > >> +av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
> > >> +"Could not extract PPS/SPS from extradata\n");
> > >> +ret = 0;
> > >>   }
> > > warn = is_avc && (avctx->codec_tag == MKTAG('a','v','c','1') ||
> > >avctx->codec_tag == MKTAG('a','v','c','2')
> > > is what you (should) want.
> > >
> > > - Andreas
> >
> > Thanks for pointing that out, you're correct.
> >
> > here's v3:
>
> After some brief discussion on IRC, this looks good to me :) .
>

Applied as 6f80953554b07635d3b52f76b03807d198a5e9d0 with the
indentation of the log message and the initial capital letter of the
commit message fixed.

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".

Re: [FFmpeg-devel] [PATCH v3] avcodec/mediacodecdec: Do not abort when H264/HEVC extradata extraction fails

2021-02-13 Thread Jan Ekström
On Sat, Feb 13, 2021 at 12:48 AM sfan5  wrote:
>
> 12.02.21 - 21:43 - Andreas Rheinhardt:
> > sfan5:
> >> Hi,
> >>
> >>
> >> attached v2 patch after discussion on IRC with JEEB (as he already
> >> mentioned).
> >>
> >> Only change is that the log level turns to debug when missing parameter
> >> sets are within spec (cf. 14496-15).
> >>
> >>
> >> -av_log(avctx, AV_LOG_ERROR, "Could not extract PPS/SPS from 
> >> extradata");
> >> -ret = AVERROR_INVALIDDATA;
> >> +const int warn = is_avc && avctx->codec_tag != 
> >> MKTAG('a','v','c','1') &&
> >> +avctx->codec_tag != MKTAG('a','v','c','2');
> >> +av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
> >> +"Could not extract PPS/SPS from extradata\n");
> >> +ret = 0;
> >>   }
> > warn = is_avc && (avctx->codec_tag == MKTAG('a','v','c','1') ||
> >avctx->codec_tag == MKTAG('a','v','c','2')
> > is what you (should) want.
> >
> > - Andreas
>
> Thanks for pointing that out, you're correct.
>
> here's v3:

After some brief discussion on IRC, this looks good to me :) .

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".

Re: [FFmpeg-devel] [PATCH v6 4/9] avcodec: add cbs for h266/vvc

2021-02-19 Thread Jan Ekström
On Fri, Feb 19, 2021 at 3:52 PM Nuo Mi  wrote:
> > >>
> > >> The current logic is that we are writing an AU, so the first NAL unit in
> > >> it is necessarily an AU start and subsequent NAL units are not?
> > >>
> > > H.266 AU contains one or more PU(3.105). One PU contains one coded
> > picture.
> > > Only the first NAL unit of an AU needs the zero_byte(B.2.2)
> > > H.265 has no PU, each AU has one coded picture(3.1)
> > > H.266's PU is the H.265's AU. In vvc_parser, we split bitstream to PU.
> >
> > Er, I don't think this is right: an AVPacket should contain all of the
> > pictures for a single timestamp - a decoder can then output at most one
> > picture from it, for the selected spatial layer.
> >
> This will make parser code very complicate :).
>
>
> > Though I don't know how the container formats are defined here, for other
> > codecs having multiple packets with the same timestamps causes ugly
> > problems in muxing/demuxing which we avoid by saying you aren't allowed to
> > do that.
> >
> We do not have container format spec for vvc yet. The codec is not register
> on http://mp4ra.org/#/codecs. How we handle svc in H.265? It will have same
> timestamp for diffrent AU.
>

FYI, there are already drafts for 14496-15 (Carriage of NAL unit based
video in ISOBMFF aka MP4) with VVC such as document N18825 .
https://isotc.iso.org/livelink/livelink?func=ll=21196449=Open=1

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".

Re: [FFmpeg-devel] [PATCH v2] Add support for the new key & value API in libaom.

2021-02-13 Thread Jan Ekström
On Wed, Feb 10, 2021 at 9:16 AM Bohan Li
 wrote:
>
> Hi Jan,
>
> Yes the modified patch looks good to me.
> Please let me know if there is anything needed from my end.
>
> Thank you very much!
>
> Bohan
>

FYI, apparently the symbol is not exported in shared builds of libaom.
I did test that versions before and after this feature got added to
verify that the ABI number could be utilized as a build-time check,
and that current release versions of libaom would still work, but
unfortunately only in static configuration.

Relevant libaom issue:
https://bugs.chromium.org/p/aomedia/issues/detail?id=2962

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] [PATCH v5 4/4] {avcodec, avformat}: add TTML encoder and muxer

2021-02-22 Thread Jan Ekström
From: Jan Ekström 

Enables encoding of other subtitle formats into TTML and writing
them out as such documents.

Signed-off-by: Jan Ekström 
---
 Changelog  |   1 +
 doc/general_contents.texi  |   1 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/ttmlenc.c   | 210 +
 libavcodec/ttmlenc.h   |  28 +
 libavcodec/version.h   |   4 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 ++
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/sub-ttmlenc | 122 +
 12 files changed, 545 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

diff --git a/Changelog b/Changelog
index ba5aebf79d..4c8d8a8b29 100644
--- a/Changelog
+++ b/Changelog
@@ -77,6 +77,7 @@ version :
 - OpenEXR image encoder
 - Simbiosis IMX decoder
 - Simbiosis IMX demuxer
+- TTML subtitle encoder and muxer
 
 
 version 4.3:
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 6acdf441d6..58c9bcf747 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1352,6 +1352,7 @@ performance on systems without hardware floating point 
support).
 @item SubViewer v1 @tab   @tab X @tab   @tab X
 @item SubViewer@tab   @tab X @tab   @tab X
 @item TED Talks captions @tab @tab X @tab   @tab X
+@item TTML @tab X @tab   @tab X @tab
 @item VobSub (IDX+SUB) @tab   @tab X @tab   @tab X
 @item VPlayer  @tab   @tab X @tab   @tab X
 @item WebVTT   @tab X @tab X @tab X @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6ec1d360ac..4b1be2e37c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -672,6 +672,7 @@ OBJS-$(CONFIG_TSCC_DECODER)+= tscc.o msrledec.o
 OBJS-$(CONFIG_TSCC2_DECODER)   += tscc2.o
 OBJS-$(CONFIG_TTA_DECODER) += tta.o ttadata.o ttadsp.o
 OBJS-$(CONFIG_TTA_ENCODER) += ttaenc.o ttaencdsp.o ttadata.o
+OBJS-$(CONFIG_TTML_ENCODER)+= ttmlenc.o ass_split.o
 OBJS-$(CONFIG_TWINVQ_DECODER)  += twinvqdec.o twinvq.o metasound_data.o
 OBJS-$(CONFIG_TXD_DECODER) += txd.o
 OBJS-$(CONFIG_ULTI_DECODER)+= ulti.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 354d146379..a91f19ae31 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -689,6 +689,7 @@ extern AVCodec ff_subviewer_decoder;
 extern AVCodec ff_subviewer1_decoder;
 extern AVCodec ff_text_encoder;
 extern AVCodec ff_text_decoder;
+extern AVCodec ff_ttml_encoder;
 extern AVCodec ff_vplayer_decoder;
 extern AVCodec ff_webvtt_encoder;
 extern AVCodec ff_webvtt_decoder;
diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
new file mode 100644
index 00..3972b4368c
--- /dev/null
+++ b/libavcodec/ttmlenc.c
@@ -0,0 +1,210 @@
+/*
+ * TTML subtitle encoder
+ * Copyright (c) 2020 24i
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * TTML subtitle encoder
+ * @see https://www.w3.org/TR/ttml1/
+ * @see https://www.w3.org/TR/ttml2/
+ * @see https://www.w3.org/TR/ttml-imsc/rec
+ */
+
+#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
+#include "libavutil/internal.h"
+#include "ass_split.h"
+#include "ass.h"
+#include "ttmlenc.h"
+
+typedef struct {
+AVCodecContext *avctx;
+ASSSplitContext *ass_ctx;
+AVBPrint buffer;
+} TTMLContext;
+
+static void ttml_text_cb(void *priv, const char *text, int len)
+{
+TTMLContext *s = priv;
+AVBPrint cur_line = { 0 };
+AVBPrint *buffer = >buffer;
+
+av_bprint_init(_line, len, AV_BPRINT_SIZE_UNLIMITED);
+
+av_bprint_append_data(_line, text, len);
+if (!av_bprint_is_complete(_line)) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Failed to move the current subtitle dialog to AVBPrint!\n");
+av_bprint_finalize(_line, NULL);
+return;
+}
+

Re: [FFmpeg-devel] [PATCH v5 0/4] Initial implementation of TTML encoding/muxing

2021-02-22 Thread Jan Ekström
On Mon, Feb 22, 2021 at 3:19 PM Jan Ekström  wrote:
>
> I've intentionally kept this initial version simple (no styling etc) to focus
> on the basics. As this goes through review, additional features can be added
> (I had initial PoC for styling implemented some time around previous VDD), and
> there is another patch set in my queue which would then add support for muxing
> TTML into MP4.
>
> Changes from the fourth version:
>   - Switched from separate escaping modes back to a single AV_ESCAPE_MODE_XML,
> with additional flags for single and double quote escaping for attributes
> (Anton noted that the AV_ESCAPE_FLAG_XML prefix makes it all long enough,
> so ATTR was left away from these).
>   - Added the libavutil minor bump, which was forgotten so far.
>   - ff_ass_split_override_codes calls are now checked for errors and a warning
> or error is logged depending on whether it was an invalid input error,
> and if AV_EF_EXPLODE was set. In case of invalid input and AV_EF_EXPLODE,
> a malformed ASS dialog will cause the encoder to fail. By default it will
> not, which matches the current behavior of all other subtitle encoders,
> which do not test the return value of ff_ass_split_override_codes at all,
> and thus just skip malformed parts of an ASS dialog.
>
> Thank you to Anton for giving the idea of the AV_EF_EXPLODE usage.
>   - Documented that AV_EF_EXPLODE is now usable for subtitle encoders.

For the record, if this seems unacceptable I can switch it to a
specifically named AVOption in the subtitle encoder.

Either way is fine by me, the explode flag was just what was noted as
an alternative first.

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] [PATCH v5 3/4] avcodec: enable usage of AV_EF_EXPLODE for subtitle encoders

2021-02-22 Thread Jan Ekström
From: Jan Ekström 

As currently it is the responsibility of the following subtitle
encoder to validate the correctness of the incoming ASS dialog line.

Signed-off-by: Jan Ekström 
---
 libavcodec/avcodec.h   | 5 -
 libavcodec/options_table.h | 4 ++--
 libavcodec/version.h   | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7dbf083a24..9fffe8bcec 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1634,7 +1634,10 @@ typedef struct AVCodecContext {
 
 /**
  * Error recognition; may misdetect some more or less valid parts as 
errors.
- * - encoding: unused
+ * - encoding: Set by user. Currently only AV_EF_EXPLODE is valid, and only
+ * for subtitle encoders, since checking the validity of an ASS
+ * dialog line is currently the responsibility of the following
+ * encoder.
  * - decoding: Set by user.
  */
 int err_recognition;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index ded9de4d67..f159a4b410 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -140,11 +140,11 @@ static const AVOption avcodec_options[] = {
 {"unofficial", "allow unofficial extensions", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
 {"experimental", "allow non-standardized experimental things", 0, 
AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, 
A|V|D|E, "strict"},
 {"b_qoffset", "QP offset between P- and B-frames", OFFSET(b_quant_offset), 
AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E},
-{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
+{"err_detect", "set error detection flags", OFFSET(err_recognition), 
AV_OPT_TYPE_FLAGS, {.i64 = 0 }, INT_MIN, INT_MAX, A|V|D|E, "err_detect"},
 {"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
 {"bitstream", "detect bitstream specification deviations", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|D, 
"err_detect"},
 {"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
-{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
+{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, 
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|D|E, "err_detect"},
 {"ignore_err", "ignore errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_IGNORE_ERR 
}, INT_MIN, INT_MAX, A|V|D, "err_detect"},
 {"careful","consider things that violate the spec, are fast to check and 
have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.i64 = 
AV_EF_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "err_detect"},
 {"compliant",  "consider all spec non compliancies as errors", 0, 
AV_OPT_TYPE_CONST, {.i64 = AV_EF_COMPLIANT | AV_EF_CAREFUL }, INT_MIN, INT_MAX, 
A|V|D, "err_detect"},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9325da1028..85fbbfe766 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR 125
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #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 v5 0/4] Initial implementation of TTML encoding/muxing

2021-02-22 Thread Jan Ekström
I've intentionally kept this initial version simple (no styling etc) to focus
on the basics. As this goes through review, additional features can be added
(I had initial PoC for styling implemented some time around previous VDD), and
there is another patch set in my queue which would then add support for muxing
TTML into MP4.

Changes from the fourth version:
  - Switched from separate escaping modes back to a single AV_ESCAPE_MODE_XML,
with additional flags for single and double quote escaping for attributes
(Anton noted that the AV_ESCAPE_FLAG_XML prefix makes it all long enough,
so ATTR was left away from these).
  - Added the libavutil minor bump, which was forgotten so far.
  - ff_ass_split_override_codes calls are now checked for errors and a warning
or error is logged depending on whether it was an invalid input error,
and if AV_EF_EXPLODE was set. In case of invalid input and AV_EF_EXPLODE,
a malformed ASS dialog will cause the encoder to fail. By default it will
not, which matches the current behavior of all other subtitle encoders,
which do not test the return value of ff_ass_split_override_codes at all,
and thus just skip malformed parts of an ASS dialog.

Thank you to Anton for giving the idea of the AV_EF_EXPLODE usage.
  - Documented that AV_EF_EXPLODE is now usable for subtitle encoders.
  - FF_CODEC_CAP_INIT_CLEANUP was added to ttmlenc, simplifying clean-up.
  - The extradata added by ttmlenc was made more specific, and a shared header
containing the value and its length was added to reduce duplication.
  - A case which would be only due to internal error was made to return
AVERROR_BUG and the relevant log line was made to note that this is an
internal error.
  - Missing includes for "libavutil/internal.h" were added.

Jan

Jan Ekström (3):
  ffprobe: switch to av_bprint_escape for XML escaping
  avcodec: enable usage of AV_EF_EXPLODE for subtitle encoders
  {avcodec,avformat}: add TTML encoder and muxer

Stefano Sabatini (1):
  avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil

 Changelog  |   1 +
 doc/general_contents.texi  |   1 +
 fftools/ffprobe.c  |  32 ++
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/avcodec.h   |   5 +-
 libavcodec/options_table.h |   4 +-
 libavcodec/ttmlenc.c   | 210 +
 libavcodec/ttmlenc.h   |  28 +
 libavcodec/version.h   |   2 +-
 libavformat/Makefile   |   1 +
 libavformat/allformats.c   |   1 +
 libavformat/ttmlenc.c  | 174 ++
 libavutil/avstring.h   |  14 +++
 libavutil/bprint.c |  29 +
 libavutil/version.h|   2 +-
 tests/fate/subtitles.mak   |   3 +
 tests/ref/fate/ffprobe_xml |   2 +-
 tests/ref/fate/sub-ttmlenc | 122 +
 tools/ffescape.c   |   7 +-
 20 files changed, 611 insertions(+), 29 deletions(-)
 create mode 100644 libavcodec/ttmlenc.c
 create mode 100644 libavcodec/ttmlenc.h
 create mode 100644 libavformat/ttmlenc.c
 create mode 100644 tests/ref/fate/sub-ttmlenc

-- 
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 v5 2/4] ffprobe: switch to av_bprint_escape for XML escaping

2021-02-22 Thread Jan Ekström
From: Jan Ekström 

Additionally update the result of the ffprobe XML writing test.

Signed-off-by: Jan Ekström 
---
 fftools/ffprobe.c  | 32 +++-
 tests/ref/fate/ffprobe_xml |  2 +-
 2 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 3453aa09ff..7635f781a6 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -1672,24 +1672,6 @@ static av_cold int xml_init(WriterContext *wctx)
 return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void 
*log_ctx)
-{
-const char *p;
-
-for (p = src; *p; p++) {
-switch (*p) {
-case '&' : av_bprintf(dst, "%s", "");  break;
-case '<' : av_bprintf(dst, "%s", "");   break;
-case '>' : av_bprintf(dst, "%s", "");   break;
-case '"' : av_bprintf(dst, "%s", ""); break;
-case '\'': av_bprintf(dst, "%s", ""); break;
-default: av_bprint_chars(dst, *p, 1);
-}
-}
-
-return dst->str;
-}
-
 #define XML_INDENT() printf("%*c", xml->indent_level * 4, ' ')
 
 static void xml_print_section_header(WriterContext *wctx)
@@ -1761,14 +1743,22 @@ static void xml_print_str(WriterContext *wctx, const 
char *key, const char *valu
 
 if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
 XML_INDENT();
+av_bprint_escape(, key, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
 printf("<%s key=\"%s\"",
-   section->element_name, xml_escape_str(, key, wctx));
+   section->element_name, buf.str);
 av_bprint_clear();
-printf(" value=\"%s\"/>\n", xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf(" value=\"%s\"/>\n", buf.str);
 } else {
 if (wctx->nb_item[wctx->level])
 printf(" ");
-printf("%s=\"%s\"", key, xml_escape_str(, value, wctx));
+
+av_bprint_escape(, value, NULL,
+ AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
+printf("%s=\"%s\"", key, buf.str);
 }
 
 av_bprint_finalize(, NULL);
diff --git a/tests/ref/fate/ffprobe_xml b/tests/ref/fate/ffprobe_xml
index ccea2874b2..bfff7bc332 100644
--- a/tests/ref/fate/ffprobe_xml
+++ b/tests/ref/fate/ffprobe_xml
@@ -51,7 +51,7 @@
 
 
 
-
+
 
 
 
-- 
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 v5 1/4] avutil/{avstring, bprint}: add XML escaping from ffprobe to avutil

2021-02-22 Thread Jan Ekström
From: Stefano Sabatini 

Base escaping only escapes values required for base character data
according to part 2.4 of XML, and if additional flags are added
single and double quotes can additionally be escaped in order
to handle single and double quoted attributes.
---
 libavutil/avstring.h | 14 ++
 libavutil/bprint.c   | 29 +
 libavutil/version.h  |  2 +-
 tools/ffescape.c |  7 +--
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index ee225585b3..fae446c302 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -324,6 +324,7 @@ enum AVEscapeMode {
 AV_ESCAPE_MODE_AUTO,  ///< Use auto-selected escaping mode.
 AV_ESCAPE_MODE_BACKSLASH, ///< Use backslash escaping.
 AV_ESCAPE_MODE_QUOTE, ///< Use single-quote escaping.
+AV_ESCAPE_MODE_XML,   ///< Use XML non-markup character data escaping.
 };
 
 /**
@@ -343,6 +344,19 @@ enum AVEscapeMode {
  */
 #define AV_ESCAPE_FLAG_STRICT (1 << 1)
 
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES (1 << 2)
+
+/**
+ * Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double
+ * quoted attributes.
+ */
+#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES (1 << 3)
+
+
 /**
  * Escape string in src, and put the escaped string in an allocated
  * string in *dst, which must be freed with av_free().
diff --git a/libavutil/bprint.c b/libavutil/bprint.c
index 2f059c5ba6..e12fb263fe 100644
--- a/libavutil/bprint.c
+++ b/libavutil/bprint.c
@@ -283,6 +283,35 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, 
const char *special_cha
 av_bprint_chars(dstbuf, '\'', 1);
 break;
 
+case AV_ESCAPE_MODE_XML:
+/* escape XML non-markup character data as per 2.4 by default: */
+/*  [^<&]* - ([^<&]* ']]>' [^<&]*) */
+
+/* additionally, given one of the AV_ESCAPE_FLAG_XML_* flags, */
+/* escape those specific characters as required. */
+for (; *src; src++) {
+switch (*src) {
+case '&' : av_bprintf(dstbuf, "%s", "");  break;
+case '<' : av_bprintf(dstbuf, "%s", "");   break;
+case '>' : av_bprintf(dstbuf, "%s", "");   break;
+case '\'':
+if (!(flags & AV_ESCAPE_FLAG_XML_SINGLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+case '"' :
+if (!(flags & AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES))
+goto XML_DEFAULT_HANDLING;
+
+av_bprintf(dstbuf, "%s", "");
+break;
+XML_DEFAULT_HANDLING:
+default: av_bprint_chars(dstbuf, *src, 1);
+}
+}
+break;
+
 /* case AV_ESCAPE_MODE_BACKSLASH or unknown mode */
 default:
 /* \-escape characters */
diff --git a/libavutil/version.h b/libavutil/version.h
index b7c5892a37..356c54d633 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  66
+#define LIBAVUTIL_VERSION_MINOR  67
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tools/ffescape.c b/tools/ffescape.c
index 0530d28c6d..3647ae5d60 100644
--- a/tools/ffescape.c
+++ b/tools/ffescape.c
@@ -78,8 +78,10 @@ int main(int argc, char **argv)
 infilename = optarg;
 break;
 case 'f':
-if  (!strcmp(optarg, "whitespace")) escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
-else if (!strcmp(optarg, "strict")) escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+if  (!strcmp(optarg, "whitespace"))   escape_flags |= 
AV_ESCAPE_FLAG_WHITESPACE;
+else if (!strcmp(optarg, "strict"))   escape_flags |= 
AV_ESCAPE_FLAG_STRICT;
+else if (!strcmp(optarg, "xml_single_quotes") escape_flags |= 
AV_ESCAPE_FLAG_XML_SINGLE_QUOTES);
+else if (!strcmp(optarg, "xml_double_quotes") escape_flags |= 
AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES);
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -f, "
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
 if  (!strcmp(optarg, "auto"))  escape_mode = 
AV_ESCAPE_MODE_AUTO;
 else if (!strcmp(optarg, "backslash")) escape_mode = 
AV_ESCAPE_MODE_BACKSLASH;
 else if (!strcmp(optarg, "quote")) escape_mode = 
AV_ESCAPE_MODE_QUOTE;
+else if (!strcmp(optarg, "xml"))   escape_mode = 
AV_ESCAPE_MODE_XML;
 else {
 av_log(NULL, AV_LOG_ERROR,
"Invalid value '%s' for option -m, "
-- 
2.29.2

___
ffmpeg-devel mailing list

[FFmpeg-devel] [PATCH] avfilter/vf_scale: reset color matrix in case of identity & non-RGB

2021-08-22 Thread Jan Ekström
Fixes passing through mismatching metadata from the input side
when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.

Fixes #9132
---
 libavfilter/vf_scale.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index ce39217515..7ca833bbb1 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -738,6 +738,15 @@ scale:
 out->width  = outlink->w;
 out->height = outlink->h;
 
+// Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
+//   the output is no longer RGB, unset the matrix.
+//   In theory this should be in swscale itself as the AVFrame
+//   based API gets in, so that not every swscale API user has
+//   to go through duplicating such sanity checks.
+if (out->colorspace == AVCOL_SPC_RGB &&
+!(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
+out->colorspace = AVCOL_SPC_UNSPECIFIED;
+
 if (scale->output_is_pal)
 avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == 
AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
 
-- 
2.31.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".


Re: [FFmpeg-devel] [PATCH] dox/examples/encode_video: add explanations in comments.

2021-08-20 Thread Jan Ekström
On Mon, Aug 16, 2021 at 4:07 PM Nicolas George  wrote:
>
> Signed-off-by: Nicolas George 
> ---

Looks good to me with the dox->doc fixup you've already done in the
commit message.

Generally I've become accustomed to trying to push people to look at
the transcode* examples since I've seen people try to do things
manually which our APIs would do for them when they see these minimal
examples and try to extend them.

Best regards,
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".


Re: [FFmpeg-devel] [PATCH v4 0/2] TTML in MP4, part 1

2021-08-23 Thread Jan Ekström
On Mon, Aug 16, 2021 at 3:26 PM Jan Ekström  wrote:
>
> To keep it simpler this first part includes only non-fragmented use
> cases if the built-in sample squashing is utilized. Contains the basic
> mapping code as well as the function that writes out the squashed documents.
>
> Works with both subtitle-only output as well as with other streams.
>
> In a separate patch set I will add additional complexity on top
> by introducing fragmentation matching based on the other streams in
> the mux (since most things that ingest fragmented MP4 with subtitles
> want the fragment time ranges to match between the video/audio streams
> and subtitles in the mux).
>
> Changes from v3:
>
> * avformat/ttmlenc: added const to the function argument codecpar, and 
> switched
> included header from avformat.h to specifically
> libavcodec/codec_par.h according to comments from Andreas.
> * avformat/movenc_ttml: applied recommendation from Andreas to deduplicate
>         AVFormatContext cleanup.
>
> Jan
>
> Jan Ekström (2):
>   avformat/ttml: split TTML paragraph based or not check into header
>   avformat/movenc: add support for TTML muxing
>
>  libavformat/Makefile |   2 +-
>  libavformat/isom.h   |   3 +
>  libavformat/movenc.c | 179 ++-
>  libavformat/movenc.h |   5 +
>  libavformat/movenc_ttml.c| 171 +
>  libavformat/movenc_ttml.h|  31 ++
>  libavformat/ttmlenc.c|   9 +-
>  libavformat/ttmlenc.h|  39 +++
>  tests/fate/subtitles.mak |   4 +
>  tests/ref/fate/sub-ttml-mp4-dfxp |  44 
>  tests/ref/fate/sub-ttml-mp4-stpp |  44 
>  11 files changed, 521 insertions(+), 10 deletions(-)
>  create mode 100644 libavformat/movenc_ttml.c
>  create mode 100644 libavformat/movenc_ttml.h
>  create mode 100644 libavformat/ttmlenc.h
>  create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
>  create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp
>

Unless there are objections, I will pull this in soon as all the
previously received reviews/comments were taken into account.

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] [PATCH 2/2] avcodec/libx265: improve full range flag setting logic

2021-08-17 Thread Jan Ekström
Unlike libx264, libx265 does not have a separate "unspecified"/"auto"
default for color range, so we do always have to specify it.
Thus, we are required to handle the RGB case on the libavcodec
side to enable the correct value to be written out in in case
of RGB content with unspecified color range being received.

In other words:
1. If the user has set color range specifically, follow that.
2. If the user has not set color range specifically, set full
   range by default in case of RGB and YUVJ pixel formats.
---
 libavcodec/libx265.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 9395120471..b5c94b64a3 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -181,10 +181,15 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 
 ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
 
-ctx->params->vui.bEnableVideoFullRangeFlag = avctx->pix_fmt == 
AV_PIX_FMT_YUVJ420P ||
- avctx->pix_fmt == 
AV_PIX_FMT_YUVJ422P ||
- avctx->pix_fmt == 
AV_PIX_FMT_YUVJ444P ||
- avctx->color_range == 
AVCOL_RANGE_JPEG;
+if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
+ctx->params->vui.bEnableVideoFullRangeFlag =
+avctx->color_range == AVCOL_RANGE_JPEG;
+else
+ctx->params->vui.bEnableVideoFullRangeFlag =
+(av_pix_fmt_desc_get(avctx->pix_fmt)->flags & AV_PIX_FMT_FLAG_RGB) 
||
+avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
+avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
+avctx->pix_fmt == AV_PIX_FMT_YUVJ444P;
 
 if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 &&
  avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
-- 
2.31.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/2] avcodec/libx264: leave full range flag unchanged if unknown

2021-08-17 Thread Jan Ekström
By default the x264 full range flag is set to -1. By not setting
it to something else, we can let libx264 handle the RGB case.
Additionally, change the preference order to user-specified range
first, and then any fall-back logic left for the YUVJ pix_fmts.

Fixes the capture part of #9374
---
 libavcodec/libx264.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 9afaf19547..d48e142e41 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -857,10 +857,12 @@ static av_cold int X264_init(AVCodecContext *avctx)
 
 x4->params.i_slice_count  = avctx->slices;
 
-x4->params.vui.b_fullrange = avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
- avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
- avctx->pix_fmt == AV_PIX_FMT_YUVJ444P ||
- avctx->color_range == AVCOL_RANGE_JPEG;
+if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
+x4->params.vui.b_fullrange = avctx->color_range == AVCOL_RANGE_JPEG;
+else if (avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
+ avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
+ avctx->pix_fmt == AV_PIX_FMT_YUVJ444P)
+x4->params.vui.b_fullrange = 1;
 
 if (avctx->colorspace != AVCOL_SPC_UNSPECIFIED)
 x4->params.vui.i_colmatrix = avctx->colorspace;
-- 
2.31.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".


Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: reset color matrix in case of identity & non-RGB

2021-08-26 Thread Jan Ekström
On Sun, Aug 22, 2021 at 11:55 PM Jan Ekström  wrote:
>
> Fixes passing through mismatching metadata from the input side
> when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.
>
> Fixes #9132
> ---
>  libavfilter/vf_scale.c | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index ce39217515..7ca833bbb1 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -738,6 +738,15 @@ scale:
>  out->width  = outlink->w;
>  out->height = outlink->h;
>
> +// Sanity check: If we've got the RGB/XYZ (identity) matrix configured, 
> and
> +//   the output is no longer RGB, unset the matrix.
> +//   In theory this should be in swscale itself as the 
> AVFrame
> +//   based API gets in, so that not every swscale API user 
> has
> +//   to go through duplicating such sanity checks.
> +if (out->colorspace == AVCOL_SPC_RGB &&
> +!(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
> +out->colorspace = AVCOL_SPC_UNSPECIFIED;
> +
>  if (scale->output_is_pal)
>  avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format 
> == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
>
> --
> 2.31.1
>

Unless there are objections, I will pull this in soon. I will also
attempt to see if I can add a programmatic FATE test for all of the
allowed configurations of vf_scale, to see if there are any other
clear-cut cases where not all metadata from the input AVFrame can be
passed on as-is and has to be reset.

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".


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: add support for setting chroma sample location

2021-08-26 Thread Jan Ekström
On Tue, Aug 24, 2021 at 12:47 AM Jan Ekström  wrote:
>
> ---
>  libavcodec/libx264.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index d48e142e41..379c167e6f 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -870,6 +870,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
>  x4->params.vui.i_colorprim = avctx->color_primaries;
>  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
>  x4->params.vui.i_transfer  = avctx->color_trc;
> +if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED)
> +x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
>
>  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
>  x4->params.b_repeat_headers = 0;
> --
> 2.31.1
>

I have re-tested these changes (for both x264 and x265), and BT.2100
content that was marked with topleft chroma location now gets that
information passed onto the output (whereas previously the content
would get interpreted as with the implicit "left" value). Thus, unless
there are objections, I will pull this set in soon.

The only difference in default would be with unlabeled H.264/HEVC with
streams that get that default value ("left") interpreted. Previously,
as there was no support for writing the data, those streams would stay
without any metadata on the output side, while now, as libavcodec
doesn't differentiate between implicit and explicit values, the value
gets written into the output, making an implicit value explicit. As
far as whether this is a problem, I would consider it a "no", as the
decoding result should be the same (due to the implicit default).

Best regards,
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".


Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: reset color matrix in case of identity & non-RGB

2021-08-27 Thread Jan Ekström
On Sat, Aug 28, 2021 at 12:03 AM Michael Niedermayer
 wrote:
>
> On Fri, Aug 27, 2021 at 01:02:31AM +0300, Jan Ekström wrote:
> > On Sun, Aug 22, 2021 at 11:55 PM Jan Ekström  wrote:
> > >
> > > Fixes passing through mismatching metadata from the input side
> > > when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.
> > >
> > > Fixes #9132
> > > ---
> > >  libavfilter/vf_scale.c | 9 +
> > >  1 file changed, 9 insertions(+)
> > >
> > > diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> > > index ce39217515..7ca833bbb1 100644
> > > --- a/libavfilter/vf_scale.c
> > > +++ b/libavfilter/vf_scale.c
> > > @@ -738,6 +738,15 @@ scale:
> > >  out->width  = outlink->w;
> > >  out->height = outlink->h;
> > >
> > > +// Sanity check: If we've got the RGB/XYZ (identity) matrix 
> > > configured, and
> > > +//   the output is no longer RGB, unset the matrix.
> > > +//   In theory this should be in swscale itself as the 
> > > AVFrame
> > > +//   based API gets in, so that not every swscale API 
> > > user has
> > > +//   to go through duplicating such sanity checks.
> > > +if (out->colorspace == AVCOL_SPC_RGB &&
> > > +!(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
> > > +out->colorspace = AVCOL_SPC_UNSPECIFIED;
> > > +
> > >  if (scale->output_is_pal)
> > >  avpriv_set_systematic_pal2((uint32_t*)out->data[1], 
> > > outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
> > >
> > > --
> > > 2.31.1
> > >
> >
> > Unless there are objections, I will pull this in soon. I will also
> > attempt to see if I can add a programmatic FATE test for all of the
> > allowed configurations of vf_scale, to see if there are any other
> > clear-cut cases where not all metadata from the input AVFrame can be
> > passed on as-is and has to be reset.
>
> no objections
>
> thx

Thanks, applied as 9dd410c80416197188337e3b7e1600be41d2ea64 .

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] [PATCH] avfilter/vf_scale: set the RGB matrix coefficients in case of RGB

2021-08-28 Thread Jan Ekström
This fixes the passing through of non-RGB matrix from input to
output when conversion from YCbCr to RGB happens.
---
 libavfilter/vf_scale.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 7ca833bbb1..17668206aa 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -738,13 +738,16 @@ scale:
 out->width  = outlink->w;
 out->height = outlink->h;
 
-// Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
-//   the output is no longer RGB, unset the matrix.
-//   In theory this should be in swscale itself as the AVFrame
-//   based API gets in, so that not every swscale API user has
-//   to go through duplicating such sanity checks.
-if (out->colorspace == AVCOL_SPC_RGB &&
-!(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
+// Sanity checks:
+//   1. If the output is RGB, set the matrix coefficients to RGB.
+//   2. If the output is not RGB and we've got the RGB/XYZ (identity)
+//  matrix configured, unset the matrix.
+//   In theory these should be in swscale itself as the AVFrame
+//   based API gets in, so that not every swscale API user has
+//   to go through duplicating such sanity checks.
+if (av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB)
+out->colorspace = AVCOL_SPC_RGB;
+else if (out->colorspace == AVCOL_SPC_RGB)
 out->colorspace = AVCOL_SPC_UNSPECIFIED;
 
 if (scale->output_is_pal)
-- 
2.31.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".


Re: [FFmpeg-devel] [PATCH v2 2/2] avcodec/libx265: add support for setting chroma sample location

2021-08-31 Thread Jan Ekström
On Tue, Aug 31, 2021 at 12:52 AM Jan Ekström  wrote:
>
> On Sun, Aug 29, 2021 at 7:43 PM Jan Ekström  wrote:
> >
> > Unlike libx264, libx265 does not handle the chroma format check
> > on its own side, so in order to not write out values which are
> > supposed to be ignored according to the specification, we limit
> > the writing out of chroma sample location to 4:2:0 only.
> > ---
> >  libavcodec/libx265.c | 13 +
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> > index 71affbf61b..839b6ce9de 100644
> > --- a/libavcodec/libx265.c
> > +++ b/libavcodec/libx265.c
> > @@ -211,6 +211,19 @@ static av_cold int libx265_encode_init(AVCodecContext 
> > *avctx)
> >  ctx->params->vui.matrixCoeffs= avctx->colorspace;
> >  }
> >
> > +// chroma sample location values are to be ignored in case of non-4:2:0
> > +// according to the specification, so we only write them out in case of
> > +// 4:2:0 (log2_chroma_{w,h} == 1).
> > +ctx->params->vui.bEnableChromaLocInfoPresentFlag =
> > +avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
> > +desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1;
>
> Checked this another time, and this check seems correct. HWAccel
> pix_fmts like VAAPI are also marked as 4:2:0, but thankfully they're
> not on the supported list for this module.
>
> For the source of the check, it is based on the following in the 
> specification:
>
> Otherwise  (chroma_format_idc  is  not  equal  to  1),  the  values
> of  the  syntax  elements chroma_sample_loc_type_top_field  and
> chroma_sample_loc_type_bottom_field  shall  be  ignored.  When
> chroma_format_idc is equal to 2 (4:2:2 chroma format) or 3 (4:4:4
> chroma format), the location of chroma samples is specified in clause
> 6.2. When chroma_format_idc is equal to 0, there is no chroma sample
> array.
>
> > +
> > +if (ctx->params->vui.bEnableChromaLocInfoPresentFlag) {
> > +ctx->params->vui.chromaSampleLocTypeTopField =
> > +ctx->params->vui.chromaSampleLocTypeBottomField =
> > +avctx->chroma_sample_location - 1;
> > +}
>
> For progressive content both values should be set to the same value.
>
> For interlaced content in theory the chroma location field value is
> not necessarily the same, but:
> 1. we have a single value in our APIs
> 2. x264 does this exact same thing, utilizes a single value interface
> and sets both fields to the same value.

Unless there are objections, I will pull this in soon.

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".


Re: [FFmpeg-devel] [PATCH v4 0/2] TTML in MP4, part 1

2021-08-25 Thread Jan Ekström
On Mon, Aug 23, 2021 at 11:31 AM Jan Ekström  wrote:
>
> On Mon, Aug 16, 2021 at 3:26 PM Jan Ekström  wrote:
> >
> > To keep it simpler this first part includes only non-fragmented use
> > cases if the built-in sample squashing is utilized. Contains the basic
> > mapping code as well as the function that writes out the squashed documents.
> >
> > Works with both subtitle-only output as well as with other streams.
> >
> > In a separate patch set I will add additional complexity on top
> > by introducing fragmentation matching based on the other streams in
> > the mux (since most things that ingest fragmented MP4 with subtitles
> > want the fragment time ranges to match between the video/audio streams
> > and subtitles in the mux).
> >
> > Changes from v3:
> >
> > * avformat/ttmlenc: added const to the function argument codecpar, and 
> > switched
> > included header from avformat.h to specifically
> > libavcodec/codec_par.h according to comments from 
> > Andreas.
> > * avformat/movenc_ttml: applied recommendation from Andreas to deduplicate
> > AVFormatContext cleanup.
> >
> > Jan
> >
> > Jan Ekström (2):
> >   avformat/ttml: split TTML paragraph based or not check into header
> >   avformat/movenc: add support for TTML muxing
> >
> >  libavformat/Makefile |   2 +-
> >  libavformat/isom.h   |   3 +
> >  libavformat/movenc.c | 179 ++-
> >  libavformat/movenc.h |   5 +
> >  libavformat/movenc_ttml.c| 171 +
> >  libavformat/movenc_ttml.h|  31 ++
> >  libavformat/ttmlenc.c|   9 +-
> >  libavformat/ttmlenc.h|  39 +++
> >  tests/fate/subtitles.mak |   4 +
> >  tests/ref/fate/sub-ttml-mp4-dfxp |  44 
> >  tests/ref/fate/sub-ttml-mp4-stpp |  44 
> >  11 files changed, 521 insertions(+), 10 deletions(-)
> >  create mode 100644 libavformat/movenc_ttml.c
> >  create mode 100644 libavformat/movenc_ttml.h
> >  create mode 100644 libavformat/ttmlenc.h
> >  create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
> >  create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp
> >
>
> Unless there are objections, I will pull this in soon as all the
> previously received reviews/comments were taken into account.
>

Applied as 460beb948ceddeb86bd2b3b17335176adcaa7223 and
e41bd075dd56f20f4eca61790bda5bf88c433bcb .

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] [PATCH] avformat/{isom, mov, movenc}: add support for CMAF DASH roles

2021-08-23 Thread Jan Ekström
From: Jan Ekström 

This information is coded in a standard MP4 KindBox and utilizes the
scheme and values as per the DASH role scheme defined in MPEG-DASH.
Other schemes are technically allowed, but where multiple schemes
define the same concepts, the DASH scheme should be utilized.

Such flagging is additionally utilized by the DASH-IF CMAF ingest
specification, enabling an encoder to inform the following component
of the roles of the incoming media streams.

A test is added for this functionality in a similar manner to the
matroska test.

Signed-off-by: Jan Ekström 
---
 libavformat/isom.c| 19 +
 libavformat/isom.h| 12 +++
 libavformat/mov.c | 68 
 libavformat/movenc.c  | 51 
 tests/fate/mov.mak|  8 ++
 .../ref/fate/mov-mp4-disposition-mpegts-remux | 81 +++
 6 files changed, 239 insertions(+)
 create mode 100644 tests/ref/fate/mov-mp4-disposition-mpegts-remux

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 4df5440023..300ba927c2 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -430,3 +430,22 @@ void ff_mov_write_chan(AVIOContext *pb, int64_t 
channel_layout)
 }
 avio_wb32(pb, 0);  // mNumberChannelDescriptions
 }
+
+static const struct MP4TrackKindValueMapping dash_role_map[] = {
+{ AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_CAPTIONS,
+"caption" },
+{ AV_DISPOSITION_COMMENT,
+"commentary" },
+{ AV_DISPOSITION_VISUAL_IMPAIRED|AV_DISPOSITION_DESCRIPTIONS,
+"description" },
+{ AV_DISPOSITION_DUB,
+"dub" },
+{ AV_DISPOSITION_FORCED,
+"forced-subtitle" },
+{ 0, NULL }
+};
+
+const struct MP4TrackKindMapping ff_mov_track_kind_table[] = {
+{ "urn:mpeg:dash:role:2011", dash_role_map },
+{ 0, NULL }
+};
diff --git a/libavformat/isom.h b/libavformat/isom.h
index ac1b3f3d56..e8e3aa3444 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -387,4 +387,16 @@ 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);
 }
 
+struct MP4TrackKindValueMapping {
+int disposition;
+const char *value;
+};
+
+struct MP4TrackKindMapping {
+const char   *scheme_uri;
+const struct  MP4TrackKindValueMapping *value_maps;
+};
+
+extern const struct MP4TrackKindMapping ff_mov_track_kind_table[];
+
 #endif /* AVFORMAT_ISOM_H */
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c556390525..f34150d326 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -28,6 +28,7 @@
 #include 
 
 #include "libavutil/attributes.h"
+#include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
@@ -6834,6 +6835,72 @@ static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return 0;
 }
 
+static int mov_read_kind(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVFormatContext *ctx = c->fc;
+AVStream *st = NULL;
+char scheme_str[1024] = { 0 }, value_str[1024] = { 0 };
+int scheme_str_len = 0, value_str_len = 0;
+int version, flags;
+char *scheme = NULL, *value = NULL;
+int64_t size = atom.size;
+
+if (atom.size < 6)
+// 4 bytes for version + flags, 2x 1 byte for null
+return AVERROR_INVALIDDATA;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+version = avio_r8(pb);
+flags   = avio_rb24(pb);
+size   -= 4;
+
+if (version != 0 || flags != 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Unsupported 'kind' box with version %d, flags: %x",
+   version, flags);
+return AVERROR_INVALIDDATA;
+}
+
+scheme_str_len = avio_get_str(pb, size, scheme_str, sizeof(scheme_str));
+if (scheme_str_len < 0)
+return AVERROR_INVALIDDATA;
+
+if (scheme_str_len == size)
+// we need to have another string, even if nullptr
+return AVERROR_INVALIDDATA;
+
+size -= scheme_str_len;
+
+value_str_len = avio_get_str(pb, size, value_str, sizeof(value_str));
+if (value_str_len < 0)
+return AVERROR_INVALIDDATA;
+
+av_log(ctx, AV_LOG_TRACE,
+   "%s stream %d KindBox(scheme: %s, value: %s)\n",
+   av_get_media_type_string(st->codecpar->codec_type),
+   st->index,
+   scheme_str, value_str);
+
+for (int i = 0; ff_mov_track_kind_table[i].scheme_uri; i++) {
+const struct MP4TrackKindMapping map = ff_mov_track_kind_table[i];
+if (!av_strstart(scheme_str, map.scheme_uri, NULL))
+continue;
+
+for (int 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: add support for setting chroma sample location

2021-08-29 Thread Jan Ekström
On Fri, Aug 27, 2021 at 12:58 AM Jan Ekström  wrote:
>
> On Tue, Aug 24, 2021 at 12:47 AM Jan Ekström  wrote:
> >
> > ---
> >  libavcodec/libx264.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index d48e142e41..379c167e6f 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -870,6 +870,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
> >  x4->params.vui.i_colorprim = avctx->color_primaries;
> >  if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
> >  x4->params.vui.i_transfer  = avctx->color_trc;
> > +if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED)
> > +x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
> >
> >  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
> >  x4->params.b_repeat_headers = 0;
> > --
> > 2.31.1
> >
>
> I have re-tested these changes (for both x264 and x265), and BT.2100
> content that was marked with topleft chroma location now gets that
> information passed onto the output (whereas previously the content
> would get interpreted as with the implicit "left" value). Thus, unless
> there are objections, I will pull this set in soon.
>
> The only difference in default would be with unlabeled H.264/HEVC with
> streams that get that default value ("left") interpreted. Previously,
> as there was no support for writing the data, those streams would stay
> without any metadata on the output side, while now, as libavcodec
> doesn't differentiate between implicit and explicit values, the value
> gets written into the output, making an implicit value explicit. As
> far as whether this is a problem, I would consider it a "no", as the
> decoding result should be the same (due to the implicit default).

Applied the x264 patch as 2f0113be3ffb566f1bb7f3140f038318c447da9f
after checking that x264 ignores chroma sample location for
non-CHROMA_420 pix_fmts.

Will be posting a v2 of the x265 patch as it requires this logic to be
in the API client.

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] [PATCH v2 2/2] avcodec/libx265: add support for setting chroma sample location

2021-08-29 Thread Jan Ekström
Unlike libx264, libx265 does not handle the chroma format check
on its own side, so in order to not write out values which are
supposed to be ignored according to the specification, we limit
the writing out of chroma sample location to 4:2:0 only.
---
 libavcodec/libx265.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 71affbf61b..839b6ce9de 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -211,6 +211,19 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 ctx->params->vui.matrixCoeffs= avctx->colorspace;
 }
 
+// chroma sample location values are to be ignored in case of non-4:2:0
+// according to the specification, so we only write them out in case of
+// 4:2:0 (log2_chroma_{w,h} == 1).
+ctx->params->vui.bEnableChromaLocInfoPresentFlag =
+avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
+desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1;
+
+if (ctx->params->vui.bEnableChromaLocInfoPresentFlag) {
+ctx->params->vui.chromaSampleLocTypeTopField =
+ctx->params->vui.chromaSampleLocTypeBottomField =
+avctx->chroma_sample_location - 1;
+}
+
 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 
0) {
 char sar[12];
 int sar_num, sar_den;
-- 
2.31.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/2] avcodec/libx265: only call av_pix_fmt_desc_get once in init

2021-08-29 Thread Jan Ekström
Now both current usages utilize an already found descriptor.
---
 libavcodec/libx265.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index b5c94b64a3..71affbf61b 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -124,9 +124,10 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 {
 libx265Context *ctx = avctx->priv_data;
 AVCPBProperties *cpb_props = NULL;
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 int ret;
 
-ctx->api = 
x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth);
+ctx->api = x265_api_get(desc->comp[0].depth);
 if (!ctx->api)
 ctx->api = x265_api_get(0);
 
@@ -186,7 +187,7 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 avctx->color_range == AVCOL_RANGE_JPEG;
 else
 ctx->params->vui.bEnableVideoFullRangeFlag =
-(av_pix_fmt_desc_get(avctx->pix_fmt)->flags & AV_PIX_FMT_FLAG_RGB) 
||
+(desc->flags & AV_PIX_FMT_FLAG_RGB) ||
 avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
 avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
 avctx->pix_fmt == AV_PIX_FMT_YUVJ444P;
-- 
2.31.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".


Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set the RGB matrix coefficients in case of RGB

2021-08-29 Thread Jan Ekström
On Sun, Aug 29, 2021 at 9:21 PM Paul B Mahol  wrote:
>
> probably fine if fate passes

Yea, FATE passes :) . I think this stuff not being noticed until now
is due to nothing checking the metadata values returned by vf_scale
(since pix_fmt and actual logic is not changed at all with these
output AVFrame metadata changes):
- The first fix I did was for RGB->YCbCr still being flagged as RGB
(and thus encoders like the libx264 wrapper would gladly comply,
leading to bugs like issue #9132 )
- This one fixes the opposite conversion where your YCbCr input has
matrix coefficients configured, and the RGB output still has that
value as-is from the av_frame_copy_props call (and once again, encoder
complies).

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".


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx265: only call av_pix_fmt_desc_get once in init

2021-08-29 Thread Jan Ekström
On Sun, Aug 29, 2021 at 8:12 PM Paul B Mahol  wrote:
>
> LGTM

Thanks, applied this patch as 06ce821bc7622c1394c5179fb69cabf02dd24869 .

Now it's just the chroma location coding bits.

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".


Re: [FFmpeg-devel] [PATCH v2 2/2] avcodec/libx265: add support for setting chroma sample location

2021-08-30 Thread Jan Ekström
On Sun, Aug 29, 2021 at 7:43 PM Jan Ekström  wrote:
>
> Unlike libx264, libx265 does not handle the chroma format check
> on its own side, so in order to not write out values which are
> supposed to be ignored according to the specification, we limit
> the writing out of chroma sample location to 4:2:0 only.
> ---
>  libavcodec/libx265.c | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index 71affbf61b..839b6ce9de 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -211,6 +211,19 @@ static av_cold int libx265_encode_init(AVCodecContext 
> *avctx)
>  ctx->params->vui.matrixCoeffs= avctx->colorspace;
>  }
>
> +// chroma sample location values are to be ignored in case of non-4:2:0
> +// according to the specification, so we only write them out in case of
> +// 4:2:0 (log2_chroma_{w,h} == 1).
> +ctx->params->vui.bEnableChromaLocInfoPresentFlag =
> +avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED &&
> +desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1;

Checked this another time, and this check seems correct. HWAccel
pix_fmts like VAAPI are also marked as 4:2:0, but thankfully they're
not on the supported list for this module.

For the source of the check, it is based on the following in the specification:

Otherwise  (chroma_format_idc  is  not  equal  to  1),  the  values
of  the  syntax  elements chroma_sample_loc_type_top_field  and
chroma_sample_loc_type_bottom_field  shall  be  ignored.  When
chroma_format_idc is equal to 2 (4:2:2 chroma format) or 3 (4:4:4
chroma format), the location of chroma samples is specified in clause
6.2. When chroma_format_idc is equal to 0, there is no chroma sample
array.

> +
> +if (ctx->params->vui.bEnableChromaLocInfoPresentFlag) {
> +ctx->params->vui.chromaSampleLocTypeTopField =
> +ctx->params->vui.chromaSampleLocTypeBottomField =
> +avctx->chroma_sample_location - 1;
> +}

For progressive content both values should be set to the same value.

For interlaced content in theory the chroma location field value is
not necessarily the same, but:
1. we have a single value in our APIs
2. x264 does this exact same thing, utilizes a single value interface
and sets both fields to the same value.

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".


Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set the RGB matrix coefficients in case of RGB

2021-08-30 Thread Jan Ekström
On Sun, Aug 29, 2021 at 10:05 PM Jan Ekström  wrote:
>
> On Sun, Aug 29, 2021 at 9:21 PM Paul B Mahol  wrote:
> >
> > probably fine if fate passes
>
> Yea, FATE passes :) . I think this stuff not being noticed until now
> is due to nothing checking the metadata values returned by vf_scale
> (since pix_fmt and actual logic is not changed at all with these
> output AVFrame metadata changes):
> - The first fix I did was for RGB->YCbCr still being flagged as RGB
> (and thus encoders like the libx264 wrapper would gladly comply,
> leading to bugs like issue #9132 )
> - This one fixes the opposite conversion where your YCbCr input has
> matrix coefficients configured, and the RGB output still has that
> value as-is from the av_frame_copy_props call (and once again, encoder
> complies).

If there are no further comments, I will soon apply this to fix both
sides of the YCbCr<->RGB conversion output in case the input format
happens to have the matrix coefficients configured (and thus copied
over by av_frame_copy_props). These can then be back-ported to 4.4
since it was the first release to plug input/filtered AVFrames'
metadata into output, which brought the issue of input metadata being
passed through as-is up.

The only question in my mind was whether to set it to
AVCOL_SPC_UNSPECIFIED or AVCOL_SPC_RGB . I chose the latter one since
the value literally matches what we are checking there: If output
pix_fmt is RGB, set output value to RGB.

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] [PATCH v2 1/2] avformat/{isom, mov, movenc}: add support for CMAF DASH roles

2021-08-30 Thread Jan Ekström
From: Jan Ekström 

This information is coded in a standard MP4 KindBox and utilizes the
scheme and values as per the DASH role scheme defined in MPEG-DASH.
Other schemes are technically allowed, but where multiple schemes
define the same concepts, the DASH scheme should be utilized.

Such flagging is additionally utilized by the DASH-IF CMAF ingest
specification, enabling an encoder to inform the following component
of the roles of the incoming media streams.

A test is added for this functionality in a similar manner to the
matroska test.

Signed-off-by: Jan Ekström 
---
 libavformat/isom.c| 19 +
 libavformat/isom.h| 12 +++
 libavformat/mov.c | 67 +++
 libavformat/movenc.c  | 51 
 tests/fate/mov.mak|  9 +++
 .../ref/fate/mov-mp4-disposition-mpegts-remux | 81 +++
 6 files changed, 239 insertions(+)
 create mode 100644 tests/ref/fate/mov-mp4-disposition-mpegts-remux

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 4df5440023..300ba927c2 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -430,3 +430,22 @@ void ff_mov_write_chan(AVIOContext *pb, int64_t 
channel_layout)
 }
 avio_wb32(pb, 0);  // mNumberChannelDescriptions
 }
+
+static const struct MP4TrackKindValueMapping dash_role_map[] = {
+{ AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_CAPTIONS,
+"caption" },
+{ AV_DISPOSITION_COMMENT,
+"commentary" },
+{ AV_DISPOSITION_VISUAL_IMPAIRED|AV_DISPOSITION_DESCRIPTIONS,
+"description" },
+{ AV_DISPOSITION_DUB,
+"dub" },
+{ AV_DISPOSITION_FORCED,
+"forced-subtitle" },
+{ 0, NULL }
+};
+
+const struct MP4TrackKindMapping ff_mov_track_kind_table[] = {
+{ "urn:mpeg:dash:role:2011", dash_role_map },
+{ 0, NULL }
+};
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 34a58c79b7..c62fcf2bfe 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -390,4 +390,16 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int 
bps, int flags)
 #define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
 #define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
 
+struct MP4TrackKindValueMapping {
+int disposition;
+const char *value;
+};
+
+struct MP4TrackKindMapping {
+const char   *scheme_uri;
+const struct  MP4TrackKindValueMapping *value_maps;
+};
+
+extern const struct MP4TrackKindMapping ff_mov_track_kind_table[];
+
 #endif /* AVFORMAT_ISOM_H */
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c5583e07c7..4330736fa3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -28,6 +28,7 @@
 #include 
 
 #include "libavutil/attributes.h"
+#include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
@@ -6835,6 +6836,71 @@ static int mov_read_dvcc_dvvc(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return 0;
 }
 
+static int mov_read_kind(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVFormatContext *ctx = c->fc;
+AVStream *st = NULL;
+char scheme_str[1024] = { 0 }, value_str[1024] = { 0 };
+int scheme_str_len = 0, value_str_len = 0;
+int version, flags;
+int64_t size = atom.size;
+
+if (atom.size < 6)
+// 4 bytes for version + flags, 2x 1 byte for null
+return AVERROR_INVALIDDATA;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+version = avio_r8(pb);
+flags   = avio_rb24(pb);
+size   -= 4;
+
+if (version != 0 || flags != 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Unsupported 'kind' box with version %d, flags: %x",
+   version, flags);
+return AVERROR_INVALIDDATA;
+}
+
+scheme_str_len = avio_get_str(pb, size, scheme_str, sizeof(scheme_str));
+if (scheme_str_len < 0)
+return AVERROR_INVALIDDATA;
+
+if (scheme_str_len == size)
+// we need to have another string, even if nullptr
+return AVERROR_INVALIDDATA;
+
+size -= scheme_str_len;
+
+value_str_len = avio_get_str(pb, size, value_str, sizeof(value_str));
+if (value_str_len < 0)
+return AVERROR_INVALIDDATA;
+
+av_log(ctx, AV_LOG_TRACE,
+   "%s stream %d KindBox(scheme: %s, value: %s)\n",
+   av_get_media_type_string(st->codecpar->codec_type),
+   st->index,
+   scheme_str, value_str);
+
+for (int i = 0; ff_mov_track_kind_table[i].scheme_uri; i++) {
+const struct MP4TrackKindMapping map = ff_mov_track_kind_table[i];
+if (!av_strstart(scheme_str, map.scheme_uri, NULL))
+continue;
+
+for (int j = 0; map.value_m

[FFmpeg-devel] [PATCH v2 0/2] Support for stream dispositions in MP4

2021-08-30 Thread Jan Ekström
First patch implements the CMAF specified way of flagging what in FFmpeg
are are called stream dispositions. Other identifiers such as HTML media track
kinds are allowed, but if there is a DASH identifier for something, it should
be utilized in stead.

Second patch is a compatibility patch for one of the vendors that supports this
feature. If this is considered a too bad of a hack, we can drop it from being
upstreamed, but at least I wanted to bring it up :) . The compatibility mode
is not the default, so it should also not proliferate such behavior.

Compared to first version:
* Missed unused variables causing additional warnings were removed.

Best regards,
Jan

Jan Ekström (2):
  avformat/{isom,mov,movenc}: add support for CMAF DASH roles
  avformat/{isom,movenc}: add kind box compatibility mode for Unified
Origin

 libavformat/isom.c| 32 
 libavformat/isom.h| 18 +
 libavformat/mov.c | 67 +++
 libavformat/movenc.c  | 57 +
 libavformat/movenc.h  |  2 +
 tests/fate/mov.mak| 17 
 .../ref/fate/mov-mp4-disposition-mpegts-remux | 81 +++
 ...p4-disposition-unified-origin-mpegts-remux | 81 +++
 8 files changed, 355 insertions(+)
 create mode 100644 tests/ref/fate/mov-mp4-disposition-mpegts-remux
 create mode 100644 
tests/ref/fate/mov-mp4-disposition-unified-origin-mpegts-remux

-- 
2.31.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 v2 2/2] avformat/{isom, movenc}: add kind box compatibility mode for Unified Origin

2021-08-30 Thread Jan Ekström
From: Jan Ekström 

Unfortunately the current production versions of this software
do not 100% adhere to the CMAF specification, and have decided
to utilize the HTML5 media track identifier for audio descriptions.

This way the default mode of operation is according to the CMAF
specification, but it is also possible to output streams with which
this piece of software is capable of interoperating with.

Signed-off-by: Jan Ekström 
---
 libavformat/isom.c| 23 --
 libavformat/isom.h|  6 ++
 libavformat/movenc.c  | 12 ++-
 libavformat/movenc.h  |  2 +
 tests/fate/mov.mak|  8 ++
 ...p4-disposition-unified-origin-mpegts-remux | 81 +++
 6 files changed, 124 insertions(+), 8 deletions(-)
 create mode 100644 
tests/ref/fate/mov-mp4-disposition-unified-origin-mpegts-remux

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 300ba927c2..fb8ad3d824 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -433,19 +433,32 @@ void ff_mov_write_chan(AVIOContext *pb, int64_t 
channel_layout)
 
 static const struct MP4TrackKindValueMapping dash_role_map[] = {
 { AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_CAPTIONS,
-"caption" },
+"caption",
+KindWritingModeCMAF|KindWritingModeUnifiedOrigin },
 { AV_DISPOSITION_COMMENT,
-"commentary" },
+"commentary",
+KindWritingModeCMAF|KindWritingModeUnifiedOrigin },
 { AV_DISPOSITION_VISUAL_IMPAIRED|AV_DISPOSITION_DESCRIPTIONS,
-"description" },
+"description",
+KindWritingModeCMAF },
 { AV_DISPOSITION_DUB,
-"dub" },
+"dub",
+KindWritingModeCMAF|KindWritingModeUnifiedOrigin },
 { AV_DISPOSITION_FORCED,
-"forced-subtitle" },
+"forced-subtitle",
+KindWritingModeCMAF|KindWritingModeUnifiedOrigin },
+{ 0, NULL }
+};
+
+static const struct MP4TrackKindValueMapping html_kind_map[] = {
+{ AV_DISPOSITION_VISUAL_IMPAIRED|AV_DISPOSITION_DESCRIPTIONS,
+"main-desc",
+ KindWritingModeUnifiedOrigin },
 { 0, NULL }
 };
 
 const struct MP4TrackKindMapping ff_mov_track_kind_table[] = {
 { "urn:mpeg:dash:role:2011", dash_role_map },
+{ "about:html-kind", html_kind_map },
 { 0, NULL }
 };
diff --git a/libavformat/isom.h b/libavformat/isom.h
index c62fcf2bfe..1252fc6603 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -390,9 +390,15 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int 
bps, int flags)
 #define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
 #define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
 
+enum MP4TrackKindWritingMode {
+KindWritingModeCMAF  = (1 << 0),
+KindWritingModeUnifiedOrigin = (1 << 1),
+};
+
 struct MP4TrackKindValueMapping {
 int disposition;
 const char *value;
+uint32_twriting_modes;
 };
 
 struct MP4TrackKindMapping {
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4070fc9ef7..baaae7d3ad 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -111,6 +111,9 @@ static const AVOption options[] = {
 { "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = MOV_PRFT_SRC_PTS}, 0, 0, 
AV_OPT_FLAG_ENCODING_PARAM, "prft"},
 { "empty_hdlr_name", "write zero-length name string in hdlr atoms within 
mdia and minf atoms", offsetof(MOVMuxContext, empty_hdlr_name), 
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
 { "movie_timescale", "set movie timescale", offsetof(MOVMuxContext, 
movie_timescale), AV_OPT_TYPE_INT, {.i64 = MOV_TIMESCALE}, 1, INT_MAX, 
AV_OPT_FLAG_ENCODING_PARAM},
+{ "kind_writing_mode", "set kind box writing mode", 
offsetof(MOVMuxContext, kind_writing_mode), AV_OPT_TYPE_INT, {.i64 = 
KindWritingModeCMAF}, KindWritingModeCMAF, KindWritingModeUnifiedOrigin, 
AV_OPT_FLAG_ENCODING_PARAM, "kind_writing_mode"},
+{ "cmaf", "CMAF writing mode", 0, AV_OPT_TYPE_CONST, {.i64 = 
KindWritingModeCMAF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"kind_writing_mode"},
+{ "unified_origin", "Compatibility mode for Unified Origin (all DASH 
except for audio description)", 0, AV_OPT_TYPE_CONST, {.i64 = 
KindWritingModeUnifiedOrigin}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"kind_writing_mode"},
 { NULL },
 };
 
@@ -3355,7 +3358,8 @@ static int mov_write_track_kind(AVIOContext *pb, const 
char *scheme_uri,
 return update_size(pb, pos);
 }
 
-static int mov_write_track_kinds(AVIOContext *pb, AVStream *st)
+static int mov_write_track_kinds(AVIOContext *pb, AVStream *st,
+ enum MP4

[FFmpeg-devel] [PATCH v4 0/2] TTML in MP4, part 1

2021-08-16 Thread Jan Ekström
To keep it simpler this first part includes only non-fragmented use
cases if the built-in sample squashing is utilized. Contains the basic
mapping code as well as the function that writes out the squashed documents.

Works with both subtitle-only output as well as with other streams.

In a separate patch set I will add additional complexity on top
by introducing fragmentation matching based on the other streams in
the mux (since most things that ingest fragmented MP4 with subtitles
want the fragment time ranges to match between the video/audio streams
and subtitles in the mux).

Changes from v3:

* avformat/ttmlenc: added const to the function argument codecpar, and switched
included header from avformat.h to specifically
libavcodec/codec_par.h according to comments from Andreas.
* avformat/movenc_ttml: applied recommendation from Andreas to deduplicate
AVFormatContext cleanup.

Jan

Jan Ekström (2):
  avformat/ttml: split TTML paragraph based or not check into header
  avformat/movenc: add support for TTML muxing

 libavformat/Makefile |   2 +-
 libavformat/isom.h   |   3 +
 libavformat/movenc.c | 179 ++-
 libavformat/movenc.h |   5 +
 libavformat/movenc_ttml.c| 171 +
 libavformat/movenc_ttml.h|  31 ++
 libavformat/ttmlenc.c|   9 +-
 libavformat/ttmlenc.h|  39 +++
 tests/fate/subtitles.mak |   4 +
 tests/ref/fate/sub-ttml-mp4-dfxp |  44 
 tests/ref/fate/sub-ttml-mp4-stpp |  44 
 11 files changed, 521 insertions(+), 10 deletions(-)
 create mode 100644 libavformat/movenc_ttml.c
 create mode 100644 libavformat/movenc_ttml.h
 create mode 100644 libavformat/ttmlenc.h
 create mode 100644 tests/ref/fate/sub-ttml-mp4-dfxp
 create mode 100644 tests/ref/fate/sub-ttml-mp4-stpp

-- 
2.31.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 v4 1/2] avformat/ttml: split TTML paragraph based or not check into header

2021-08-16 Thread Jan Ekström
From: Jan Ekström 

This way it can be re-utilized in movenc.

Signed-off-by: Jan Ekström 
---
 libavformat/ttmlenc.c |  9 ++---
 libavformat/ttmlenc.h | 39 +++
 2 files changed, 41 insertions(+), 7 deletions(-)
 create mode 100644 libavformat/ttmlenc.h

diff --git a/libavformat/ttmlenc.c b/libavformat/ttmlenc.c
index 8546d35196..896fc81958 100644
--- a/libavformat/ttmlenc.c
+++ b/libavformat/ttmlenc.c
@@ -30,6 +30,7 @@
 #include "libavutil/avstring.h"
 #include "avformat.h"
 #include "internal.h"
+#include "ttmlenc.h"
 #include "libavcodec/ttmlenc.h"
 #include "libavutil/internal.h"
 
@@ -138,13 +139,7 @@ static int ttml_write_header(AVFormatContext *ctx)
   0);
 const char *printed_lang = (lang && lang->value) ? lang->value : "";
 
-// Not perfect, but decide whether the packet is a document or not
-// by the existence of the lavc ttmlenc extradata.
-ttml_ctx->input_type = (st->codecpar->extradata &&
-st->codecpar->extradata_size >= 
TTMLENC_EXTRADATA_SIGNATURE_SIZE &&
-!memcmp(st->codecpar->extradata,
-TTMLENC_EXTRADATA_SIGNATURE,
-TTMLENC_EXTRADATA_SIGNATURE_SIZE)) ?
+ttml_ctx->input_type = ff_is_ttml_stream_paragraph_based(st->codecpar) 
?
PACKET_TYPE_PARAGRAPH :
PACKET_TYPE_DOCUMENT;
 
diff --git a/libavformat/ttmlenc.h b/libavformat/ttmlenc.h
new file mode 100644
index 00..5a6954f3c1
--- /dev/null
+++ b/libavformat/ttmlenc.h
@@ -0,0 +1,39 @@
+/*
+ * Generic TTML helpers
+ * Copyright (c) 2021 24i
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_TTMLENC_H
+#define AVFORMAT_TTMLENC_H
+
+#include "libavcodec/codec_par.h"
+#include "libavcodec/ttmlenc.h"
+
+static inline unsigned int ff_is_ttml_stream_paragraph_based(const 
AVCodecParameters *codecpar)
+{
+// Not perfect, but decide whether the packet is a document or not
+// by the existence of the lavc ttmlenc extradata.
+return (codecpar->extradata &&
+codecpar->extradata_size >= TTMLENC_EXTRADATA_SIGNATURE_SIZE &&
+!memcmp(codecpar->extradata,
+TTMLENC_EXTRADATA_SIGNATURE,
+TTMLENC_EXTRADATA_SIGNATURE_SIZE));
+}
+
+#endif /* AVFORMAT_TTMLENC_H */
-- 
2.31.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 v4 2/2] avformat/movenc: add support for TTML muxing

2021-08-16 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| 171 +
 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, 480 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 bcc202300b..1bb948769c 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -57,6 +57,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[] = {
@@ -120,6 +122,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)
 {
@@ -1788,7 +1791,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 &&
@@ -2662,6 +2687,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);
@@ -2788,6 +2821,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

[FFmpeg-devel] [PATCH] avformat/isom_tags: prefer in24 for 24bit PCM in MOV

2021-08-14 Thread Jan Ekström
In 1c42fd93236e7869ef4d9fe3650dd3e951387321 the ipcm identifier was
added in order to demux additional raw audio from Sony MP4 files.
Unfortunately, it was not noticed that this same list is utilized
for muxing as well, thus causing ipcm to get preferred compared
to the identifier officially specified in QTFF documentation.

This fixes the order of preference for 24bit PCM, where ipcm is
still allowed, but in24 is the first match - thus being preferred.

Fixes fate-acodec-pcm-s24be.
---
 libavformat/isom_tags.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
index e2e589b658..d0400b18fc 100644
--- a/libavformat/isom_tags.c
+++ b/libavformat/isom_tags.c
@@ -312,10 +312,10 @@ const AVCodecTag ff_codec_movaudio_tags[] = {
 { AV_CODEC_ID_PCM_S16LE,   MKTAG('s', 'o', 'w', 't') },
 { AV_CODEC_ID_PCM_S16BE,   MKTAG('l', 'p', 'c', 'm') },
 { AV_CODEC_ID_PCM_S16LE,   MKTAG('l', 'p', 'c', 'm') },
-{ AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'p', 'c', 'm') },
-{ AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'p', 'c', 'm') },
 { AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'n', '2', '4') },
 { AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'n', '2', '4') },
+{ AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'p', 'c', 'm') },
+{ AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'p', 'c', 'm') },
 { AV_CODEC_ID_PCM_S32BE,   MKTAG('i', 'n', '3', '2') },
 { AV_CODEC_ID_PCM_S32LE,   MKTAG('i', 'n', '3', '2') },
 { AV_CODEC_ID_PCM_S8,  MKTAG('s', 'o', 'w', 't') },
-- 
2.31.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".


Re: [FFmpeg-devel] [PATCH] avformat/isom_tags: prefer in24 for 24bit PCM in MOV

2021-08-14 Thread Jan Ekström
On Sat, Aug 14, 2021 at 8:25 PM Paul B Mahol  wrote:
>
> Patch is OK, apply at will.

Thanks, applied as 087fbfe5bc2272aa1cfd9f4c49438436b68a1ddc .

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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] libavformat/isom_tags.c: add ipcm to list of tags

2021-08-14 Thread Jan Ekström
On Sat, Aug 14, 2021 at 7:43 PM Andriy Gelman  wrote:
>
> On Sat, 14. Aug 12:14, Stephen Hutchinson wrote:
> > ffmpeg | branch: master | Stephen Hutchinson  | Wed Jul 
> > 14 20:16:41 2021 -0400| [1c42fd93236e7869ef4d9fe3650dd3e951387321] | 
> > committer: Paul B Mahol
> >
> > libavformat/isom_tags.c: add ipcm to list of tags
> >
> > Fixes http://trac.ffmpeg.org/ticket/9219
> >
> > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1c42fd93236e7869ef4d9fe3650dd3e951387321
> > ---
> >
> >  libavformat/isom_tags.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
> > index 1666b9d4a5..e2e589b658 100644
> > --- a/libavformat/isom_tags.c
> > +++ b/libavformat/isom_tags.c
> > @@ -312,6 +312,8 @@ const AVCodecTag ff_codec_movaudio_tags[] = {
> >  { AV_CODEC_ID_PCM_S16LE,   MKTAG('s', 'o', 'w', 't') },
> >  { AV_CODEC_ID_PCM_S16BE,   MKTAG('l', 'p', 'c', 'm') },
> >  { AV_CODEC_ID_PCM_S16LE,   MKTAG('l', 'p', 'c', 'm') },
> > +{ AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'p', 'c', 'm') },
> > +{ AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'p', 'c', 'm') },
> >  { AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'n', '2', '4') },
> >  { AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'n', '2', '4') },
> >  { AV_CODEC_ID_PCM_S32BE,   MKTAG('i', 'n', '3', '2') },
> >
>
> This break fate for me:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210715001641.2598-1-qyo...@gmail.com/
>

Seems like it just wasn't noticed that ff_codec_movaudio_tags is
utilized for both demux and mux; Thus putting ipcm earlier in the list
compared to in24 meant that instead of the standard MOV/QTFF PCM tag
the ipcm one got picked by default (as it was the first matching
identifier).

After a cursory look I cannot find references to ipcm in either QTFF
or ISOBMFF specs, so I'd say we just pull in24 to before ipcm in the
order for signed 24bit audio (both of the lines visible in the
context). This fixes the test as well as makes us default to the QTFF
specified identifier again.

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".


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libx265: improve full range flag setting logic

2021-08-18 Thread Jan Ekström
On Wed, Aug 18, 2021 at 4:36 AM myp...@gmail.com  wrote:
>
> On Wed, Aug 18, 2021 at 5:01 AM Jan Ekström  wrote:
> >
> > Unlike libx264, libx265 does not have a separate "unspecified"/"auto"
> > default for color range, so we do always have to specify it.
> > Thus, we are required to handle the RGB case on the libavcodec
> > side to enable the correct value to be written out in in case
> > of RGB content with unspecified color range being received.
> >
> > In other words:
> > 1. If the user has set color range specifically, follow that.
> > 2. If the user has not set color range specifically, set full
> >range by default in case of RGB and YUVJ pixel formats.
> > ---
> >  libavcodec/libx265.c | 13 +
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> > index 9395120471..b5c94b64a3 100644
> > --- a/libavcodec/libx265.c
> > +++ b/libavcodec/libx265.c
> > @@ -181,10 +181,15 @@ static av_cold int libx265_encode_init(AVCodecContext 
> > *avctx)
> >
> >  ctx->params->vui.bEnableVideoSignalTypePresentFlag = 1;
> >
> > -ctx->params->vui.bEnableVideoFullRangeFlag = avctx->pix_fmt == 
> > AV_PIX_FMT_YUVJ420P ||
> > - avctx->pix_fmt == 
> > AV_PIX_FMT_YUVJ422P ||
> > - avctx->pix_fmt == 
> > AV_PIX_FMT_YUVJ444P ||
> > - avctx->color_range == 
> > AVCOL_RANGE_JPEG;
> > +if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
> > +ctx->params->vui.bEnableVideoFullRangeFlag =
> > +avctx->color_range == AVCOL_RANGE_JPEG;
> > +else
> > +ctx->params->vui.bEnableVideoFullRangeFlag =
> > +(av_pix_fmt_desc_get(avctx->pix_fmt)->flags & 
> > AV_PIX_FMT_FLAG_RGB) ||
> > +avctx->pix_fmt == AV_PIX_FMT_YUVJ420P ||
> > +avctx->pix_fmt == AV_PIX_FMT_YUVJ422P ||
> > +avctx->pix_fmt == AV_PIX_FMT_YUVJ444P;
> >
> >  if ((avctx->color_primaries <= AVCOL_PRI_SMPTE432 &&
> >   avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
> > --
> > 2.31.1
> Patchset LGTM

Thanks, applied as 7ca71b79f2b3256a0eef1a099b857ac9e4017e36 and
dbe40478e293f78c5a5e4302eb3f38257106ee86 .

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".


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libx264: leave full range flag unchanged if unknown

2021-08-18 Thread Jan Ekström
On Wed, Aug 18, 2021 at 10:00 AM Paul B Mahol  wrote:
>
> lgtm

Thanks, applied as 7ca71b79f2b3256a0eef1a099b857ac9e4017e36 .

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] [PATCH 2/2] avcodec/libx265: add support for setting chroma sample location

2021-08-23 Thread Jan Ekström
---
 libavcodec/libx265.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index b5c94b64a3..c58882170b 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -210,6 +210,14 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
 ctx->params->vui.matrixCoeffs= avctx->colorspace;
 }
 
+if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
+ctx->params->vui.bEnableChromaLocInfoPresentFlag = 1;
+
+ctx->params->vui.chromaSampleLocTypeTopField =
+ctx->params->vui.chromaSampleLocTypeBottomField =
+avctx->chroma_sample_location - 1;
+}
+
 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 
0) {
 char sar[12];
 int sar_num, sar_den;
-- 
2.31.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/2] avcodec/libx264: add support for setting chroma sample location

2021-08-23 Thread Jan Ekström
---
 libavcodec/libx264.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index d48e142e41..379c167e6f 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -870,6 +870,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
 x4->params.vui.i_colorprim = avctx->color_primaries;
 if (avctx->color_trc != AVCOL_TRC_UNSPECIFIED)
 x4->params.vui.i_transfer  = avctx->color_trc;
+if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED)
+x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
 
 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
 x4->params.b_repeat_headers = 0;
-- 
2.31.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] tests/fate: move TTML-in-MP4 tests from subtitles.mak to mov.mak

2021-08-25 Thread Jan Ekström
subtitles.mak utilizes a more strict comparator and - to be honest -
the tests feel more at home in this location.
---
 tests/fate/mov.mak  | 4 
 tests/fate/subtitles.mak| 4 
 tests/ref/fate/{sub-ttml-mp4-dfxp => mov-mp4-ttml-dfxp} | 4 ++--
 tests/ref/fate/{sub-ttml-mp4-stpp => mov-mp4-ttml-stpp} | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)
 rename tests/ref/fate/{sub-ttml-mp4-dfxp => mov-mp4-ttml-dfxp} (90%)
 rename tests/ref/fate/{sub-ttml-mp4-stpp => mov-mp4-ttml-stpp} (90%)

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 4c1014be92..0c9177aa81 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -132,6 +132,10 @@ FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL 
MOV_DEMUXER MJPEG_DECODER \
   += fate-mov-cover-image
 fate-mov-cover-image: CMD = transcode mov 
$(TARGET_SAMPLES)/cover_art/Owner-iTunes_9.0.3.15.m4a mp4 "-map 0 -map 0:v -c:a 
copy -c:v:0 copy -filter:v:1 scale -c:v:1 png" "-map 0 -t 0.1 -c copy" "" 
"-show_entries stream_disposition=attached_pic:stream=index,codec_name"
 
+FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL SRT_DEMUXER MOV_DEMUXER 
SUBRIP_DECODER TTML_ENCODER TTML_MUXER MOV_MUXER) += fate-mov-mp4-ttml-stpp 
fate-mov-mp4-ttml-dfxp
+fate-mov-mp4-ttml-stpp: CMD = transcode srt 
$(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt mp4 "-map 0:s -c:s ttml 
-time_base:s 1:1000" "-map 0 -c copy" "" "-of json -show_entries 
packet:stream=index,codec_type,codec_tag_string,codec_tag,codec_name,time_base,start_time,duration_ts,duration,nb_frames,nb_read_packets:stream_tags"
+fate-mov-mp4-ttml-dfxp: CMD = transcode srt 
$(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt mp4 "-map 0:s -c:s ttml 
-time_base:s 1:1000 -tag:s dfxp -strict unofficial" "-map 0 -c copy" "" "-of 
json -show_entries 
packet:stream=index,codec_type,codec_tag_string,codec_tag,codec_name,time_base,start_time,duration_ts,duration,nb_frames,nb_read_packets:stream_tags"
+
 FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MOV_FFMPEG_FFPROBE-yes)
 
 fate-mov: $(FATE_MOV) $(FATE_MOV_FFPROBE) $(FATE_MOV_FASTSTART) 
$(FATE_MOV_FFMPEG_FFPROBE-yes)
diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
index 880109f201..ee65afe35b 100644
--- a/tests/fate/subtitles.mak
+++ b/tests/fate/subtitles.mak
@@ -109,10 +109,6 @@ fate-sub-dvb: CMD = framecrc -i 
$(TARGET_SAMPLES)/sub/dvbsubtest_filter.ts -map
 FATE_SUBTITLES-$(call ALLYES, FILE_PROTOCOL PIPE_PROTOCOL SRT_DEMUXER 
SUBRIP_DECODER TTML_ENCODER TTML_MUXER) += fate-sub-ttmlenc
 fate-sub-ttmlenc: CMD = fmtstdout ttml -i 
$(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt
 
-FATE_SUBTITLES-$(call ALLYES, FILE_PROTOCOL SRT_DEMUXER MOV_DEMUXER 
SUBRIP_DECODER TTML_ENCODER TTML_MUXER MOV_MUXER) += fate-sub-ttml-mp4-stpp 
fate-sub-ttml-mp4-dfxp
-fate-sub-ttml-mp4-stpp: CMD = transcode srt 
$(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt mp4 "-map 0:s -c:s ttml 
-time_base:s 1:1000" "-map 0 -c copy" "" "-of json -show_entries 
packet:stream=index,codec_type,codec_tag_string,codec_tag,codec_name,time_base,start_time,duration_ts,duration,nb_frames,nb_read_packets:stream_tags"
-fate-sub-ttml-mp4-dfxp: CMD = transcode srt 
$(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt mp4 "-map 0:s -c:s ttml 
-time_base:s 1:1000 -tag:s dfxp -strict unofficial" "-map 0 -c copy" "" "-of 
json -show_entries 
packet:stream=index,codec_type,codec_tag_string,codec_tag,codec_name,time_base,start_time,duration_ts,duration,nb_frames,nb_read_packets:stream_tags"
-
 FATE_SUBTITLES-$(call ENCMUX, ASS, ASS) += $(FATE_SUBTITLES_ASS-yes)
 FATE_SUBTITLES += $(FATE_SUBTITLES-yes)
 
diff --git a/tests/ref/fate/sub-ttml-mp4-dfxp b/tests/ref/fate/mov-mp4-ttml-dfxp
similarity index 90%
rename from tests/ref/fate/sub-ttml-mp4-dfxp
rename to tests/ref/fate/mov-mp4-ttml-dfxp
index 0172e5b7e6..e24b5d618b 100644
--- a/tests/ref/fate/sub-ttml-mp4-dfxp
+++ b/tests/ref/fate/mov-mp4-ttml-dfxp
@@ -1,5 +1,5 @@
-2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/sub-ttml-mp4-dfxp.mp4
-8519 tests/data/fate/sub-ttml-mp4-dfxp.mp4
+2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/mov-mp4-ttml-dfxp.mp4
+8519 tests/data/fate/mov-mp4-ttml-dfxp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
diff --git a/tests/ref/fate/sub-ttml-mp4-stpp b/tests/ref/fate/mov-mp4-ttml-stpp
similarity index 90%
rename from tests/ref/fate/sub-ttml-mp4-stpp
rename to tests/ref/fate/mov-mp4-ttml-stpp
index a5165b568d..77bd23b7bf 100644
--- a/tests/ref/fate/sub-ttml-mp4-stpp
+++ b/tests/ref/fate/mov-mp4-ttml-stpp
@@ -1,5 +1,5 @@
-cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/sub-ttml-mp4-stpp.mp4
-8547 tests/data/fate/sub-ttml-mp4-stpp.mp4
+cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/mov-mp4-ttml-stpp.mp4
+8547 tests/data/fate/mov-mp4-ttml-stpp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-- 
2.31.1

___
ffmpeg-devel mailing list

<    2   3   4   5   6   7   8   9   10   11   >