Re: [FFmpeg-devel] [PATCH v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Paul B Mahol
LGTM, will apply if there are no objections in next 24h
___
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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Dennis Mungai
On Thu, 25 Nov 2021 at 12:04, Paul B Mahol  wrote:

> LGTM, will apply if there are no objections in next 24h


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

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


[FFmpeg-devel] [PATCH v3 1/2] avutil/hwcontext_vulkan: fully support customizable validation layers

2021-11-25 Thread Wu Jianhua
Validation layer is an indispensable part of developing on Vulkan.

The following commands is on how to enable validation layers:

ffmpeg -init_hw_device 
vulkan=0,debug=1,validation_layers=VK_LAYER_LUNARG_monitor+VK_LAYER_LUNARG_api_dump

Signed-off-by: Wu Jianhua 
---
 libavutil/hwcontext_vulkan.c | 164 ---
 libavutil/vulkan_functions.h |   1 +
 2 files changed, 136 insertions(+), 29 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 644ed947f8..515e27aad8 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -146,6 +146,13 @@ typedef struct AVVkFrameInternal {
 }  
\
 } while(0)
 
+#define RELEASE_PROPS(props, count)
\
+if (props) {   
\
+for (int i = 0; i < count; i++)
\
+av_free((void *)((props)[i])); 
\
+av_free((void *)props);
\
+}
+
 static const struct {
 enum AVPixelFormat pixfmt;
 const VkFormat vkfmts[4];
@@ -511,25 +518,129 @@ static int check_extensions(AVHWDeviceContext *ctx, int 
dev, AVDictionary *opts,
 return 0;
 
 fail:
-if (extension_names)
-for (int i = 0; i < extensions_found; i++)
-av_free((void *)extension_names[i]);
-av_free(extension_names);
+RELEASE_PROPS(extension_names, extensions_found);
 av_free(user_exts_str);
 av_free(sup_ext);
 return err;
 }
 
+static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
+   const char * const **dst, uint32_t *num, 
int *debug_mode)
+{
+static const char default_layer[] = { "VK_LAYER_KHRONOS_validation" };
+
+int found = 0, err = 0;
+VulkanDevicePriv *priv = ctx->internal->priv;
+FFVulkanFunctions *vk = &priv->vkfn;
+
+uint32_t sup_layer_count;
+VkLayerProperties *sup_layers;
+
+AVDictionaryEntry *user_layers;
+char *user_layers_str = NULL;
+char *save, *token;
+
+const char **enabled_layers = NULL;
+uint32_t enabled_layers_count = 0;
+
+AVDictionaryEntry *debug_opt = av_dict_get(opts, "debug", NULL, 0);
+int debug = debug_opt && strtol(debug_opt->value, NULL, 10);
+
+/* If `debug=0`, enable no layers at all. */
+if (debug_opt && !debug)
+return 0;
+
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, NULL);
+sup_layers = av_malloc_array(sup_layer_count, sizeof(VkLayerProperties));
+if (!sup_layers)
+return AVERROR(ENOMEM);
+vk->EnumerateInstanceLayerProperties(&sup_layer_count, sup_layers);
+
+av_log(ctx, AV_LOG_VERBOSE, "Supported validation layers:\n");
+for (int i = 0; i < sup_layer_count; i++)
+av_log(ctx, AV_LOG_VERBOSE, "\t%s\n", sup_layers[i].layerName);
+
+/* If `debug=1` is specified, enable the standard validation layer 
extension */
+if (debug) {
+*debug_mode = debug;
+for (int i = 0; i < sup_layer_count; i++) {
+if (!strcmp(default_layer, sup_layers[i].layerName)) {
+found = 1;
+av_log(ctx, AV_LOG_VERBOSE,
+"Default validation layer %s is enabled\n", default_layer);
+ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, 
default_layer);
+break;
+}
+}
+}
+
+user_layers = av_dict_get(opts, "validation_layers", NULL, 0);
+if (!user_layers)
+goto end;
+
+user_layers_str = av_strdup(user_layers->value);
+if (!user_layers_str) {
+err = AVERROR(EINVAL);
+goto fail;
+}
+
+token = av_strtok(user_layers_str, "+", &save);
+while (token) {
+found = 0;
+if (!strcmp(default_layer, token)) {
+if (debug) {
+/* if the `debug=1`, default_layer is enabled, skip here */
+token = av_strtok(NULL, "+", &save);
+continue;
+}
+else {
+/* if the `debug=0, enable debug mode to load its callback 
properly */
+*debug_mode = debug;
+}
+}
+for (int j = 0; j < sup_layer_count; j++) {
+if (!strcmp(token, sup_layers[j].layerName)) {
+found = 1;
+break;
+}
+}
+if (found) {
+av_log(ctx, AV_LOG_VERBOSE, "Requested Validation Layer: %s\n", 
token);
+ADD_VAL_TO_LIST(enabled_layers, enabled_layers_count, token);
+} else {
+av_log(ctx, AV_LOG_ERROR,
+   "Validation Layer \"%s\" not support.\n", token);
+err = AVERROR(EINVAL);
+goto fail;
+}
+token = av_strtok(NULL, "+", &save);
+}
+
+av_free(us

[FFmpeg-devel] [PATCH v3 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Wu Jianhua
This filter flips the input video both horizontally and vertically
in one compute pipeline, and it's no need to use two pipelines for
hflip_vulkan,vflip_vulkan anymore.

Signed-off-by: Wu Jianhua 
---
 configure|  1 +
 libavfilter/allfilters.c |  1 +
 libavfilter/vf_flip_vulkan.c | 39 +++-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d068b11073..a7562b53c3 100755
--- a/configure
+++ b/configure
@@ -3569,6 +3569,7 @@ atempo_filter_select="rdft"
 avgblur_opencl_filter_deps="opencl"
 avgblur_vulkan_filter_deps="vulkan spirv_compiler"
 azmq_filter_deps="libzmq"
+bflip_vulkan_filter_deps="vulkan spirv_compiler"
 blackframe_filter_deps="gpl"
 bm3d_filter_deps="avcodec"
 bm3d_filter_select="dct"
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4bf17ef292..041292853a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -175,6 +175,7 @@ extern const AVFilter ff_vf_avgblur_opencl;
 extern const AVFilter ff_vf_avgblur_vulkan;
 extern const AVFilter ff_vf_bbox;
 extern const AVFilter ff_vf_bench;
+extern const AVFilter ff_vf_bflip_vulkan;
 extern const AVFilter ff_vf_bilateral;
 extern const AVFilter ff_vf_bitplanenoise;
 extern const AVFilter ff_vf_blackdetect;
diff --git a/libavfilter/vf_flip_vulkan.c b/libavfilter/vf_flip_vulkan.c
index e9e04db91b..e20766e9ed 100644
--- a/libavfilter/vf_flip_vulkan.c
+++ b/libavfilter/vf_flip_vulkan.c
@@ -26,7 +26,8 @@
 
 enum FlipType {
 FLIP_VERTICAL,
-FLIP_HORIZONTAL
+FLIP_HORIZONTAL,
+FLIP_BOTH
 };
 
 typedef struct FlipVulkanContext {
@@ -104,6 +105,9 @@ static av_cold int init_filter(AVFilterContext *ctx, 
AVFrame *in, enum FlipType
 case FLIP_VERTICAL:
 GLSLF(2, vec4 res = texture(input_image[%i], ivec2(pos.x, 
size.y - pos.y));   ,i);
 break;
+case FLIP_BOTH:
+GLSLF(2, vec4 res = texture(input_image[%i], ivec2(size.xy - 
pos.xy));, i);
+break;
 default:
 GLSLF(2, vec4 res = texture(input_image[%i], pos); 
   ,i);
 break;
@@ -267,6 +271,11 @@ static int vflip_vulkan_filter_frame(AVFilterLink *link, 
AVFrame *in)
 return flip_vulkan_filter_frame(link, in, FLIP_VERTICAL);
 }
 
+static int bflip_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
+{
+return flip_vulkan_filter_frame(link, in, FLIP_BOTH);
+}
+
 static const AVOption hflip_vulkan_options[] = {
 { NULL },
 };
@@ -330,3 +339,31 @@ const AVFilter ff_vf_vflip_vulkan = {
 .priv_class = &vflip_vulkan_class,
 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
 };
+
+static const AVOption bflip_vulkan_options[] = {
+{ NULL },
+};
+
+AVFILTER_DEFINE_CLASS(bflip_vulkan);
+
+static const AVFilterPad bflip_vulkan_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_VIDEO,
+.filter_frame = &bflip_vulkan_filter_frame,
+.config_props = &ff_vk_filter_config_input,
+}
+};
+
+const AVFilter ff_vf_bflip_vulkan = {
+.name   = "bflip_vulkan",
+.description= NULL_IF_CONFIG_SMALL("Flip both horizontally and 
vertically"),
+.priv_size  = sizeof(FlipVulkanContext),
+.init   = &ff_vk_filter_init,
+.uninit = &flip_vulkan_uninit,
+FILTER_INPUTS(bflip_vulkan_inputs),
+FILTER_OUTPUTS(flip_vulkan_outputs),
+FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
+.priv_class = &bflip_vulkan_class,
+.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
+};
-- 
2.25.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 v3 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Gyan Doshi



On 2021-11-25 02:38 pm, Wu Jianhua wrote:

This filter flips the input video both horizontally and vertically
in one compute pipeline, and it's no need to use two pipelines for
hflip_vulkan,vflip_vulkan anymore.


bflip is not an intuitive name.

Either hvflip, or since h+v flip  == 180 deg rotation, maybe rotate180 
or rot180


Regards,
Gyan



Signed-off-by: Wu Jianhua 
---
  configure|  1 +
  libavfilter/allfilters.c |  1 +
  libavfilter/vf_flip_vulkan.c | 39 +++-
  3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d068b11073..a7562b53c3 100755
--- a/configure
+++ b/configure
@@ -3569,6 +3569,7 @@ atempo_filter_select="rdft"
  avgblur_opencl_filter_deps="opencl"
  avgblur_vulkan_filter_deps="vulkan spirv_compiler"
  azmq_filter_deps="libzmq"
+bflip_vulkan_filter_deps="vulkan spirv_compiler"
  blackframe_filter_deps="gpl"
  bm3d_filter_deps="avcodec"
  bm3d_filter_select="dct"
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4bf17ef292..041292853a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -175,6 +175,7 @@ extern const AVFilter ff_vf_avgblur_opencl;
  extern const AVFilter ff_vf_avgblur_vulkan;
  extern const AVFilter ff_vf_bbox;
  extern const AVFilter ff_vf_bench;
+extern const AVFilter ff_vf_bflip_vulkan;
  extern const AVFilter ff_vf_bilateral;
  extern const AVFilter ff_vf_bitplanenoise;
  extern const AVFilter ff_vf_blackdetect;
diff --git a/libavfilter/vf_flip_vulkan.c b/libavfilter/vf_flip_vulkan.c
index e9e04db91b..e20766e9ed 100644
--- a/libavfilter/vf_flip_vulkan.c
+++ b/libavfilter/vf_flip_vulkan.c
@@ -26,7 +26,8 @@
  
  enum FlipType {

  FLIP_VERTICAL,
-FLIP_HORIZONTAL
+FLIP_HORIZONTAL,
+FLIP_BOTH
  };
  
  typedef struct FlipVulkanContext {

@@ -104,6 +105,9 @@ static av_cold int init_filter(AVFilterContext *ctx, 
AVFrame *in, enum FlipType
  case FLIP_VERTICAL:
  GLSLF(2, vec4 res = texture(input_image[%i], ivec2(pos.x, 
size.y - pos.y));   ,i);
  break;
+case FLIP_BOTH:
+GLSLF(2, vec4 res = texture(input_image[%i], ivec2(size.xy - 
pos.xy));, i);
+break;
  default:
  GLSLF(2, vec4 res = texture(input_image[%i], pos);
,i);
  break;
@@ -267,6 +271,11 @@ static int vflip_vulkan_filter_frame(AVFilterLink *link, 
AVFrame *in)
  return flip_vulkan_filter_frame(link, in, FLIP_VERTICAL);
  }
  
+static int bflip_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)

+{
+return flip_vulkan_filter_frame(link, in, FLIP_BOTH);
+}
+
  static const AVOption hflip_vulkan_options[] = {
  { NULL },
  };
@@ -330,3 +339,31 @@ const AVFilter ff_vf_vflip_vulkan = {
  .priv_class = &vflip_vulkan_class,
  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
  };
+
+static const AVOption bflip_vulkan_options[] = {
+{ NULL },
+};
+
+AVFILTER_DEFINE_CLASS(bflip_vulkan);
+
+static const AVFilterPad bflip_vulkan_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_VIDEO,
+.filter_frame = &bflip_vulkan_filter_frame,
+.config_props = &ff_vk_filter_config_input,
+}
+};
+
+const AVFilter ff_vf_bflip_vulkan = {
+.name   = "bflip_vulkan",
+.description= NULL_IF_CONFIG_SMALL("Flip both horizontally and 
vertically"),
+.priv_size  = sizeof(FlipVulkanContext),
+.init   = &ff_vk_filter_init,
+.uninit = &flip_vulkan_uninit,
+FILTER_INPUTS(bflip_vulkan_inputs),
+FILTER_OUTPUTS(flip_vulkan_outputs),
+FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
+.priv_class = &bflip_vulkan_class,
+.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
+};


___
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 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Lynne
25 Nov 2021, 10:22 by ffm...@gyani.pro:

>
>
> On 2021-11-25 02:38 pm, Wu Jianhua wrote:
>
>> This filter flips the input video both horizontally and vertically
>> in one compute pipeline, and it's no need to use two pipelines for
>> hflip_vulkan,vflip_vulkan anymore.
>>
>
> bflip is not an intuitive name.
>
> Either hvflip, or since h+v flip  == 180 deg rotation, maybe rotate180 or 
> rot180
>
> Regards,
> Gyan
>

I think I'd prefer if it was called 'transpose_vulkan', with the same options
as the regular transpose filter, but with only a single direction currently
supported.
That way, we'd have a template to which we could implement more
modes later on.
___
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 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Wu, Jianhua
Lynne:
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Thursday, November 25, 2021 5:33 PM
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avfilter: add a bflip_vulkan filter
> 
> 25 Nov 2021, 10:22 by ffm...@gyani.pro:
> 
> >
> >
> > On 2021-11-25 02:38 pm, Wu Jianhua wrote:
> >
> >> This filter flips the input video both horizontally and vertically in
> >> one compute pipeline, and it's no need to use two pipelines for
> >> hflip_vulkan,vflip_vulkan anymore.
> >>
> >
> > bflip is not an intuitive name.
> >
> > Either hvflip, or since h+v flip  == 180 deg rotation, maybe rotate180
> > or rot180
> >
> > Regards,
> > Gyan
> >
> 
> I think I'd prefer if it was called 'transpose_vulkan', with the same options 
> as
> the regular transpose filter, but with only a single direction currently
> supported.
> That way, we'd have a template to which we could implement more modes
> later on.
> 

Does transpose only indicate switches the row and column indices? Ummm..I'm not 
sure.
Maybe rotate 180 is more better.

Thanks,
Jianhua


___
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 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Lynne
25 Nov 2021, 10:39 by jianhua...@intel.com:

> Lynne:
>
>> From: ffmpeg-devel  On Behalf Of
>> Lynne
>> Sent: Thursday, November 25, 2021 5:33 PM
>> To: FFmpeg development discussions and patches > de...@ffmpeg.org>
>> Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avfilter: add a bflip_vulkan 
>> filter
>>
>> 25 Nov 2021, 10:22 by ffm...@gyani.pro:
>>
>> >
>> >
>> > On 2021-11-25 02:38 pm, Wu Jianhua wrote:
>> >
>> >> This filter flips the input video both horizontally and vertically in
>> >> one compute pipeline, and it's no need to use two pipelines for
>> >> hflip_vulkan,vflip_vulkan anymore.
>> >>
>> >
>> > bflip is not an intuitive name.
>> >
>> > Either hvflip, or since h+v flip  == 180 deg rotation, maybe rotate180
>> > or rot180
>> >
>> > Regards,
>> > Gyan
>> >
>>
>> I think I'd prefer if it was called 'transpose_vulkan', with the same 
>> options as
>> the regular transpose filter, but with only a single direction currently
>> supported.
>> That way, we'd have a template to which we could implement more modes
>> later on.
>>
>
> Does transpose only indicate switches the row and column indices? Ummm..I'm 
> not sure.
> Maybe rotate 180 is more better.
>

You're right, transpose only does flips by 90 degrees.
I think you should just call it 'flip_vulkan' in this case.
___
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 2/2] avfilter: add a bflip_vulkan filter

2021-11-25 Thread Gyan Doshi



On 2021-11-25 03:28 pm, Lynne wrote:

25 Nov 2021, 10:39 by jianhua...@intel.com:


Lynne:


From: ffmpeg-devel  On Behalf Of
Lynne
Sent: Thursday, November 25, 2021 5:33 PM
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] avfilter: add a bflip_vulkan filter

25 Nov 2021, 10:22 by ffm...@gyani.pro:



On 2021-11-25 02:38 pm, Wu Jianhua wrote:


This filter flips the input video both horizontally and vertically in
one compute pipeline, and it's no need to use two pipelines for
hflip_vulkan,vflip_vulkan anymore.


bflip is not an intuitive name.

Either hvflip, or since h+v flip  == 180 deg rotation, maybe rotate180
or rot180

Regards,
Gyan


I think I'd prefer if it was called 'transpose_vulkan', with the same options as
the regular transpose filter, but with only a single direction currently
supported.
That way, we'd have a template to which we could implement more modes
later on.


Does transpose only indicate switches the row and column indices? Ummm..I'm not 
sure.
Maybe rotate 180 is more better.


You're right, transpose only does flips by 90 degrees.
I think you should just call it 'flip_vulkan' in this case.


That name indicates a generic filter with option to choose flip type. If 
that's the plan, apt name, but else something specific is clearer.


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

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


[FFmpeg-devel] [PATCH v3 1/1] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
V3: Try sending long-line patch as attachment

 doc/ffprobe.xsd | 1 +
 fftools/ffprobe.c   | 1 +
 tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
 tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
 tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
 tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
 tests/ref/fate/flv-demux| 4 ++--
 tests/ref/fate/mov-zombie   | 2 +-
 tests/ref/fate/mxf-probe-d10| 1 +
 tests/ref/fate/oggopus-demux| 2 +-
 tests/ref/fate/ts-demux | 2 +-
 tests/ref/fate/ts-opus-demux| 2 +-
 tests/ref/fate/ts-small-demux   | 2 +-
 14 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd
index b65e54dbef..3af621a17a 100644
--- a/doc/ffprobe.xsd
+++ b/doc/ffprobe.xsd
@@ -215,6 +215,7 @@
   
   
   
+  
   
 
   
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 971bf1bab1..367c708e52 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2783,6 +2783,7 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id
   par->extradata_size);
 
 if (par->extradata_size > 0) {
+print_int("extradata_size", par->extradata_size);
 writer_print_data_hash(w, "extradata_hash", par->extradata,
 par->extradata_size);
 }
diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
index a3b205539a..4b2a8624db 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf
@@ -1 +1 @@
-0ea04f40869068b282a67e5b8f2a6127 *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
+29e4e502a912b6d863e75d44e156ed31 *tests/data/fate/concat-demuxer-extended-lavf-mxf.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
index 9cbc8df831..1dedc6bf43 100644
--- a/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10
@@ -1 +1 @@
-88abe27eddff160aafd622ed02c26eb6 *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
+8de04a786521677a593283c44a53572e *tests/data/fate/concat-demuxer-extended-lavf-mxf_d10.ffprobe
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
index fc8034bd29..2fe703e2a6 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf
@@ -120,5 +120,5 @@ audio|1|65280|1.36|65280|1.36|1920|0.04|3840|207872|K_|1
 Strings Metadata
 video|0|37|1.48|34|1.36|1|0.04|24786|212480|K_|1
 Strings Metadata
-0|mpeg2video|4|video|[0][0][0][0]|0x|352|288|0|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|51|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
+0|mpeg2video|4|video|[0][0][0][0]|0x|352|288|0|0|0|0|1|1:1|11:9|yuv420p|8|tv|unknown|unknown|unknown|left|progressive|1|N/A|25/1|25/1|1/25|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|51|22|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
 1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|1|unknown|16|N/A|0/0|0/0|1/48000|0|0.00|N/A|N/A|768000|N/A|N/A|N/A|N/A|50|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
diff --git a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10 b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
index 59c6372ef2..0a3af658f6 100644
--- a/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
+++ b/tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10
@@ -78,5 +78,5 @@ video|0|34|1.36|34|1.36|1|0.04|15|1924096|K_|1
 Strings Metadata
 audio|1|65280|1.36|65280|1.36|1920|0.04|7680|2074624|K_|1
 Strings Metadata
-0|mpeg2video|0|video|[0][0][0][0]|0x|720|608|0|0|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|tb|1|N/A|25/1|25/1|1/25|0|0.00|N/A|N/A|3000|N/A|N/A|N/A|N/A|35|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
+0|mpeg2video|0|video|[0][0][0][0]|0x|720|608|0|0|0|0|0|1:1|45:38|yuv422p|5|tv|unknown|unknown|unknown|topleft|tb|1|N/A|25/1|25/1|1/25|0|0.00|N/A|N/A|3000|N/A|N/A|N/A|N/A|35|22|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0x060A2B340101010501010D001301
 1|pcm_s16le|unknown|audio|[0][0][0][0]|0x|s16|48000|2|unknown|16|N/A|0/0|0

Re: [FFmpeg-devel] [PATCH v3 7/7] avformat/rtp: support for RGB/BGR for rfc4175

2021-11-25 Thread lance . lmwang
On Wed, Nov 24, 2021 at 04:49:18PM +0100, Lynne wrote:
> 24 Nov 2021, 16:27 by lance.lmw...@gmail.com:
> 
> > From: Limin Wang 
> >
> > Signed-off-by: Limin Wang 
> > ---
> >  libavformat/rtpdec_rfc4175.c | 20 
> >  libavformat/rtpenc_rfc4175.c |  8 
> >  libavformat/sdp.c|  6 ++
> >  3 files changed, 34 insertions(+)
> >
> 
> Much better, thanks.
> Patchset looks good to me now.

thanks, have pushed the patchset.

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

-- 
Thanks,
Limin Wang
___
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] avformat/rtp: add localaddr for network interface selection

2021-11-25 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 doc/protocols.texi |  4 
 libavformat/rtpproto.c | 17 ++---
 libavformat/rtsp.c |  3 +++
 libavformat/rtsp.h |  1 +
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index c100f23..d207df0 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1087,6 +1087,10 @@ set to 1) or to a default remote address (if set to 0).
 @item localport=@var{n}
 Set the local RTP port to @var{n}.
 
+@item localaddr=@var{addr}
+Local IP address of a network interface used for sending packets or joining
+multicast groups.
+
 @item timeout=@var{n}
 Set timeout (in microseconds) of socket I/O operations to @var{n}.
 
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 7dd6042..c92cda6 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -61,6 +61,7 @@ typedef struct RTPContext {
 char *block;
 char *fec_options_str;
 int64_t rw_timeout;
+char *localaddr;
 } RTPContext;
 
 #define OFFSET(x) offsetof(RTPContext, x)
@@ -80,6 +81,7 @@ static const AVOption options[] = {
 { "sources","Source list", 
 OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL },  
 .flags = D|E },
 { "block",  "Block list",  
 OFFSET(block),   AV_OPT_TYPE_STRING, { .str = NULL },  
 .flags = D|E },
 { "fec","FEC", 
 OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL },  
 .flags = E },
+{ "localaddr",  "Local address",   
 OFFSET(localaddr),   AV_OPT_TYPE_STRING, { .str = NULL },  
 .flags = D|E },
 { NULL }
 };
 
@@ -173,6 +175,7 @@ static av_printf_format(3, 4) void url_add_option(char 
*buf, int buf_size, const
 static void build_udp_url(RTPContext *s,
   char *buf, int buf_size,
   const char *hostname,
+  const char *localaddr,
   int port, int local_port,
   const char *include_sources,
   const char *exclude_sources)
@@ -195,6 +198,8 @@ static void build_udp_url(RTPContext *s,
 url_add_option(buf, buf_size, "sources=%s", include_sources);
 if (exclude_sources && exclude_sources[0])
 url_add_option(buf, buf_size, "block=%s", exclude_sources);
+if (localaddr && localaddr[0])
+url_add_option(buf, buf_size, "localaddr=%s", localaddr);
 }
 
 /**
@@ -284,6 +289,12 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 ff_ip_parse_blocks(h, s->block, &s->filters);
 block = s->block;
 }
+if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
+av_freep(&s->localaddr);
+s->localaddr = av_strdup(buf);
+if (!s->localaddr)
+goto fail;
+}
 }
 if (s->rw_timeout >= 0)
 h->rw_timeout = s->rw_timeout;
@@ -314,7 +325,7 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 
 for (i = 0; i < max_retry_count; i++) {
 build_udp_url(s, buf, sizeof(buf),
-  hostname, rtp_port, s->local_rtpport,
+  hostname, s->localaddr, rtp_port, s->local_rtpport,
   sources, block);
 if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, 
&h->interrupt_callback,
  NULL, h->protocol_whitelist, 
h->protocol_blacklist, h) < 0)
@@ -328,7 +339,7 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 if (s->local_rtcpport < 0) {
 s->local_rtcpport = s->local_rtpport + 1;
 build_udp_url(s, buf, sizeof(buf),
-  hostname, s->rtcp_port, s->local_rtcpport,
+  hostname, s->localaddr, s->rtcp_port, 
s->local_rtcpport,
   sources, block);
 if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags,
  &h->interrupt_callback, NULL,
@@ -339,7 +350,7 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 break;
 }
 build_udp_url(s, buf, sizeof(buf),
-  hostname, s->rtcp_port, s->local_rtcpport,
+  hostname, s->localaddr, s->rtcp_port, s->local_rtcpport,
   sources, block);
 if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, 
&h->interrupt_callback,
  NULL, h->protocol_whitelist, 
h->protocol_blacklist, h) < 0)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index a1aa969..3897826 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -74,6 +74,7 @@
 #d

[FFmpeg-devel] [PATCH 2/2] avformat/udp: remove local localaddr array

2021-11-25 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 libavformat/udp.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index bbe5aec..b8b0e19 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -623,7 +623,7 @@ end:
 /* return non zero if error */
 static int udp_open(URLContext *h, const char *uri, int flags)
 {
-char hostname[1024], localaddr[1024] = "";
+char hostname[1024];
 int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
 UDPContext *s = h->priv_data;
 int is_output;
@@ -708,7 +708,8 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 s->burst_bits = strtoll(buf, NULL, 10);
 }
 if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
-av_strlcpy(localaddr, buf, sizeof(localaddr));
+av_freep(&s->localaddr);
+s->localaddr = av_strdup(buf);
 }
 if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
 if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
@@ -748,10 +749,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
 s->local_port = port;
 
-if (localaddr[0])
-udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
-else
-udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
+udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
 if (udp_fd < 0)
 goto fail;
 
-- 
1.8.3.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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread James Almer
Have all the concerns people had been addressed? I'm also certain the
design itself wasn't well received.
This is big and needs more than 24 hours or just one person LGTMing it, so
please wait.

Also, patch 15/16 breaks FATE. Even if 16/16 fixes the tests, it will make
bisecting annoying, so it needs to be green.


On Thu, Nov 25, 2021 at 6:04 AM Paul B Mahol  wrote:

> LGTM, will apply if there are no objections in next 24h
> ___
> 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 2/2] avformat/udp: remove local localaddr array

2021-11-25 Thread Martin Storsjö

On Thu, 25 Nov 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
libavformat/udp.c | 10 --
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index bbe5aec..b8b0e19 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -623,7 +623,7 @@ end:
/* return non zero if error */
static int udp_open(URLContext *h, const char *uri, int flags)
{
-char hostname[1024], localaddr[1024] = "";
+char hostname[1024];
int port, udp_fd = -1, tmp, bind_ret = -1, dscp = -1;
UDPContext *s = h->priv_data;
int is_output;
@@ -708,7 +708,8 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
s->burst_bits = strtoll(buf, NULL, 10);
}
if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
-av_strlcpy(localaddr, buf, sizeof(localaddr));
+av_freep(&s->localaddr);
+s->localaddr = av_strdup(buf);
}
if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
if ((ret = ff_ip_parse_sources(h, buf, &s->filters)) < 0)
@@ -748,10 +749,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
if ((s->is_multicast || s->local_port <= 0) && (h->flags & AVIO_FLAG_READ))
s->local_port = port;

-if (localaddr[0])
-udp_fd = udp_socket_create(h, &my_addr, &len, localaddr);
-else
-udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
+udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
if (udp_fd < 0)
goto fail;

--
1.8.3.1


This patch LGTM.

// Martin

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/rtp: add localaddr for network interface selection

2021-11-25 Thread Martin Storsjö

On Thu, 25 Nov 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
doc/protocols.texi |  4 
libavformat/rtpproto.c | 17 ++---
libavformat/rtsp.c |  3 +++
libavformat/rtsp.h |  1 +
4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index c100f23..d207df0 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1087,6 +1087,10 @@ set to 1) or to a default remote address (if set to 0).
@item localport=@var{n}
Set the local RTP port to @var{n}.

+@item localaddr=@var{addr}
+Local IP address of a network interface used for sending packets or joining
+multicast groups.


Just to clarify things for myself for understanding this: Today, if 
receiving UDP unicast, we can use udp://: to select which 
local IP address to listen on? But for multicast, we'd do 
udp://:?localaddr= to select which address to 
use for joining the group?


// Martin

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

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


Re: [FFmpeg-devel] [PATCH] avformat/http: prevent truncation of sanitized_path

2021-11-25 Thread Anton Khirnov
Quoting James Almer (2021-06-09 22:01:02)
> path1 and sanitized_path are both MAX_URL_SIZE bytes long, yet the latter is
> copied from the former with the addition of one extra character.
> 
> Should fix a -Wformat-truncation warning.
> 
> Signed-off-by: James Almer 
> ---
>  libavformat/http.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index 1fc95c768c..1e7d97a027 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -192,7 +192,7 @@ static int http_open_cnx_internal(URLContext *h, 
> AVDictionary **options)
>  char *hashmark;
>  char hostname[1024], hoststr[1024], proto[10];
>  char auth[1024], proxyauth[1024] = "";
> -char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE];
> +char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1];

Looks ok, was about to write the same patch.

-- 
Anton Khirnov
___
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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of James Almer
> Sent: Thursday, November 25, 2021 11:52 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v15 00/16] *** SUBJECT HERE ***
> 
> Have all the concerns people had been addressed? I'm also certain the
> design itself wasn't well received.
> This is big and needs more than 24 hours or just one person LGTMing it, so
> please wait.

James, just a little note: After 16 version and many weeks, the window for 
architecture discussions is closed for me.
I've been asking for comments often enough - and way more often than others
usually do.

Let alone small changes, but at this point it's a take-it-or-leave it decision:

Nice new features vs. nothing for another 10 years.

PS: It's of course totally fine when somebody would speak up asking for some
more time, but otherwise, there has been more than enough time by now.


> Also, patch 15/16 breaks FATE. Even if 16/16 fixes the tests, it will make
> bisecting annoying, so it needs to be green.
> 

Yes, one commit is from fftools, the other one from avcodec. Squashing them 
would 
solve the problem - Shall I do this

Kind regards,
sw
___
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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Hendrik Leppkes
On Thu, Nov 25, 2021 at 1:12 PM Soft Works  wrote:
>
>
>
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of James 
> > Almer
> > Sent: Thursday, November 25, 2021 11:52 AM
> > To: FFmpeg development discussions and patches 
> > Subject: Re: [FFmpeg-devel] [PATCH v15 00/16] *** SUBJECT HERE ***
> >
> > Have all the concerns people had been addressed? I'm also certain the
> > design itself wasn't well received.
> > This is big and needs more than 24 hours or just one person LGTMing it, so
> > please wait.
>
> James, just a little note: After 16 version and many weeks, the window for
> architecture discussions is closed for me.
> I've been asking for comments often enough - and way more often than others
> usually do.
>
> Let alone small changes, but at this point it's a take-it-or-leave it 
> decision:
>
> Nice new features vs. nothing for another 10 years.
>
> PS: It's of course totally fine when somebody would speak up asking for some
> more time, but otherwise, there has been more than enough time by now.
>
>
> > Also, patch 15/16 breaks FATE. Even if 16/16 fixes the tests, it will make
> > bisecting annoying, so it needs to be green.
> >
>
> Yes, one commit is from fftools, the other one from avcodec. Squashing them 
> would
> solve the problem - Shall I do this
>

I would be more curious about why does it break?
If we view fftools as a user of our libraries, shouldn't all the
library commits be neutral to fftools, and not introduce changes,
unless there is an API break in there, which is something we wanted to
avoid?

I have not checked what exactly breaks there, but its always a warning
sign when this happens.

Otherwise, instead of merging complex changes into one mega commit,
fate tests should probably be updated instead, even if its going to be
updated again in the next commit.

Speaking of mega commits, I think the first commit should be broken up
more. There is no reason that all this has to happen in one commit,
eg. introducing AVFrame structure changes, new frame helper functions,
decode support, could and (imho) should all be separate changes.
I'm pretty sure I have commented on this already a long time ago, too.

- Hendrik
___
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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Hendrik
> Leppkes
> Sent: Thursday, November 25, 2021 1:18 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v15 00/16] *** SUBJECT HERE ***
> 
> On Thu, Nov 25, 2021 at 1:12 PM Soft Works  wrote:
> >
> >
> >
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of James
> Almer
> > > Sent: Thursday, November 25, 2021 11:52 AM
> > > To: FFmpeg development discussions and patches 
> > > Subject: Re: [FFmpeg-devel] [PATCH v15 00/16] *** SUBJECT HERE ***
> > >
> > > Have all the concerns people had been addressed? I'm also certain the
> > > design itself wasn't well received.
> > > This is big and needs more than 24 hours or just one person LGTMing it,
> so
> > > please wait.
> >
> > James, just a little note: After 16 version and many weeks, the window for
> > architecture discussions is closed for me.
> > I've been asking for comments often enough - and way more often than others
> > usually do.
> >
> > Let alone small changes, but at this point it's a take-it-or-leave it
> decision:
> >
> > Nice new features vs. nothing for another 10 years.
> >
> > PS: It's of course totally fine when somebody would speak up asking for
> some
> > more time, but otherwise, there has been more than enough time by now.
> >
> >
> > > Also, patch 15/16 breaks FATE. Even if 16/16 fixes the tests, it will
> make
> > > bisecting annoying, so it needs to be green.
> > >
> >
> > Yes, one commit is from fftools, the other one from avcodec. Squashing them
> would
> > solve the problem - Shall I do this
> >
> 
> I would be more curious about why does it break?
> If we view fftools as a user of our libraries, shouldn't all the
> library commits be neutral to fftools, and not introduce changes,
> unless there is an API break in there, which is something we wanted to
> avoid?
> 
> I have not checked what exactly breaks there, but its always a warning
> sign when this happens.

That's a good point, I'll check that.


> Speaking of mega commits, I think the first commit should be broken up
> more. There is no reason that all this has to happen in one commit,
> eg. introducing AVFrame structure changes, new frame helper functions,
> decode support, could and (imho) should all be separate changes.

Sure, I can do that. Working with GIT in a way non-linear way, i.e. to
"stage" the actual commits that you are submitting is a tedious process, 
so I kept it simple for the time being.

> I'm pretty sure I have commented on this already a long time ago, too.

What I remember is that you stopped responding after I had addressed 
your suggestions.

Thanks,
sw
___
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] avformat/rtp: add localaddr for network interface selection

2021-11-25 Thread lance . lmwang
On Thu, Nov 25, 2021 at 12:56:24PM +0200, Martin Storsjö wrote:
> On Thu, 25 Nov 2021, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > doc/protocols.texi |  4 
> > libavformat/rtpproto.c | 17 ++---
> > libavformat/rtsp.c |  3 +++
> > libavformat/rtsp.h |  1 +
> > 4 files changed, 22 insertions(+), 3 deletions(-)
> > 
> > diff --git a/doc/protocols.texi b/doc/protocols.texi
> > index c100f23..d207df0 100644
> > --- a/doc/protocols.texi
> > +++ b/doc/protocols.texi
> > @@ -1087,6 +1087,10 @@ set to 1) or to a default remote address (if set to 
> > 0).
> > @item localport=@var{n}
> > Set the local RTP port to @var{n}.
> > 
> > +@item localaddr=@var{addr}
> > +Local IP address of a network interface used for sending packets or joining
> > +multicast groups.
> 
> Just to clarify things for myself for understanding this: Today, if
> receiving UDP unicast, we can use udp://: to select which
> local IP address to listen on? But for multicast, we'd do
> udp://:?localaddr= to select which address to
> use for joining the group?

yes, it's useful to select/bind which network interface to use for the multicast
stream in case you have many network port, udp have support it already, but rtp 
haven't
yet. 

> 
> // Martin
> 

-- 
Thanks,
Limin Wang
___
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/9] lavd/v4l2: detect device name truncation

2021-11-25 Thread Anton Khirnov
Silences the following warning with gcc 10:
src/libavdevice/v4l2.c: In function ‘v4l2_get_device_list’:
src/libavdevice/v4l2.c:1042:64: warning: ‘%s’ directive output may be truncated 
writing up to 255 bytes into a region of size 251 [-Wformat-truncation=]
 1042 | ret = snprintf(device_name, sizeof(device_name), "/dev/%s", 
entry->d_name);
  |^~
src/libavdevice/v4l2.c:1042:15: note: ‘snprintf’ output between 6 and 261 bytes 
into a destination of size 256
 1042 | ret = snprintf(device_name, sizeof(device_name), "/dev/%s", 
entry->d_name);
  |   
^~~~

Previous patches intending to silence it have proposed increasing the
buffer size, but doing that correctly seems to be tricky. Failing on
truncation is simpler and just as effective (as excessively long device
names are unlikely).
---
 libavdevice/v4l2.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index c286b31c69..80efc88203 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -1033,13 +1033,19 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
 while ((entry = readdir(dir))) {
 AVDeviceInfo *device = NULL;
 struct v4l2_capability cap;
-int fd = -1;
+int fd = -1, size;
 char device_name[256];
 
 if (!v4l2_is_v4l_dev(entry->d_name))
 continue;
 
-snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
+size = snprintf(device_name, sizeof(device_name), "/dev/%s", 
entry->d_name);
+if (size >= sizeof(device_name)) {
+av_log(ctx, AV_LOG_ERROR, "Device name too long.\n");
+ret = AVERROR(ENOSYS);
+goto fail;
+}
+
 if ((fd = device_open(ctx, device_name)) < 0)
 continue;
 
-- 
2.33.0

___
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/9] lavd/jack: increase buffer size for snprintf()

2021-11-25 Thread Anton Khirnov
Maximum output size with a 32-bit int is 17 bytes, or 26 with a 64-bit
int.

Silences the following gcc 10 warning:
src/libavdevice/jack.c: In function ‘audio_read_header’:
src/libavdevice/jack.c:171:45: warning: ‘snprintf’ output may be truncated 
before the last format character [-Wformat-truncation=]
  171 | snprintf(str, sizeof(str), "input_%d", i + 1);
  | ^
src/libavdevice/jack.c:171:9: note: ‘snprintf’ output between 8 and 17 bytes 
into a destination of size 16
  171 | snprintf(str, sizeof(str), "input_%d", i + 1);
  | ^
---
 libavdevice/jack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavdevice/jack.c b/libavdevice/jack.c
index 31534134f3..0d5465e407 100644
--- a/libavdevice/jack.c
+++ b/libavdevice/jack.c
@@ -167,7 +167,7 @@ static int start_jack(AVFormatContext *context)
 
 /* Register JACK ports */
 for (i = 0; i < self->nports; i++) {
-char str[16];
+char str[32];
 snprintf(str, sizeof(str), "input_%d", i + 1);
 self->ports[i] = jack_port_register(self->client, str,
 JACK_DEFAULT_AUDIO_TYPE,
-- 
2.33.0

___
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/9] lavd/v4l2: reduce variable scope

2021-11-25 Thread Anton Khirnov
device and cap are local to the loop iteration, there is no need for
them to retain their values. Especially for device it may be dangerous,
since it points to av_malloc'ed data.
---
 libavdevice/v4l2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 777867db86..c286b31c69 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -1019,8 +1019,6 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
 struct video_data *s = ctx->priv_data;
 DIR *dir;
 struct dirent *entry;
-AVDeviceInfo *device = NULL;
-struct v4l2_capability cap;
 int ret = 0;
 
 if (!device_list)
@@ -1033,6 +1031,8 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
 return ret;
 }
 while ((entry = readdir(dir))) {
+AVDeviceInfo *device = NULL;
+struct v4l2_capability cap;
 int fd = -1;
 char device_name[256];
 
-- 
2.33.0

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

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


[FFmpeg-devel] [PATCH 5/9] lavfi/vf_subtitles: stop using deprecated ass_set_aspect_ratio()

2021-11-25 Thread Anton Khirnov
It has been deprecated in favor of ass_set_pixel_aspect() since version
0.11.0, roughly ~2014. Even Debian oldoldstable (stretch) has 0.13.
---
 configure  | 2 +-
 libavfilter/vf_subtitles.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index d068b11073..4d9000567b 100755
--- a/configure
+++ b/configure
@@ -6430,7 +6430,7 @@ enabled libaribb24&& { check_pkg_config 
libaribb24 "aribb24 > 1.0.3" "ar
die "ERROR: libaribb24 requires version higher 
than 1.0.3 or --enable-gpl."; }
 enabled lv2   && require_pkg_config lv2 lilv-0 "lilv/lilv.h" 
lilv_world_new
 enabled libiec61883   && require libiec61883 libiec61883/iec61883.h 
iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
-enabled libass&& require_pkg_config libass libass ass/ass.h 
ass_library_init
+enabled libass&& require_pkg_config libass "libass >= 0.11.0" 
ass/ass.h ass_library_init
 enabled libbluray && require_pkg_config libbluray libbluray 
libbluray/bluray.h bd_open
 enabled libbs2b   && require_pkg_config libbs2b libbs2b bs2b.h 
bs2b_open
 enabled libcelt   && require libcelt celt/celt.h celt_decode -lcelt0 &&
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 377160c72b..3fc4eeb63d 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -147,8 +147,8 @@ static int config_input(AVFilterLink *inlink)
 
 ass_set_frame_size  (ass->renderer, inlink->w, inlink->h);
 if (ass->original_w && ass->original_h)
-ass_set_aspect_ratio(ass->renderer, (double)inlink->w / inlink->h,
- (double)ass->original_w / ass->original_h);
+ass_set_pixel_aspect(ass->renderer, (double)inlink->w / inlink->h /
+ ((double)ass->original_w / ass->original_h));
 if (ass->shaping != -1)
 ass_set_shaper(ass->renderer, ass->shaping);
 
-- 
2.33.0

___
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 6/9] lavf/ftp: check for truncation in snprintf

2021-11-25 Thread Anton Khirnov
Silences e.g. the following warning in gcc 10:
src/libavformat/ftp.c: In function ‘ftp_move’:
src/libavformat/ftp.c:1122:46: warning: ‘%s’ directive output may be truncated 
writing up to 4095 bytes into a region of size 4091 [-Wformat-truncation=]
 1122 | snprintf(command, sizeof(command), "RNTO %s\r\n", path);
  |  ^~   
src/libavformat/ftp.c:1122:5: note: ‘snprintf’ output between 8 and 4103 bytes 
into a destination of size 4096
 1122 | snprintf(command, sizeof(command), "RNTO %s\r\n", path);
  | ^~~
---
 libavformat/ftp.c | 64 ++-
 1 file changed, 52 insertions(+), 12 deletions(-)

diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 69caa7670c..883668b37b 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -250,13 +250,19 @@ static int ftp_auth(FTPContext *s)
 
 if (strpbrk(s->user, "\r\n"))
 return AVERROR(EINVAL);
-snprintf(buf, sizeof(buf), "USER %s\r\n", s->user);
+err = snprintf(buf, sizeof(buf), "USER %s\r\n", s->user);
+if (err >= sizeof(buf))
+return AVERROR(ENOSYS);
+
 err = ftp_send_command(s, buf, user_codes, NULL);
 if (err == 331) {
 if (s->password) {
 if (strpbrk(s->password, "\r\n"))
 return AVERROR(EINVAL);
-snprintf(buf, sizeof(buf), "PASS %s\r\n", s->password);
+err = snprintf(buf, sizeof(buf), "PASS %s\r\n", s->password);
+if (err >= sizeof(buf))
+return AVERROR(ENOSYS);
+
 err = ftp_send_command(s, buf, pass_codes, NULL);
 } else
 return AVERROR(EACCES);
@@ -397,9 +403,13 @@ static int ftp_file_size(FTPContext *s)
 {
 char command[CONTROL_BUFFER_SIZE];
 char *res = NULL;
+int ret;
 static const int size_codes[] = {213, 0};
 
-snprintf(command, sizeof(command), "SIZE %s\r\n", s->path);
+ret = snprintf(command, sizeof(command), "SIZE %s\r\n", s->path);
+if (ret >= sizeof(command))
+return AVERROR(ENOSYS);
+
 if (ftp_send_command(s, command, size_codes, &res) == 213 && res && 
strlen(res) > 4) {
 s->filesize = strtoll(&res[4], NULL, 10);
 } else {
@@ -416,9 +426,12 @@ static int ftp_retrieve(FTPContext *s)
 {
 char command[CONTROL_BUFFER_SIZE];
 static const int retr_codes[] = {150, 125, 0};
-int resp_code;
+int resp_code, ret;
+
+ret = snprintf(command, sizeof(command), "RETR %s\r\n", s->path);
+if (ret >= sizeof(command))
+return AVERROR(ENOSYS);
 
-snprintf(command, sizeof(command), "RETR %s\r\n", s->path);
 resp_code = ftp_send_command(s, command, retr_codes, NULL);
 if (resp_code != 125 && resp_code != 150)
 return AVERROR(EIO);
@@ -432,9 +445,12 @@ static int ftp_store(FTPContext *s)
 {
 char command[CONTROL_BUFFER_SIZE];
 static const int stor_codes[] = {150, 125, 0};
-int resp_code;
+int resp_code, ret;
+
+ret = snprintf(command, sizeof(command), "STOR %s\r\n", s->path);
+if (ret >= sizeof(command))
+return AVERROR(ENOSYS);
 
-snprintf(command, sizeof(command), "STOR %s\r\n", s->path);
 resp_code = ftp_send_command(s, command, stor_codes, NULL);
 if (resp_code != 125 && resp_code != 150)
 return AVERROR(EIO);
@@ -471,8 +487,12 @@ static int ftp_set_dir(FTPContext *s)
 {
 static const int cwd_codes[] = {250, 550, 0}; /* 550 is incorrect code */
 char command[MAX_URL_SIZE];
+int ret;
+
+ret = snprintf(command, sizeof(command), "CWD %s\r\n", s->path);
+if (ret >= sizeof(command))
+return AVERROR(ENOSYS);
 
-snprintf(command, sizeof(command), "CWD %s\r\n", s->path);
 if (ftp_send_command(s, command, cwd_codes, NULL) != 250)
 return AVERROR(EIO);
 return 0;
@@ -1082,13 +1102,23 @@ static int ftp_delete(URLContext *h)
 if ((ret = ftp_connect(h, h->filename)) < 0)
 goto cleanup;
 
-snprintf(command, sizeof(command), "DELE %s\r\n", s->path);
+ret = snprintf(command, sizeof(command), "DELE %s\r\n", s->path);
+if (ret >= sizeof(command)) {
+ret = AVERROR(ENOSYS);
+goto cleanup;
+}
+
 if (ftp_send_command(s, command, del_codes, NULL) == 250) {
 ret = 0;
 goto cleanup;
 }
 
-snprintf(command, sizeof(command), "RMD %s\r\n", s->path);
+ret = snprintf(command, sizeof(command), "RMD %s\r\n", s->path);
+if (ret >= sizeof(command)) {
+ret = AVERROR(ENOSYS);
+goto cleanup;
+}
+
 if (ftp_send_command(s, command, rmd_codes, NULL) == 250)
 ret = 0;
 else
@@ -1110,7 +1140,12 @@ static int ftp_move(URLContext *h_src, URLContext *h_dst)
 if ((ret = ftp_connect(h_src, h_src->filename)) < 0)
 goto cleanup;
 
-snprintf(command, sizeof(command), "RNFR %s\r\n", s->path);
+ret = snprintf(command, sizeof(command), "RNFR %s\r\n", s->path);
+ 

[FFmpeg-devel] [PATCH 8/9] lavf/mov: drop a never-executed block

2021-11-25 Thread Anton Khirnov
MOVStts.duration is unsigned since 203b0e3561d.
---
 libavformat/mov.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 451cb78bbf..e85eeb0a0e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3965,16 +3965,6 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
 current_offset += sample_size;
 stream_size += sample_size;
 
-/* A negative sample duration is invalid based on the spec,
- * but some samples need it to correct the DTS. */
-if (sc->stts_data[stts_index].duration < 0) {
-av_log(mov->fc, AV_LOG_WARNING,
-   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
-   sc->stts_data[stts_index].duration, stts_index,
-   st->index);
-dts_correction += sc->stts_data[stts_index].duration - 1;
-sc->stts_data[stts_index].duration = 1;
-}
 current_dts += sc->stts_data[stts_index].duration;
 if (!dts_correction || current_dts + dts_correction > 
last_dts) {
 current_dts += dts_correction;
-- 
2.33.0

___
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 7/9] lavf/img2enc: avoid a useless copy of the url

2021-11-25 Thread Anton Khirnov
img2enc keeps a private (and possibly truncated) copy of the url that is
never modified. Just use AVFormatContext.url instead.
---
 libavformat/img2enc.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 62202de9f4..44895490e6 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -36,7 +36,6 @@ typedef struct VideoMuxData {
 const AVClass *class;  /**< Class for private options. */
 int img_number;
 int split_planes;   /**< use independent file for each Y, U, V plane */
-char path[1024];
 char tmp[4][1024];
 char target[4][1024];
 int update;
@@ -53,14 +52,12 @@ static int write_header(AVFormatContext *s)
 AVStream *st = s->streams[0];
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format);
 
-av_strlcpy(img->path, s->url, sizeof(img->path));
-
 if (st->codecpar->codec_id == AV_CODEC_ID_GIF) {
 img->muxer = "gif";
 } else if (st->codecpar->codec_id == AV_CODEC_ID_FITS) {
 img->muxer = "fits";
 } else if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) {
-const char *str = strrchr(img->path, '.');
+const char *str = strrchr(s->url, '.');
 img->split_planes = str
  && !av_strcasecmp(str + 1, "y")
  && s->nb_streams == 1
@@ -136,29 +133,29 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
 AVDictionary *options = NULL;
 
 if (img->update) {
-av_strlcpy(filename, img->path, sizeof(filename));
+av_strlcpy(filename, s->url, sizeof(filename));
 } else if (img->use_strftime) {
 time_t now0;
 struct tm *tm, tmpbuf;
 time(&now0);
 tm = localtime_r(&now0, &tmpbuf);
-if (!strftime(filename, sizeof(filename), img->path, tm)) {
+if (!strftime(filename, sizeof(filename), s->url, tm)) {
 av_log(s, AV_LOG_ERROR, "Could not get frame filename with 
strftime\n");
 return AVERROR(EINVAL);
 }
 } else if (img->frame_pts) {
-if (av_get_frame_filename2(filename, sizeof(filename), img->path, 
pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
+if (av_get_frame_filename2(filename, sizeof(filename), s->url, 
pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
 av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the 
frames.");
 return AVERROR(EINVAL);
 }
-} else if (av_get_frame_filename2(filename, sizeof(filename), img->path,
+} else if (av_get_frame_filename2(filename, sizeof(filename), s->url,
   img->img_number,
   AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0 &&
img->img_number > 1) {
 av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern '%s'. "
"Use '-frames:v 1' for a single image, or '-update' option, or 
use a pattern such as %%03d within the filename.\n",
-   img->img_number, img->path);
+   img->img_number, s->url);
 return AVERROR(EINVAL);
 }
 for (i = 0; i < 4; i++) {
-- 
2.33.0

___
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 9/9] lavf/protocols: avoid discarding const in avio_enum_protocols()

2021-11-25 Thread Anton Khirnov
Instead of storing the protocol pointer in the opaque iteration state,
store just the index of the next protocol, similarly to how
ff_urlcontext_child_class_iterate() works.
---
 libavformat/protocols.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index b108aa6c7e..948fae411f 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -93,17 +93,17 @@ const AVClass *ff_urlcontext_child_class_iterate(void 
**iter)
 
 const char *avio_enum_protocols(void **opaque, int output)
 {
-const URLProtocol **p = *opaque;
+uintptr_t i;
 
-p = p ? p + 1 : url_protocols;
-*opaque = p;
-if (!*p) {
-*opaque = NULL;
-return NULL;
+for (i = (uintptr_t)*opaque; url_protocols[i]; i++) {
+const URLProtocol *p = url_protocols[i];
+if ((output && p->url_write) || (!output && p->url_read)) {
+*opaque = (void*)(uintptr_t)(i + 1);
+return p->name;
+}
 }
-if ((output && (*p)->url_write) || (!output && (*p)->url_read))
-return (*p)->name;
-return avio_enum_protocols(opaque, output);
+*opaque = NULL;
+return NULL;
 }
 
 const AVClass *avio_protocol_get_class(const char *name)
-- 
2.33.0

___
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/9] lavf/v4l2: do not use a context variable unnecessarily

2021-11-25 Thread Anton Khirnov
fd is local to the loop iteration, it is better to store it on stack
than modify the context.
---
 libavdevice/v4l2.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index b5997fba33..777867db86 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -1033,16 +1033,17 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
 return ret;
 }
 while ((entry = readdir(dir))) {
+int fd = -1;
 char device_name[256];
 
 if (!v4l2_is_v4l_dev(entry->d_name))
 continue;
 
 snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
-if ((s->fd = device_open(ctx, device_name)) < 0)
+if ((fd = device_open(ctx, device_name)) < 0)
 continue;
 
-if (v4l2_ioctl(s->fd, VIDIOC_QUERYCAP, &cap) < 0) {
+if (v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
 ret = AVERROR(errno);
 av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", 
av_err2str(ret));
 goto fail;
@@ -1064,8 +1065,7 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
   &device_list->nb_devices, device)) < 
0)
 goto fail;
 
-v4l2_close(s->fd);
-s->fd = -1;
+v4l2_close(fd);
 continue;
 
   fail:
@@ -1074,9 +1074,8 @@ static int v4l2_get_device_list(AVFormatContext *ctx, 
AVDeviceInfoList *device_l
 av_freep(&device->device_description);
 av_freep(&device);
 }
-if (s->fd >= 0)
-v4l2_close(s->fd);
-s->fd = -1;
+if (fd >= 0)
+v4l2_close(fd);
 break;
 }
 closedir(dir);
-- 
2.33.0

___
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] lavu/frame: drop mentions of non-refcounted frames

2021-11-25 Thread Anton Khirnov
All frames we deal with should always be refcounted now.
---
 libavutil/frame.h | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavutil/frame.h b/libavutil/frame.h
index 753234792e..f7be2340fd 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -314,6 +314,9 @@ typedef struct AVFrame {
  * This might be different from the first allocated byte. For video,
  * it could even point to the end of the image data.
  *
+ * All pointers in data and extended_data must point into one of the
+ * AVBufferRef in buf or extended_buf.
+ *
  * Some decoders access areas outside 0,0 - width,height, please
  * see avcodec_align_dimensions2(). Some filters and swscale can read
  * up to 16 bytes beyond the planes, if these filters are to be used,
@@ -482,10 +485,10 @@ typedef struct AVFrame {
 uint64_t channel_layout;
 
 /**
- * AVBuffer references backing the data for this frame. If all elements of
- * this array are NULL, then this frame is not reference counted. This 
array
- * must be filled contiguously -- if buf[i] is non-NULL then buf[j] must
- * also be non-NULL for all j < i.
+ * AVBuffer references backing the data for this frame. All the pointers in
+ * data and extended_data must point inside one of the buffers in buf or
+ * extended_buf. This array must be filled contiguously -- if buf[i] is
+ * non-NULL then buf[j] must also be non-NULL for all j < i.
  *
  * There may be at most one AVBuffer per data plane, so for video this 
array
  * always contains all the references. For planar audio with more than
-- 
2.33.0

___
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] lavu/frame: clarify doxy

2021-11-25 Thread Anton Khirnov
AVFrame.data[] elements not used by the format should ALWAYS be null,
hwaccel formats are not an exception.
---
 libavutil/frame.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavutil/frame.h b/libavutil/frame.h
index f7be2340fd..b7be3fa441 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -322,8 +322,7 @@ typedef struct AVFrame {
  * up to 16 bytes beyond the planes, if these filters are to be used,
  * then 16 extra bytes must be allocated.
  *
- * NOTE: Except for hwaccel formats, pointers not needed by the format
- * MUST be set to NULL.
+ * NOTE: Pointers not needed by the format MUST be set to NULL.
  *
  * @attention In case of video, the data[] pointers can point to the
  * end of image data in order to reverse line order, when used in
-- 
2.33.0

___
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 8/9] lavf/mov: drop a never-executed block

2021-11-25 Thread Gyan Doshi




On 2021-11-25 08:34 pm, Anton Khirnov wrote:

MOVStts.duration is unsigned since 203b0e3561d.
---
  libavformat/mov.c | 10 --
  1 file changed, 10 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 451cb78bbf..e85eeb0a0e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3965,16 +3965,6 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
  current_offset += sample_size;
  stream_size += sample_size;
  
-/* A negative sample duration is invalid based on the spec,

- * but some samples need it to correct the DTS. */
-if (sc->stts_data[stts_index].duration < 0) {
-av_log(mov->fc, AV_LOG_WARNING,
-   "Invalid SampleDelta %d in STTS, at %d st:%d\n",
-   sc->stts_data[stts_index].duration, stts_index,
-   st->index);
-dts_correction += sc->stts_data[stts_index].duration - 1;
-sc->stts_data[stts_index].duration = 1;
-}
  current_dts += sc->stts_data[stts_index].duration;
  if (!dts_correction || current_dts + dts_correction > 
last_dts) {
  current_dts += dts_correction;


See 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20211123131106.8652-1-ffm...@gyani.pro/


Although stts duration should be and is now unsigned, some writers treat 
it as signed and use negative values for DTS correction.


Michael is reviewing my patch and is offering critiques + suggestions.

Regards,
Gyan
___
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 v15 01/16] global: Prepare AVFrame for subtitle handling

2021-11-25 Thread Anton Khirnov
Quoting Soft Works (2021-11-25 01:48:11)
> Root commit for adding subtitle filtering capabilities.
> In detail:
> 
> - Add type (AVMediaType) field to AVFrame
>   Replaces previous way of distinction which was based on checking
>   width and height to determine whether a frame is audio or video
> - Add subtitle fields to AVFrame
> - Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
>   allocation logic. Cannot and must not be used interchangeably, hence
>   the new struct
> - Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
> - Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
> - Add avcodec_decode_subtitle3 which takes subtitle frames,
>   serving as compatibility shim to legacy subtitle decoding
> - Add additional methods for conversion between old and new API
> 
> Signed-off-by: softworkz 
> ---
>  libavcodec/avcodec.c   |  19 ---
>  libavcodec/avcodec.h   |  75 ++--
>  libavcodec/decode.c|  53 ++--
>  libavcodec/pgssubdec.c |   1 +
>  libavcodec/utils.c |  11 ++
>  libavfilter/vf_subtitles.c |  50 ++--
>  libavformat/utils.c|   1 +
>  libavutil/Makefile |   2 +
>  libavutil/frame.c  | 194 ++---
>  libavutil/frame.h  |  93 +-
>  libavutil/subfmt.c | 243 +
>  libavutil/subfmt.h | 185 
>  12 files changed, 802 insertions(+), 125 deletions(-)
>  create mode 100644 libavutil/subfmt.c
>  create mode 100644 libavutil/subfmt.h

First of all, this should be split. It does way way more than just
"prepare AVFrame". It adds random things all over the place, some of
them completely spurious (like the single include in pgssubdec).

>  
> +/**
> + * Return subtitle format from a codec descriptor
> + *
> + * @param codec_descriptor codec descriptor
> + * @return the subtitle type (e.g. bitmap, text)
> + */
> +enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const 
> AVCodecDescriptor *codec_descriptor);

New functions should be namespaced along the lines of av(_)_
In this case, something like avcodec_descriptor_get_subtitle_format()

Also, it seems to introduce an assumption that bitmap and text are
mutually exclusive, while descriptors treat them as flags.

> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 753234792e..742f4ba07e 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -34,6 +34,7 @@
>  #include "rational.h"
>  #include "samplefmt.h"
>  #include "pixfmt.h"
> +#include "subfmt.h"
>  #include "version.h"
>  
>  
> @@ -278,7 +279,7 @@ typedef struct AVRegionOfInterest {
>  } AVRegionOfInterest;
>  
>  /**
> - * This structure describes decoded (raw) audio or video data.
> + * This structure describes decoded (raw) audio, video or subtitle data.
>   *
>   * AVFrame must be allocated using av_frame_alloc(). Note that this only
>   * allocates the AVFrame itself, the buffers for the data must be managed
> @@ -309,6 +310,13 @@ typedef struct AVRegionOfInterest {
>   */
>  typedef struct AVFrame {
>  #define AV_NUM_DATA_POINTERS 8
> +/**
> + * Media type of the frame (audio, video, subtitles..)
> + *
> + * See AVMEDIA_TYPE_xxx
> + */
> +enum AVMediaType type;
> +
>  /**
>   * pointer to the picture/channel planes.
>   * This might be different from the first allocated byte. For video,
> @@ -390,7 +398,7 @@ typedef struct AVFrame {
>  /**
>   * format of the frame, -1 if unknown or unset
>   * Values correspond to enum AVPixelFormat for video frames,
> - * enum AVSampleFormat for audio)
> + * enum AVSampleFormat for audio, AVSubtitleType for subtitles)
>   */
>  int format;
>  
> @@ -481,6 +489,39 @@ typedef struct AVFrame {
>   */
>  uint64_t channel_layout;
>  
> +/**
> + * Display start time, relative to packet pts, in ms.
> + */
> +uint32_t subtitle_start_time;
> +
> +/**
> + * Display end time, relative to packet pts, in ms.
> + */
> +uint32_t subtitle_end_time;
> +
> +/**
> + * Number of items in the @ref subtitle_areas array.
> + */
> +unsigned num_subtitle_areas;
> +
> +/**
> + * Array of subtitle areas, may be empty.
> + */
> +AVSubtitleArea **subtitle_areas;
> +
> +/**
> + * Usually the same as packet pts, in AV_TIME_BASE.
> + *
> + * @deprecated This is kept for compatibility reasons and corresponds to
> + * AVSubtitle->pts. Might be removed in the future.
> + */
> +int64_t subtitle_pts;
> +
> +/**
> + * Header containing style information for text subtitles.
> + */
> +AVBufferRef *subtitle_header;

This is breaking ABI.

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

To unsubscribe, visit link above, or email
ffmpeg-de

Re: [FFmpeg-devel] [PATCH v15 10/16] avfilter/textmod: Add textmod, censor and show_speaker filters

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 12:48:38AM +, Soft Works wrote:
> - textmod {S -> S)
>   Modify subtitle text in a number of ways
> 
> - censor {S -> S)
>   Censor subtitles using a word list
> 
> - show_speaker {S -> S)
>   Prepend speaker names from ASS subtitles to the visible text lines
> 
> Signed-off-by: softworkz 
> ---
>  doc/filters.texi | 206 
>  libavfilter/Makefile |   5 +
>  libavfilter/allfilters.c |   3 +
>  libavfilter/sf_textmod.c | 697 +++
>  4 files changed, 911 insertions(+)
>  create mode 100644 libavfilter/sf_textmod.c

I cant test this as it does not apply

Applying: avfilter/textmod: Add textmod, censor and show_speaker filters
.git/rebase-apply/patch:108: trailing whitespace.
Replace one or more characters. Requires the find and replace parameters to be 
specified. 
.git/rebase-apply/patch:112: trailing whitespace.
Remove certain characters. Requires the find parameter to be specified. 
.git/rebase-apply/patch:115: trailing whitespace.
Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ','). 
.git/rebase-apply/patch:119: trailing whitespace.
Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ','). 
.git/rebase-apply/patch:158: trailing whitespace.
Renders graphic subtitles as video frames. 
error: sha1 information is lacking or useless (doc/filters.texi).
error: could not build fake ancestor
Patch failed at 0001 avfilter/textmod: Add textmod, censor and show_speaker 
filters
Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".



[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell


signature.asc
Description: PGP signature
___
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] doc/APIchanges: fix typo

2021-11-25 Thread Anton Khirnov
---
 doc/APIchanges | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 565f7e091e..51fc259d3f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -24,7 +24,7 @@ API changes, most recent first:
   Add "disposition" AVOption to AVStream's class.
 
 2021-11-12 - xx - lavu 57.8.100 - hwcontext_vulkan.h
-  Added AVFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
+  Added AVVkFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
   nb_encode_queues, queue_family_decode_index, and nb_decode_queues.
 
 2021-10-18 - xx - lavf 59.8.100 - avio.h
-- 
2.33.0

___
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 v15 01/16] global: Prepare AVFrame for subtitle handling

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 12:48:11AM +, Soft Works wrote:
> Root commit for adding subtitle filtering capabilities.
> In detail:
> 
> - Add type (AVMediaType) field to AVFrame
>   Replaces previous way of distinction which was based on checking
>   width and height to determine whether a frame is audio or video
> - Add subtitle fields to AVFrame
> - Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
>   allocation logic. Cannot and must not be used interchangeably, hence
>   the new struct
> - Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
> - Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
> - Add avcodec_decode_subtitle3 which takes subtitle frames,
>   serving as compatibility shim to legacy subtitle decoding
> - Add additional methods for conversion between old and new API
> 
> Signed-off-by: softworkz 
> ---
>  libavcodec/avcodec.c   |  19 ---
>  libavcodec/avcodec.h   |  75 ++--
>  libavcodec/decode.c|  53 ++--
>  libavcodec/pgssubdec.c |   1 +
>  libavcodec/utils.c |  11 ++
>  libavfilter/vf_subtitles.c |  50 ++--
>  libavformat/utils.c|   1 +
>  libavutil/Makefile |   2 +
>  libavutil/frame.c  | 194 ++---
>  libavutil/frame.h  |  93 +-
>  libavutil/subfmt.c | 243 +
>  libavutil/subfmt.h | 185 
>  12 files changed, 802 insertions(+), 125 deletions(-)
>  create mode 100644 libavutil/subfmt.c
>  create mode 100644 libavutil/subfmt.h
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index c00a9b2af8..13e3711b9c 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -422,25 +422,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>  av_bsf_flush(avci->bsf);
>  }
>  
> -void avsubtitle_free(AVSubtitle *sub)
> -{
> -int i;
> -
> -for (i = 0; i < sub->num_rects; i++) {
> -av_freep(&sub->rects[i]->data[0]);
> -av_freep(&sub->rects[i]->data[1]);
> -av_freep(&sub->rects[i]->data[2]);
> -av_freep(&sub->rects[i]->data[3]);
> -av_freep(&sub->rects[i]->text);
> -av_freep(&sub->rects[i]->ass);
> -av_freep(&sub->rects[i]);
> -}
> -
> -av_freep(&sub->rects);
> -
> -memset(sub, 0, sizeof(*sub));
> -}
> -
>  av_cold int avcodec_close(AVCodecContext *avctx)
>  {
>  int i;
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 7ee8bc2b7c..0c5819b116 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -35,6 +35,7 @@
>  #include "libavutil/frame.h"
>  #include "libavutil/log.h"
>  #include "libavutil/pixfmt.h"
> +#include "libavutil/subfmt.h"
>  #include "libavutil/rational.h"
>  
>  #include "codec.h"
> @@ -1674,7 +1675,7 @@ typedef struct AVCodecContext {
>  
>  /**
>   * Header containing style information for text subtitles.
> - * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
> + * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
>   * [Script Info] and [V4+ Styles] section, plus the [Events] line and
>   * the Format line following. It shouldn't include any Dialogue line.
>   * - encoding: Set/allocated/freed by user (before avcodec_open2())
> @@ -2238,63 +2239,8 @@ typedef struct AVHWAccel {
>   * @}
>   */
>  
> -enum AVSubtitleType {
> -SUBTITLE_NONE,
> -
> -SUBTITLE_BITMAP,///< A bitmap, pict will be set
> -
> -/**
> - * Plain text, the text field must be set by the decoder and is
> - * authoritative. ass and pict fields may contain approximations.
> - */
> -SUBTITLE_TEXT,
> -
> -/**
> - * Formatted text, the ass field must be set by the decoder and is
> - * authoritative. pict and text fields may contain approximations.
> - */
> -SUBTITLE_ASS,
> -};

doesnt build so i cannot bisect breakages reliably

CC  libavcodec/libzvbi-teletextdec.o
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_text’:
libavcodec/libzvbi-teletextdec.c:227:26: error: ‘SUBTITLE_NONE’ undeclared 
(first use in this function); did you mean ‘SUBTITLE_ASS’?
 sub_rect->type = SUBTITLE_NONE;
  ^
  SUBTITLE_ASS
libavcodec/libzvbi-teletextdec.c:227:26: note: each undeclared identifier is 
reported only once for each function it appears in
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_ass’:
libavcodec/libzvbi-teletextdec.c:405:26: error: ‘SUBTITLE_NONE’ undeclared 
(first use in this function); did you mean ‘SUBTITLE_ASS’?
 sub_rect->type = SUBTITLE_NONE;
  ^
  SUBTITLE_ASS
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_bitmap’:
libavcodec/libzvbi-teletextdec.c:465:26: error: ‘SUBTITLE_NONE’ undeclared 
(first use in this function); did you mean ‘SUBTITLE_ASS’?
   

Re: [FFmpeg-devel] [PATCH v15 08/16] fftools/ffmpeg: Replace sub2video with subtitle frame filtering

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 12:48:33AM +, Soft Works wrote:
> This commit actually enables subtitle filtering in ffmpeg by
> sending and receiving subtitle frames to and from a filtergraph.
> 
> The heartbeat functionality from the previous sub2video implementation
> is retained and applied to all subtitle frames (bitmap, text, ..).
> 
> The other part of sub2video functionality is retained by
> auto-insertion of the new graphicsub2video filter.
> 
> Justification for changed test refs:
> 
> - sub2video
>   The new results are identical excepting the last frame which
>   is due to the implementation changes
> 
> - sub2video_basic
>   The previous results had some incorrect output because multiple
>   frames had the same dts
>   The non-empty content frames are visually identical, the different
>   CRC is due to the different blending algorithm that is being used.
> 
> - sub2video_time_limited
>   The third frame in the previous ref was a repetition, which doesn't
>   happen anymore with the new subtitle filtering.
> 
> - sub-dvb
>   Running ffprobe -show_frames on the source file shows that there
>   are 7 subtitle frames with 0 rects in the source at the start
>   and 2 at the end. This translates to the 14 and 4 additional
>   entries in the new test results.
> 
> - filter-overlay-dvdsub-2397
>   Overlay results have slightly different CRCs due to different
>   blending implementation
> 
> Signed-off-by: softworkz 
> ---
>  fftools/ffmpeg.c  | 523 +++---
>  fftools/ffmpeg.h  |  15 +-
>  fftools/ffmpeg_filter.c   | 217 ++---
>  fftools/ffmpeg_hw.c   |   2 +-
>  fftools/ffmpeg_opt.c  |   3 +-
>  tests/ref/fate/filter-overlay-dvdsub-2397 | 181 
>  tests/ref/fate/sub-dvb| 162 ---
>  tests/ref/fate/sub2video  | 116 ++---
>  tests/ref/fate/sub2video_basic| 135 ++
>  tests/ref/fate/sub2video_time_limited |   4 +-
>  10 files changed, 684 insertions(+), 674 deletions(-)

breaks:
./ffmpeg -i ~/tickets/153/bbc_small.ts -filter_complex '[0:v][0:s]overlay' 
-qscale 2 -t 3 file.avi

[graphicsub2video @ 0x55788ca17ac0] [IMGUTILS @ 0x7fff1c9730d0] Picture size 
0x0 is invalid
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[libmp3lame @ 0x55788cabc040] 3 frames left in the queue on closing
Conversion failed!


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
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/1] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 03:05:23AM +, Soft Works wrote:
> Signed-off-by: softworkz 
> ---
> v2: As suggested by Marton, I'm always prniting extradata_size now instead of 
> an 'attachment_size' value.
> The downside is that a number of tests need to be changed and probably, 
> Patchwork won't get it right again (due to long lines).
> 
>  doc/ffprobe.xsd | 1 +
>  fftools/ffprobe.c   | 1 +
>  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
>  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
>  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
>  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
>  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
>  tests/ref/fate/flv-demux| 4 ++--
>  tests/ref/fate/mov-zombie   | 2 +-
>  tests/ref/fate/mxf-probe-d10| 1 +
>  tests/ref/fate/oggopus-demux| 2 +-
>  tests/ref/fate/ts-demux | 2 +-
>  tests/ref/fate/ts-opus-demux| 2 +-
>  tests/ref/fate/ts-small-demux   | 2 +-
>  14 files changed, 15 insertions(+), 12 deletions(-)

doesnt apply (maybe long line issue)
so i cannot test this

Applying: fftools/ffprobe: print size of attachment streams (extradata_size)
error: corrupt patch at line 106
error: could not build fake ancestor
Patch failed at 0001 fftools/ffprobe: print size of attachment streams 
(extradata_size)

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


signature.asc
Description: PGP signature
___
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 1/1] avutils/hwcontext: When deriving a hwdevice, search for existing device in both directions

2021-11-25 Thread Anton Khirnov
Quoting Soft Works (2021-11-25 03:41:32)
> @@ -687,6 +720,11 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef 
> **dst_ref_ptr,
>  ret = AVERROR(ENOMEM);
>  goto fail;
>  }
> +tmp_ctx->internal->derived_devices[type] = 
> av_buffer_ref(dst_ref);
> +if (!tmp_ctx->internal->derived_devices[type]) {
> +ret = AVERROR(ENOMEM);
> +goto fail;
> +}

This means that once you derive a device of a certain type, you can
never truly close it without also killing the parent device. That
strikes me as
- potentially troublesome
- a behavior change

Also, I don't see it as completely obvious that all derivations should
always return the same child instance.

-- 
Anton Khirnov
___
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/1] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Michael
> Niedermayer
> Sent: Thursday, November 25, 2021 5:39 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v2 1/1] fftools/ffprobe: print size of
> attachment streams (extradata_size)
> 
> On Thu, Nov 25, 2021 at 03:05:23AM +, Soft Works wrote:
> > Signed-off-by: softworkz 
> > ---
> > v2: As suggested by Marton, I'm always prniting extradata_size now instead
> of an 'attachment_size' value.
> > The downside is that a number of tests need to be changed and probably,
> Patchwork won't get it right again (due to long lines).
> >
> >  doc/ffprobe.xsd | 1 +
> >  fftools/ffprobe.c   | 1 +
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
> >  tests/ref/fate/flv-demux| 4 ++--
> >  tests/ref/fate/mov-zombie   | 2 +-
> >  tests/ref/fate/mxf-probe-d10| 1 +
> >  tests/ref/fate/oggopus-demux| 2 +-
> >  tests/ref/fate/ts-demux | 2 +-
> >  tests/ref/fate/ts-opus-demux| 2 +-
> >  tests/ref/fate/ts-small-demux   | 2 +-
> >  14 files changed, 15 insertions(+), 12 deletions(-)
> 
> doesnt apply (maybe long line issue)
> so i cannot test this
> 

I have already sent a v3 where the patch is included as an attachment.
Hope this will do it...

Thanks,
sw

___
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] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 10:32:21AM +, Soft Works wrote:
> Signed-off-by: softworkz 
> ---
> V3: Try sending long-line patch as attachment
> 
>  doc/ffprobe.xsd | 1 +
>  fftools/ffprobe.c   | 1 +
>  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
>  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
>  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
>  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
>  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
>  tests/ref/fate/flv-demux| 4 ++--
>  tests/ref/fate/mov-zombie   | 2 +-
>  tests/ref/fate/mxf-probe-d10| 1 +
>  tests/ref/fate/oggopus-demux| 2 +-
>  tests/ref/fate/ts-demux | 2 +-
>  tests/ref/fate/ts-opus-demux| 2 +-
>  tests/ref/fate/ts-small-demux   | 2 +-
>  14 files changed, 15 insertions(+), 12 deletions(-)

Applying: 
error: corrupt patch at line 152
Patch failed at 0001 


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.


signature.asc
Description: PGP signature
___
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/1] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Anton Khirnov
Quoting Michael Niedermayer (2021-11-25 17:38:59)
> On Thu, Nov 25, 2021 at 03:05:23AM +, Soft Works wrote:
> > Signed-off-by: softworkz 
> > ---
> > v2: As suggested by Marton, I'm always prniting extradata_size now instead 
> > of an 'attachment_size' value.
> > The downside is that a number of tests need to be changed and probably, 
> > Patchwork won't get it right again (due to long lines).
> > 
> >  doc/ffprobe.xsd | 1 +
> >  fftools/ffprobe.c   | 1 +
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
> >  tests/ref/fate/flv-demux| 4 ++--
> >  tests/ref/fate/mov-zombie   | 2 +-
> >  tests/ref/fate/mxf-probe-d10| 1 +
> >  tests/ref/fate/oggopus-demux| 2 +-
> >  tests/ref/fate/ts-demux | 2 +-
> >  tests/ref/fate/ts-opus-demux| 2 +-
> >  tests/ref/fate/ts-small-demux   | 2 +-
> >  14 files changed, 15 insertions(+), 12 deletions(-)
> 
> doesnt apply (maybe long line issue)
> so i cannot test this
> 
> Applying: fftools/ffprobe: print size of attachment streams (extradata_size)
> error: corrupt patch at line 106
> error: could not build fake ancestor
> Patch failed at 0001 fftools/ffprobe: print size of attachment streams 
> (extradata_size)

I've encountered this before, IIRC the problem is in the mailing list
software that breaks very long lines.

Properly the ML software should be fixed to not mangle text patches.

A workaround is to send such patches as something other than text/plain

-- 
Anton Khirnov
___
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/1] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 05:42:27PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-11-25 17:38:59)
> > On Thu, Nov 25, 2021 at 03:05:23AM +, Soft Works wrote:
> > > Signed-off-by: softworkz 
> > > ---
> > > v2: As suggested by Marton, I'm always prniting extradata_size now 
> > > instead of an 'attachment_size' value.
> > > The downside is that a number of tests need to be changed and probably, 
> > > Patchwork won't get it right again (due to long lines).
> > > 
> > >  doc/ffprobe.xsd | 1 +
> > >  fftools/ffprobe.c   | 1 +
> > >  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
> > >  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
> > >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
> > >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
> > >  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
> > >  tests/ref/fate/flv-demux| 4 ++--
> > >  tests/ref/fate/mov-zombie   | 2 +-
> > >  tests/ref/fate/mxf-probe-d10| 1 +
> > >  tests/ref/fate/oggopus-demux| 2 +-
> > >  tests/ref/fate/ts-demux | 2 +-
> > >  tests/ref/fate/ts-opus-demux| 2 +-
> > >  tests/ref/fate/ts-small-demux   | 2 +-
> > >  14 files changed, 15 insertions(+), 12 deletions(-)
> > 
> > doesnt apply (maybe long line issue)
> > so i cannot test this
> > 
> > Applying: fftools/ffprobe: print size of attachment streams (extradata_size)
> > error: corrupt patch at line 106
> > error: could not build fake ancestor
> > Patch failed at 0001 fftools/ffprobe: print size of attachment streams 
> > (extradata_size)
> 
> I've encountered this before, IIRC the problem is in the mailing list
> software that breaks very long lines.
> 
> Properly the ML software should be fixed to not mangle text patches.

what i remember was that the RFC demanded breaking lines, and that somehow
occured in the middle of the mail handling. 
Id assume this must affect many projects but i dont remember seeing an
existing solution

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"


signature.asc
Description: PGP signature
___
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] doc/APIchanges: fix typo

2021-11-25 Thread Lynne
25 Nov 2021, 17:26 by an...@khirnov.net:

> ---
>  doc/APIchanges | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 565f7e091e..51fc259d3f 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -24,7 +24,7 @@ API changes, most recent first:
>  Add "disposition" AVOption to AVStream's class.
>  
>  2021-11-12 - xx - lavu 57.8.100 - hwcontext_vulkan.h
> -  Added AVFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
> +  Added AVVkFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index,
>  nb_encode_queues, queue_family_decode_index, and nb_decode_queues.  
>

LGTM
___
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] configure: do not include -lvulkan in vulkan's pkg-config check

2021-11-25 Thread Lynne
24 Nov 2021, 20:19 by d...@lynne.ee:

> Also fixes the non-pkg-config check.
>
> Patch attached.
>

Ping.
___
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] fftools/ffprobe: print size of attachment streams (extradata_size)

2021-11-25 Thread Soft Works
Another attempt: Created on Linux and zipped...


> -Original Message-
> From: ffmpeg-devel  On Behalf Of Michael
> Niedermayer
> Sent: Thursday, November 25, 2021 5:42 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v3 1/1] fftools/ffprobe: print size of
> attachment streams (extradata_size)
> 
> On Thu, Nov 25, 2021 at 10:32:21AM +, Soft Works wrote:
> > Signed-off-by: softworkz 
> > ---
> > V3: Try sending long-line patch as attachment
> >
> >  doc/ffprobe.xsd | 1 +
> >  fftools/ffprobe.c   | 1 +
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf | 2 +-
> >  tests/ref/fate/concat-demuxer-extended-lavf-mxf_d10 | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple1-lavf-mxf_d10  | 2 +-
> >  tests/ref/fate/concat-demuxer-simple2-lavf-ts   | 2 +-
> >  tests/ref/fate/flv-demux| 4 ++--
> >  tests/ref/fate/mov-zombie   | 2 +-
> >  tests/ref/fate/mxf-probe-d10| 1 +
> >  tests/ref/fate/oggopus-demux| 2 +-
> >  tests/ref/fate/ts-demux | 2 +-
> >  tests/ref/fate/ts-opus-demux| 2 +-
> >  tests/ref/fate/ts-small-demux   | 2 +-
> >  14 files changed, 15 insertions(+), 12 deletions(-)
> 
> Applying:
> error: corrupt patch at line 152
> Patch failed at 0001
> 
> 
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Dictatorship: All citizens are under surveillance, all their steps and
> actions recorded, for the politicians to enforce control.
> Democracy: All politicians are under surveillance, all their steps and
> actions recorded, for the citizens to enforce control.
<>
___
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 1/1] avutils/hwcontext: When deriving a hwdevice, search for existing device in both directions

2021-11-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton
> Khirnov
> Sent: Thursday, November 25, 2021 5:40 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v4 1/1] avutils/hwcontext: When deriving a
> hwdevice, search for existing device in both directions
> 
> Quoting Soft Works (2021-11-25 03:41:32)
> > @@ -687,6 +720,11 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef
> **dst_ref_ptr,
> >  ret = AVERROR(ENOMEM);
> >  goto fail;
> >  }
> > +tmp_ctx->internal->derived_devices[type] =
> av_buffer_ref(dst_ref);
> > +if (!tmp_ctx->internal->derived_devices[type]) {
> > +ret = AVERROR(ENOMEM);
> > +goto fail;
> > +}
> 
> This means that once you derive a device of a certain type, you can
> never truly close it without also killing the parent device. That
> strikes me as
> - potentially troublesome
> - a behavior change
> 
> Also, I don't see it as completely obvious that all derivations should
> always return the same child instance.


It creates the behavior that everybody wants and expects who is working 
with HW devices derivation.

softworkz

___
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] avformat/mov: add option max_stts_delta

2021-11-25 Thread Michael Niedermayer
On Thu, Nov 25, 2021 at 10:51:15AM +0530, Gyan Doshi wrote:
> 
> 
> On 2021-11-25 12:56 am, Michael Niedermayer wrote:
> > On Wed, Nov 24, 2021 at 10:58:00AM +0530, Gyan Doshi wrote:
> > > 
> > > On 2021-11-24 01:16 am, Michael Niedermayer wrote:
> > > > On Tue, Nov 23, 2021 at 06:41:06PM +0530, Gyan Doshi wrote:
> > > > > Very high stts sample deltas may occasionally be intended but usually
> > > > > they are written in error or used to store a negative value for dts 
> > > > > correction
> > > > > when treated as signed 32-bit integers.
> > > > > 
> > > > > This option lets the user set an upper limit, beyond which the delta
> > > > > is clamped to 1. Negative values of under 1 second are used to adjust
> > > > > dts.
> > > > > 
> > > > > Unit is the track time scale. Default is INT_MAX which maintains 
> > > > > current handling.
> > > > > ---
> > > > >doc/demuxers.texi  |  6 ++
> > > > >libavformat/isom.h |  1 +
> > > > >libavformat/mov.c  | 14 +-
> > > > >3 files changed, 16 insertions(+), 5 deletions(-)
> > > > > 
> > > > > diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> > > > > index cab8a7072c..15078b9b1b 100644
> > > > > --- a/doc/demuxers.texi
> > > > > +++ b/doc/demuxers.texi
> > > > > @@ -713,6 +713,12 @@ specify.
> > > > >@item decryption_key
> > > > >16-byte key, in hex, to decrypt files encrypted using ISO Common 
> > > > > Encryption (CENC/AES-128 CTR; ISO/IEC 23001-7).
> > > > > +
> > > > > +@item max_stts_delta
> > > > > +The sample offsets stored in a track's stts box are 32-bit unsigned 
> > > > > integers. However, very large values usually indicate
> > > > > +a value written by error or a storage of a small negative value as a 
> > > > > way to correct accumulated DTS delay.
> > > > > +Range is 0 to UINT_MAX. Default is INT_MAX.
> > > > > +
> > > > >@end table
> > > > >@subsection Audible AAX
> > > > > diff --git a/libavformat/isom.h b/libavformat/isom.h
> > > > > index ef8f19b18c..625dea8421 100644
> > > > > --- a/libavformat/isom.h
> > > > > +++ b/libavformat/isom.h
> > > > > @@ -305,6 +305,7 @@ typedef struct MOVContext {
> > > > >int32_t movie_display_matrix[3][3]; ///< display matrix from 
> > > > > mvhd
> > > > >int have_read_mfra_size;
> > > > >uint32_t mfra_size;
> > > > > +uint32_t max_stts_delta;
> > > > >} MOVContext;
> > > > >int ff_mp4_read_descr_len(AVIOContext *pb);
> > > > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > > > index 451cb78bbf..bbda07ac42 100644
> > > > > --- a/libavformat/mov.c
> > > > > +++ b/libavformat/mov.c
> > > > > @@ -3965,14 +3965,17 @@ static void mov_build_index(MOVContext *mov, 
> > > > > AVStream *st)
> > > > >current_offset += sample_size;
> > > > >stream_size += sample_size;
> > > > > -/* A negative sample duration is invalid based on 
> > > > > the spec,
> > > > > - * but some samples need it to correct the DTS. */
> > > > > -if (sc->stts_data[stts_index].duration < 0) {
> > > > > +/* STTS sample offsets are uint32 but some files 
> > > > > store it as int32
> > > > > + * with negative values used to correct DTS delays.
> > > > > +   There may be abnormally large values as well. */
> > > > > +if (sc->stts_data[stts_index].duration > 
> > > > > mov->max_stts_delta) {
> > > > > +// assume high delta is a negative correction if 
> > > > > less than 1 second
> > > > > +int32_t delta_magnitude = *((int32_t 
> > > > > *)&sc->stts_data[stts_index].duration);
> > > > >av_log(mov->fc, AV_LOG_WARNING,
> > > > > -   "Invalid SampleDelta %d in STTS, at %d 
> > > > > st:%d\n",
> > > > > +   "Correcting too large SampleDelta %u in 
> > > > > STTS, at %d st:%d.\n",
> > > > >   sc->stts_data[stts_index].duration, 
> > > > > stts_index,
> > > > >   st->index);
> > > > > -dts_correction += 
> > > > > sc->stts_data[stts_index].duration - 1;
> > > > > +dts_correction += (delta_magnitude < 0 && 
> > > > > FFABS(delta_magnitude) < sc->time_scale ? delta_magnitude - 1 : 0);
> > > > >sc->stts_data[stts_index].duration = 1;
> > > > >}
> > > > >current_dts += sc->stts_data[stts_index].duration;
> > > > > @@ -8566,6 +8569,7 @@ static const AVOption mov_options[] = {
> > > > >{ "decryption_key", "The media decryption key (hex)", 
> > > > > OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = 
> > > > > AV_OPT_FLAG_DECODING_PARAM },
> > > > >{ "enable_drefs", "Enable external track support.", 
> > > > > OFFSET(enable_drefs), AV_OPT_TYPE_BOOL,
> > > > >{.i64 = 0}, 0, 1, FLAGS },
> > > > > +{ "max_stts_delta", "treat offsets

[FFmpeg-devel] 5.0 release

2021-11-25 Thread Michael Niedermayer
Hi all

just wanted to remind everyone of the plan (suggested by jb) to make the
5.0 release in december
i dont know if that will work out but please avoid introducing 
risky changes until the release branch splits off
and if you know of any regressions, security issues or other major bugs,
please help fixing them

Also still open is the question about calling it "LTS" or calling
a later 5.x.x LTS

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


signature.asc
Description: PGP signature
___
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 v15 01/16] global: Prepare AVFrame for subtitle handling

2021-11-25 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton
> Khirnov
> Sent: Thursday, November 25, 2021 4:56 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v15 01/16] global: Prepare AVFrame for
> subtitle handling
> 
> Quoting Soft Works (2021-11-25 01:48:11)
> > Root commit for adding subtitle filtering capabilities.
> > In detail:
> >
> > - Add type (AVMediaType) field to AVFrame
> >   Replaces previous way of distinction which was based on checking
> >   width and height to determine whether a frame is audio or video
> > - Add subtitle fields to AVFrame
> > - Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
> >   allocation logic. Cannot and must not be used interchangeably, hence
> >   the new struct
> > - Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
> > - Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
> > - Add avcodec_decode_subtitle3 which takes subtitle frames,
> >   serving as compatibility shim to legacy subtitle decoding
> > - Add additional methods for conversion between old and new API
> >
> > Signed-off-by: softworkz 
> > ---
> >  libavcodec/avcodec.c   |  19 ---
> >  libavcodec/avcodec.h   |  75 ++--
> >  libavcodec/decode.c|  53 ++--
> >  libavcodec/pgssubdec.c |   1 +
> >  libavcodec/utils.c |  11 ++
> >  libavfilter/vf_subtitles.c |  50 ++--
> >  libavformat/utils.c|   1 +
> >  libavutil/Makefile |   2 +
> >  libavutil/frame.c  | 194 ++---
> >  libavutil/frame.h  |  93 +-
> >  libavutil/subfmt.c | 243 +
> >  libavutil/subfmt.h | 185 
> >  12 files changed, 802 insertions(+), 125 deletions(-)
> >  create mode 100644 libavutil/subfmt.c
> >  create mode 100644 libavutil/subfmt.h
> 
> First of all, this should be split. It does way way more than just
> "prepare AVFrame". It adds random things all over the place, some of
> them completely spurious (like the single include in pgssubdec).


I double-checked. It cannot be split without breaking compilation.

What this commit does is to relocate and promote AVSubtitle and 
AVSubtitleRect to the public API - alongside the new AVSubtitleArea
(the replacement for AVSubtitleRect. AVFrame is the replacement for
AVSubtitle)

AVSubtitle and AVSubtitleRect are immediately marked deprecated, 
but that's the only way to make the transition and retain compatibility.

Same promotion happens for the subtitle enum which transitions from
e.g. SUBTITLE_BITMAP to AV_SUBTITLE_FMT_BITMAP. Previous constants
are kept for compatibility.

For this promotion, the code files need to be relocated to libavutil.
This in turn requires some header changes. 

All files in this commit are depending on those references and 
need to be changed in a single commit.

The include change to pgssubdec is not spurious but required. 
Same is needed for the teletext decoder (which I had forgotten).
Why exactly those two codecs? => because these are the two that
can handle both, text and bitmap subs, that's why they need the 
subtitle type enum constants.

Andreas hat reviewed this part a while ago and this is the 
result we ended up with after a few iterations. 

Kind regards,
softworkz



> 
> >
> > +/**
> > + * Return subtitle format from a codec descriptor
> > + *
> > + * @param codec_descriptor codec descriptor
> > + * @return the subtitle type (e.g. bitmap, text)
> > + */
> > +enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const
> AVCodecDescriptor *codec_descriptor);
> 
> New functions should be namespaced along the lines of av(_)_
> In this case, something like avcodec_descriptor_get_subtitle_format()
> 
> Also, it seems to introduce an assumption that bitmap and text are
> mutually exclusive, while descriptors treat them as flags.
> 
> > diff --git a/libavutil/frame.h b/libavutil/frame.h
> > index 753234792e..742f4ba07e 100644
> > --- a/libavutil/frame.h
> > +++ b/libavutil/frame.h
> > @@ -34,6 +34,7 @@
> >  #include "rational.h"
> >  #include "samplefmt.h"
> >  #include "pixfmt.h"
> > +#include "subfmt.h"
> >  #include "version.h"
> >
> >
> > @@ -278,7 +279,7 @@ typedef struct AVRegionOfInterest {
> >  } AVRegionOfInterest;
> >
> >  /**
> > - * This structure describes decoded (raw) audio or video data.
> > + * This structure describes decoded (raw) audio, video or subtitle data.
> >   *
> >   * AVFrame must be allocated using av_frame_alloc(). Note that this only
> >   * allocates the AVFrame itself, the buffers for the data must be managed
> > @@ -309,6 +310,13 @@ typedef struct AVRegionOfInterest {
> >   */
> >  typedef struct AVFrame {
> >  #define AV_NUM_DATA_POINTERS 8
> > +/**
> > + * Media type of the frame (audio, video, subtitles..)
> > + *
> > + * See AVMEDIA_TYPE_xxx
> > + */
> > +enum AVMediaType type;
> > +
> >  /**
> >   

[FFmpeg-devel] [PATCH v2] lavu/avframe: add a time_base field

2021-11-25 Thread Lynne
This adds a time_base field (currently unused), analogue to the 
AVPacket.time_base field.
This allows for API clients to exchange AVFrames directly, without
needing to plumb extra data from sources via side mechanisms.

Patch attached.

>From 7a5b8fe31ff7e193ddd776daf8aac1c2c528d8d2 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Thu, 25 Nov 2021 18:26:20 +0100
Subject: [PATCH] lavu/avframe: add a time_base field

This adds a time_base field (currently unused), analogue to the
AVPacket.time_base field.
---
 libavutil/frame.c | 2 ++
 libavutil/frame.h | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d4d3ad6988..64eed5b0dd 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -63,6 +63,7 @@ static void get_frame_defaults(AVFrame *frame)
 frame->pkt_duration= 0;
 frame->pkt_pos = -1;
 frame->pkt_size= -1;
+frame->time_base   = (AVRational){ 0, 1 };
 frame->key_frame   = 1;
 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
 frame->format  = -1; /* unknown */
@@ -278,6 +279,7 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
 dst->pkt_pos= src->pkt_pos;
 dst->pkt_size   = src->pkt_size;
 dst->pkt_duration   = src->pkt_duration;
+dst->time_base  = src->time_base;
 dst->reordered_opaque   = src->reordered_opaque;
 dst->quality= src->quality;
 dst->best_effort_timestamp  = src->best_effort_timestamp;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 753234792e..66fe3070f8 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -421,6 +421,12 @@ typedef struct AVFrame {
  */
 int64_t pkt_dts;
 
+/**
+ * Time base for the timestamps in this frame. May be 0, in which case the
+ * time_base from the frame source should be used.
+ */
+AVRational time_base;
+
 /**
  * picture number in bitstream order
  */
-- 
2.34.0

___
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 v15 00/16] *** SUBJECT HERE ***

2021-11-25 Thread Soft Works
Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
  allocation logic. Cannot and must not be used interchangeably, hence
  the new struct
- Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
- Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
- Add avcodec_decode_subtitle3 which takes subtitle frames,
  serving as compatibility shim to legacy subtitle decoding
- Add additional methods for conversion between old and new API

New in V15

- Rebased to upstream changes 
- avcodec/subtitles: Migrate subtitle encoders to frame-based API and provide 
compatibility shim for legacy api
- fftools/ffmpeg: Use new frame-based subtitle encoding API
- AVSubtitleArea: copy flags field, make params const
- graphicsubs2text: Don't emit duplicate frames
- graphicsubs2text: Combined OCR output into a single AVSubtitleArea
  (I have a prototype for detecting text colors and positions, but it's not 
ready at this point)
- splitcc: cleanup local subtitle_header ref
- stripstyles: add parameter for ass layer selection
- avcodec/subtitles: deferred loading of ass header for text subtitle encoders
- verified all example command lines in the docs are working, added somre more

Kind regards,
softworkz



softworkz (16):
  global: Prepare AVFrame for subtitle handling
  global: Move ass helper functions to avutil as avpriv_ and extend ass
dialog parsing
  fftools/play,probe: Adjust for subtitle changes
  avfilter/subtitles: Add subtitles.c for subtitle frame allocation
  avfilter/avfilter: Handle subtitle frames
  avfilter/sbuffer: Add sbuffersrc and sbuffersink filters
  avfilter/overlaygraphicsubs: Add overlaygraphicsubs and
graphicsub2video filters
  fftools/ffmpeg: Replace sub2video with subtitle frame filtering
  avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video
filters
  avfilter/textmod: Add textmod, censor and show_speaker filters
  avfilter/stripstyles: Add stripstyles filter
  avfilter/splitcc: Add splitcc filter for closed caption handling
  avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)
  avfilter/subscale: Add filter for scaling and/or re-arranging
graphical subtitles
  avcodec/subtitles: Migrate subtitle encoders to frame-based API and
provide a compatibility shim for the legacy api
  fftools/ffmpeg: Use new frame-based subtitle encoding API

 configure |   7 +-
 doc/filters.texi  | 756 +++
 fftools/ffmpeg.c  | 553 ++-
 fftools/ffmpeg.h  |  15 +-
 fftools/ffmpeg_filter.c   | 217 +++--
 fftools/ffmpeg_hw.c   |   2 +-
 fftools/ffmpeg_opt.c  |   3 +-
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  48 +-
 libavcodec/Makefile   |  56 +-
 libavcodec/ass.h  | 129 +--
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |  83 +-
 libavcodec/avcodec.c  |  19 -
 libavcodec/avcodec.h  |  82 +-
 libavcodec/ccaption_dec.c |  19 +-
 libavcodec/decode.c   |  53 +-
 libavcodec/dvbsubenc.c|  85 +-
 libavcodec/dvdsubenc.c|  89 +-
 libavcodec/encode.c   |  97 +-
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   | 115 ++-
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/pgssubdec.c|   1 +
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   | 104 ++-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/tests/avcodec.c|   2 -
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  95 +-
 libavcodec/utils.c|  11 +
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  81 +-
 libavcodec/xsubenc.c  |  65 +-
 libavfilter/Makefile  |  15 +
 libavfilter/allfilters.c   

[FFmpeg-devel] [PATCH v15 01/16] global: Prepare AVFrame for subtitle handling

2021-11-25 Thread Soft Works
Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
  allocation logic. Cannot and must not be used interchangeably, hence
  the new struct
- Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
- Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
- Add avcodec_decode_subtitle3 which takes subtitle frames,
  serving as compatibility shim to legacy subtitle decoding
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.c   |  19 ---
 libavcodec/avcodec.h   |  75 ++--
 libavcodec/decode.c|  53 ++--
 libavcodec/pgssubdec.c |   1 +
 libavcodec/utils.c |  11 ++
 libavfilter/vf_subtitles.c |  50 ++--
 libavformat/utils.c|   1 +
 libavutil/Makefile |   2 +
 libavutil/frame.c  | 194 ++---
 libavutil/frame.h  |  93 +-
 libavutil/subfmt.c | 243 +
 libavutil/subfmt.h | 185 
 12 files changed, 802 insertions(+), 125 deletions(-)
 create mode 100644 libavutil/subfmt.c
 create mode 100644 libavutil/subfmt.h

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..13e3711b9c 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -422,25 +422,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 av_bsf_flush(avci->bsf);
 }
 
-void avsubtitle_free(AVSubtitle *sub)
-{
-int i;
-
-for (i = 0; i < sub->num_rects; i++) {
-av_freep(&sub->rects[i]->data[0]);
-av_freep(&sub->rects[i]->data[1]);
-av_freep(&sub->rects[i]->data[2]);
-av_freep(&sub->rects[i]->data[3]);
-av_freep(&sub->rects[i]->text);
-av_freep(&sub->rects[i]->ass);
-av_freep(&sub->rects[i]);
-}
-
-av_freep(&sub->rects);
-
-memset(sub, 0, sizeof(*sub));
-}
-
 av_cold int avcodec_close(AVCodecContext *avctx)
 {
 int i;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7ee8bc2b7c..0c5819b116 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -1674,7 +1675,7 @@ typedef struct AVCodecContext {
 
 /**
  * Header containing style information for text subtitles.
- * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+ * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  * the Format line following. It shouldn't include any Dialogue line.
  * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2238,63 +2239,8 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-SUBTITLE_NONE,
-
-SUBTITLE_BITMAP,///< A bitmap, pict will be set
-
-/**
- * Plain text, the text field must be set by the decoder and is
- * authoritative. ass and pict fields may contain approximations.
- */
-SUBTITLE_TEXT,
-
-/**
- * Formatted text, the ass field must be set by the decoder and is
- * authoritative. pict and text fields may contain approximations.
- */
-SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x0001
 
-typedef struct AVSubtitleRect {
-int x; ///< top left corner  of pict, undefined when pict is not 
set
-int y; ///< top left corner  of pict, undefined when pict is not 
set
-int w; ///< widthof pict, undefined when pict is not 
set
-int h; ///< height   of pict, undefined when pict is not 
set
-int nb_colors; ///< number of colors in pict, undefined when pict is not 
set
-
-/**
- * data+linesize for the bitmap of this subtitle.
- * Can be set for text/ass as well once they are rendered.
- */
-uint8_t *data[4];
-int linesize[4];
-
-enum AVSubtitleType type;
-
-char *text; ///< 0 terminated plain UTF-8 text
-
-/**
- * 0 terminated ASS/SSA compatible event line.
- * The presentation of this is unaffected by the other values in this
- * struct.
- */
-char *ass;
-
-int flags;
-} AVSubtitleRect;
-
-typedef struct AVSubtitle {
-uint16_t format; /* 0 = graphics */
-uint32_t start_display_time; /* relative to packet pts, in ms */
-uint32_t end_display_time; /* relative to packet pts, in ms */
-unsigned num_rects;
-AVSubtitleRect **rects;
-int64_t pts;///< Same as packet pts, in AV_TIME_BASE
-

[FFmpeg-devel] [PATCH v15 03/16] fftools/play, probe: Adjust for subtitle changes

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  48 ++
 2 files changed, 78 insertions(+), 72 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..0af32888da 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -152,7 +152,6 @@ typedef struct Clock {
 /* Common struct for handling all types of decoded data and allocated render 
buffers. */
 typedef struct Frame {
 AVFrame *frame;
-AVSubtitle sub;
 int serial;
 double pts;   /* presentation timestamp for the frame */
 double duration;  /* estimated duration of the frame */
@@ -586,7 +585,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, 
PacketQueue *queue, S
 return 0;
 }
 
-static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
+static int decoder_decode_frame(Decoder *d, AVFrame *frame) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
@@ -620,6 +619,9 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 }
 }
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+ret = avcodec_receive_frame(d->avctx, frame);
+break;
 }
 if (ret == AVERROR_EOF) {
 d->finished = d->pkt_serial;
@@ -652,25 +654,11 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both 
returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
-d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
-}
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -683,7 +671,6 @@ static void decoder_destroy(Decoder *d) {
 static void frame_queue_unref_item(Frame *vp)
 {
 av_frame_unref(vp->frame);
-avsubtitle_free(&vp->sub);
 }
 
 static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, 
int keep_last)
@@ -981,7 +968,7 @@ static void video_image_display(VideoState *is)
 if (frame_queue_nb_remaining(&is->subpq) > 0) {
 sp = frame_queue_peek(&is->subpq);
 
-if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 
1000)) {
+if (vp->pts >= sp->pts + ((float) sp->frame->subtitle_start_time / 
1000)) {
 if (!sp->uploaded) {
 uint8_t* pixels[4];
 int pitch[4];
@@ -993,25 +980,27 @@ static void video_image_display(VideoState *is)
 if (realloc_texture(&is->sub_texture, 
SDL_PIXELFORMAT_ARGB, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
 return;
 
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = sp->sub.rects[i];
+for (i = 0; i < sp->frame->num_subtitle_areas; i++) {
+AVSubtitleArea *area = sp->frame->subtitle_areas[i];
+SDL_Rect sdl_rect = { .x = area->x, .y = area->y, .w = 
area->w, .h = area->h };
 
-sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
-sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
-sub_rect->w = av_clip(sub_rect->w, 0, sp->width  - 
sub_rect->x);
-sub_rect->h = av_clip(sub_rect->h, 0, sp->height - 
sub_rect->y);
+area->x = av_clip(area->x, 0, sp->width );
+area->y = av_clip(area->y, 0, sp->height);
+area->w = av_clip(area->w, 0, sp->width  - area->x);
+area->h = av_clip(area->h, 0, sp->height - area->y);
 
 is->sub_convert_ctx = 
sws_getCachedContext(is->sub_convert_ctx,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
-sub_rect->w, sub_rec

[FFmpeg-devel] [PATCH v15 02/16] global: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++
 libavcodec/ass.h  | 129 
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  19 +--
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   |  20 +--
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   |  16 +-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  15 +-
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  16 +-
 libavutil/Makefile|   2 +
 {libavcodec => libavutil}/ass.c   |  73 +
 libavutil/ass_internal.h  | 139 ++
 {libavcodec => libavutil}/ass_split.c |  30 ++--
 .../ass_split_internal.h  |  24 +--
 26 files changed, 331 insertions(+), 256 deletions(-)
 rename {libavcodec => libavutil}/ass.c (73%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (94%)
 rename libavcodec/ass_split.h => libavutil/ass_split_internal.h (89%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 14fbd2ecbc..df4fb53749 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -209,10 +209,10 @@ OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o 
pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)+= arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)+= argo.o
-OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER) += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER) += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER) += assenc.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER) += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)+= asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)+= asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)+= asvdec.o asv.o mpeg12data.o
@@ -252,7 +252,7 @@ OBJS-$(CONFIG_BRENDER_PIX_DECODER) += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER) += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)+= cavs.o cavsdec.o cavsdsp.o \
   cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)  += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER) += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)+= cdxl.o
@@ -424,7 +424,7 @@ OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \
   jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o 
jpeg2000dsp.o \
@@ -446,7 +446,7 @@ OBJS-$(CONFIG_MAGICYUV_ENCODER)+= magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o metasound_data.o \
   twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
@@ -461,8 +461,8 @@ OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)+= mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)+= motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCODER) += movtextenc.o ass_split.o
+OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o
+OBJS-$(CONFIG_MOVTEXT

[FFmpeg-devel] [PATCH v15 06/16] avfilter/sbuffer: Add sbuffersrc and sbuffersink filters

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/allfilters.c |  2 ++
 libavfilter/buffersink.c | 63 +++
 libavfilter/buffersink.h | 15 +
 libavfilter/buffersrc.c  | 72 
 libavfilter/buffersrc.h  |  1 +
 6 files changed, 154 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d068b11073..e4d1443237 100755
--- a/configure
+++ b/configure
@@ -7758,7 +7758,7 @@ print_enabled_components(){
 fi
 done
 if [ "$name" = "filter_list" ]; then
-for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer 
vsink_buffer ssink_sbuffer; do
 printf "&ff_%s,\n" $c >> $TMPH
 done
 fi
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4bf17ef292..4072f08385 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -550,8 +550,10 @@ extern const AVFilter ff_avsrc_movie;
  * being the same while having different 'types'). */
 extern  const AVFilter ff_asrc_abuffer;
 extern  const AVFilter ff_vsrc_buffer;
+extern  const AVFilter ff_ssrc_sbuffer;
 extern  const AVFilter ff_asink_abuffer;
 extern  const AVFilter ff_vsink_buffer;
+extern  const AVFilter ff_ssink_sbuffer;
 extern const AVFilter ff_af_afifo;
 extern const AVFilter ff_vf_fifo;
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index b8ddafec35..8306312acc 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -29,6 +29,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -57,6 +59,10 @@ typedef struct BufferSinkContext {
 int *sample_rates;  ///< list of accepted sample 
rates, terminated by -1
 int sample_rates_size;
 
+/* only used for subtitles */
+enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle 
types, must be terminated with -1
+int subtitle_types_size;
+
 AVFrame *peeked_frame;
 } BufferSinkContext;
 
@@ -168,6 +174,15 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void)
 return NULL;
 return params;
 }
+
+AVSBufferSinkParams *av_sbuffersink_params_alloc(void)
+{
+AVSBufferSinkParams *params = av_mallocz(sizeof(AVSBufferSinkParams));
+
+if (!params)
+return NULL;
+return params;
+}
 #endif
 
 static av_cold int common_init(AVFilterContext *ctx)
@@ -305,6 +320,28 @@ static int asink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+static int ssink_query_formats(AVFilterContext *ctx)
+{
+BufferSinkContext *buf = ctx->priv;
+AVFilterFormats *formats = NULL;
+unsigned i;
+int ret;
+
+CHECK_LIST_SIZE(subtitle_types)
+if (buf->subtitle_types_size) {
+for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++)
+if ((ret = ff_add_subtitle_type(&formats, buf->subtitle_types[i])) 
< 0)
+return ret;
+if ((ret = ff_set_common_formats(ctx, formats)) < 0)
+return ret;
+} else {
+if ((ret = ff_default_query_formats(ctx)) < 0)
+return ret;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(BufferSinkContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
@@ -322,9 +359,16 @@ static const AVOption abuffersink_options[] = {
 { NULL },
 };
 #undef FLAGS
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM
+static const AVOption sbuffersink_options[] = {
+{ "subtitle_types", "set the supported subtitle formats", 
OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+{ NULL },
+};
+#undef FLAGS
 
 AVFILTER_DEFINE_CLASS(buffersink);
 AVFILTER_DEFINE_CLASS(abuffersink);
+AVFILTER_DEFINE_CLASS(sbuffersink);
 
 static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
 {
@@ -363,3 +407,22 @@ const AVFilter ff_asink_abuffer = {
 .outputs   = NULL,
 FILTER_QUERY_FUNC(asink_query_formats),
 };
+
+static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+const AVFilter ff_ssink_sbuffer = {
+.name  = "sbuffersink",
+.description   = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make 
them available to the end of the filter graph."),
+.priv_class= &sbuffersink_class,
+.priv_size = sizeof(BufferSinkContext),
+.init  = common_init,
+.activate  = activate,
+FILTER_INPUTS(avfilter_ssink_sbuffer_inputs),
+.outputs   = NULL,
+FILTER_QUERY_FUNC(ssink_query_formats),
+};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..b439b586c5 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -129,6 +129,21 @@ typedef struct AVABufferSinkP

[FFmpeg-devel] [PATCH v15 07/16] avfilter/overlaygraphicsubs: Add overlaygraphicsubs and graphicsub2video filters

2021-11-25 Thread Soft Works
- overlaygraphicsubs (VS -> V)
  Overlay graphic subtitles onto a video stream

- graphicsub2video {S -> V)
  Converts graphic subtitles to video frames (with alpha)
  Gets auto-inserted for retaining compatibility with
  sub2video command lines

Signed-off-by: softworkz 
---
 doc/filters.texi| 118 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_overlaygraphicsubs.c | 737 
 4 files changed, 859 insertions(+)
 create mode 100644 libavfilter/vf_overlaygraphicsubs.c

diff --git a/doc/filters.texi b/doc/filters.texi
index c3ccaf97c4..e08936e6ba 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25543,6 +25543,124 @@ tools.
 
 @c man end VIDEO SINKS
 
+@chapter Subtitle Filters
+@c man begin SUBTITLE FILTERS
+
+When you configure your FFmpeg build, you can disable any of the
+existing filters using @code{--disable-filters}.
+
+Below is a description of the currently available subtitle filters.
+
+@section graphicsub2video
+
+Renders graphic subtitles as video frames. 
+
+This filter replaces the previous "sub2video" hack which did the conversion 
implicitly and up-front as subtitle filtering wasn't possible at that time.
+To retain compatibility with earlier sub2video command lines, this filter is 
being auto-inserted in those cases.
+
+For overlaying graphicsal subtitles it is recommended to use the 
'overlay_graphicsubs' filter which is more efficient and takes less processing 
resources.
+
+This filter is still useful in cases where the overlay is done with hardware 
acceleration (e.g. overlay_qsv, overlay_vaapi, overlay_cuda) for preparing the 
overlay frames.
+
+Inputs:
+@itemize
+@item 0: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+
+It accepts the following parameters:
+
+@table @option
+@item size, s
+Set the size of the output video frame.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+(not recommended - better use overlay_graphicsubs)
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:1]graphicsub2video[subs];[0:0][subs]overlay" output.mp4
+@end example
+
+@item
+Overlay PGS subtitles implicitly 
+The graphicsub2video is inserted automatically for compatibility with legacy 
command lines. 
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlay" output.mp4
+@end example
+@end itemize
+
+@section overlaygraphicsubs
+
+Overlay graphic subtitles onto a video stream.
+
+This filter can blend graphical subtitles on a video stream directly, i.e. 
without creating full-size alpha images first.
+The blending operation is limited to the area of the subtitle rectangles, 
which also means that no processing is done at times where no subtitles are to 
be displayed.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+Set the expression for the x and y coordinates of the overlaid video
+on the main video. Default value is "0" for both expressions. In case
+the expression is invalid, it is set to a huge value (meaning that the
+overlay will not be displayed within the output visible area).
+
+@item eof_action
+See @ref{framesync}.
+
+@item eval
+Set when the expressions for @option{x}, and @option{y} are evaluated.
+
+It accepts the following values:
+@table @samp
+@item init
+only evaluate expressions once during the filter initialization or
+when a command is processed
+
+@item frame
+evaluate expressions for each incoming frame
+@end table
+
+Default value is @samp{frame}.
+
+@item shortest
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
+@end example
+@end itemize
+@c man end SUBTITLE FILTERS
+
 @chapter Multimedia Filters
 @c man begin MULTIMEDIA FILTERS
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 99f3047965..6c790391b8 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -293,6 +293,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)   

[FFmpeg-devel] [PATCH v15 04/16] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

2021-11-25 Thread Soft Works
Analog to avfilter/video.c and avfilter/audio.c

Signed-off-by: softworkz 
---
 libavfilter/Makefile|  1 +
 libavfilter/avfilter.c  |  4 +++
 libavfilter/internal.h  |  1 +
 libavfilter/subtitles.c | 63 +
 libavfilter/subtitles.h | 44 
 5 files changed, 113 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e27aeeff6..99f3047965 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -19,6 +19,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
video.o  \
 
 OBJS-$(HAVE_THREADS) += pthread.o
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..df5b8f483c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -43,6 +43,7 @@
 #include "formats.h"
 #include "framepool.h"
 #include "internal.h"
+#include "subtitles.h"
 
 #include "libavutil/ffversion.h"
 const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
@@ -1475,6 +1476,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, 
AVFrame **rframe)
 case AVMEDIA_TYPE_AUDIO:
 out = ff_get_audio_buffer(link, frame->nb_samples);
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+out = ff_get_subtitles_buffer(link, link->format);
+break;
 default:
 return AVERROR(EINVAL);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..fc09ef574c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -90,6 +90,7 @@ struct AVFilterPad {
 union {
 AVFrame *(*video)(AVFilterLink *link, int w, int h);
 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
+AVFrame *(*subtitle)(AVFilterLink *link, int format);
 } get_buffer;
 
 /**
diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
new file mode 100644
index 00..951bfd612c
--- /dev/null
+++ b/libavfilter/subtitles.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+
+#include "subtitles.h"
+#include "avfilter.h"
+#include "internal.h"
+
+
+AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+return ff_get_subtitles_buffer(link->dst->outputs[0], format);
+}
+
+AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *frame;
+
+frame = av_frame_alloc();
+if (!frame)
+return NULL;
+
+frame->format = format;
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+
+if (av_frame_get_buffer2(frame, 0) < 0) {
+av_frame_free(&frame);
+return NULL;
+}
+
+return frame;
+}
+
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *ret = NULL;
+
+if (link->dstpad->get_buffer.subtitle)
+ret = link->dstpad->get_buffer.subtitle(link, format);
+
+if (!ret)
+ret = ff_default_get_subtitles_buffer(link, format);
+
+return ret;
+}
diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
new file mode 100644
index 00..4a9115126e
--- /dev/null
+++ b/libavfilter/subtitles.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 recei

[FFmpeg-devel] [PATCH v15 05/16] avfilter/avfilter: Handle subtitle frames

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 libavfilter/avfilter.c  |  8 +---
 libavfilter/avfilter.h  | 11 +++
 libavfilter/avfiltergraph.c |  5 +
 libavfilter/formats.c   | 22 ++
 libavfilter/formats.h   |  3 +++
 libavfilter/internal.h  | 18 +++---
 6 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index df5b8f483c..75d5e86539 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -56,7 +56,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->linesize[0], ref->linesize[1], ref->linesize[2], 
ref->linesize[3],
 ref->pts, ref->pkt_pos);
 
-if (ref->width) {
+switch(ref->type) {
+case AVMEDIA_TYPE_VIDEO:
 ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
 ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den,
 ref->width, ref->height,
@@ -64,12 +65,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->top_field_first ? 'T' : 'B',/* Top / Bottom */
 ref->key_frame,
 av_get_picture_type_char(ref->pict_type));
-}
-if (ref->nb_samples) {
+break;
+case AVMEDIA_TYPE_AUDIO:
 ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
 ref->channel_layout,
 ref->nb_samples,
 ref->sample_rate);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f7208754a7..ee2f5b594d 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -45,6 +45,7 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "libavfilter/version.h"
@@ -327,6 +328,12 @@ typedef struct AVFilter {
  * and outputs use the same sample rate and channel count/layout.
  */
 const enum AVSampleFormat *samples_list;
+/**
+ * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE
+ * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE
+ * inputs and outputs.
+ */
+const enum AVSubtitleType *subs_list;
 /**
  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
  */
@@ -335,6 +342,10 @@ typedef struct AVFilter {
  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
  */
 enum AVSampleFormat sample_fmt;
+/**
+ * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list.
+ */
+enum AVSubtitleType sub_fmt;
 } formats;
 
 int priv_size;  ///< size of private data to allocate for the filter
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..96f35a792c 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -311,6 +311,8 @@ static int filter_link_check_formats(void *log, 
AVFilterLink *link, AVFilterForm
 return ret;
 break;
 
+case AVMEDIA_TYPE_SUBTITLE:
+return 0;
 default:
 av_assert0(!"reached");
 }
@@ -441,6 +443,9 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 if (!link)
 continue;
 
+if (link->type == AVMEDIA_TYPE_SUBTITLE)
+continue;
+
 neg = ff_filter_get_negotiation(link);
 av_assert0(neg);
 for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..46dbbd2975 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/avcodec.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 return 0;
 }
 
+int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt)
+{
+ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
+return 0;
+}
+
 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
 {
 int fmts[2] = { fmt, -1 };
@@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
 return NULL;
 fmt++;
 }
+} else if (type == AVMEDIA_TYPE_SUBTITLE) {
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_BITMAP) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_ASS) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_TEXT) < 0)
+return NULL;
 }
 
 return ret;
@@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx)
 type= 

[FFmpeg-devel] [PATCH v15 08/16] fftools/ffmpeg: Replace sub2video with subtitle frame filtering

2021-11-25 Thread Soft Works
This commit actually enables subtitle filtering in ffmpeg by
sending and receiving subtitle frames to and from a filtergraph.

The heartbeat functionality from the previous sub2video implementation
is retained and applied to all subtitle frames (bitmap, text, ..).

The other part of sub2video functionality is retained by
auto-insertion of the new graphicsub2video filter.

Justification for changed test refs:

- sub2video
  The new results are identical excepting the last frame which
  is due to the implementation changes

- sub2video_basic
  The previous results had some incorrect output because multiple
  frames had the same dts
  The non-empty content frames are visually identical, the different
  CRC is due to the different blending algorithm that is being used.

- sub2video_time_limited
  The third frame in the previous ref was a repetition, which doesn't
  happen anymore with the new subtitle filtering.

- sub-dvb
  Running ffprobe -show_frames on the source file shows that there
  are 7 subtitle frames with 0 rects in the source at the start
  and 2 at the end. This translates to the 14 and 4 additional
  entries in the new test results.

- filter-overlay-dvdsub-2397
  Overlay results have slightly different CRCs due to different
  blending implementation

Signed-off-by: softworkz 
---
 fftools/ffmpeg.c  | 523 +++---
 fftools/ffmpeg.h  |  15 +-
 fftools/ffmpeg_filter.c   | 217 ++---
 fftools/ffmpeg_hw.c   |   2 +-
 fftools/ffmpeg_opt.c  |   3 +-
 tests/ref/fate/filter-overlay-dvdsub-2397 | 181 
 tests/ref/fate/sub-dvb| 162 ---
 tests/ref/fate/sub2video  | 116 ++---
 tests/ref/fate/sub2video_basic| 135 ++
 tests/ref/fate/sub2video_time_limited |   4 +-
 10 files changed, 684 insertions(+), 674 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3761ea0c38..c697c12777 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -169,163 +169,6 @@ static int restore_tty;
 static void free_input_threads(void);
 #endif
 
-/* sub2video hack:
-   Convert subtitles to video with alpha to insert them in filter graphs.
-   This is a temporary solution until libavfilter gets real subtitles support.
- */
-
-static int sub2video_get_blank_frame(InputStream *ist)
-{
-int ret;
-AVFrame *frame = ist->sub2video.frame;
-
-av_frame_unref(frame);
-ist->sub2video.frame->width  = ist->dec_ctx->width  ? ist->dec_ctx->width  
: ist->sub2video.w;
-ist->sub2video.frame->height = ist->dec_ctx->height ? ist->dec_ctx->height 
: ist->sub2video.h;
-ist->sub2video.frame->format = AV_PIX_FMT_RGB32;
-if ((ret = av_frame_get_buffer(frame, 0)) < 0)
-return ret;
-memset(frame->data[0], 0, frame->height * frame->linesize[0]);
-return 0;
-}
-
-static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h,
-AVSubtitleRect *r)
-{
-uint32_t *pal, *dst2;
-uint8_t *src, *src2;
-int x, y;
-
-if (r->type != SUBTITLE_BITMAP) {
-av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n");
-return;
-}
-if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) {
-av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) 
overflowing %d %d\n",
-r->x, r->y, r->w, r->h, w, h
-);
-return;
-}
-
-dst += r->y * dst_linesize + r->x * 4;
-src = r->data[0];
-pal = (uint32_t *)r->data[1];
-for (y = 0; y < r->h; y++) {
-dst2 = (uint32_t *)dst;
-src2 = src;
-for (x = 0; x < r->w; x++)
-*(dst2++) = pal[*(src2++)];
-dst += dst_linesize;
-src += r->linesize[0];
-}
-}
-
-static void sub2video_push_ref(InputStream *ist, int64_t pts)
-{
-AVFrame *frame = ist->sub2video.frame;
-int i;
-int ret;
-
-av_assert1(frame->data[0]);
-ist->sub2video.last_pts = frame->pts = pts;
-for (i = 0; i < ist->nb_filters; i++) {
-ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, frame,
-   AV_BUFFERSRC_FLAG_KEEP_REF |
-   AV_BUFFERSRC_FLAG_PUSH);
-if (ret != AVERROR_EOF && ret < 0)
-av_log(NULL, AV_LOG_WARNING, "Error while add the frame to buffer 
source(%s).\n",
-   av_err2str(ret));
-}
-}
-
-void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
-{
-AVFrame *frame = ist->sub2video.frame;
-int8_t *dst;
-int dst_linesize;
-int num_rects, i;
-int64_t pts, end_pts;
-
-if (!frame)
-return;
-if (sub) {
-pts   = av_rescale_q(sub->pts + sub->start_display_time * 1000LL,
- AV_TIME_BASE_Q, ist->st->time_base);
-end_pts   = av_rescale_q(sub->pts + sub->end_display_ti

[FFmpeg-devel] [PATCH v15 09/16] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2021-11-25 Thread Soft Works
- overlaytextsubs {VS -> V)
  Overlay text subtitles onto a video stream.

- textsubs2video {S -> V)
  Converts text subtitles to video frames

Signed-off-by: softworkz 
---
 configure|   2 +
 doc/filters.texi | 113 ++
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   4 +-
 libavfilter/avfilter.c   |  18 +-
 libavfilter/vf_overlaytextsubs.c | 624 +++
 6 files changed, 757 insertions(+), 6 deletions(-)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index e4d1443237..db1db0a0a6 100755
--- a/configure
+++ b/configure
@@ -3642,6 +3642,7 @@ overlay_opencl_filter_deps="opencl"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlaytextsubs_filter_deps="avcodec libass"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
@@ -3686,6 +3687,7 @@ superequalizer_filter_deps="avcodec"
 superequalizer_filter_select="rdft"
 surround_filter_deps="avcodec"
 surround_filter_select="rdft"
+textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index e08936e6ba..6407e6f80a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25659,6 +25659,119 @@ Overlay PGS subtitles
 ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
 @end example
 @end itemize
+
+@section overlaytextsubs
+
+Overlay text subtitles onto a video stream.
+
+This filter supersedes the classic @ref{subtitles} filter opposed to which it 
does no longer require to open and access the source stream separately, which 
is often causing problems or doesn't even work for non-local or slow sources.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item alpha
+Process alpha channel, by default alpha channel is untouched.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time 
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay ASS subtitles with animations:
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:v]overlaytextsubs" -map 0 -y out.mkv
+@end example
+@end itemize
+
+@section textsub2video
+
+Converts text subtitles to video frames.
+
+For overlaying text subtitles onto video frames it is recommended to use the 
overlay_textsubs filter.
+The textsub2video is useful for for creating transparent text-frames when 
overlay is done via hw acceleration 
+
+Inputs:
+@itemize
+@item 0: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item rate, r
+Set the framerate for updating overlay frames.
+Normally, overlay frames will only be updated each time when the subtitles to 
display are changing.
+In cases where subtitles include advanced features (like animation), this 
parameter determines the frequency by which the overlay frames should be 
updated.
+
+@item size, s
+Set the output frame size.
+Allows to override the size of output video frames.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time.
+@end table
+
 @c man end SUBTITLE FILTERS
 
 @

[FFmpeg-devel] [PATCH v15 10/16] avfilter/textmod: Add textmod, censor and show_speaker filters

2021-11-25 Thread Soft Works
- textmod {S -> S)
  Modify subtitle text in a number of ways

- censor {S -> S)
  Censor subtitles using a word list

- show_speaker {S -> S)
  Prepend speaker names from ASS subtitles to the visible text lines

Signed-off-by: softworkz 
---
 doc/filters.texi | 206 
 libavfilter/Makefile |   5 +
 libavfilter/allfilters.c |   3 +
 libavfilter/sf_textmod.c | 697 +++
 4 files changed, 911 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 6407e6f80a..fb468b0368 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25551,6 +25551,145 @@ existing filters using @code{--disable-filters}.
 
 Below is a description of the currently available subtitle filters.
 
+
+@section censor
+
+Censor selected words in text subtitles.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The censoring mode to apply.
+
+Supported censoring modes are:
+
+@table @var
+@item 0, keep_first_last
+Replace all characters with the 'censor_char' except the first and the last 
character of a word.
+For words with less than 4 characters, the last character will be replaced as 
well.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 1, keep_first
+Replace all characters with the 'censor_char' except the first character of a 
word.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 2, all
+Replace all characters with the 'censor_char'.
+@end table
+
+@item words
+A list of words to censor, separated by 'separator'.
+
+@item words_file
+Specify a file from which to load the contents for the 'words' parameter.
+
+@item censor_char
+Single character used as replacement for censoring.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Censor a few given words with a pound character.
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex 
"[0:1]censor=words='diss,louder,hope,beam,word':censor_char='#'" -map 0 -y 
output.mkv
+@end example
+@end itemize
+
+
+@section textmod
+
+Modify subtitle text in a number of ways.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The kind of text modification to apply
+
+Supported operation modes are:
+
+@table @var
+@item 0, leet
+Convert subtitle text to 'leet speak'. It's primarily useful for testing as 
the modification will be visible with almost all text lines.
+@item 1, to_upper
+Change all text to upper case. Might improve readability.
+@item 2, to_lower
+Change all text to lower case.
+@item 3, replace_chars
+Replace one or more characters. Requires the find and replace parameters to be 
specified. 
+Both need to be equal in length.
+The first char in find is replaced by the first char in replace, same for all 
subsequent chars.
+@item 4, remove_chars
+Remove certain characters. Requires the find parameter to be specified. 
+All chars in the find parameter string will be removed from all subtitle text.
+@item 5, replace_words
+Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ','). 
+The number of words in the find and replace parameters needs to be equal.
+The first word in find is replaced by the first word in replace, same for all 
subsequent words
+@item 6, remove_words
+Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ','). 
+All words in the find parameter string will be removed from all subtitle text.
+@end table
+
+@item find
+Required for replace_chars, remove_chars, replace_words and remove_words.
+
+@item find_file
+Specify a file from which to load the contents for the 'find' parameter.
+
+@item replace
+Required for replace_chars and replace_words.
+
+@item replace_file
+Specify a file from which to load the contents for the 'replace' parameter.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Change all characters to upper case while keeping all styles and animations:
+@example
+ffmpeg -i "https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; 
-filter_complex "[0:s]textmod=mode=to_upper" -map 0 -y out.mkv
+@end example
+@item
+Remove a set of symbol characters for am improved and sm

[FFmpeg-devel] [PATCH v15 11/16] avfilter/stripstyles: Add stripstyles filter

2021-11-25 Thread Soft Works
- stripstyles {S -> S)
  Remove all inline styles from subtitle events

Signed-off-by: softworkz 
---
 doc/filters.texi |  37 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_stripstyles.c | 196 +++
 4 files changed, 235 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index fb468b0368..7d07fc8d04 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25611,6 +25611,43 @@ ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.
 @end example
 @end itemize
 
+@section stripstyles
+
+Remove all inline styles from subtitle events.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item remove_animated
+Also remove text which is subject to animation (default: true)
+Usually, animated text elements are used used in addition to static subtitle 
lines for creating effects, so in most cases it is safe to remove the animation 
content.
+If subtitle text is missing, try setting this to false.
+
+@item select_layer
+Process only ASS subtitle events from a specific layer. This allows to filter 
out certain effects where an ASS author duplicates the text onto multiple 
layers.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Remove styles and animations from ASS subtitles and output events from ass 
layer 0 only. Then convert asn save as SRT stream:
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:1]stripstyles=select_layer=0" -map 0 -c:s srt output.mkv
+@end example
+@end itemize
+
 
 @section textmod
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7fac60ab43..599ca0e54a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -555,6 +555,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 69f4c47e6a..378d1dcaac 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -543,6 +543,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..82cb9c7647
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * text subtitle filter which removes inline-styles from subtitles
+ */
+
+#include "libavutil/opt.h"
+#include "internal.h"
+#include "libavutil/ass_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+} DialogContext;
+
+static void dialog_text_cb(void *priv, const char *text, int len)
+{
+DialogContext *s = priv;
+
+av_log(s->ss_ctx, AV_LOG_DEBUG, "dialog_text_cb: %s\n", text);
+
+if (!s->drawing_scale && (!s->is_animated || !s->ss_ctx->remove_animated))
+av_bprint_append_data(&s->buffer, text, len);
+}
+
+static void dialog_new_line_cb(void *priv, int forced)
+{
+DialogContext *s = priv;
+if (!s->drawing_scale && !s->is_animated)
+av_bprint_append_data(&s->buffer, forced ? "\\N" : "\\n", 2);
+}
+
+static void di

[FFmpeg-devel] [PATCH v15 12/16] avfilter/splitcc: Add splitcc filter for closed caption handling

2021-11-25 Thread Soft Works
- splitcc {V -> VS)
  Extract closed-caption (A53) data from video
  frames as subtitle Frames

ffmpeg -y -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex 
"[0:v]splitcc[vid1],textmod=mode=remove_chars:find='@',[vid1]overlay_textsubs" 
output.mkv

Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  63 
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_splitcc.c | 316 +++
 5 files changed, 382 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index db1db0a0a6..bcd7102e6c 100755
--- a/configure
+++ b/configure
@@ -3680,6 +3680,7 @@ spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
+splitcc_filter_deps="avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 7d07fc8d04..e6443a956d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25961,6 +25961,69 @@ ffmpeg -i INPUT -filter_complex 
"showspeaker=format=colon:style='@{\\c&HDD&\
 @end example
 @end itemize
 
+
+@section splitcc
+
+Split-out closed-caption/A53 subtitles from video frame side data.
+
+This filter provides an input and an output for video frames, which are just 
passed through without modification.
+The second out provides subtitle frames which are extracted from video frame 
side data.
+
+Inputs:
+@itemize
+@item 0: Video [ALL]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@item 1: Subtitles [TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item use_cc_styles
+Emit closed caption style header. 
+This will make closed captions appear in white font with a black rectangle 
background.
+
+@item real_time
+Emit subtitle events as they are decoded for real-time display.
+
+@item real_time_latency_msec
+Minimum elapsed time between emitting real-time subtitle events.
+Only applies to real_time mode.
+
+@item data_field
+Select data field. Possible values:
+
+@table @samp
+@item auto
+Pick first one that appears.
+@item first
+@item second
+@end table
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Extract closed captions as text subtitle stream and overlay it onto the video 
in cc style (black bar background):
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=use_cc_styles=1[vid1][sub1];[vid1][sub1]overlaytextsubs" 
output.mkv
+@end example
+
+@item
+A nicer variant, using realtime output from cc_dec and rendering it with the 
render_latest_only parameter from overlaytextsubs to avoid ghosting by timely 
overlap.
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=real_time=1:real_time_latency_msec=200[vid1][sub1];[vid1][sub1]overlaytextsubs=render_latest_only=1"
 output.mkv
+@end example
+@end itemize
+
+
 @section textsub2video
 
 Converts text subtitles to video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 599ca0e54a..5364e11491 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -555,6 +555,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 378d1dcaac..1444ca873a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -543,6 +543,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..0ebbd500f1
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * MERCHANTAB

[FFmpeg-devel] [PATCH v15 13/16] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  55 +
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_graphicsub2text.c | 354 +++
 5 files changed, 413 insertions(+)
 create mode 100644 libavfilter/sf_graphicsub2text.c

diff --git a/configure b/configure
index bcd7102e6c..f04408a69c 100755
--- a/configure
+++ b/configure
@@ -3616,6 +3616,7 @@ frei0r_filter_deps="frei0r"
 frei0r_src_filter_deps="frei0r"
 fspp_filter_deps="gpl"
 gblur_vulkan_filter_deps="vulkan spirv_compiler"
+graphicsub2text_filter_deps="libtesseract"
 hflip_vulkan_filter_deps="vulkan spirv_compiler"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index e6443a956d..3e5bdbfa18 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25727,6 +25727,61 @@ ffmpeg -i 
"https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; -filter_comple
 @end example
 @end itemize
 
+@section graphicsub2text
+
+Converts graphic subtitles to text subtitles by performing OCR.
+
+For this filter to be available, ffmpeg needs to be compiled with libtesseract 
(see https://github.com/tesseract-ocr/tesseract).
+Language models need to be downloaded from 
https://github.com/tesseract-ocr/tessdata and put into as subfolder named 
'tessdata' or into a folder specified via the environment variable 
'TESSDATA_PREFIX'. 
+The path can also be specified via filter option (see below).
+
+Note: These models are including the data for both OCR modes.
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [text]
+
+It accepts the following parameters:
+
+@table @option
+@item ocr_mode
+The character recognition mode to use.
+
+Supported OCR modes are:
+
+@table @var
+@item 0, tesseract
+This is the classic libtesseract operation mode. It is fast but less accurate 
than LSTM.
+@item 1, lstm
+Newer OCR implementation based on ML models. Provides usually better results, 
requires more processing resources.
+@item 2, both
+Use a combination of both modes.
+@end table
+
+@item tessdata_path
+The path to a folder containing the language models to be used.
+
+@item language
+The recognition language. It needs to match the first three characters of a  
language model file in the tessdata path.
+
+@end table
+
+
+@subsection Examples
+
+@itemize
+@item
+Convert DVB graphic subtitles to ASS (text) subtitles
+
+Note: For this to work, you need to have the data file 'eng.traineddata' in a 
'tessdata' subfolder (see above).
+@example
+ffmpeg ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts"; 
-filter_complex "[0:13]graphicsub2text=ocr_mode=both" -c:s ass -y output.mkv
+@end example
+@end itemize
+
+
 @section graphicsub2video
 
 Renders graphic subtitles as video frames. 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 5364e11491..a1ad37ab9f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -294,6 +294,8 @@ OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += 
vf_gblur_vulkan.o vulkan.o vulka
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
 OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
+OBJS-$(CONFIG_GRAPHICSUB2TEXT_FILTER)+= sf_graphicsub2text.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
 OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 1444ca873a..f8a64d4032 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -542,6 +542,7 @@ extern const AVFilter ff_avf_showwaves;
 extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
+extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
diff --git a/libavfilter/sf_graphicsub2text.c b/libavfilter/sf_graphicsub2text.c
new file mode 100644
index 00..1f256f5c65
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 m

[FFmpeg-devel] [PATCH v15 14/16] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 883 ++
 5 files changed, 1050 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index f04408a69c..f9203a34f7 100755
--- a/configure
+++ b/configure
@@ -3682,6 +3682,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 3e5bdbfa18..47496f1902 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26133,6 +26133,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating 
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the 
+latter being separated as 'arrange_h' and 'arrange_v'. 
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating 
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply 
+these alignments for the target positioning. 
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply 
+these alignments for the target positioning. 
+Bitmaps that do not fit inside the margins borders are 
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g. 
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec. 
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make sure tha

[FFmpeg-devel] [PATCH v15 15/16] avcodec/subtitles: Migrate subtitle encoders to frame-based API and provide a compatibility shim for the legacy api

2021-11-25 Thread Soft Works
Also introduce deferred loading of ass headers for all cases where it can't be 
taken from the context of a decoder.

Signed-off-by: softworkz 
---
 libavcodec/assenc.c|  81 -
 libavcodec/avcodec.h   |   7 +++
 libavcodec/dvbsubenc.c |  85 +++---
 libavcodec/dvdsubenc.c |  89 +---
 libavcodec/encode.c|  97 +-
 libavcodec/movtextenc.c| 103 +
 libavcodec/srtenc.c|  96 ++
 libavcodec/tests/avcodec.c |   2 -
 libavcodec/ttmlenc.c   |  82 +++--
 libavcodec/webvttenc.c |  73 +++---
 libavcodec/xsubenc.c   |  65 ---
 11 files changed, 540 insertions(+), 240 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b0e475834b..2566b1d4dc 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -28,42 +28,77 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
+static void check_write_header(AVCodecContext* avctx, const AVFrame* frame)
+{
+if (avctx->extradata_size)
+return;
+
+if (frame->subtitle_header && frame->subtitle_header->size > 0) {
+const char* subtitle_header = (char*)frame->subtitle_header->data;
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(frame->subtitle_header->size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+if (!avctx->extradata_size) {
+const char* subtitle_header = 
avpriv_ass_get_subtitle_header_default(0);
+if (!subtitle_header)
+return;
+
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(avctx->extradata_size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+av_freep(&subtitle_header);
+}
+}
+
 static av_cold int ass_encode_init(AVCodecContext *avctx)
 {
-avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
-if (!avctx->extradata)
-return AVERROR(ENOMEM);
-memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
-avctx->extradata_size = avctx->subtitle_header_size;
-avctx->extradata[avctx->extradata_size] = 0;
+if (avctx->subtitle_header_size) {
+avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
+avctx->extradata_size   = avctx->subtitle_header_size;
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
 return 0;
 }
 
-static int ass_encode_frame(AVCodecContext *avctx,
-unsigned char *buf, int bufsize,
-const AVSubtitle *sub)
+static int ass_encode_frame(AVCodecContext* avctx, AVPacket* avpkt,
+const AVFrame* frame, int* got_packet)
 {
-int i, len, total_len = 0;
+int len, total_len = 0;
 
-for (i=0; inum_rects; i++) {
-const char *ass = sub->rects[i]->ass;
+check_write_header(avctx, frame);
 
-if (sub->rects[i]->type != SUBTITLE_ASS) {
-av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (frame->subtitle_areas[i]->type != AV_SUBTITLE_FMT_ASS) {
+av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type 
supported.\n");
 return AVERROR(EINVAL);
 }
 
-len = av_strlcpy(buf+total_len, ass, bufsize-total_len);
+if (ass) {
+len = av_strlcpy((char *)avpkt->data + total_len, ass, avpkt->size 
- total_len);
 
-if (len > bufsize-total_len-1) {
-av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
-return AVERROR_BUFFER_TOO_SMALL;
-}
+if (len > avpkt->size - 1) {
+av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS 
event.\n");
+return AVERROR_BUFFER_TOO_SMALL;
+}
 
-total_len += len;
+total_len += len;
+}
 }
 
-return total_len;
+avpkt->size = total_len;
+*got_packet = total_len > 0;
+
+return 0;
 }
 
 #if CONFIG_SSA_ENCODER
@@ -73,7 +108,7 @@ const AVCodec ff_ssa_encoder = {
 .type = AVMEDIA_TYPE_SUBTITLE,
 .id   = AV_CODEC_ID_ASS,
 .init = ass_encode_init,
-.encode_sub   = ass_encode_frame,
+.encode2  = ass_encode_frame,
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
@@ -85,7 +120,7 @@ const AVCo

[FFmpeg-devel] [PATCH v15 16/16] fftools/ffmpeg: Use new frame-based subtitle encoding API

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 fftools/ffmpeg.c | 60 
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c697c12777..603b4c23e0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -896,10 +896,9 @@ error:
 static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
 {
 const int subtitle_out_max_size = 1024 * 1024;
-int subtitle_out_size, nb, i;
+int nb, i;
 AVCodecContext *enc;
 AVPacket *pkt = ost->pkt;
-AVSubtitle out_sub = { 0 };
 int64_t pts;
 
 if (!frame)
@@ -917,12 +916,14 @@ static void do_subtitle_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 enc = ost->enc_ctx;
 
 if (!subtitle_out) {
-subtitle_out = av_malloc(subtitle_out_max_size);
+subtitle_out = av_mallocz(subtitle_out_max_size);
 if (!subtitle_out) {
 av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
 exit_program(1);
 }
 }
+else
+memset(subtitle_out, 0, subtitle_out_max_size);
 
 /* Note: DVB subtitle need one packet to draw them and one other
packet to clear them */
@@ -947,44 +948,43 @@ static void do_subtitle_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 frame->subtitle_end_time  -= frame->subtitle_start_time;
 frame->subtitle_start_time = 0;
 
-av_frame_get_subtitle(&out_sub, frame);
-
 for (i = 0; i < nb; i++) {
-const unsigned save_num_rects = out_sub.num_rects;
+int ret, got_packet = 0;
+const unsigned save_num_rects = frame->num_subtitle_areas;
+
+pkt->data = subtitle_out;
+pkt->size = subtitle_out_max_size;
 
 ost->frames_encoded++;
 
 if (i == 1)
-out_sub.num_rects = 0;
+frame->num_subtitle_areas = 0;
 
-subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, 
subtitle_out_max_size, &out_sub);
+ret = avcodec_encode_subtitle2(enc, pkt, frame, &got_packet);
 
 if (i == 1)
-out_sub.num_rects = save_num_rects;
+frame->num_subtitle_areas = save_num_rects;
 
-if (subtitle_out_size < 0) {
-av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
-exit_program(1);
-}
-
-//av_packet_unref(pkt);
-pkt->data = subtitle_out;
-pkt->size = subtitle_out_size;
-pkt->pts  = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, 
ost->mux_timebase);
-pkt->duration = av_rescale_q(frame->subtitle_end_time, (AVRational){ 
1, 1000 }, ost->mux_timebase);
-if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
-/* XXX: the pts correction is handled here. Maybe handling
-   it in the codec would be better */
-if (i == 0)
-pkt->pts += av_rescale_q(frame->subtitle_start_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
-else
-pkt->pts += av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+if (ret < 0) {
+av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed: %d\n", ret);
+exit_program(ret);
+}
+
+if (got_packet) {
+pkt->pts  = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, 
ost->mux_timebase);
+pkt->duration = av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
+/* XXX: the pts correction is handled here. Maybe handling
+   it in the codec would be better */
+if (i == 0)
+pkt->pts += av_rescale_q(frame->subtitle_start_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+else
+pkt->pts += av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+}
+pkt->dts = pkt->pts;
+output_packet(of, pkt, ost, 0);
 }
-pkt->dts = pkt->pts;
-output_packet(of, pkt, ost, 0);
 }
-
-avsubtitle_free(&out_sub);
 }
 
 static void do_video_out(OutputFile *of,
-- 
2.30.2.windows.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 v16 00/16] Subtitle Filtering

2021-11-25 Thread Soft Works
Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
  allocation logic. Cannot and must not be used interchangeably, hence
  the new struct
- Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
- Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
- Add avcodec_decode_subtitle3 which takes subtitle frames,
  serving as compatibility shim to legacy subtitle decoding
- Add additional methods for conversion between old and new API

New in V15

- Added missing reference to subfmt.h iun libzvbi-teletextdec.c
- Fixed Fate error in patch 15/16
- Removed all trsiling whitespace in tilers.texi

New in V15

- Rebased to upstream changes 
- avcodec/subtitles: Migrate subtitle encoders to frame-based API and provide 
compatibility shim for legacy api
- fftools/ffmpeg: Use new frame-based subtitle encoding API
- AVSubtitleArea: copy flags field, make params const
- graphicsubs2text: Don't emit duplicate frames
- graphicsubs2text: Combined OCR output into a single AVSubtitleArea
  (I have a prototype for detecting text colors and positions, but it's not 
ready at this point)
- splitcc: cleanup local subtitle_header ref
- stripstyles: add parameter for ass layer selection
- avcodec/subtitles: deferred loading of ass header for text subtitle encoders
- verified all example command lines in the docs are working, added somre more

Kind regards,
softworkz


softworkz (16):
  global: Prepare AVFrame for subtitle handling
  global: Move ass helper functions to avutil as avpriv_ and extend ass
dialog parsing
  fftools/play,probe: Adjust for subtitle changes
  avfilter/subtitles: Add subtitles.c for subtitle frame allocation
  avfilter/avfilter: Handle subtitle frames
  avfilter/sbuffer: Add sbuffersrc and sbuffersink filters
  avfilter/overlaygraphicsubs: Add overlaygraphicsubs and
graphicsub2video filters
  fftools/ffmpeg: Replace sub2video with subtitle frame filtering
  avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video
filters
  avfilter/textmod: Add textmod, censor and show_speaker filters
  avfilter/stripstyles: Add stripstyles filter
  avfilter/splitcc: Add splitcc filter for closed caption handling
  avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)
  avfilter/subscale: Add filter for scaling and/or re-arranging
graphical subtitles
  avcodec/subtitles: Migrate subtitle encoders to frame-based API and
provide a compatibility shim for the legacy api
  fftools/ffmpeg: Use new frame-based subtitle encoding API

 configure |   7 +-
 doc/filters.texi  | 756 +++
 fftools/ffmpeg.c  | 553 ++-
 fftools/ffmpeg.h  |  15 +-
 fftools/ffmpeg_filter.c   | 217 +++--
 fftools/ffmpeg_hw.c   |   2 +-
 fftools/ffmpeg_opt.c  |   3 +-
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  48 +-
 libavcodec/Makefile   |  56 +-
 libavcodec/ass.h  | 129 +--
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |  83 +-
 libavcodec/avcodec.c  |  19 -
 libavcodec/avcodec.h  |  82 +-
 libavcodec/ccaption_dec.c |  19 +-
 libavcodec/decode.c   |  53 +-
 libavcodec/dvbsubenc.c|  85 +-
 libavcodec/dvdsubenc.c|  89 +-
 libavcodec/encode.c   |  98 +-
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  15 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   | 115 ++-
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/pgssubdec.c|   1 +
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   | 104 ++-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/tests/avcodec.c|   2 -
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  95 +-
 libavcodec/utils.c|  11 +
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c 

[FFmpeg-devel] [PATCH v16 01/16] global: Prepare AVFrame for subtitle handling

2021-11-25 Thread Soft Works
Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
  allocation logic. Cannot and must not be used interchangeably, hence
  the new struct
- Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
- Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
- Add avcodec_decode_subtitle3 which takes subtitle frames,
  serving as compatibility shim to legacy subtitle decoding
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.c |  19 ---
 libavcodec/avcodec.h |  75 ++
 libavcodec/decode.c  |  53 +--
 libavcodec/libzvbi-teletextdec.c |   1 +
 libavcodec/pgssubdec.c   |   1 +
 libavcodec/utils.c   |  11 ++
 libavfilter/vf_subtitles.c   |  50 +--
 libavformat/utils.c  |   1 +
 libavutil/Makefile   |   2 +
 libavutil/frame.c| 194 +---
 libavutil/frame.h|  93 +++-
 libavutil/subfmt.c   | 243 +++
 libavutil/subfmt.h   | 185 +++
 13 files changed, 803 insertions(+), 125 deletions(-)
 create mode 100644 libavutil/subfmt.c
 create mode 100644 libavutil/subfmt.h

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..13e3711b9c 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -422,25 +422,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 av_bsf_flush(avci->bsf);
 }
 
-void avsubtitle_free(AVSubtitle *sub)
-{
-int i;
-
-for (i = 0; i < sub->num_rects; i++) {
-av_freep(&sub->rects[i]->data[0]);
-av_freep(&sub->rects[i]->data[1]);
-av_freep(&sub->rects[i]->data[2]);
-av_freep(&sub->rects[i]->data[3]);
-av_freep(&sub->rects[i]->text);
-av_freep(&sub->rects[i]->ass);
-av_freep(&sub->rects[i]);
-}
-
-av_freep(&sub->rects);
-
-memset(sub, 0, sizeof(*sub));
-}
-
 av_cold int avcodec_close(AVCodecContext *avctx)
 {
 int i;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7ee8bc2b7c..0c5819b116 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -1674,7 +1675,7 @@ typedef struct AVCodecContext {
 
 /**
  * Header containing style information for text subtitles.
- * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+ * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  * the Format line following. It shouldn't include any Dialogue line.
  * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2238,63 +2239,8 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-SUBTITLE_NONE,
-
-SUBTITLE_BITMAP,///< A bitmap, pict will be set
-
-/**
- * Plain text, the text field must be set by the decoder and is
- * authoritative. ass and pict fields may contain approximations.
- */
-SUBTITLE_TEXT,
-
-/**
- * Formatted text, the ass field must be set by the decoder and is
- * authoritative. pict and text fields may contain approximations.
- */
-SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x0001
 
-typedef struct AVSubtitleRect {
-int x; ///< top left corner  of pict, undefined when pict is not 
set
-int y; ///< top left corner  of pict, undefined when pict is not 
set
-int w; ///< widthof pict, undefined when pict is not 
set
-int h; ///< height   of pict, undefined when pict is not 
set
-int nb_colors; ///< number of colors in pict, undefined when pict is not 
set
-
-/**
- * data+linesize for the bitmap of this subtitle.
- * Can be set for text/ass as well once they are rendered.
- */
-uint8_t *data[4];
-int linesize[4];
-
-enum AVSubtitleType type;
-
-char *text; ///< 0 terminated plain UTF-8 text
-
-/**
- * 0 terminated ASS/SSA compatible event line.
- * The presentation of this is unaffected by the other values in this
- * struct.
- */
-char *ass;
-
-int flags;
-} AVSubtitleRect;
-
-typedef struct AVSubtitle {
-uint16_t format; /* 0 = graphics */
-uint32_t start_display_time; /* relative to packet pts, in ms */
-uint32_t end_display_time; /* relative to packet pts, in ms */
-unsigned num_rects;

[FFmpeg-devel] [PATCH v16 02/16] global: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++
 libavcodec/ass.h  | 129 
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  19 +--
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   |  20 +--
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   |  16 +-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  15 +-
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  16 +-
 libavutil/Makefile|   2 +
 {libavcodec => libavutil}/ass.c   |  73 +
 libavutil/ass_internal.h  | 139 ++
 {libavcodec => libavutil}/ass_split.c |  30 ++--
 .../ass_split_internal.h  |  24 +--
 26 files changed, 331 insertions(+), 256 deletions(-)
 rename {libavcodec => libavutil}/ass.c (73%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (94%)
 rename libavcodec/ass_split.h => libavutil/ass_split_internal.h (89%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 14fbd2ecbc..df4fb53749 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -209,10 +209,10 @@ OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o 
pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)+= arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)+= argo.o
-OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER) += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER) += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER) += assenc.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER) += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)+= asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)+= asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)+= asvdec.o asv.o mpeg12data.o
@@ -252,7 +252,7 @@ OBJS-$(CONFIG_BRENDER_PIX_DECODER) += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER) += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)+= cavs.o cavsdec.o cavsdsp.o \
   cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)  += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER) += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)+= cdxl.o
@@ -424,7 +424,7 @@ OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \
   jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o 
jpeg2000dsp.o \
@@ -446,7 +446,7 @@ OBJS-$(CONFIG_MAGICYUV_ENCODER)+= magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o metasound_data.o \
   twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
@@ -461,8 +461,8 @@ OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)+= mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)+= motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCODER) += movtextenc.o ass_split.o
+OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o
+OBJS-$(CONFIG_MOVTEXT

[FFmpeg-devel] [PATCH v16 03/16] fftools/play, probe: Adjust for subtitle changes

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  48 ++
 2 files changed, 78 insertions(+), 72 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..0af32888da 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -152,7 +152,6 @@ typedef struct Clock {
 /* Common struct for handling all types of decoded data and allocated render 
buffers. */
 typedef struct Frame {
 AVFrame *frame;
-AVSubtitle sub;
 int serial;
 double pts;   /* presentation timestamp for the frame */
 double duration;  /* estimated duration of the frame */
@@ -586,7 +585,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, 
PacketQueue *queue, S
 return 0;
 }
 
-static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
+static int decoder_decode_frame(Decoder *d, AVFrame *frame) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
@@ -620,6 +619,9 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 }
 }
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+ret = avcodec_receive_frame(d->avctx, frame);
+break;
 }
 if (ret == AVERROR_EOF) {
 d->finished = d->pkt_serial;
@@ -652,25 +654,11 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both 
returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
-d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
-}
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -683,7 +671,6 @@ static void decoder_destroy(Decoder *d) {
 static void frame_queue_unref_item(Frame *vp)
 {
 av_frame_unref(vp->frame);
-avsubtitle_free(&vp->sub);
 }
 
 static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, 
int keep_last)
@@ -981,7 +968,7 @@ static void video_image_display(VideoState *is)
 if (frame_queue_nb_remaining(&is->subpq) > 0) {
 sp = frame_queue_peek(&is->subpq);
 
-if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 
1000)) {
+if (vp->pts >= sp->pts + ((float) sp->frame->subtitle_start_time / 
1000)) {
 if (!sp->uploaded) {
 uint8_t* pixels[4];
 int pitch[4];
@@ -993,25 +980,27 @@ static void video_image_display(VideoState *is)
 if (realloc_texture(&is->sub_texture, 
SDL_PIXELFORMAT_ARGB, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
 return;
 
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = sp->sub.rects[i];
+for (i = 0; i < sp->frame->num_subtitle_areas; i++) {
+AVSubtitleArea *area = sp->frame->subtitle_areas[i];
+SDL_Rect sdl_rect = { .x = area->x, .y = area->y, .w = 
area->w, .h = area->h };
 
-sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
-sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
-sub_rect->w = av_clip(sub_rect->w, 0, sp->width  - 
sub_rect->x);
-sub_rect->h = av_clip(sub_rect->h, 0, sp->height - 
sub_rect->y);
+area->x = av_clip(area->x, 0, sp->width );
+area->y = av_clip(area->y, 0, sp->height);
+area->w = av_clip(area->w, 0, sp->width  - area->x);
+area->h = av_clip(area->h, 0, sp->height - area->y);
 
 is->sub_convert_ctx = 
sws_getCachedContext(is->sub_convert_ctx,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
-sub_rect->w, sub_rec

[FFmpeg-devel] [PATCH v16 04/16] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

2021-11-25 Thread Soft Works
Analog to avfilter/video.c and avfilter/audio.c

Signed-off-by: softworkz 
---
 libavfilter/Makefile|  1 +
 libavfilter/avfilter.c  |  4 +++
 libavfilter/internal.h  |  1 +
 libavfilter/subtitles.c | 63 +
 libavfilter/subtitles.h | 44 
 5 files changed, 113 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e27aeeff6..99f3047965 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -19,6 +19,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
video.o  \
 
 OBJS-$(HAVE_THREADS) += pthread.o
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..df5b8f483c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -43,6 +43,7 @@
 #include "formats.h"
 #include "framepool.h"
 #include "internal.h"
+#include "subtitles.h"
 
 #include "libavutil/ffversion.h"
 const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
@@ -1475,6 +1476,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, 
AVFrame **rframe)
 case AVMEDIA_TYPE_AUDIO:
 out = ff_get_audio_buffer(link, frame->nb_samples);
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+out = ff_get_subtitles_buffer(link, link->format);
+break;
 default:
 return AVERROR(EINVAL);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..fc09ef574c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -90,6 +90,7 @@ struct AVFilterPad {
 union {
 AVFrame *(*video)(AVFilterLink *link, int w, int h);
 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
+AVFrame *(*subtitle)(AVFilterLink *link, int format);
 } get_buffer;
 
 /**
diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
new file mode 100644
index 00..951bfd612c
--- /dev/null
+++ b/libavfilter/subtitles.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+
+#include "subtitles.h"
+#include "avfilter.h"
+#include "internal.h"
+
+
+AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+return ff_get_subtitles_buffer(link->dst->outputs[0], format);
+}
+
+AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *frame;
+
+frame = av_frame_alloc();
+if (!frame)
+return NULL;
+
+frame->format = format;
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+
+if (av_frame_get_buffer2(frame, 0) < 0) {
+av_frame_free(&frame);
+return NULL;
+}
+
+return frame;
+}
+
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *ret = NULL;
+
+if (link->dstpad->get_buffer.subtitle)
+ret = link->dstpad->get_buffer.subtitle(link, format);
+
+if (!ret)
+ret = ff_default_get_subtitles_buffer(link, format);
+
+return ret;
+}
diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
new file mode 100644
index 00..4a9115126e
--- /dev/null
+++ b/libavfilter/subtitles.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 recei

[FFmpeg-devel] [PATCH v16 05/16] avfilter/avfilter: Handle subtitle frames

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 libavfilter/avfilter.c  |  8 +---
 libavfilter/avfilter.h  | 11 +++
 libavfilter/avfiltergraph.c |  5 +
 libavfilter/formats.c   | 22 ++
 libavfilter/formats.h   |  3 +++
 libavfilter/internal.h  | 18 +++---
 6 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index df5b8f483c..75d5e86539 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -56,7 +56,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->linesize[0], ref->linesize[1], ref->linesize[2], 
ref->linesize[3],
 ref->pts, ref->pkt_pos);
 
-if (ref->width) {
+switch(ref->type) {
+case AVMEDIA_TYPE_VIDEO:
 ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
 ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den,
 ref->width, ref->height,
@@ -64,12 +65,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->top_field_first ? 'T' : 'B',/* Top / Bottom */
 ref->key_frame,
 av_get_picture_type_char(ref->pict_type));
-}
-if (ref->nb_samples) {
+break;
+case AVMEDIA_TYPE_AUDIO:
 ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
 ref->channel_layout,
 ref->nb_samples,
 ref->sample_rate);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f7208754a7..ee2f5b594d 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -45,6 +45,7 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "libavfilter/version.h"
@@ -327,6 +328,12 @@ typedef struct AVFilter {
  * and outputs use the same sample rate and channel count/layout.
  */
 const enum AVSampleFormat *samples_list;
+/**
+ * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE
+ * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE
+ * inputs and outputs.
+ */
+const enum AVSubtitleType *subs_list;
 /**
  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
  */
@@ -335,6 +342,10 @@ typedef struct AVFilter {
  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
  */
 enum AVSampleFormat sample_fmt;
+/**
+ * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list.
+ */
+enum AVSubtitleType sub_fmt;
 } formats;
 
 int priv_size;  ///< size of private data to allocate for the filter
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..96f35a792c 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -311,6 +311,8 @@ static int filter_link_check_formats(void *log, 
AVFilterLink *link, AVFilterForm
 return ret;
 break;
 
+case AVMEDIA_TYPE_SUBTITLE:
+return 0;
 default:
 av_assert0(!"reached");
 }
@@ -441,6 +443,9 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 if (!link)
 continue;
 
+if (link->type == AVMEDIA_TYPE_SUBTITLE)
+continue;
+
 neg = ff_filter_get_negotiation(link);
 av_assert0(neg);
 for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..46dbbd2975 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavcodec/avcodec.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 return 0;
 }
 
+int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt)
+{
+ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
+return 0;
+}
+
 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
 {
 int fmts[2] = { fmt, -1 };
@@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
 return NULL;
 fmt++;
 }
+} else if (type == AVMEDIA_TYPE_SUBTITLE) {
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_BITMAP) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_ASS) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_TEXT) < 0)
+return NULL;
 }
 
 return ret;
@@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx)
 type= 

[FFmpeg-devel] [PATCH v16 06/16] avfilter/sbuffer: Add sbuffersrc and sbuffersink filters

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/allfilters.c |  2 ++
 libavfilter/buffersink.c | 63 +++
 libavfilter/buffersink.h | 15 +
 libavfilter/buffersrc.c  | 72 
 libavfilter/buffersrc.h  |  1 +
 6 files changed, 154 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d068b11073..e4d1443237 100755
--- a/configure
+++ b/configure
@@ -7758,7 +7758,7 @@ print_enabled_components(){
 fi
 done
 if [ "$name" = "filter_list" ]; then
-for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer 
vsink_buffer ssink_sbuffer; do
 printf "&ff_%s,\n" $c >> $TMPH
 done
 fi
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4bf17ef292..4072f08385 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -550,8 +550,10 @@ extern const AVFilter ff_avsrc_movie;
  * being the same while having different 'types'). */
 extern  const AVFilter ff_asrc_abuffer;
 extern  const AVFilter ff_vsrc_buffer;
+extern  const AVFilter ff_ssrc_sbuffer;
 extern  const AVFilter ff_asink_abuffer;
 extern  const AVFilter ff_vsink_buffer;
+extern  const AVFilter ff_ssink_sbuffer;
 extern const AVFilter ff_af_afifo;
 extern const AVFilter ff_vf_fifo;
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index b8ddafec35..8306312acc 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -29,6 +29,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -57,6 +59,10 @@ typedef struct BufferSinkContext {
 int *sample_rates;  ///< list of accepted sample 
rates, terminated by -1
 int sample_rates_size;
 
+/* only used for subtitles */
+enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle 
types, must be terminated with -1
+int subtitle_types_size;
+
 AVFrame *peeked_frame;
 } BufferSinkContext;
 
@@ -168,6 +174,15 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void)
 return NULL;
 return params;
 }
+
+AVSBufferSinkParams *av_sbuffersink_params_alloc(void)
+{
+AVSBufferSinkParams *params = av_mallocz(sizeof(AVSBufferSinkParams));
+
+if (!params)
+return NULL;
+return params;
+}
 #endif
 
 static av_cold int common_init(AVFilterContext *ctx)
@@ -305,6 +320,28 @@ static int asink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+static int ssink_query_formats(AVFilterContext *ctx)
+{
+BufferSinkContext *buf = ctx->priv;
+AVFilterFormats *formats = NULL;
+unsigned i;
+int ret;
+
+CHECK_LIST_SIZE(subtitle_types)
+if (buf->subtitle_types_size) {
+for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++)
+if ((ret = ff_add_subtitle_type(&formats, buf->subtitle_types[i])) 
< 0)
+return ret;
+if ((ret = ff_set_common_formats(ctx, formats)) < 0)
+return ret;
+} else {
+if ((ret = ff_default_query_formats(ctx)) < 0)
+return ret;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(BufferSinkContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
@@ -322,9 +359,16 @@ static const AVOption abuffersink_options[] = {
 { NULL },
 };
 #undef FLAGS
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM
+static const AVOption sbuffersink_options[] = {
+{ "subtitle_types", "set the supported subtitle formats", 
OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+{ NULL },
+};
+#undef FLAGS
 
 AVFILTER_DEFINE_CLASS(buffersink);
 AVFILTER_DEFINE_CLASS(abuffersink);
+AVFILTER_DEFINE_CLASS(sbuffersink);
 
 static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
 {
@@ -363,3 +407,22 @@ const AVFilter ff_asink_abuffer = {
 .outputs   = NULL,
 FILTER_QUERY_FUNC(asink_query_formats),
 };
+
+static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+const AVFilter ff_ssink_sbuffer = {
+.name  = "sbuffersink",
+.description   = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make 
them available to the end of the filter graph."),
+.priv_class= &sbuffersink_class,
+.priv_size = sizeof(BufferSinkContext),
+.init  = common_init,
+.activate  = activate,
+FILTER_INPUTS(avfilter_ssink_sbuffer_inputs),
+.outputs   = NULL,
+FILTER_QUERY_FUNC(ssink_query_formats),
+};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..b439b586c5 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -129,6 +129,21 @@ typedef struct AVABufferSinkP

[FFmpeg-devel] [PATCH v16 07/16] avfilter/overlaygraphicsubs: Add overlaygraphicsubs and graphicsub2video filters

2021-11-25 Thread Soft Works
- overlaygraphicsubs (VS -> V)
  Overlay graphic subtitles onto a video stream

- graphicsub2video {S -> V)
  Converts graphic subtitles to video frames (with alpha)
  Gets auto-inserted for retaining compatibility with
  sub2video command lines

Signed-off-by: softworkz 
---
 doc/filters.texi| 118 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_overlaygraphicsubs.c | 737 
 4 files changed, 859 insertions(+)
 create mode 100644 libavfilter/vf_overlaygraphicsubs.c

diff --git a/doc/filters.texi b/doc/filters.texi
index c3ccaf97c4..dcbe718664 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25543,6 +25543,124 @@ tools.
 
 @c man end VIDEO SINKS
 
+@chapter Subtitle Filters
+@c man begin SUBTITLE FILTERS
+
+When you configure your FFmpeg build, you can disable any of the
+existing filters using @code{--disable-filters}.
+
+Below is a description of the currently available subtitle filters.
+
+@section graphicsub2video
+
+Renders graphic subtitles as video frames.
+
+This filter replaces the previous "sub2video" hack which did the conversion 
implicitly and up-front as subtitle filtering wasn't possible at that time.
+To retain compatibility with earlier sub2video command lines, this filter is 
being auto-inserted in those cases.
+
+For overlaying graphicsal subtitles it is recommended to use the 
'overlay_graphicsubs' filter which is more efficient and takes less processing 
resources.
+
+This filter is still useful in cases where the overlay is done with hardware 
acceleration (e.g. overlay_qsv, overlay_vaapi, overlay_cuda) for preparing the 
overlay frames.
+
+Inputs:
+@itemize
+@item 0: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+
+It accepts the following parameters:
+
+@table @option
+@item size, s
+Set the size of the output video frame.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+(not recommended - better use overlay_graphicsubs)
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:1]graphicsub2video[subs];[0:0][subs]overlay" output.mp4
+@end example
+
+@item
+Overlay PGS subtitles implicitly
+The graphicsub2video is inserted automatically for compatibility with legacy 
command lines.
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlay" output.mp4
+@end example
+@end itemize
+
+@section overlaygraphicsubs
+
+Overlay graphic subtitles onto a video stream.
+
+This filter can blend graphical subtitles on a video stream directly, i.e. 
without creating full-size alpha images first.
+The blending operation is limited to the area of the subtitle rectangles, 
which also means that no processing is done at times where no subtitles are to 
be displayed.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+Set the expression for the x and y coordinates of the overlaid video
+on the main video. Default value is "0" for both expressions. In case
+the expression is invalid, it is set to a huge value (meaning that the
+overlay will not be displayed within the output visible area).
+
+@item eof_action
+See @ref{framesync}.
+
+@item eval
+Set when the expressions for @option{x}, and @option{y} are evaluated.
+
+It accepts the following values:
+@table @samp
+@item init
+only evaluate expressions once during the filter initialization or
+when a command is processed
+
+@item frame
+evaluate expressions for each incoming frame
+@end table
+
+Default value is @samp{frame}.
+
+@item shortest
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
+@end example
+@end itemize
+@c man end SUBTITLE FILTERS
+
 @chapter Multimedia Filters
 @c man begin MULTIMEDIA FILTERS
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 99f3047965..6c790391b8 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -293,6 +293,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  

[FFmpeg-devel] [PATCH v16 08/16] fftools/ffmpeg: Replace sub2video with subtitle frame filtering

2021-11-25 Thread Soft Works
This commit actually enables subtitle filtering in ffmpeg by
sending and receiving subtitle frames to and from a filtergraph.

The heartbeat functionality from the previous sub2video implementation
is retained and applied to all subtitle frames (bitmap, text, ..).

The other part of sub2video functionality is retained by
auto-insertion of the new graphicsub2video filter.

Justification for changed test refs:

- sub2video
  The new results are identical excepting the last frame which
  is due to the implementation changes

- sub2video_basic
  The previous results had some incorrect output because multiple
  frames had the same dts
  The non-empty content frames are visually identical, the different
  CRC is due to the different blending algorithm that is being used.

- sub2video_time_limited
  The third frame in the previous ref was a repetition, which doesn't
  happen anymore with the new subtitle filtering.

- sub-dvb
  Running ffprobe -show_frames on the source file shows that there
  are 7 subtitle frames with 0 rects in the source at the start
  and 2 at the end. This translates to the 14 and 4 additional
  entries in the new test results.

- filter-overlay-dvdsub-2397
  Overlay results have slightly different CRCs due to different
  blending implementation

Signed-off-by: softworkz 
---
 fftools/ffmpeg.c  | 523 +++---
 fftools/ffmpeg.h  |  15 +-
 fftools/ffmpeg_filter.c   | 217 ++---
 fftools/ffmpeg_hw.c   |   2 +-
 fftools/ffmpeg_opt.c  |   3 +-
 tests/ref/fate/filter-overlay-dvdsub-2397 | 181 
 tests/ref/fate/sub-dvb| 162 ---
 tests/ref/fate/sub2video  | 116 ++---
 tests/ref/fate/sub2video_basic| 135 ++
 tests/ref/fate/sub2video_time_limited |   4 +-
 10 files changed, 684 insertions(+), 674 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 3761ea0c38..c697c12777 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -169,163 +169,6 @@ static int restore_tty;
 static void free_input_threads(void);
 #endif
 
-/* sub2video hack:
-   Convert subtitles to video with alpha to insert them in filter graphs.
-   This is a temporary solution until libavfilter gets real subtitles support.
- */
-
-static int sub2video_get_blank_frame(InputStream *ist)
-{
-int ret;
-AVFrame *frame = ist->sub2video.frame;
-
-av_frame_unref(frame);
-ist->sub2video.frame->width  = ist->dec_ctx->width  ? ist->dec_ctx->width  
: ist->sub2video.w;
-ist->sub2video.frame->height = ist->dec_ctx->height ? ist->dec_ctx->height 
: ist->sub2video.h;
-ist->sub2video.frame->format = AV_PIX_FMT_RGB32;
-if ((ret = av_frame_get_buffer(frame, 0)) < 0)
-return ret;
-memset(frame->data[0], 0, frame->height * frame->linesize[0]);
-return 0;
-}
-
-static void sub2video_copy_rect(uint8_t *dst, int dst_linesize, int w, int h,
-AVSubtitleRect *r)
-{
-uint32_t *pal, *dst2;
-uint8_t *src, *src2;
-int x, y;
-
-if (r->type != SUBTITLE_BITMAP) {
-av_log(NULL, AV_LOG_WARNING, "sub2video: non-bitmap subtitle\n");
-return;
-}
-if (r->x < 0 || r->x + r->w > w || r->y < 0 || r->y + r->h > h) {
-av_log(NULL, AV_LOG_WARNING, "sub2video: rectangle (%d %d %d %d) 
overflowing %d %d\n",
-r->x, r->y, r->w, r->h, w, h
-);
-return;
-}
-
-dst += r->y * dst_linesize + r->x * 4;
-src = r->data[0];
-pal = (uint32_t *)r->data[1];
-for (y = 0; y < r->h; y++) {
-dst2 = (uint32_t *)dst;
-src2 = src;
-for (x = 0; x < r->w; x++)
-*(dst2++) = pal[*(src2++)];
-dst += dst_linesize;
-src += r->linesize[0];
-}
-}
-
-static void sub2video_push_ref(InputStream *ist, int64_t pts)
-{
-AVFrame *frame = ist->sub2video.frame;
-int i;
-int ret;
-
-av_assert1(frame->data[0]);
-ist->sub2video.last_pts = frame->pts = pts;
-for (i = 0; i < ist->nb_filters; i++) {
-ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, frame,
-   AV_BUFFERSRC_FLAG_KEEP_REF |
-   AV_BUFFERSRC_FLAG_PUSH);
-if (ret != AVERROR_EOF && ret < 0)
-av_log(NULL, AV_LOG_WARNING, "Error while add the frame to buffer 
source(%s).\n",
-   av_err2str(ret));
-}
-}
-
-void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
-{
-AVFrame *frame = ist->sub2video.frame;
-int8_t *dst;
-int dst_linesize;
-int num_rects, i;
-int64_t pts, end_pts;
-
-if (!frame)
-return;
-if (sub) {
-pts   = av_rescale_q(sub->pts + sub->start_display_time * 1000LL,
- AV_TIME_BASE_Q, ist->st->time_base);
-end_pts   = av_rescale_q(sub->pts + sub->end_display_ti

[FFmpeg-devel] [PATCH v16 09/16] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2021-11-25 Thread Soft Works
- overlaytextsubs {VS -> V)
  Overlay text subtitles onto a video stream.

- textsubs2video {S -> V)
  Converts text subtitles to video frames

Signed-off-by: softworkz 
---
 configure|   2 +
 doc/filters.texi | 113 ++
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   4 +-
 libavfilter/avfilter.c   |  18 +-
 libavfilter/vf_overlaytextsubs.c | 624 +++
 6 files changed, 757 insertions(+), 6 deletions(-)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index e4d1443237..db1db0a0a6 100755
--- a/configure
+++ b/configure
@@ -3642,6 +3642,7 @@ overlay_opencl_filter_deps="opencl"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlaytextsubs_filter_deps="avcodec libass"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
@@ -3686,6 +3687,7 @@ superequalizer_filter_deps="avcodec"
 superequalizer_filter_select="rdft"
 surround_filter_deps="avcodec"
 surround_filter_select="rdft"
+textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index dcbe718664..fedd907185 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25659,6 +25659,119 @@ Overlay PGS subtitles
 ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
 @end example
 @end itemize
+
+@section overlaytextsubs
+
+Overlay text subtitles onto a video stream.
+
+This filter supersedes the classic @ref{subtitles} filter opposed to which it 
does no longer require to open and access the source stream separately, which 
is often causing problems or doesn't even work for non-local or slow sources.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item alpha
+Process alpha channel, by default alpha channel is untouched.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay ASS subtitles with animations:
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:v]overlaytextsubs" -map 0 -y out.mkv
+@end example
+@end itemize
+
+@section textsub2video
+
+Converts text subtitles to video frames.
+
+For overlaying text subtitles onto video frames it is recommended to use the 
overlay_textsubs filter.
+The textsub2video is useful for for creating transparent text-frames when 
overlay is done via hw acceleration
+
+Inputs:
+@itemize
+@item 0: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item rate, r
+Set the framerate for updating overlay frames.
+Normally, overlay frames will only be updated each time when the subtitles to 
display are changing.
+In cases where subtitles include advanced features (like animation), this 
parameter determines the frequency by which the overlay frames should be 
updated.
+
+@item size, s
+Set the output frame size.
+Allows to override the size of output video frames.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time.
+@end table
+
 @c man end SUBTITLE FILTERS
 
 @ch

[FFmpeg-devel] [PATCH v16 10/16] avfilter/textmod: Add textmod, censor and show_speaker filters

2021-11-25 Thread Soft Works
- textmod {S -> S)
  Modify subtitle text in a number of ways

- censor {S -> S)
  Censor subtitles using a word list

- show_speaker {S -> S)
  Prepend speaker names from ASS subtitles to the visible text lines

Signed-off-by: softworkz 
---
 doc/filters.texi | 206 
 libavfilter/Makefile |   5 +
 libavfilter/allfilters.c |   3 +
 libavfilter/sf_textmod.c | 697 +++
 4 files changed, 911 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index fedd907185..183463108d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25551,6 +25551,145 @@ existing filters using @code{--disable-filters}.
 
 Below is a description of the currently available subtitle filters.
 
+
+@section censor
+
+Censor selected words in text subtitles.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The censoring mode to apply.
+
+Supported censoring modes are:
+
+@table @var
+@item 0, keep_first_last
+Replace all characters with the 'censor_char' except the first and the last 
character of a word.
+For words with less than 4 characters, the last character will be replaced as 
well.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 1, keep_first
+Replace all characters with the 'censor_char' except the first character of a 
word.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 2, all
+Replace all characters with the 'censor_char'.
+@end table
+
+@item words
+A list of words to censor, separated by 'separator'.
+
+@item words_file
+Specify a file from which to load the contents for the 'words' parameter.
+
+@item censor_char
+Single character used as replacement for censoring.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Censor a few given words with a pound character.
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex 
"[0:1]censor=words='diss,louder,hope,beam,word':censor_char='#'" -map 0 -y 
output.mkv
+@end example
+@end itemize
+
+
+@section textmod
+
+Modify subtitle text in a number of ways.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The kind of text modification to apply
+
+Supported operation modes are:
+
+@table @var
+@item 0, leet
+Convert subtitle text to 'leet speak'. It's primarily useful for testing as 
the modification will be visible with almost all text lines.
+@item 1, to_upper
+Change all text to upper case. Might improve readability.
+@item 2, to_lower
+Change all text to lower case.
+@item 3, replace_chars
+Replace one or more characters. Requires the find and replace parameters to be 
specified.
+Both need to be equal in length.
+The first char in find is replaced by the first char in replace, same for all 
subsequent chars.
+@item 4, remove_chars
+Remove certain characters. Requires the find parameter to be specified.
+All chars in the find parameter string will be removed from all subtitle text.
+@item 5, replace_words
+Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ',').
+The number of words in the find and replace parameters needs to be equal.
+The first word in find is replaced by the first word in replace, same for all 
subsequent words
+@item 6, remove_words
+Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ',').
+All words in the find parameter string will be removed from all subtitle text.
+@end table
+
+@item find
+Required for replace_chars, remove_chars, replace_words and remove_words.
+
+@item find_file
+Specify a file from which to load the contents for the 'find' parameter.
+
+@item replace
+Required for replace_chars and replace_words.
+
+@item replace_file
+Specify a file from which to load the contents for the 'replace' parameter.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Change all characters to upper case while keeping all styles and animations:
+@example
+ffmpeg -i "https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; 
-filter_complex "[0:s]textmod=mode=to_upper" -map 0 -y out.mkv
+@end example
+@item
+Remove a set of symbol characters for am improved and smooth

[FFmpeg-devel] [PATCH v16 11/16] avfilter/stripstyles: Add stripstyles filter

2021-11-25 Thread Soft Works
- stripstyles {S -> S)
  Remove all inline styles from subtitle events

Signed-off-by: softworkz 
---
 doc/filters.texi |  37 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_stripstyles.c | 196 +++
 4 files changed, 235 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 183463108d..0d6502f282 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25611,6 +25611,43 @@ ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.
 @end example
 @end itemize
 
+@section stripstyles
+
+Remove all inline styles from subtitle events.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item remove_animated
+Also remove text which is subject to animation (default: true)
+Usually, animated text elements are used used in addition to static subtitle 
lines for creating effects, so in most cases it is safe to remove the animation 
content.
+If subtitle text is missing, try setting this to false.
+
+@item select_layer
+Process only ASS subtitle events from a specific layer. This allows to filter 
out certain effects where an ASS author duplicates the text onto multiple 
layers.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Remove styles and animations from ASS subtitles and output events from ass 
layer 0 only. Then convert asn save as SRT stream:
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:1]stripstyles=select_layer=0" -map 0 -c:s srt output.mkv
+@end example
+@end itemize
+
 
 @section textmod
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7fac60ab43..599ca0e54a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -555,6 +555,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 69f4c47e6a..378d1dcaac 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -543,6 +543,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..82cb9c7647
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * text subtitle filter which removes inline-styles from subtitles
+ */
+
+#include "libavutil/opt.h"
+#include "internal.h"
+#include "libavutil/ass_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+} DialogContext;
+
+static void dialog_text_cb(void *priv, const char *text, int len)
+{
+DialogContext *s = priv;
+
+av_log(s->ss_ctx, AV_LOG_DEBUG, "dialog_text_cb: %s\n", text);
+
+if (!s->drawing_scale && (!s->is_animated || !s->ss_ctx->remove_animated))
+av_bprint_append_data(&s->buffer, text, len);
+}
+
+static void dialog_new_line_cb(void *priv, int forced)
+{
+DialogContext *s = priv;
+if (!s->drawing_scale && !s->is_animated)
+av_bprint_append_data(&s->buffer, forced ? "\\N" : "\\n", 2);
+}
+
+static void di

[FFmpeg-devel] [PATCH v16 12/16] avfilter/splitcc: Add splitcc filter for closed caption handling

2021-11-25 Thread Soft Works
- splitcc {V -> VS)
  Extract closed-caption (A53) data from video
  frames as subtitle Frames

ffmpeg -y -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex 
"[0:v]splitcc[vid1],textmod=mode=remove_chars:find='@',[vid1]overlay_textsubs" 
output.mkv

Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  63 
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_splitcc.c | 316 +++
 5 files changed, 382 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index db1db0a0a6..bcd7102e6c 100755
--- a/configure
+++ b/configure
@@ -3680,6 +3680,7 @@ spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
+splitcc_filter_deps="avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 0d6502f282..bb0e6c5add 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25961,6 +25961,69 @@ ffmpeg -i INPUT -filter_complex 
"showspeaker=format=colon:style='@{\\c&HDD&\
 @end example
 @end itemize
 
+
+@section splitcc
+
+Split-out closed-caption/A53 subtitles from video frame side data.
+
+This filter provides an input and an output for video frames, which are just 
passed through without modification.
+The second out provides subtitle frames which are extracted from video frame 
side data.
+
+Inputs:
+@itemize
+@item 0: Video [ALL]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@item 1: Subtitles [TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item use_cc_styles
+Emit closed caption style header.
+This will make closed captions appear in white font with a black rectangle 
background.
+
+@item real_time
+Emit subtitle events as they are decoded for real-time display.
+
+@item real_time_latency_msec
+Minimum elapsed time between emitting real-time subtitle events.
+Only applies to real_time mode.
+
+@item data_field
+Select data field. Possible values:
+
+@table @samp
+@item auto
+Pick first one that appears.
+@item first
+@item second
+@end table
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Extract closed captions as text subtitle stream and overlay it onto the video 
in cc style (black bar background):
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=use_cc_styles=1[vid1][sub1];[vid1][sub1]overlaytextsubs" 
output.mkv
+@end example
+
+@item
+A nicer variant, using realtime output from cc_dec and rendering it with the 
render_latest_only parameter from overlaytextsubs to avoid ghosting by timely 
overlap.
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=real_time=1:real_time_latency_msec=200[vid1][sub1];[vid1][sub1]overlaytextsubs=render_latest_only=1"
 output.mkv
+@end example
+@end itemize
+
+
 @section textsub2video
 
 Converts text subtitles to video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 599ca0e54a..5364e11491 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -555,6 +555,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 378d1dcaac..1444ca873a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -543,6 +543,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..0ebbd500f1
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * MERCHANTABI

[FFmpeg-devel] [PATCH v16 13/16] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  55 +
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_graphicsub2text.c | 354 +++
 5 files changed, 413 insertions(+)
 create mode 100644 libavfilter/sf_graphicsub2text.c

diff --git a/configure b/configure
index bcd7102e6c..f04408a69c 100755
--- a/configure
+++ b/configure
@@ -3616,6 +3616,7 @@ frei0r_filter_deps="frei0r"
 frei0r_src_filter_deps="frei0r"
 fspp_filter_deps="gpl"
 gblur_vulkan_filter_deps="vulkan spirv_compiler"
+graphicsub2text_filter_deps="libtesseract"
 hflip_vulkan_filter_deps="vulkan spirv_compiler"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index bb0e6c5add..877a4c01e8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25727,6 +25727,61 @@ ffmpeg -i 
"https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; -filter_comple
 @end example
 @end itemize
 
+@section graphicsub2text
+
+Converts graphic subtitles to text subtitles by performing OCR.
+
+For this filter to be available, ffmpeg needs to be compiled with libtesseract 
(see https://github.com/tesseract-ocr/tesseract).
+Language models need to be downloaded from 
https://github.com/tesseract-ocr/tessdata and put into as subfolder named 
'tessdata' or into a folder specified via the environment variable 
'TESSDATA_PREFIX'.
+The path can also be specified via filter option (see below).
+
+Note: These models are including the data for both OCR modes.
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [text]
+
+It accepts the following parameters:
+
+@table @option
+@item ocr_mode
+The character recognition mode to use.
+
+Supported OCR modes are:
+
+@table @var
+@item 0, tesseract
+This is the classic libtesseract operation mode. It is fast but less accurate 
than LSTM.
+@item 1, lstm
+Newer OCR implementation based on ML models. Provides usually better results, 
requires more processing resources.
+@item 2, both
+Use a combination of both modes.
+@end table
+
+@item tessdata_path
+The path to a folder containing the language models to be used.
+
+@item language
+The recognition language. It needs to match the first three characters of a  
language model file in the tessdata path.
+
+@end table
+
+
+@subsection Examples
+
+@itemize
+@item
+Convert DVB graphic subtitles to ASS (text) subtitles
+
+Note: For this to work, you need to have the data file 'eng.traineddata' in a 
'tessdata' subfolder (see above).
+@example
+ffmpeg ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts"; 
-filter_complex "[0:13]graphicsub2text=ocr_mode=both" -c:s ass -y output.mkv
+@end example
+@end itemize
+
+
 @section graphicsub2video
 
 Renders graphic subtitles as video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 5364e11491..a1ad37ab9f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -294,6 +294,8 @@ OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += 
vf_gblur_vulkan.o vulkan.o vulka
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
 OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
+OBJS-$(CONFIG_GRAPHICSUB2TEXT_FILTER)+= sf_graphicsub2text.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
 OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 1444ca873a..f8a64d4032 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -542,6 +542,7 @@ extern const AVFilter ff_avf_showwaves;
 extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
+extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
diff --git a/libavfilter/sf_graphicsub2text.c b/libavfilter/sf_graphicsub2text.c
new file mode 100644
index 00..1f256f5c65
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 mor

[FFmpeg-devel] [PATCH v16 14/16] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 883 ++
 5 files changed, 1050 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index f04408a69c..f9203a34f7 100755
--- a/configure
+++ b/configure
@@ -3682,6 +3682,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 877a4c01e8..c9548551c1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26133,6 +26133,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the
+latter being separated as 'arrange_h' and 'arrange_v'.
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+Bitmaps that do not fit inside the margins borders are
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g.
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec.
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make sure that subtitle 

[FFmpeg-devel] [PATCH v16 15/16] avcodec/subtitles: Migrate subtitle encoders to frame-based API and provide a compatibility shim for the legacy api

2021-11-25 Thread Soft Works
Also introduce deferred loading of ass headers for all cases where it can't be 
taken from the context of a decoder.

Signed-off-by: softworkz 
---
 libavcodec/assenc.c|  81 -
 libavcodec/avcodec.h   |   7 +++
 libavcodec/dvbsubenc.c |  85 +++---
 libavcodec/dvdsubenc.c |  89 +---
 libavcodec/encode.c|  98 ++-
 libavcodec/movtextenc.c| 103 +
 libavcodec/srtenc.c|  96 ++
 libavcodec/tests/avcodec.c |   2 -
 libavcodec/ttmlenc.c   |  82 +++--
 libavcodec/webvttenc.c |  73 +++---
 libavcodec/xsubenc.c   |  65 ---
 11 files changed, 541 insertions(+), 240 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b0e475834b..2566b1d4dc 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -28,42 +28,77 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
+static void check_write_header(AVCodecContext* avctx, const AVFrame* frame)
+{
+if (avctx->extradata_size)
+return;
+
+if (frame->subtitle_header && frame->subtitle_header->size > 0) {
+const char* subtitle_header = (char*)frame->subtitle_header->data;
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(frame->subtitle_header->size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+if (!avctx->extradata_size) {
+const char* subtitle_header = 
avpriv_ass_get_subtitle_header_default(0);
+if (!subtitle_header)
+return;
+
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(avctx->extradata_size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+av_freep(&subtitle_header);
+}
+}
+
 static av_cold int ass_encode_init(AVCodecContext *avctx)
 {
-avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
-if (!avctx->extradata)
-return AVERROR(ENOMEM);
-memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
-avctx->extradata_size = avctx->subtitle_header_size;
-avctx->extradata[avctx->extradata_size] = 0;
+if (avctx->subtitle_header_size) {
+avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
+avctx->extradata_size   = avctx->subtitle_header_size;
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
 return 0;
 }
 
-static int ass_encode_frame(AVCodecContext *avctx,
-unsigned char *buf, int bufsize,
-const AVSubtitle *sub)
+static int ass_encode_frame(AVCodecContext* avctx, AVPacket* avpkt,
+const AVFrame* frame, int* got_packet)
 {
-int i, len, total_len = 0;
+int len, total_len = 0;
 
-for (i=0; inum_rects; i++) {
-const char *ass = sub->rects[i]->ass;
+check_write_header(avctx, frame);
 
-if (sub->rects[i]->type != SUBTITLE_ASS) {
-av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (frame->subtitle_areas[i]->type != AV_SUBTITLE_FMT_ASS) {
+av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type 
supported.\n");
 return AVERROR(EINVAL);
 }
 
-len = av_strlcpy(buf+total_len, ass, bufsize-total_len);
+if (ass) {
+len = av_strlcpy((char *)avpkt->data + total_len, ass, avpkt->size 
- total_len);
 
-if (len > bufsize-total_len-1) {
-av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
-return AVERROR_BUFFER_TOO_SMALL;
-}
+if (len > avpkt->size - 1) {
+av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS 
event.\n");
+return AVERROR_BUFFER_TOO_SMALL;
+}
 
-total_len += len;
+total_len += len;
+}
 }
 
-return total_len;
+avpkt->size = total_len;
+*got_packet = total_len > 0;
+
+return 0;
 }
 
 #if CONFIG_SSA_ENCODER
@@ -73,7 +108,7 @@ const AVCodec ff_ssa_encoder = {
 .type = AVMEDIA_TYPE_SUBTITLE,
 .id   = AV_CODEC_ID_ASS,
 .init = ass_encode_init,
-.encode_sub   = ass_encode_frame,
+.encode2  = ass_encode_frame,
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
@@ -85,7 +120,7 @@ const AVC

[FFmpeg-devel] [PATCH v16 16/16] fftools/ffmpeg: Use new frame-based subtitle encoding API

2021-11-25 Thread Soft Works
Signed-off-by: softworkz 
---
 fftools/ffmpeg.c | 60 
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c697c12777..603b4c23e0 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -896,10 +896,9 @@ error:
 static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
 {
 const int subtitle_out_max_size = 1024 * 1024;
-int subtitle_out_size, nb, i;
+int nb, i;
 AVCodecContext *enc;
 AVPacket *pkt = ost->pkt;
-AVSubtitle out_sub = { 0 };
 int64_t pts;
 
 if (!frame)
@@ -917,12 +916,14 @@ static void do_subtitle_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 enc = ost->enc_ctx;
 
 if (!subtitle_out) {
-subtitle_out = av_malloc(subtitle_out_max_size);
+subtitle_out = av_mallocz(subtitle_out_max_size);
 if (!subtitle_out) {
 av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n");
 exit_program(1);
 }
 }
+else
+memset(subtitle_out, 0, subtitle_out_max_size);
 
 /* Note: DVB subtitle need one packet to draw them and one other
packet to clear them */
@@ -947,44 +948,43 @@ static void do_subtitle_out(OutputFile *of, OutputStream 
*ost, AVFrame *frame)
 frame->subtitle_end_time  -= frame->subtitle_start_time;
 frame->subtitle_start_time = 0;
 
-av_frame_get_subtitle(&out_sub, frame);
-
 for (i = 0; i < nb; i++) {
-const unsigned save_num_rects = out_sub.num_rects;
+int ret, got_packet = 0;
+const unsigned save_num_rects = frame->num_subtitle_areas;
+
+pkt->data = subtitle_out;
+pkt->size = subtitle_out_max_size;
 
 ost->frames_encoded++;
 
 if (i == 1)
-out_sub.num_rects = 0;
+frame->num_subtitle_areas = 0;
 
-subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, 
subtitle_out_max_size, &out_sub);
+ret = avcodec_encode_subtitle2(enc, pkt, frame, &got_packet);
 
 if (i == 1)
-out_sub.num_rects = save_num_rects;
+frame->num_subtitle_areas = save_num_rects;
 
-if (subtitle_out_size < 0) {
-av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n");
-exit_program(1);
-}
-
-//av_packet_unref(pkt);
-pkt->data = subtitle_out;
-pkt->size = subtitle_out_size;
-pkt->pts  = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, 
ost->mux_timebase);
-pkt->duration = av_rescale_q(frame->subtitle_end_time, (AVRational){ 
1, 1000 }, ost->mux_timebase);
-if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
-/* XXX: the pts correction is handled here. Maybe handling
-   it in the codec would be better */
-if (i == 0)
-pkt->pts += av_rescale_q(frame->subtitle_start_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
-else
-pkt->pts += av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+if (ret < 0) {
+av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed: %d\n", ret);
+exit_program(ret);
+}
+
+if (got_packet) {
+pkt->pts  = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, 
ost->mux_timebase);
+pkt->duration = av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
+/* XXX: the pts correction is handled here. Maybe handling
+   it in the codec would be better */
+if (i == 0)
+pkt->pts += av_rescale_q(frame->subtitle_start_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+else
+pkt->pts += av_rescale_q(frame->subtitle_end_time, 
(AVRational){ 1, 1000 }, ost->mux_timebase);
+}
+pkt->dts = pkt->pts;
+output_packet(of, pkt, ost, 0);
 }
-pkt->dts = pkt->pts;
-output_packet(of, pkt, ost, 0);
 }
-
-avsubtitle_free(&out_sub);
 }
 
 static void do_video_out(OutputFile *of,
-- 
2.30.2.windows.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/libsrt: add missing version check for snddropdelay

2021-11-25 Thread Marton Balint




On Sat, 20 Nov 2021, lance.lmw...@gmail.com wrote:


On Fri, Nov 19, 2021 at 09:29:01PM +0100, Marton Balint wrote:

Signed-off-by: Marton Balint 
---
 libavformat/libsrt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c
index 145eea2f7c..19b9cb9895 100644
--- a/libavformat/libsrt.c
+++ b/libavformat/libsrt.c
@@ -320,7 +320,9 @@ static int libsrt_set_options_pre(URLContext *h, int fd)
 int latency = s->latency / 1000;
 int rcvlatency = s->rcvlatency / 1000;
 int peerlatency = s->peerlatency / 1000;
+#if SRT_VERSION_VALUE >= 0x010302
 int snddropdelay = s->snddropdelay > 0 ? s->snddropdelay / 1000 : 
s->snddropdelay;
+#endif
 int connect_timeout = s->connect_timeout;


LGTM


Thanks, will apply.

Regards,
Marton
___
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/mpegts: fix stream index in verbose log message

2021-11-25 Thread Marton Balint




On Mon, 22 Nov 2021, Marton Balint wrote:


Signed-off-by: Marton Balint 
---
libavformat/mpegts.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 29a267436f..36ab7ab3af 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2238,11 +2238,10 @@ static AVStream *find_matching_stream(MpegTSContext 
*ts, int pid, unsigned int p
  int stream_identifier, int 
pmt_stream_idx, struct Program *p)
{
AVFormatContext *s = ts->stream;
-int i;
AVStream *found = NULL;

if (stream_identifier) { /* match based on "stream identifier descriptor" 
if present */
-for (i = 0; i < p->nb_streams; i++) {
+for (int i = 0; i < p->nb_streams; i++) {
if (p->streams[i].stream_identifier == stream_identifier)
if (!found || pmt_stream_idx == i) /* fallback to idx based 
guess if multiple streams have the same identifier */
found = s->streams[p->streams[i].idx];
@@ -2255,7 +2254,7 @@ static AVStream *find_matching_stream(MpegTSContext *ts, 
int pid, unsigned int p
av_log(ts->stream, AV_LOG_VERBOSE,
   "re-using existing %s stream %d (pid=0x%x) for new pid=0x%x\n",
   av_get_media_type_string(found->codecpar->codec_type),
-   i, found->id, pid);
+   found->index, found->id, pid);
}

return found;
--
2.31.1


Will apply.

Regards,
Marton
___
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] avcodec/mjpeg_parser: skip markers after EOI, not by size

2021-11-25 Thread Alex Xu (Hello71)
The check for m->size >= 0xF000 is intended to avoid skipping too much
garbage data between JPEG frames in test_roman (thus missing next SOI),
but it erroneously also skips valid markers between SOI and SOS. Instead
of this, we should simply skip parsing markers other than SOI after EOI.
That way, we will not accidentally skip over SOI due to some garbage
between frames. There is still a small risk of encountering FFD8 in the
garbage data, but the chance of this is fairly low.

Fixes: https://trac.ffmpeg.org/ticket/8967
---
 libavcodec/mjpeg_parser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mjpeg_parser.c b/libavcodec/mjpeg_parser.c
index 16a5902c7c..62b923b625 100644
--- a/libavcodec/mjpeg_parser.c
+++ b/libavcodec/mjpeg_parser.c
@@ -80,10 +80,10 @@ static int find_frame_end(MJPEGParserContext *m, const 
uint8_t *buf, int buf_siz
 pc->frame_start_found=0;
 pc->state=0;
 return i-3;
+} else if((state>>16)==0xFFD9 && (state&0x)!=0xFFD8){
+state= 0xFFD900|(state&0xFF);
 } else if(state<0xFFD0 || state>0xFFD9){
 m->size= (state&0x)-1;
-if (m->size >= 0xF000)
-m->size = 0;
 }
 }
 if(m->size>0){
-- 
2.34.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] avfilter: add audio dynamic smooth filter

2021-11-25 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi|  20 +
 libavfilter/Makefile|   1 +
 libavfilter/af_adynamicsmooth.c | 142 
 libavfilter/allfilters.c|   1 +
 4 files changed, 164 insertions(+)
 create mode 100644 libavfilter/af_adynamicsmooth.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 04cbf4231d..0347e66d0c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -843,6 +843,26 @@ Compute derivative/integral of audio stream.
 
 Applying both filters one after another produces original audio.
 
+@section adynamicsmooth
+
+Apply dynamic smoothing to input audio stream.
+
+A description of the accepted options follows.
+
+@table @option
+@item sensitivity
+Set an amount of sensitivity to frequency fluctations. Default is 2.
+Allowed range is from 0 to 1e+06.
+
+@item basefreq
+Set a base frequency for smoothing. Default value is 22050.
+Allowed range is from 2 to 1e+06.
+@end table
+
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section aecho
 
 Apply echoing to the input audio.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 551d13aadc..c8082c4a2f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -44,6 +44,7 @@ OBJS-$(CONFIG_ADECORRELATE_FILTER)   += 
af_adecorrelate.o
 OBJS-$(CONFIG_ADELAY_FILTER) += af_adelay.o
 OBJS-$(CONFIG_ADENORM_FILTER)+= af_adenorm.o
 OBJS-$(CONFIG_ADERIVATIVE_FILTER)+= af_aderivative.o
+OBJS-$(CONFIG_ADYNAMICSMOOTH_FILTER) += af_adynamicsmooth.o
 OBJS-$(CONFIG_AECHO_FILTER)  += af_aecho.o
 OBJS-$(CONFIG_AEMPHASIS_FILTER)  += af_aemphasis.o
 OBJS-$(CONFIG_AEVAL_FILTER)  += aeval.o
diff --git a/libavfilter/af_adynamicsmooth.c b/libavfilter/af_adynamicsmooth.c
new file mode 100644
index 00..4e00fecc6a
--- /dev/null
+++ b/libavfilter/af_adynamicsmooth.c
@@ -0,0 +1,142 @@
+/*
+ * 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
+ */
+
+#include "libavutil/ffmath.h"
+#include "libavutil/opt.h"
+#include "avfilter.h"
+#include "audio.h"
+#include "formats.h"
+
+typedef struct AudioDynamicSmoothContext {
+const AVClass *class;
+
+double sensitivity;
+double basefreq;
+
+AVFrame *coeffs;
+} AudioDynamicSmoothContext;
+
+static int config_input(AVFilterLink *inlink)
+{
+AVFilterContext *ctx = inlink->dst;
+AudioDynamicSmoothContext *s = ctx->priv;
+
+s->coeffs = ff_get_audio_buffer(inlink, 3);
+if (!s->coeffs)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+{
+AVFilterContext *ctx = inlink->dst;
+AVFilterLink *outlink = ctx->outputs[0];
+AudioDynamicSmoothContext *s = ctx->priv;
+const double sensitivity = s->sensitivity;
+const double wc = s->basefreq / in->sample_rate;
+AVFrame *out;
+
+if (av_frame_is_writable(in)) {
+out = in;
+} else {
+out = ff_get_audio_buffer(outlink, in->nb_samples);
+if (!out) {
+av_frame_free(&in);
+return AVERROR(ENOMEM);
+}
+av_frame_copy_props(out, in);
+}
+
+for (int ch = 0; ch < out->channels; ch++) {
+const double *src = (const double *)in->extended_data[ch];
+double *dst = (double *)out->extended_data[ch];
+double *coeffs = (double *)s->coeffs->extended_data[ch];
+double low1 = coeffs[0];
+double low2 = coeffs[1];
+double inz  = coeffs[2];
+
+for (int n = 0; n < out->nb_samples; n++) {
+double low1z = low1;
+double low2z = low2;
+double bandz = low2z - low1z;
+double wd = wc + sensitivity * fabs(bandz);
+double g = fmin(1., wd * (5.9948827 + wd * (-11.969296 + wd * 
15.959062)));
+
+low1 = low1z + g * (0.5 * (src[n] + inz)   - low1z);
+low2 = low2z + g * (0.5 * (low1   + low1z) - low2z);
+inz = src[n];
+dst[n] = ctx->is_disabled ? src[n] : low2;
+}
+
+coeffs[0] = low1;
+coeffs[1] = low2;
+coeffs[2] = inz;
+}
+
+if (out != in)
+av_frame_free(&in);
+return ff_filter_frame(ou

[FFmpeg-devel] [PATCH] avformat/img2dec: probe JFIF/Exif header

2021-11-25 Thread Alex Xu (Hello71)
Due to reasons, mpv doesn't pass filename when probing. mpv also sets
default probescore threshold to 26. Since the current jpeg_probe
implementation returns 25 until EOI, it means that the whole image needs
to be probed to succeed. Worse, the whole image is not passed at once;
increasingly large buffers are tried before that. Adding it up together,
if many demuxers are enabled, moderately large JPEG files (few MB) can
take several seconds to open, despite taking less than 1 second to
actually decode.

Therefore, adjust the heuristic to be more optimistic if proper JFIF or
Exif segments are found. While not strictly required, the vast majority
of JPEG-ish files have one or the other or both.
---
 libavformat/img2dec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b535831e1c..a6084ceef0 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -749,7 +749,7 @@ static int j2k_probe(const AVProbeData *p)
 static int jpeg_probe(const AVProbeData *p)
 {
 const uint8_t *b = p->buf;
-int i, state = SOI;
+int i, state = SOI, got_header = 0;
 
 if (AV_RB16(b) != 0xFFD8 ||
 AV_RB32(b) == 0xFFD8FFF7)
@@ -789,7 +789,11 @@ static int jpeg_probe(const AVProbeData *p)
 break;
 case DQT:
 case APP0:
+if (AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F'))
+got_header = 1;
 case APP1:
+if (AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f'))
+got_header = 1;
 case APP2:
 case APP3:
 case APP4:
@@ -817,7 +821,7 @@ static int jpeg_probe(const AVProbeData *p)
 if (state == EOI)
 return AVPROBE_SCORE_EXTENSION + 1;
 if (state == SOS)
-return AVPROBE_SCORE_EXTENSION / 2;
+return AVPROBE_SCORE_EXTENSION / 2 + got_header;
 return AVPROBE_SCORE_EXTENSION / 8 + 1;
 }
 
-- 
2.34.0

___
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] webp: implement FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM

2021-11-25 Thread Alex Xu (Hello71)
Roughly doubles webp performance for common applications (ffmpeg,
ffprobe, mpv) due to speeding up avformat_find_stream_info.

Lossy needs no patches since vp8.c already implements skip_frame.
Lossless needs hook to understand skip_frame. Also the "image data not
found" message is fixed, which was already broken with manual
-skip_frame but would now be exposed in default operation.
---
 libavcodec/webp.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index d5a81fd527..f24aa979ac 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1126,6 +1126,9 @@ static int vp8_lossless_decode_frame(AVCodecContext 
*avctx, AVFrame *p,
 h = s->height;
 }
 
+if (avctx->skip_frame == AVDISCARD_ALL)
+return data_size;
+
 /* parse transformations */
 s->nb_transforms = 0;
 s->reduced_width = s->width;
@@ -1524,7 +1527,7 @@ exif_end:
 }
 }
 
-if (!*got_frame) {
+if (!*got_frame && avctx->skip_frame < 0) {
 av_log(avctx, AV_LOG_ERROR, "image data not found\n");
 return AVERROR_INVALIDDATA;
 }
@@ -1565,5 +1568,5 @@ const AVCodec ff_webp_decoder = {
 .decode = webp_decode_frame,
 .close  = webp_decode_close,
 .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
-.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
+.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | 
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
 };
-- 
2.34.0

___
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] avformat/rtp: add localaddr for network interface selection

2021-11-25 Thread Martin Storsjö

On Thu, 25 Nov 2021, lance.lmw...@gmail.com wrote:


From: Limin Wang 

Signed-off-by: Limin Wang 
---
doc/protocols.texi |  4 
libavformat/rtpproto.c | 17 ++---
libavformat/rtsp.c |  3 +++
libavformat/rtsp.h |  1 +
4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index a1aa969..3897826 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -74,6 +74,7 @@
#define COMMON_OPTS() \
{ "reorder_queue_size", "set number of packets to buffer for handling of 
reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 
INT_MAX, DEC }, \
{ "buffer_size","Underlying protocol send/receive buffer size", 
 OFFSET(buffer_size),   AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC|ENC }, 
\
+{ "localaddr",  "local address",   
  OFFSET(localaddr), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC|ENC }, \
{ "pkt_size",   "Underlying protocol send packet size", 
 OFFSET(pkt_size),  AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, ENC } \


As far as I can see, this is only used in sdp_read_header; wouldn't it be 
better to move this option to sdp_options then?


The rest of the patch seems fine I think.

// Martin

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

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


[FFmpeg-devel] [PATCH 1/2] avformat/mxf: support MCA audio information

2021-11-25 Thread Marc-Antoine Arnaud
---
 doc/demuxers.texi |  10 ++
 libavformat/mxf.h |   1 +
 libavformat/mxfdec.c  | 293 +-
 libavformat/version.h |   2 +-
 4 files changed, 299 insertions(+), 7 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index cab8a7072c..23b6753602 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -770,6 +770,16 @@ MJPEG stream. Turning this option on by setting it to 1 
will result in a stricte
 of the boundary value.
 @end table
 
+@section mxf
+
+MXF demuxer.
+
+@table @option
+
+@item -skip_audio_reordering @var{bool}
+This option will disable the audio reordering based on Multi-Channel Audio 
(MCA) labelling (SMPTE ST-377-4).
+@end table
+
 @section rawvideo
 
 Raw video demuxer.
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index fe9c52732c..cddbcb13c9 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -50,6 +50,7 @@ enum MXFMetadataSetType {
 TaggedValue,
 TapeDescriptor,
 AVCSubDescriptor,
+MCASubDescriptor,
 };
 
 enum MXFFrameLayout {
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index af9d33f796..58ba330475 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -51,11 +51,14 @@
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/mathematics.h"
 #include "libavcodec/bytestream.h"
+#include "libavcodec/internal.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timecode.h"
 #include "libavutil/opt.h"
 #include "avformat.h"
+#include "avlanguage.h"
 #include "internal.h"
 #include "mxf.h"
 
@@ -177,6 +180,8 @@ typedef struct {
 int body_sid;
 MXFWrappingScheme wrapping;
 int edit_units_per_packet; /* how many edit units to read at a time (PCM, 
ClipWrapped) */
+int require_reordering;
+int channel_ordering[FF_SANE_NB_CHANNELS];
 } MXFTrack;
 
 typedef struct MXFDescriptor {
@@ -205,6 +210,8 @@ typedef struct MXFDescriptor {
 unsigned int vert_subsampling;
 UID *file_descriptors_refs;
 int file_descriptors_count;
+UID *sub_descriptors_refs;
+int sub_descriptors_count;
 int linked_track_id;
 uint8_t *extradata;
 int extradata_size;
@@ -217,6 +224,15 @@ typedef struct MXFDescriptor {
 size_t coll_size;
 } MXFDescriptor;
 
+typedef struct MXFMCASubDescriptor {
+MXFMetadataSet meta;
+UID uid;
+UID mca_link_id;
+UID mca_group_link_id;
+UID mca_label_dictionary_id;
+char *language;
+} MXFMCASubDescriptor;
+
 typedef struct MXFIndexTableSegment {
 MXFMetadataSet meta;
 int edit_unit_byte_count;
@@ -290,6 +306,7 @@ typedef struct MXFContext {
 int nb_index_tables;
 MXFIndexTable *index_tables;
 int eia608_extract;
+int skip_audio_reordering;
 } MXFContext;
 
 /* NOTE: klv_offset is not set (-1) for local keys */
@@ -311,6 +328,9 @@ static const uint8_t mxf_system_item_key_cp[]  
= { 0x06,0x0e,0x2b,0x
 static const uint8_t mxf_system_item_key_gc[]  = { 
0x06,0x0e,0x2b,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x03,0x01,0x14 };
 static const uint8_t mxf_klv_key[] = { 
0x06,0x0e,0x2b,0x34 };
 static const uint8_t mxf_apple_coll_prefix[]   = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01 };
+static const uint8_t mxf_audio_channel[]   = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x03,0x02,0x01 };
+static const uint8_t mxf_soundfield_group[]= { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x0d,0x03,0x02,0x02 };
+
 /* complete keys to match */
 static const uint8_t mxf_crypto_source_container_ul[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 
};
 static const uint8_t mxf_encrypted_triplet_key[]   = { 
0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 
};
@@ -323,6 +343,15 @@ static const uint8_t mxf_indirect_value_utf16be[]  
= { 0x42,0x01,0x10,0x
 static const uint8_t mxf_apple_coll_max_cll[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x01 
};
 static const uint8_t mxf_apple_coll_max_fall[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x0e,0x20,0x04,0x01,0x05,0x03,0x01,0x02 
};
 
+static const uint8_t mxf_mca_label_dictionary_id[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x01,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_tag_symbol[]  = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x02,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_tag_name[]= { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x03,0x00,0x00,0x00 
};
+static const uint8_t mxf_mca_link_id[] = { 
0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x0e,0x01,0x03,0x07,0x01,0x05,0x00,0x00,0x00 
};
+static const uint8_t mxf_soundfield_group_link_id[]= { 
0x06,0x0e,0x2b,0x

[FFmpeg-devel] [PATCH 2/2] avformat/mxf: add documentation for eia608_extract parameter

2021-11-25 Thread Marc-Antoine Arnaud
---
 doc/demuxers.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 23b6753602..587ce11c95 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -776,6 +776,9 @@ MXF demuxer.
 
 @table @option
 
+@item -eia608_extract @var{bool}
+Extract EIA-608 captions from SMPTE 436M track
+
 @item -skip_audio_reordering @var{bool}
 This option will disable the audio reordering based on Multi-Channel Audio 
(MCA) labelling (SMPTE ST-377-4).
 @end table
-- 
2.33.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] lavu/avframe: add a time_base field

2021-11-25 Thread Marton Balint




On Thu, 25 Nov 2021, Lynne wrote:


This adds a time_base field (currently unused), analogue to the
AVPacket.time_base field.
This allows for API clients to exchange AVFrames directly, without
needing to plumb extra data from sources via side mechanisms.


The objections raised before still stand I believe, and again, the main 
concern is that the API user won't know when to use the packet or frame 
timebase and when to use the frame/packet source timebase.


You write this in the doxy:

Time base for the timestamps in this frame. May be 0, in which case the
time_base from the frame source should be used.


One could easily think - based on this text alone - that every user of 
avcodec_receive_frame should check if AVFrame->time_base is 0 to 
calculate real PTS...


I'd be a lot more willing to accept this if you could document explicitly 
that AVFrame->time_base (and AVPacket->time_base) is not used by the API 
right now, and is similar to e.g. *opaque field. And later, if by using 
some magic flag or new API or whatever it turns out to make sense to 
actually use AVPacket/AVFrame time base, the doxy text can be extended 
accordingly.


Regards,
Marton
___
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] avformat/rtp: add localaddr for network interface selection

2021-11-25 Thread lance . lmwang
On Thu, Nov 25, 2021 at 10:09:17PM +0200, Martin Storsjö wrote:
> On Thu, 25 Nov 2021, lance.lmw...@gmail.com wrote:
> 
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> > doc/protocols.texi |  4 
> > libavformat/rtpproto.c | 17 ++---
> > libavformat/rtsp.c |  3 +++
> > libavformat/rtsp.h |  1 +
> > 4 files changed, 22 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> > index a1aa969..3897826 100644
> > --- a/libavformat/rtsp.c
> > +++ b/libavformat/rtsp.c
> > @@ -74,6 +74,7 @@
> > #define COMMON_OPTS() \
> > { "reorder_queue_size", "set number of packets to buffer for handling 
> > of reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { 
> > .i64 = -1 }, -1, INT_MAX, DEC }, \
> > { "buffer_size","Underlying protocol send/receive buffer size", 
> >  OFFSET(buffer_size),   AV_OPT_TYPE_INT, { .i64 = 
> > -1 }, -1, INT_MAX, DEC|ENC }, \
> > +{ "localaddr",  "local address",   
> >   OFFSET(localaddr), AV_OPT_TYPE_STRING, {.str 
> > = NULL}, 0, 0, DEC|ENC }, \
> > { "pkt_size",   "Underlying protocol send packet size", 
> >  OFFSET(pkt_size),  AV_OPT_TYPE_INT, { .i64 = 
> > -1 }, -1, INT_MAX, ENC } \
> 
> As far as I can see, this is only used in sdp_read_header; wouldn't it be
> better to move this option to sdp_options then?

OK, I'll move for sdp_iotions only.

> 
> The rest of the patch seems fine I think.
> 
> // Martin
> 

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

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


[FFmpeg-devel] [PATCH V3 1/5] hwcontext_vaapi: Use PRIME_2 memory type for modifiers.

2021-11-25 Thread Wenbin Chen
From: Bas Nieuwenhuizen 

This way we can pass explicit modifiers in. Sometimes the
modifier matters for the number of memory planes that
libva accepts, in particular when dealing with
driver-compressed textures. Furthermore the driver might
not actually be able to determine the implicit modifier
if all the buffer-passing has used explicit modifier.
All these issues should be resolved by passing in the
modifier, and for that we switch to using the PRIME_2
memory type.

Tested with experimental radeonsi patches for modifiers
and kmsgrab. Also tested with radeonsi without the
patches to double-check it works without PRIME_2 support.

v2:
  Cache PRIME_2 support to avoid doing two calls every time on
  libva drivers that do not support it.

v3:
  Remove prime2_vas usage.

Signed-off-by: Bas Nieuwenhuizen 
---
 libavutil/hwcontext_vaapi.c | 158 ++--
 1 file changed, 114 insertions(+), 44 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 83e542876d..75acc851d6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -79,6 +79,9 @@ typedef struct VAAPIFramesContext {
 unsigned int rt_format;
 // Whether vaDeriveImage works.
 int derive_works;
+// Caches whether VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 is unsupported for
+// surface imports.
+int prime_2_import_unsupported;
 } VAAPIFramesContext;
 
 typedef struct VAAPIMapping {
@@ -1022,32 +1025,17 @@ static void vaapi_unmap_from_drm(AVHWFramesContext 
*dst_fc,
 static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
   const AVFrame *src, int flags)
 {
+VAAPIFramesContext *src_vafc = src_fc->internal->priv;
 AVHWFramesContext  *dst_fc =
 (AVHWFramesContext*)dst->hw_frames_ctx->data;
 AVVAAPIDeviceContext  *dst_dev = dst_fc->device_ctx->hwctx;
 const AVDRMFrameDescriptor *desc;
 const VAAPIFormatDescriptor *format_desc;
 VASurfaceID surface_id;
-VAStatus vas;
+VAStatus vas = VA_STATUS_SUCCESS;
+int use_prime2;
 uint32_t va_fourcc;
-int err, i, j, k;
-
-unsigned long buffer_handle;
-VASurfaceAttribExternalBuffers buffer_desc;
-VASurfaceAttrib attrs[2] = {
-{
-.type  = VASurfaceAttribMemoryType,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypeInteger,
-.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
-},
-{
-.type  = VASurfaceAttribExternalBufferDescriptor,
-.flags = VA_SURFACE_ATTRIB_SETTABLE,
-.value.type= VAGenericValueTypePointer,
-.value.value.p = &buffer_desc,
-}
-};
+int err, i, j;
 
 desc = (AVDRMFrameDescriptor*)src->data[0];
 
@@ -1083,35 +1071,117 @@ static int vaapi_map_from_drm(AVHWFramesContext 
*src_fc, AVFrame *dst,
 format_desc = vaapi_format_from_fourcc(va_fourcc);
 av_assert0(format_desc);
 
-buffer_handle = desc->objects[0].fd;
-buffer_desc.pixel_format = va_fourcc;
-buffer_desc.width= src_fc->width;
-buffer_desc.height   = src_fc->height;
-buffer_desc.data_size= desc->objects[0].size;
-buffer_desc.buffers  = &buffer_handle;
-buffer_desc.num_buffers  = 1;
-buffer_desc.flags= 0;
-
-k = 0;
-for (i = 0; i < desc->nb_layers; i++) {
-for (j = 0; j < desc->layers[i].nb_planes; j++) {
-buffer_desc.pitches[k] = desc->layers[i].planes[j].pitch;
-buffer_desc.offsets[k] = desc->layers[i].planes[j].offset;
-++k;
+use_prime2 = !src_vafc->prime_2_import_unsupported &&
+ desc->objects[0].format_modifier != DRM_FORMAT_MOD_INVALID;
+if (use_prime2) {
+VADRMPRIMESurfaceDescriptor prime_desc;
+VASurfaceAttrib prime_attrs[2] = {
+{
+.type  = VASurfaceAttribMemoryType,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypeInteger,
+.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+},
+{
+.type  = VASurfaceAttribExternalBufferDescriptor,
+.flags = VA_SURFACE_ATTRIB_SETTABLE,
+.value.type= VAGenericValueTypePointer,
+.value.value.p = &prime_desc,
+}
+};
+prime_desc.fourcc = va_fourcc;
+prime_desc.width = src_fc->width;
+prime_desc.height = src_fc->height;
+prime_desc.num_objects = desc->nb_objects;
+for (i = 0; i < desc->nb_objects; ++i) {
+prime_desc.objects[i].fd = desc->objects[i].fd;
+prime_desc.objects[i].size = desc->objects[i].size;
+prime_desc.objects[i].drm_format_modifier =
+desc->objects[i].format_modifier;
 }
-}
-buffer_desc.num_planes = k;
 
-if (format_desc->chroma_planes

[FFmpeg-devel] [PATCH V3 2/5] libavutil/hwcontext_vaapi: Add a new nv12 format map to support vulkan frame

2021-11-25 Thread Wenbin Chen
Vulkan will map nv12 to R8 and GR88, so add this map to vaapi to support
vulkan frame.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vaapi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 75acc851d6..994b744e4d 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -992,6 +992,7 @@ static const struct {
 } vaapi_drm_format_map[] = {
 #ifdef DRM_FORMAT_R8
 DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_RG88),
+DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_GR88),
 #endif
 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
 #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
-- 
2.25.1

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

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


[FFmpeg-devel] [PATCH V3 3/5] libavutil/hwcontext_vulkan: Allocate vkFrame in one memory

2021-11-25 Thread Wenbin Chen
The vaapi can import external frame, but the planes of the external
frames should be in the same drm object. A new option "contiguous_planes"
is added to device. This flag tells device to allocate places in one
memory. When device is derived from vaapi this flag will be enabled.
A new flag frame_flag is also added to AVVulkanFramesContext. User
can use this flag to force enable or disable this behaviour.
A new variable "offset "is added to AVVKFrame. It describe describe the
offset from the memory currently bound to the VkImage.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_vulkan.c | 67 +++-
 libavutil/hwcontext_vulkan.h | 24 +
 2 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 644ed947f8..b8076fb425 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -103,8 +103,14 @@ typedef struct VulkanDevicePriv {
 /* Settings */
 int use_linear_images;
 
+/* allocate planes in a contiguous memory */
+int contiguous_planes;
+
 /* Nvidia */
 int dev_is_nvidia;
+
+/* Intel */
+int dev_is_intel;
 } VulkanDevicePriv;
 
 typedef struct VulkanFramesPriv {
@@ -146,6 +152,8 @@ typedef struct AVVkFrameInternal {
 }  
\
 } while(0)
 
+#define VKF_FLAG(x, f) (((x) & (~AV_VK_FRAME_FLAG_NONE)) & (f))
+
 static const struct {
 enum AVPixelFormat pixfmt;
 const VkFormat vkfmts[4];
@@ -1268,6 +1276,13 @@ static int 
vulkan_device_create_internal(AVHWDeviceContext *ctx,
 if (opt_d)
 p->use_linear_images = strtol(opt_d->value, NULL, 10);
 
+opt_d = av_dict_get(opts, "contiguous_planes", NULL, 0);
+if (opt_d)
+p->contiguous_planes = strtol(opt_d->value, NULL, 10);
+else
+p->contiguous_planes = -1;
+
+
 hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
 hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
 
@@ -1319,6 +1334,8 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
 
 p->dev_is_nvidia = (p->props.properties.vendorID == 0x10de);
 
+p->dev_is_intel = (p->props.properties.vendorID == 0x8086);
+
 vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, 
NULL);
 if (!queue_num) {
 av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n");
@@ -1636,8 +1653,12 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 AVHWDeviceContext *ctx = hwfc->device_ctx;
 VulkanDevicePriv *p = ctx->internal->priv;
 FFVulkanFunctions *vk = &p->vkfn;
+AVVulkanFramesContext *hwfctx = hwfc->hwctx;
 const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
 VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } };
+VkMemoryRequirements memory_requirements = { 0 };
+int mem_size = 0;
+int mem_size_list[AV_NUM_DATA_POINTERS] = { 0 };
 
 AVVulkanDeviceContext *hwctx = ctx->hwctx;
 
@@ -1665,6 +1686,19 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 req.memoryRequirements.size = FFALIGN(req.memoryRequirements.size,
   
p->props.properties.limits.minMemoryMapAlignment);
 
+if (VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY)) {
+if (memory_requirements.size == 0) {
+memory_requirements = req.memoryRequirements;
+} else if (memory_requirements.memoryTypeBits != 
req.memoryRequirements.memoryTypeBits) {
+av_log(hwfc, AV_LOG_ERROR, "the param for each planes are not 
the same\n");
+return AVERROR(EINVAL);
+}
+
+mem_size_list[i] = req.memoryRequirements.size;
+mem_size += mem_size_list[i];
+continue;
+}
+
 /* In case the implementation prefers/requires dedicated allocation */
 use_ded_mem = ded_req.prefersDedicatedAllocation |
   ded_req.requiresDedicatedAllocation;
@@ -1686,6 +1720,29 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, 
AVVkFrame *f,
 bind_info[i].memory = f->mem[i];
 }
 
+if (VKF_FLAG(hwfctx->flags, AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY)) {
+memory_requirements.size = mem_size;
+
+/* Allocate memory */
+if ((err = alloc_mem(ctx, &memory_requirements,
+f->tiling == VK_IMAGE_TILING_LINEAR ?
+VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT :
+VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+(void *)(((uint8_t *)alloc_pnext)),
+&f->flags, &f->mem[0])))
+return err;
+
+f->size[0] = memory_requirements.size;
+
+for (int i = 0; i < planes; i++) {
+bind_info[i].sType  = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
+   

  1   2   >