[FFmpeg-devel] [PATCH 22/38] avfilter/avfilter: Remove unused count

2021-09-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/avfilter.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index a04f8ed62f..c614eb0740 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -812,7 +812,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
const char *args)
 {
 const AVOption *o = NULL;
-int ret, count = 0;
+int ret;
 char *av_uninit(parsed_key), *av_uninit(value);
 const char *key;
 int offset= -1;
@@ -875,10 +875,9 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 
 av_free(value);
 av_free(parsed_key);
-count++;
 }
 
-return count;
+return 0;
 }
 
 int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 23/38] avfilter/avfilter: Remove redundant parsing code

2021-09-12 Thread Andreas Rheinhardt
avfilter_init_str() (via process_options()) both applies options
extracted from the given string directly to the relevant (private)
context as well as to an AVDictionary that is later given to
avfilter_init_dict() which applies these options again. This is
unnecessary, so leave applying the options to avfilter_init_dict();
this also has the advantage that all unrecognized options are reported
before erroring out in case there are unrecognized options, whereas
the current code stops after the first such option.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/avfilter.c | 18 --
 1 file changed, 18 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index c614eb0740..11d4e01807 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -853,25 +853,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 
 av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
 
-if (av_opt_find(ctx, key, NULL, 0, 0)) {
-ret = av_opt_set(ctx, key, value, 0);
-if (ret < 0) {
-av_free(value);
-av_free(parsed_key);
-return ret;
-}
-} else {
 av_dict_set(options, key, value, 0);
-if ((ret = av_opt_set(ctx->priv, key, value, 
AV_OPT_SEARCH_CHILDREN)) < 0) {
-if (!av_opt_find(ctx->priv, key, NULL, 0, 
AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) {
-if (ret == AVERROR_OPTION_NOT_FOUND)
-av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", 
key);
-av_free(value);
-av_free(parsed_key);
-return ret;
-}
-}
-}
 
 av_free(value);
 av_free(parsed_key);
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 24/38] avfilter/avfilter: Use AV_DICT_DONT_STRDUP_(KEY|VAL) when possible

2021-09-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/avfilter.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 11d4e01807..cc499fd5ed 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -822,6 +822,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 
 while (*args) {
 const char *shorthand = NULL;
+int flags = AV_DICT_DONT_STRDUP_VAL;
 
 o = av_opt_next(ctx->priv, o);
 if (o) {
@@ -846,6 +847,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 args++;
 if (parsed_key) {
 key = parsed_key;
+flags |= AV_DICT_DONT_STRDUP_KEY;
 while ((o = av_opt_next(ctx->priv, o))); /* discard all remaining 
shorthand */
 } else {
 key = shorthand;
@@ -853,10 +855,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 
 av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
 
-av_dict_set(options, key, value, 0);
-
-av_free(value);
-av_free(parsed_key);
+av_dict_set(options, key, value, flags);
 }
 
 return 0;
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 25/38] avfilter/avfilter: Honour the short options documentation

2021-09-12 Thread Andreas Rheinhardt
The documentation for filter arguments states that short options must
precede long options (i.e. those of the form key=value). Yet if
process_options() encounters arguments not abiding by this, it simply
treats short options after a long option as if it were parsing short
options for the first time. In particular, it overwrites options already
set earlier, possibly via other short options. This is not how it is
intended (as a comment in the code indicates).

This commit modifies the code to reject further shorthand options
after a long option has been encountered. After all, avfilter_init_str()
errors out upon unrecognized options, so it is intended to be picky.

Signed-off-by: Andreas Rheinhardt 
---
The while loop that is removed below is actually just an elaborate
"o = NULL", which av_opt_next() interprets as "start the iteration".

 libavfilter/avfilter.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc499fd5ed..165ab1f44a 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -814,6 +814,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 const AVOption *o = NULL;
 int ret;
 char *av_uninit(parsed_key), *av_uninit(value);
+const AVClass *priv = ctx->filter->priv_class;
 const char *key;
 int offset= -1;
 
@@ -824,8 +825,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 const char *shorthand = NULL;
 int flags = AV_DICT_DONT_STRDUP_VAL;
 
-o = av_opt_next(ctx->priv, o);
-if (o) {
+if (priv && (o = av_opt_next(ctx->priv, o))) {
 if (o->type == AV_OPT_TYPE_CONST || o->offset == offset)
 continue;
 offset = o->offset;
@@ -848,7 +848,7 @@ static int process_options(AVFilterContext *ctx, 
AVDictionary **options,
 if (parsed_key) {
 key = parsed_key;
 flags |= AV_DICT_DONT_STRDUP_KEY;
-while ((o = av_opt_next(ctx->priv, o))); /* discard all remaining 
shorthand */
+priv = NULL; /* reject all remaining shorthand */
 } else {
 key = shorthand;
 }
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 26/38] avfilter/avfilter: Don't fail upon options for filter without AVClass

2021-09-12 Thread Andreas Rheinhardt
Commit 62549f9655c48f0ec061087fa33a96040ce01145 added a check to
(the predecessor of) avfilter_init_str() to error out if options
were provided to a filter without options (or rather, without private
class). This was fine at the time, yet soon afterwards commit
fdd93eabfb2644f541f7aac9943abce26776ea73 added a generic option
for all AVFilterContexts and since then it is wrong to error out
in case options have been provided to a filter without AVClass.

To workaround this issue, several filters with timeline support
added AVClasses and empty options; these will be removed in subsequent
commits. Furthermore, the super2xsai filter supports slice threading,
but no options and so has no AVClass, making it impossible to set
the number of threads when using avfilter_init_str() (and therefore
from the ffmpeg-tool). This is fixed by this commit, too.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/avfilter.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 165ab1f44a..c76b74f214 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -922,12 +922,6 @@ int avfilter_init_str(AVFilterContext *filter, const char 
*args)
 int ret = 0;
 
 if (args && *args) {
-if (!filter->filter->priv_class) {
-av_log(filter, AV_LOG_ERROR, "This filter does not take any "
-   "options, but options were provided: %s.\n", args);
-return AVERROR(EINVAL);
-}
-
 ret = process_options(filter, &options, args);
 if (ret < 0)
 goto fail;
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 27/38] avfilter/vf_vif: Remove empty options and AVClass

2021-09-12 Thread Andreas Rheinhardt
This filter only had an AVClass and empty options because up until
recently, avfilter_init_str() errored out when options were provided
for a filter without an AVClass. But setting (generic) options is
necessary to take advantage of timeline support. So with
avfilter_init_str() fixed, the AVClass and the options can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/vf_vif.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/libavfilter/vf_vif.c b/libavfilter/vf_vif.c
index da3069c1f6..13714d8673 100644
--- a/libavfilter/vf_vif.c
+++ b/libavfilter/vf_vif.c
@@ -28,7 +28,6 @@
 #include 
 
 #include "libavutil/avstring.h"
-#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "framesync.h"
@@ -40,7 +39,6 @@
 #define NUM_DATA_BUFS 13
 
 typedef struct VIFContext {
-const AVClass *class;
 FFFrameSync fs;
 const AVPixFmtDescriptor *desc;
 int width;
@@ -57,14 +55,6 @@ typedef struct VIFContext {
 uint64_t nb_frames;
 } VIFContext;
 
-#define OFFSET(x) offsetof(VIFContext, x)
-
-static const AVOption vif_options[] = {
-{ NULL }
-};
-
-AVFILTER_DEFINE_CLASS(vif);
-
 static const uint8_t vif_filter1d_width1[4] = { 17, 9, 5, 3 };
 
 static const float vif_filter1d_table[4][17] =
@@ -643,7 +633,6 @@ const AVFilter ff_vf_vif = {
 .uninit= uninit,
 .query_formats = query_formats,
 .priv_size = sizeof(VIFContext),
-.priv_class= &vif_class,
 .activate  = activate,
 FILTER_INPUTS(vif_inputs),
 FILTER_OUTPUTS(vif_outputs),
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 28/38] avfilter/vf_swapuv: Remove empty options and AVClass

2021-09-12 Thread Andreas Rheinhardt
This filter only had an AVClass and empty options because up until
recently, avfilter_init_str() errored out when options were provided
for a filter without an AVClass. But setting (generic) options is
necessary to take advantage of timeline support. So with
avfilter_init_str() fixed, the AVClass and the options can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/vf_swapuv.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/libavfilter/vf_swapuv.c b/libavfilter/vf_swapuv.c
index 0c285e547c..8c323873c3 100644
--- a/libavfilter/vf_swapuv.c
+++ b/libavfilter/vf_swapuv.c
@@ -23,24 +23,12 @@
  * swap UV filter
  */
 
-#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "libavutil/version.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
 
-typedef struct SwapUVContext {
-const AVClass *class;
-} SwapUVContext;
-
-static const AVOption swapuv_options[] = {
-{ NULL }
-};
-
-AVFILTER_DEFINE_CLASS(swapuv);
-
 static void do_swap(AVFrame *frame)
 {
 FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
@@ -113,8 +101,6 @@ const AVFilter ff_vf_swapuv = {
 .name  = "swapuv",
 .description   = NULL_IF_CONFIG_SMALL("Swap U and V components."),
 .query_formats = query_formats,
-.priv_size = sizeof(SwapUVContext),
-.priv_class= &swapuv_class,
 FILTER_INPUTS(swapuv_inputs),
 FILTER_OUTPUTS(swapuv_outputs),
 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 29/38] avfilter/vf_vflip: Remove empty options and AVClass

2021-09-12 Thread Andreas Rheinhardt
This filter only had an AVClass and empty options because up until
recently, avfilter_init_str() errored out when options were provided
for a filter without an AVClass. But setting (generic) options is
necessary to take advantage of timeline support. So with
avfilter_init_str() fixed, the AVClass and the options can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/vf_vflip.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c
index 0d624512f9..c447663c11 100644
--- a/libavfilter/vf_vflip.c
+++ b/libavfilter/vf_vflip.c
@@ -24,24 +24,16 @@
  */
 
 #include "libavutil/internal.h"
-#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "video.h"
 
 typedef struct FlipContext {
-const AVClass *class;
 int vsub;   ///< vertical chroma subsampling
 int bayer;
 } FlipContext;
 
-static const AVOption vflip_options[] = {
-{ NULL }
-};
-
-AVFILTER_DEFINE_CLASS(vflip);
-
 static int config_input(AVFilterLink *link)
 {
 FlipContext *flip = link->dst->priv;
@@ -146,7 +138,6 @@ const AVFilter ff_vf_vflip = {
 .name= "vflip",
 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
 .priv_size   = sizeof(FlipContext),
-.priv_class  = &vflip_class,
 FILTER_INPUTS(avfilter_vf_vflip_inputs),
 FILTER_OUTPUTS(avfilter_vf_vflip_outputs),
 .flags   = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 30/38] avfilter/vf_hflip: Remove empty options and AVClass

2021-09-12 Thread Andreas Rheinhardt
This filter only had an AVClass and empty options because up until
recently, avfilter_init_str() errored out when options were provided
for a filter without an AVClass. But setting (generic) options is
necessary to take advantage of timeline support. So with
avfilter_init_str() fixed, the AVClass and the options can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/hflip.h| 1 -
 libavfilter/vf_hflip.c | 8 
 2 files changed, 9 deletions(-)

diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
index a40b98470b..956eb982a1 100644
--- a/libavfilter/hflip.h
+++ b/libavfilter/hflip.h
@@ -25,7 +25,6 @@
 #include "avfilter.h"
 
 typedef struct FlipContext {
-const AVClass *class;
 int max_step[4];///< max pixel step for each plane, expressed as a 
number of bytes
 int bayer_plus1;///< 1 .. not a Bayer input format, 2 .. Bayer input 
format
 int planewidth[4];  ///< width of each plane
diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index 7b5650a821..bdff052b45 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -26,7 +26,6 @@
 
 #include 
 
-#include "libavutil/opt.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "hflip.h"
@@ -37,12 +36,6 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/imgutils.h"
 
-static const AVOption hflip_options[] = {
-{ NULL }
-};
-
-AVFILTER_DEFINE_CLASS(hflip);
-
 static int query_formats(AVFilterContext *ctx)
 {
 AVFilterFormats *pix_fmts = NULL;
@@ -248,7 +241,6 @@ const AVFilter ff_vf_hflip = {
 .name  = "hflip",
 .description   = NULL_IF_CONFIG_SMALL("Horizontally flip the input 
video."),
 .priv_size = sizeof(FlipContext),
-.priv_class= &hflip_class,
 .query_formats = query_formats,
 FILTER_INPUTS(avfilter_vf_hflip_inputs),
 FILTER_OUTPUTS(avfilter_vf_hflip_outputs),
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 31/38] avfilter/vf_hflip: Don't call av_pix_fmt_desc_get() twice

2021-09-12 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/vf_hflip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
index bdff052b45..e15cf22f9e 100644
--- a/libavfilter/vf_hflip.c
+++ b/libavfilter/vf_hflip.c
@@ -39,10 +39,10 @@
 static int query_formats(AVFilterContext *ctx)
 {
 AVFilterFormats *pix_fmts = NULL;
+const AVPixFmtDescriptor *desc;
 int fmt, ret;
 
-for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
-const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
+for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) {
 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
   desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
   (desc->log2_chroma_w != desc->log2_chroma_h &&
-- 
2.30.2

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

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


[FFmpeg-devel] [PATCH 32/38] avfilter/vf_grayworld: Remove empty options and AVClass

2021-09-12 Thread Andreas Rheinhardt
This filter only had an AVClass and empty options because up until
recently, avfilter_init_str() errored out when options were provided
for a filter without an AVClass. But setting (generic) options is
necessary to take advantage of timeline support. So with
avfilter_init_str() fixed, the AVClass and the options can be removed.

Signed-off-by: Andreas Rheinhardt 
---
 libavfilter/vf_grayworld.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/libavfilter/vf_grayworld.c b/libavfilter/vf_grayworld.c
index fd424527e2..b6b39af677 100644
--- a/libavfilter/vf_grayworld.c
+++ b/libavfilter/vf_grayworld.c
@@ -26,7 +26,6 @@
   */
 
 #include "libavutil/imgutils.h"
-#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 
 #include "avfilter.h"
@@ -42,20 +41,11 @@ typedef struct ThreadData {
 } ThreadData;
 
 typedef struct GrayWorldContext {
-const AVClass *class;
 float *tmpplab;
 int *line_count_pels;
 float *line_sum;
 } GrayWorldContext;
 
-#define OFFSET(x) offsetof(GrayWorldContext, x)
-#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM
-static const AVOption grayworld_options[] = {
-{ NULL }
-};
-
-AVFILTER_DEFINE_CLASS(grayworld);
-
 static int query_formats(AVFilterContext *ctx)
 {
 static const enum AVPixelFormat pix_fmts[] = {
@@ -328,7 +318,6 @@ const AVFilter ff_vf_grayworld = {
 .name  = "grayworld",
 .description   = NULL_IF_CONFIG_SMALL("Adjust white balance using LAB gray 
world algorithm"),
 .priv_size = sizeof(GrayWorldContext),
-.priv_class= &grayworld_class,
 .query_formats = query_formats,
 FILTER_INPUTS(grayworld_inputs),
 FILTER_OUTPUTS(grayworld_outputs),
-- 
2.30.2

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

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


Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Lynne
12 Sept 2021, 05:21 by softwo...@hotmail.com:

> This is the root commit for adding subtitle filtering capabilities.
> Adding the media type property to AVFrame replaces the previous
> way of distinction which was based on checking width and height
> to determine whether a frame is audio or video.
>
> Signed-off-by: softworkz 
>

Why do you need a new allocation function av_frame_get_buffer2
when it has the same syntax as av_frame_get_buffer?
Also, could you please drop all but one of the filter patches
when sending new versions? You're overspamming the ML
and it's hard to keep up.
Finally, why not combine the 2 subtitle overlay filters into one?
There's no need for explicitness between text and bitmap subs.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Lynne
12 Sept 2021, 13:31 by d...@lynne.ee:

> 12 Sept 2021, 05:21 by softwo...@hotmail.com:
>
>> This is the root commit for adding subtitle filtering capabilities.
>> Adding the media type property to AVFrame replaces the previous
>> way of distinction which was based on checking width and height
>> to determine whether a frame is audio or video.
>>
>> Signed-off-by: softworkz 
>>
>
> Why do you need a new allocation function av_frame_get_buffer2
> when it has the same syntax as av_frame_get_buffer?
> Also, could you please drop all but one of the filter patches
> when sending new versions? You're overspamming the ML
> and it's hard to keep up.
> Finally, why not combine the 2 subtitle overlay filters into one?
> There's no need for explicitness between text and bitmap subs.
>

Just read why (the media type). Says a lot about the ML overload.

Could the media type be set as unknown during the deprecation
period by default by the old alloc function for audio and video?
Subtitle allocations can set it to _SUBTITLES. That way, you can
still keep compatibility, as the old users detect AVFrame type based
on the 'format' field, without adding a new alloc function.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Andreas Rheinhardt
Lynne:
> 12 Sept 2021, 05:21 by softwo...@hotmail.com:
> 
>> This is the root commit for adding subtitle filtering capabilities.
>> Adding the media type property to AVFrame replaces the previous
>> way of distinction which was based on checking width and height
>> to determine whether a frame is audio or video.
>>
>> Signed-off-by: softworkz 
>>
> 
> Why do you need a new allocation function av_frame_get_buffer2
> when it has the same syntax as av_frame_get_buffer?
> Also, could you please drop all but one of the filter patches
> when sending new versions? You're overspamming the ML
> and it's hard to keep up.
> Finally, why not combine the 2 subtitle overlay filters into one?
> There's no need for explicitness between text and bitmap subs.

Because they have different semantics: The new one checks allocates
according to AVFrame.type, the old one according to the old semantics.
That way a user unaware of the type field always doesn't get surprised.

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

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


Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Andreas Rheinhardt
Lynne:
> 12 Sept 2021, 13:31 by d...@lynne.ee:
> 
>> 12 Sept 2021, 05:21 by softwo...@hotmail.com:
>>
>>> This is the root commit for adding subtitle filtering capabilities.
>>> Adding the media type property to AVFrame replaces the previous
>>> way of distinction which was based on checking width and height
>>> to determine whether a frame is audio or video.
>>>
>>> Signed-off-by: softworkz 
>>>
>>
>> Why do you need a new allocation function av_frame_get_buffer2
>> when it has the same syntax as av_frame_get_buffer?
>> Also, could you please drop all but one of the filter patches
>> when sending new versions? You're overspamming the ML
>> and it's hard to keep up.
>> Finally, why not combine the 2 subtitle overlay filters into one?
>> There's no need for explicitness between text and bitmap subs.
>>
> 
> Just read why (the media type). Says a lot about the ML overload.
> 
> Could the media type be set as unknown during the deprecation
> period by default by the old alloc function for audio and video?
> Subtitle allocations can set it to _SUBTITLES. That way, you can
> still keep compatibility, as the old users detect AVFrame type based
> on the 'format' field, without adding a new alloc function.

The decode API should (when it is ported; haven't looked whether this
already happens in this commit) ensure that AVFrame.type is set
according to the data contained in the frame. If a user unaware of the
decodes (say) video and then wants to utilize said AVFrame for audio, he
may do so by resetting the fields corresponding to video and setting the
audio related fields; you do not need to call av_frame_unref on it (say
you want to keep the metadata and the timing related stuff, so you reset
manually). If he then gives this frame to av_frame_get_buffer, it will
be inconsistent, i.e. av_frame_get_buffer should error out. And then the
user app will be broken.
(I of course admit that lots of users will not be affected by this, as
they always reset their frames with av_frame_unref. But we have to think
of the odd cases, too.)

- Andreas
___
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/4] avformat/mxfdec: check channel number in mxf_get_d10_aes3_packet()

2021-09-12 Thread Tomas Härdin
sön 2021-09-05 klockan 21:24 +0200 skrev Michael Niedermayer:
> Fixes: Out of array access
> Fixes: 37030/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-
> 5387719147651072
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mxfdec.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index 55f2e5c767..ebe411b04d 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -552,6 +552,10 @@ static int mxf_get_d10_aes3_packet(AVIOContext
> *pb, AVStream *st, AVPacket *pkt,
>  data_ptr = pkt->data;
>  end_ptr = pkt->data + length;
>  buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
> +
> +    if (st->codecpar->channels > 8)
> +    return AVERROR_INVALIDDATA;

Looks fine. Double-checked S331m, AES is limited to 8 channels

/Tomas

___
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/mxf: support MCA audio information

2021-09-12 Thread Tomas Härdin
@@ -2681,6 +2845,88 @@ static int
mxf_parse_structural_metadata(MXFContext *mxf)
 st->internal->need_parsing = AVSTREAM_PARSE_FULL;
 }
 st->codecpar->bits_per_coded_sample =
av_get_bits_per_sample(st->codecpar->codec_id);
+
+    current_channel = 0;
+
+
+
+    for (j = 0; j < FFMIN(descriptor->channels,
FF_SANE_NB_CHANNELS); ++j) {

I feel like we should error out with an appropriate message rather than
silently ignoring any extra channels. Otherwise this looks pretty good

/Tomas

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

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


[FFmpeg-devel] [PATCH v2] avcodec/h274: don't read from uninitialized array members

2021-09-12 Thread Niklas Haas
From: Niklas Haas 

This bug flew under the radar because, in practice, these values are
0-initialized for the first invocation. But for subsequent invocations
(with different h/v values), reading from the uninitialized parts of
`out` is undefined behavior.

Avoid this by simply adjusting the iteration range of the following
loops. Has the added benefit of being a minor speedup.
---
 libavcodec/h274.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h274.c b/libavcodec/h274.c
index 5e2cf150ea..781878d7ad 100644
--- a/libavcodec/h274.c
+++ b/libavcodec/h274.c
@@ -74,9 +74,9 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, 
uint8_t v,
 
 // 64x64 inverse integer transform
 for (int y = 0; y < 64; y++) {
-for (int x = 0; x < 64; x++) {
+for (int x = 0; x <= freq_h; x++) {
 int32_t sum = 0;
-for (int p = 0; p < 64; p++)
+for (int p = 0; p <= freq_v; p++)
 sum += R64T[y][p] * out[x][p];
 tmp[y][x] = (sum + 128) >> 8;
 }
@@ -85,7 +85,7 @@ static void init_slice_c(int8_t out[64][64], uint8_t h, 
uint8_t v,
 for (int y = 0; y < 64; y++) {
 for (int x = 0; x < 64; x++) {
 int32_t sum = 0;
-for (int p = 0; p < 64; p++)
+for (int p = 0; p <= freq_h; p++)
 sum += tmp[y][p] * R64T[x][p]; // R64T^T = R64
 // Renormalize and clip to [-127, 127]
 out[y][x] = av_clip((sum + 128) >> 8, -127, 127);
-- 
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] libavutil/hwcontext_qsv: fix a bug for mapping qsv frame to vaapi

2021-09-12 Thread Xiang, Haihao
On Fri, 2021-09-10 at 02:19 +, Chen, Wenbin wrote:
> > -Original Message-
> > From: ffmpeg-devel  On Behalf Of
> > James Almer
> > Sent: Thursday, September 9, 2021 8:48 PM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: fix a bug for
> > mapping qsv frame to vaapi
> > 
> > On 9/9/2021 6:13 AM, Wenbin Chen wrote:
> > > Command below failed.
> > > ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128
> > > -init_hw_device qsv=qs@va -hwaccel qsv -hwaccel_device qs
> > > -filter_hw_device va -c:v h264_qsv
> > > -i 1080P.264 -vf "hwmap,format=vaapi" -c:v h264_vaapi output.264
> > > 
> > > Cause: Assign pair->first directly to data[3] in vaapi frame.
> > > pair->first is *VASurfaceID while data[3] in vaapi frame is
> > > VASurfaceID. I fix this line of code. Now the command above works.
> > > 
> > > Signed-off-by: Wenbin Chen 
> > > ---
> > >   libavutil/hwcontext_qsv.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > > index d431e71eab..6539cae619 100644
> > > --- a/libavutil/hwcontext_qsv.c
> > > +++ b/libavutil/hwcontext_qsv.c
> > > @@ -781,7 +781,7 @@ static int qsv_map_from(AVHWFramesContext *ctx,
> > >   case AV_HWDEVICE_TYPE_VAAPI:
> > >   {
> > >   mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
> > > -child_data = pair->first;
> > > +child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
> > 
> > You can probably remove the intptr_t casting.
> 
> If intptr_t is removed, it will report compile warning
> "cast to pointer from integer of different size"

How about to add a comment here? If so, others can understand why this casting
is needed.

Thanks
Haihao


>  
> > 
> > Also, shouldn't this same fix be done for all three child device types
> > used in this function? Which for that matter, child_data seems to be set
> > for a d3d11va child device, but then never used.
> 
> Dxva and d3d11 frames store the pointer to surface while vaapi frames store
> surface, 
> so this part of code for dxva and d3d11va should be correct.
> 
> D3d11 and dxva share dxva codec, the child_data is used in this part of code.
> > 
> > >   break;
> > >   }
> > >   #endif
> > > 
> > 
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 01/12] lavf/concat: refactor parsing

2021-09-12 Thread Nicolas George
Nicolas George (12021-08-31):
> Signed-off-by: Nicolas George 
> ---
>  libavformat/concatdec.c | 255 ++--
>  1 file changed, 167 insertions(+), 88 deletions(-)

Will push this series soon.

Regards,

-- 
  Nicolas George


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] ffmpeg_hw: make hardware selection for filters more user friendly

2021-09-12 Thread Xiang, Haihao
On Thu, 2021-08-19 at 04:44 +, Xiang, Haihao wrote:
> On Wed, 2021-08-04 at 05:17 +, Soft Works wrote:
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of
> > > Haihao Xiang
> > > Sent: Tuesday, 29 June 2021 03:46
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Haihao Xiang 
> > > Subject: [FFmpeg-devel] [PATCH] ffmpeg_hw: make hardware selection for
> > > filters more user friendly
> > > 
> > > When a device is derived from a source device, there are at least 2
> > > devices,
> > > and usually the derived device is the expected device, so let's pick the
> > > last
> > > device if user doesn't specify the filter device with filter_hw_device
> > > option
> > > 
> > > After applying this patch, the command below can work:
> > > 
> > > $> ffmpeg -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device
> > > qsv=hw@va -f lavfi -i yuvtestsrc  -vf
> > > format=nv12,hwupload=extra_hw_frames=64 -c:v h264_qsv -y out.h264
> > > ---
> > >  fftools/ffmpeg_hw.c | 20 +---
> > >  1 file changed, 13 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index
> > > fc4a5d31d6..14e2cb0177 100644
> > > --- a/fftools/ffmpeg_hw.c
> > > +++ b/fftools/ffmpeg_hw.c
> > > @@ -527,15 +527,21 @@ int hw_device_setup_for_filter(FilterGraph *fg)
> > >  HWDevice *dev;
> > >  int i;
> > > 
> > > -// If the user has supplied exactly one hardware device then just
> > > -// give it straight to every filter for convenience.  If more than
> > > -// one device is available then the user needs to pick one explcitly
> > > -// with the filter_hw_device option.
> > > +// Pick the last hardware device if the user doesn't pick the device
> > > for
> > > +// filters explicitly with the filter_hw_device option.
> > >  if (filter_hw_device)
> > >  dev = filter_hw_device;
> > > -else if (nb_hw_devices == 1)
> > > -dev = hw_devices[0];
> > > -else
> > > +else if (nb_hw_devices > 0) {
> > > +dev = hw_devices[nb_hw_devices - 1];
> > > +
> > > +if (nb_hw_devices > 1)
> > > +av_log(NULL, AV_LOG_WARNING, "There are %d hardware devices.
> > > device "
> > > +   "%s of type %s is picked for filters by default. Set
> > > hardware "
> > > +   "device explicitly with the filter_hw_device option if
> > > device "
> > > +   "%s is not usable for filters.\n",
> > > +   nb_hw_devices, dev->name,
> > > +   av_hwdevice_get_type_name(dev->type), dev->name);
> > > +} else
> > >  dev = NULL;
> > > 
> > >  if (dev) {
> > > --
> > 
> > Haihao,
> > 
> > Thanks for the patch, I hadn't seen it. Due to working off an older baseline
> > version,  I wasn't actually aware of the current code which had been added
> > by
> > Mark Thompson in April 2020: 
> > 
> > - when a single hw device is initialized, all filters are automatically set
> > to
> > that device context
> > - when more than one device is initialized, it silently does nothing
> > 
> > This leads to the following behavior: you have a working command line with a
> > single device. Then you add initialization for a second device and the
> > command
> > line stops working.
> > 
> > @mark - would you mind to comment?
> > I suppose the idea was that when there's more than a single device, the user
> > needs to set filter_hw_device explicitly. But IMO, this doesn't go well
> > together with making an automatic selection: either there's always an
> > automatic selection or never, but the current behavior is confusing.
> > 
> > Now, that there's already an automatic selection for cases with a single
> > device, the "never" option is practically off the table. For those reasons,
> > Haihao's patch would LGTM.
> > 
> 
> Could someone help to merge this patch if no more comment ?

Ping again.

Thanks
Haihao


___
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] [Discussion] Releases schedules

2021-09-12 Thread Jean-Baptiste Kempf
Hello folks,

This is a topic that has come regularly on the table, in various discussions in 
the community, in IRL, on IRC and on the mailing list; but also when talking 
with downstreams applications and distributions...

Currently, it's quite difficult to know when is coming the next release, which 
branch is going to be maintained for how long, so it's a bit of guess/luck to 
know which version to use, and many people use a random sha1. Even for 
distributions that have LTS this is difficult. It's also annoying for 
downstreams, that might have some patches above the top of line, or backporting 
some patches. And a few other drawbacks, including security...

And finally, the maintenance of a branch belongs mostly to the goodwill of a 
few of us, and it could be tiring for them...

(And for exemple, which branch today has all the security fixes, besides 
4.4.x?, without looking at the git repo)

Clarity would help a lot the FFmpeg direct and indirect users.
So I'd love to start a discussion here, about this topic.

--- 
Here is my opinion, depending on what I heard from the downstreams requirements.

It would be nice to have:
- one major release per year, allowing to break library API/ABI/behavior, 
(probably in December to fit Ubuntu release schedule),
- one or two or three small releases per year, adding features, without 
deprecation nor ABI changes, during the year,
- mark the major release as LTS every two year, and maintained it for security 
for a longer time (2 years, for example) than the usual main release.

This would allow to only have to maintain the LTS branch and the last release 
(which can be the same) in addition with the development branch.
And as a downstream dev, you also know when you need to care about API changes 
and which version is supported.
This would be also quite simple to explain to the users/downstreams of FFmpeg.


Thoughts?

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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/dv: always set audio packet duration

2021-09-12 Thread Paul B Mahol
will apply soon
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avcodec/wmadec: fix WMA gapless playback

2021-09-12 Thread Paul B Mahol
will apply soon
___
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 signal to distortion ratio filter

2021-09-12 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |   7 ++
 libavfilter/Makefile |   1 +
 libavfilter/af_asdr.c| 237 +++
 libavfilter/allfilters.c |   1 +
 4 files changed, 246 insertions(+)
 create mode 100644 libavfilter/af_asdr.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 8f20ccf8c6..6af7344820 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2531,6 +2531,13 @@ noise removed from input signal.
 
 This filter supports the all above options as @ref{commands}.
 
+@section asdr
+Measure Audio Signal-to-Distortion Ratio.
+
+This filter takes two audio streams for input, and outputs first
+audio stream.
+Results are in dB per channel at end of either input.
+
 @section asetnsamples
 
 Set the number of samples per each output audio frame.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 76c65c3f42..865252ef3f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -82,6 +82,7 @@ OBJS-$(CONFIG_AREALTIME_FILTER)  += f_realtime.o
 OBJS-$(CONFIG_ARESAMPLE_FILTER)  += af_aresample.o
 OBJS-$(CONFIG_AREVERSE_FILTER)   += f_reverse.o
 OBJS-$(CONFIG_ARNNDN_FILTER) += af_arnndn.o
+OBJS-$(CONFIG_ASDR_FILTER)   += af_asdr.o
 OBJS-$(CONFIG_ASEGMENT_FILTER)   += f_segment.o
 OBJS-$(CONFIG_ASELECT_FILTER)+= f_select.o
 OBJS-$(CONFIG_ASENDCMD_FILTER)   += f_sendcmd.o
diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
new file mode 100644
index 00..220da74a85
--- /dev/null
+++ b/libavfilter/af_asdr.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * 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/audio_fifo.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "audio.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "filters.h"
+#include "internal.h"
+
+typedef struct AudioSDRContext {
+int channels;
+int64_t pts;
+double *sum_u;
+double *sum_uv;
+
+AVFrame *cache[2];
+
+AVAudioFifo *fifo[2];
+} AudioSDRContext;
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVSampleFormat sample_fmts[] = {
+AV_SAMPLE_FMT_DBLP,
+AV_SAMPLE_FMT_NONE
+};
+int ret = ff_set_common_all_channel_counts(ctx);
+if (ret < 0)
+return ret;
+
+ret = ff_set_common_formats_from_list(ctx, sample_fmts);
+if (ret < 0)
+return ret;
+
+return ff_set_common_all_samplerates(ctx);
+}
+
+static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
+{
+AudioSDRContext *s = ctx->priv;
+
+for (int ch = 0; ch < u->channels; ch++) {
+const double *const us = (double *)u->extended_data[ch];
+const double *const vs = (double *)v->extended_data[ch];
+double sum_uv = s->sum_uv[ch];
+double sum_u = s->sum_u[ch];
+
+for (int n = 0; n < u->nb_samples; n++) {
+sum_u  += us[n] * us[n];
+sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
+}
+
+s->sum_uv[ch] = sum_uv;
+s->sum_u[ch]  = sum_u;
+}
+}
+
+static int activate(AVFilterContext *ctx)
+{
+AudioSDRContext *s = ctx->priv;
+AVFrame *frame = NULL;
+int ret, status;
+int available;
+int64_t pts;
+
+FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
+
+for (int i = 0; i < 2; i++) {
+ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
+if (ret > 0) {
+if (s->pts == AV_NOPTS_VALUE)
+s->pts = frame->pts;
+ret = av_audio_fifo_write(s->fifo[i], (void 
**)frame->extended_data,
+  frame->nb_samples);
+av_frame_free(&frame);
+if (ret < 0)
+return ret;
+}
+}
+
+available = FFMIN(av_audio_fifo_size(s->fifo[0]), 
av_audio_fifo_size(s->fifo[1]));
+if (available > 0) {
+AVFrame *out;
+
+if (!s->cache[0] || s->cache[0]->nb_samples < available) {
+av_frame_free(&s->cache[0]);
+s->cache[0] = ff_get_audio_buffer(ctx->outputs[0], available);
+if (!s->cache[0])
+  

Re: [FFmpeg-devel] [PATCH] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Nicolas George
Paul B Mahol (12021-09-12):
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |   7 ++
>  libavfilter/Makefile |   1 +
>  libavfilter/af_asdr.c| 237 +++
>  libavfilter/allfilters.c |   1 +
>  4 files changed, 246 insertions(+)
>  create mode 100644 libavfilter/af_asdr.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8f20ccf8c6..6af7344820 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2531,6 +2531,13 @@ noise removed from input signal.
>  
>  This filter supports the all above options as @ref{commands}.
>  
> +@section asdr
> +Measure Audio Signal-to-Distortion Ratio.
> +
> +This filter takes two audio streams for input, and outputs first
> +audio stream.
> +Results are in dB per channel at end of either input.
> +
>  @section asetnsamples
>  
>  Set the number of samples per each output audio frame.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 76c65c3f42..865252ef3f 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -82,6 +82,7 @@ OBJS-$(CONFIG_AREALTIME_FILTER)  += f_realtime.o
>  OBJS-$(CONFIG_ARESAMPLE_FILTER)  += af_aresample.o
>  OBJS-$(CONFIG_AREVERSE_FILTER)   += f_reverse.o
>  OBJS-$(CONFIG_ARNNDN_FILTER) += af_arnndn.o
> +OBJS-$(CONFIG_ASDR_FILTER)   += af_asdr.o
>  OBJS-$(CONFIG_ASEGMENT_FILTER)   += f_segment.o
>  OBJS-$(CONFIG_ASELECT_FILTER)+= f_select.o
>  OBJS-$(CONFIG_ASENDCMD_FILTER)   += f_sendcmd.o
> diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
> new file mode 100644
> index 00..220da74a85
> --- /dev/null
> +++ b/libavfilter/af_asdr.c
> @@ -0,0 +1,237 @@
> +/*
> + * Copyright (c) 2021 Paul B Mahol
> + *
> + * 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/audio_fifo.h"
> +#include "libavutil/channel_layout.h"
> +#include "libavutil/common.h"
> +#include "libavutil/opt.h"
> +
> +#include "audio.h"
> +#include "avfilter.h"
> +#include "formats.h"
> +#include "filters.h"
> +#include "internal.h"
> +
> +typedef struct AudioSDRContext {
> +int channels;
> +int64_t pts;
> +double *sum_u;
> +double *sum_uv;
> +
> +AVFrame *cache[2];
> +
> +AVAudioFifo *fifo[2];
> +} AudioSDRContext;
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +static const enum AVSampleFormat sample_fmts[] = {
> +AV_SAMPLE_FMT_DBLP,
> +AV_SAMPLE_FMT_NONE
> +};
> +int ret = ff_set_common_all_channel_counts(ctx);
> +if (ret < 0)
> +return ret;
> +
> +ret = ff_set_common_formats_from_list(ctx, sample_fmts);
> +if (ret < 0)
> +return ret;
> +
> +return ff_set_common_all_samplerates(ctx);
> +}
> +
> +static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
> +{
> +AudioSDRContext *s = ctx->priv;
> +
> +for (int ch = 0; ch < u->channels; ch++) {
> +const double *const us = (double *)u->extended_data[ch];
> +const double *const vs = (double *)v->extended_data[ch];
> +double sum_uv = s->sum_uv[ch];
> +double sum_u = s->sum_u[ch];
> +
> +for (int n = 0; n < u->nb_samples; n++) {
> +sum_u  += us[n] * us[n];
> +sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
> +}
> +
> +s->sum_uv[ch] = sum_uv;
> +s->sum_u[ch]  = sum_u;
> +}
> +}
> +
> +static int activate(AVFilterContext *ctx)
> +{
> +AudioSDRContext *s = ctx->priv;
> +AVFrame *frame = NULL;
> +int ret, status;
> +int available;
> +int64_t pts;
> +
> +FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
> +

> +for (int i = 0; i < 2; i++) {
> +ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
> +if (ret > 0) {
> +if (s->pts == AV_NOPTS_VALUE)
> +s->pts = frame->pts;
> +ret = av_audio_fifo_write(s->fifo[i], (void 
> **)frame->extended_data,
> +  frame->nb_samples);
> +av_frame_free(&frame);
> +if (ret < 0)
> +return ret;
> +}
> +}
> +
> +available = FFMIN(av_audio_fifo_s

Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Sunday, 12 September 2021 13:38
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle
> Filtering - Add AVMediaType property to AVFrame
> 
> 12 Sept 2021, 13:31 by d...@lynne.ee:
> 
> > 12 Sept 2021, 05:21 by softwo...@hotmail.com:
> >
> >> This is the root commit for adding subtitle filtering
> capabilities.
> >> Adding the media type property to AVFrame replaces the previous
> >> way of distinction which was based on checking width and height
> >> to determine whether a frame is audio or video.
> >>
> >> Signed-off-by: softworkz 
> >>
> >
> > Why do you need a new allocation function av_frame_get_buffer2
> > when it has the same syntax as av_frame_get_buffer?
> > Also, could you please drop all but one of the filter patches
> > when sending new versions? You're overspamming the ML
> > and it's hard to keep up.
> > Finally, why not combine the 2 subtitle overlay filters into one?
> > There's no need for explicitness between text and bitmap subs.
> >
> 
> Just read why (the media type). Says a lot about the ML overload.
> 
> Could the media type be set as unknown during the deprecation
> period by default by the old alloc function for audio and video?

That would defeat the actual purpose of that property.

> Subtitle allocations can set it to _SUBTITLES. That way, you can
> still keep compatibility, as the old users detect AVFrame type based
> on the 'format' field, without adding a new alloc function.

No, they can't use the format field because it is used for both,
audio (sampleformat) and video (pixfmt).
The existing code was checking for width and/or height to distinguish
between video and audio which is now using the type instead:

Before:

if (frame->width) {
...
}
if (frame->nb_samples) {
...
}

After:

switch(frame->type) {
case AVMEDIA_TYPE_VIDEO:
...
case AVMEDIA_TYPE_AUDIO:
...
case AVMEDIA_TYPE_SUBTITLE:
...
}


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 v5 07/12] avfilter/sbuffer: Add sbuffersrv and sbuffersink filters

2021-09-12 Thread Andreas Rheinhardt
Soft Works:
> Signed-off-by: softworkz 
> ---
>  configure|  2 +-
>  libavfilter/allfilters.c | 10 +++---
>  libavfilter/buffersink.c | 63 +++
>  libavfilter/buffersink.h | 15 +
>  libavfilter/buffersrc.c  | 72 
>  libavfilter/buffersrc.h  |  1 +
>  libavfilter/version.h|  2 +-
>  7 files changed, 159 insertions(+), 6 deletions(-)
> 
> diff --git a/configure b/configure
> index af410a9d11..2f2777df9f 100755
> --- a/configure
> +++ b/configure
> @@ -7716,7 +7716,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 0c6b2347c8..b27ef6f027 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -531,10 +531,12 @@ extern const AVFilter ff_avsrc_movie;
>   * they are formatted to not be found by the grep
>   * as they are manually added again (due to their 'names'
>   * being the same while having different 'types'). */
> -extern  const AVFilter ff_asrc_abuffer;
> -extern  const AVFilter ff_vsrc_buffer;
> -extern  const AVFilter ff_asink_abuffer;
> -extern  const AVFilter ff_vsink_buffer;
> +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;
>  
You seem to have overlooked the comment above.

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

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


Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Andreas Rheinhardt
> Sent: Sunday, 12 September 2021 14:04
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle
> Filtering - Add AVMediaType property to AVFrame
> 
> Lynne:
> > 12 Sept 2021, 13:31 by d...@lynne.ee:
> >
> >> 12 Sept 2021, 05:21 by softwo...@hotmail.com:
> >>
> >>> This is the root commit for adding subtitle filtering
> capabilities.
> >>> Adding the media type property to AVFrame replaces the previous
> >>> way of distinction which was based on checking width and height
> >>> to determine whether a frame is audio or video.
> >>>
> >>> Signed-off-by: softworkz 
> >>>
> >>
> >> Why do you need a new allocation function av_frame_get_buffer2
> >> when it has the same syntax as av_frame_get_buffer?
> >> Also, could you please drop all but one of the filter patches
> >> when sending new versions? You're overspamming the ML
> >> and it's hard to keep up.
> >> Finally, why not combine the 2 subtitle overlay filters into one?
> >> There's no need for explicitness between text and bitmap subs.
> >>
> >
> > Just read why (the media type). Says a lot about the ML overload.
> >
> > Could the media type be set as unknown during the deprecation
> > period by default by the old alloc function for audio and video?
> > Subtitle allocations can set it to _SUBTITLES. That way, you can
> > still keep compatibility, as the old users detect AVFrame type
> based
> > on the 'format' field, without adding a new alloc function.
> The decode API should (when it is ported; haven't looked whether this
> already happens in this commit) ensure that AVFrame.type is set
> according to the data contained in the frame. 

Not done yet, but makes sense.

> If a user unaware of
> the
> decodes (say) video and then wants to utilize said AVFrame for audio,
> he
> may do so by resetting the fields corresponding to video and setting
> the
> audio related fields; you do not need to call av_frame_unref on it
> (say
> you want to keep the metadata and the timing related stuff, so you
> reset
> manually). If he then gives this frame to av_frame_get_buffer, it
> will
> be inconsistent, i.e. av_frame_get_buffer should error out. And then
> the
> user app will be broken.
> (I of course admit that lots of users will not be affected by this,
> as
> they always reset their frames with av_frame_unref. But we have to
> think
> of the odd cases, too.)

Isn't that a bit "too odd"? It's almost always possible to construct 
odd cases that would be broken in case they would exist.

I don't want to open architecture design discussion, but from my 
perspective:

- Due to the not really comprehensive documentation of API usage,
  it's often the code inside ffmpeg itself that demonstrates how 
  certain APIs should be used

- So when a patch doesn't break any public API usage within the ffmpeg
  package, shouldn't that be sufficient to assume that external use
  of the APIs won't be broken either?
  Of course, assuming that the external user has done its implementation
  following the way it's used within ffmpeg.

It's not that I want to argue about that subject, just in case there
exists a different philosophy, I'd like to know for better understanding.

Thanks,
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 v5 08/12] avfilter/overlay_graphicsubs: Add overlay_graphicsubs and graphicsub2video filters

2021-09-12 Thread Andreas Rheinhardt
Soft Works:
> Signed-off-by: softworkz 
> ---
>  doc/filters.texi | 104 
>  libavfilter/Makefile |   2 +
>  libavfilter/allfilters.c |   2 +
>  libavfilter/vf_overlay_graphicsubs.c | 731 +++
>  4 files changed, 839 insertions(+)
>  create mode 100644 libavfilter/vf_overlay_graphicsubs.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 9ad6031d23..a6da018259 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -25016,6 +25016,110 @@ 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.
> +
> +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 overlay_graphicsubs
> +
> +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.
> +
> +
> +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: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
> +@c man end SUBTITLE FILTERS
> +
>  @chapter Multimedia Filters
>  @c man begin MULTIMEDIA FILTERS
>  
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index a510dd12b4..f9b33d4ead 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -289,6 +289,7 @@ OBJS-$(CONFIG_FSPP_FILTER)   += vf_fspp.o 
> qp_table.o
>  OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
>  OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
>  OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
> +OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlay_graphicsubs.o 
> framesync.o
>  OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphm

Re: [FFmpeg-devel] [PATCH v5 00/12] Subtitle Filtering

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Hendrik Leppkes
> Sent: Sunday, 12 September 2021 07:30
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v5 00/12] Subtitle Filtering
> 
> On Sun, Sep 12, 2021 at 6:21 AM Soft Works 
> wrote:
> >
> >
> >
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of
> > > Soft Works
> > > Sent: Sunday, 12 September 2021 05:21
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: [FFmpeg-devel] [PATCH v5 00/12] Subtitle Filtering
> > >
> > > v5 Update:
> > >
> > > - Merge AVSubtitle into AVFrame
> > > - Move FATE test adjustments to corresponding commit
> > > - Move documentation updates to corresponding filter commits
> > > - Remove mediatype parameter from av_frame_get_buffer2
> >
> > This patchset provides proof that merging AVSubtitle into AVFrame
> > is doable and not far away to achieve. It obsoletes the need for
> > a "subtitle api", as that purpose will be served by the AVFrame
> > API. It might still make sense to add a number of functions for
> > dealing with AVSubtitleRect (e.g. av_subtitlerect_alloc, _free)
> > as these should probably be ref-counted to avoid copying.
> > I have added a minimal internal ref counting which serves the
> current
> > use cases, but I'm open to suggestions..
> >
> 
> The key that this patchset does not do however is preserve
> compatibility.
> As mentioned in another thread, we don't just change APIs, certainly
> not overnight, and basically not ever. We introduce replacements, and
> deprecate the old ones (and remove after a grace period)
> 
> That means if my application does not use deprecated functionality,
> it
> has to continue working after this patchset - and that is absolutely
> not the case.
> 
> So what needs to happen is that existing subtitle functions need to
> continue to be functional and unchanged, including all structures and
> whatnot. They can be deprecated and removed in ~2 years
> This fact alone makes it also easier to split such changes into
> smaller pieces, because you only add, you don't remove or replace.
> 
> So back to small atomic commits, which is easy if you don't update
> everything in one go, because you are not allowed to anyway. Old
> functions have to be preserved.
> 
> Internally, there should be a compatibility layer. I would recommend
> at first not changing encoders and decoders internally, and instead
> build the compatibility so that it uses the old internal API to feed
> the new external API.
> This can be changed and reversed in a follow-up change later.

Thanks Hendrik, but then we are just back at my previous patchset
which provides exactly this: compatibility.

If you say APIs should not (or even "never" be changed), then we
need to have AVSubtitle around for quite a long time.

In that case though I see absolutely no benefit in merging AVSubtitle
into AVFrame at all. That "glue/compatibility code" would make things
just unnecessarily complicated. It would be even impossible at some 
point because we can't copy the AVSubtitleRect data because we don't
know the size of the allocated memory, so we can just free it at some
point.

All-in-all that doesn't seem to be worth all the hazzle. Again, 
that brings me back to my original approach:

Simply attach AVSubtitle to AVFrame (ref-counted of course).
That's nice and clean and compatible.

What I agree is that it's not nice to store it in buf[0]. I'll 
better add two separate properties for it: An AVBufferRef and
a direct AVSubtitle pointer for convenience.

Regards,
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 v5 00/12] Subtitle Filtering

2021-09-12 Thread Hendrik Leppkes
On Sun, Sep 12, 2021 at 10:07 PM Soft Works  wrote:
>
> All-in-all that doesn't seem to be worth all the hazzle. Again,
> that brings me back to my original approach:
>

It is for us, if its not for you, what can we say.
The only approach to go forwards is to prepare proper, clean and fully
featured integration that results in a clean API once the deprecation
period is over and the old stuff can get removed. Anything else would
be a hack and only serve your desired purpose, not the long-term API
design of FFmpeg, which unfortunately is just not acceptable.

This is the same approach that has been taken with many refactoring
projects in the past. If this would've been easy, patchsets to move
subtitles to AVFrame wouldn't have been all stuck in WIP development
branches by established FFmpeg developers.

If you are interested in doing it properly, we will listen and guide,
but if not... thats the only way its going to get accepted.

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


[FFmpeg-devel] [PATCH] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |   7 ++
 libavfilter/Makefile |   1 +
 libavfilter/af_asdr.c| 197 +++
 libavfilter/allfilters.c |   1 +
 4 files changed, 206 insertions(+)
 create mode 100644 libavfilter/af_asdr.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 8f20ccf8c6..6af7344820 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2531,6 +2531,13 @@ noise removed from input signal.
 
 This filter supports the all above options as @ref{commands}.
 
+@section asdr
+Measure Audio Signal-to-Distortion Ratio.
+
+This filter takes two audio streams for input, and outputs first
+audio stream.
+Results are in dB per channel at end of either input.
+
 @section asetnsamples
 
 Set the number of samples per each output audio frame.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 76c65c3f42..865252ef3f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -82,6 +82,7 @@ OBJS-$(CONFIG_AREALTIME_FILTER)  += f_realtime.o
 OBJS-$(CONFIG_ARESAMPLE_FILTER)  += af_aresample.o
 OBJS-$(CONFIG_AREVERSE_FILTER)   += f_reverse.o
 OBJS-$(CONFIG_ARNNDN_FILTER) += af_arnndn.o
+OBJS-$(CONFIG_ASDR_FILTER)   += af_asdr.o
 OBJS-$(CONFIG_ASEGMENT_FILTER)   += f_segment.o
 OBJS-$(CONFIG_ASELECT_FILTER)+= f_select.o
 OBJS-$(CONFIG_ASENDCMD_FILTER)   += f_sendcmd.o
diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
new file mode 100644
index 00..25032445cd
--- /dev/null
+++ b/libavfilter/af_asdr.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2021 Paul B Mahol
+ *
+ * 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/channel_layout.h"
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "audio.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "filters.h"
+#include "internal.h"
+
+typedef struct AudioSDRContext {
+int channels;
+int64_t pts;
+double *sum_u;
+double *sum_uv;
+
+AVFrame *cache[2];
+} AudioSDRContext;
+
+static int query_formats(AVFilterContext *ctx)
+{
+static const enum AVSampleFormat sample_fmts[] = {
+AV_SAMPLE_FMT_DBLP,
+AV_SAMPLE_FMT_NONE
+};
+int ret = ff_set_common_all_channel_counts(ctx);
+if (ret < 0)
+return ret;
+
+ret = ff_set_common_formats_from_list(ctx, sample_fmts);
+if (ret < 0)
+return ret;
+
+return ff_set_common_all_samplerates(ctx);
+}
+
+static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
+{
+AudioSDRContext *s = ctx->priv;
+
+for (int ch = 0; ch < u->channels; ch++) {
+const double *const us = (double *)u->extended_data[ch];
+const double *const vs = (double *)v->extended_data[ch];
+double sum_uv = s->sum_uv[ch];
+double sum_u = s->sum_u[ch];
+
+for (int n = 0; n < u->nb_samples; n++) {
+sum_u  += us[n] * us[n];
+sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
+}
+
+s->sum_uv[ch] = sum_uv;
+s->sum_u[ch]  = sum_u;
+}
+}
+
+static int activate(AVFilterContext *ctx)
+{
+AudioSDRContext *s = ctx->priv;
+int ret, status;
+int available;
+int64_t pts;
+
+FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
+
+available = FFMIN(ff_inlink_queued_samples(ctx->inputs[0]), 
ff_inlink_queued_samples(ctx->inputs[1]));
+if (available > 0) {
+AVFrame *out;
+
+for (int i = 0; i < 2; i++) {
+ret = ff_inlink_consume_samples(ctx->inputs[i], available, 
available, &s->cache[i]);
+if (ret > 0) {
+if (s->pts == AV_NOPTS_VALUE)
+s->pts = s->cache[i]->pts;
+}
+}
+
+sdr(ctx, s->cache[0], s->cache[1]);
+
+av_frame_free(&s->cache[1]);
+out = s->cache[0];
+out->nb_samples = available;
+out->pts = s->pts;
+s->pts += available;
+s->cache[0] = NULL;
+
+return ff_filter_frame(ctx->outputs[0], out);
+}
+
+for (int i = 0; i < 2; i++) {
+if (ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts)) {
+ff_outlink_set_status(ctx->outputs[0], s

[FFmpeg-devel] Animated WebP decoder

2021-09-12 Thread Martin Reboredo
v3 Update:
- Add a libwebpdecoder based WebP decoder for animated pictures.
- Adapt the native decoder for the new demuxer.

v2 Update:
- Cleanups based on reviews.

This patchset introduces an initial implementation of a decoder for the 
animated WebP format. The native decoder doesn't provide support for it and 
this implementation
decodes frame by frame instead of proceeding with the entire file instead. 
Otherwise, in the case of a sole image it will send the data completely.


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

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


[FFmpeg-devel] [PATCH v3 1/4] avcodec/webp: compatibilize with avformat/webpdec

2021-09-12 Thread Martin Reboredo
The demuxer implementation splits some RIFF chunks (`RIFF`/`VP8X`/`ANMF` + 
frame chunk) or sends the picture chunks separately.
The internal WebP decoder waits for a complete file instead and by consequence 
it needs to be modified to support this kind of fractioned input.

Fixes FATE tests with WebP.

Signed-off-by: Martin Reboredo 
---
 libavcodec/webp.c | 41 -
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 3efd4438d9..7858d69481 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -40,6 +40,7 @@
  *   - XMP metadata
  */
 
+#include "libavformat/internal.h"
 #include "libavutil/imgutils.h"
 
 #define BITSTREAM_READER_LE
@@ -191,6 +192,7 @@ typedef struct WebPContext {
 AVFrame *alpha_frame;   /* AVFrame for alpha data decompressed 
from VP8L */
 AVPacket *pkt;  /* AVPacket to be passed to the 
underlying VP8 decoder */
 AVCodecContext *avctx;  /* parent AVCodecContext */
+int read_header;/* RIFF header has been read */
 int initialized;/* set once the VP8 context is 
initialized */
 int has_alpha;  /* has a separate alpha chunk */
 enum AlphaCompression alpha_compression; /* compression type for alpha 
chunk */
@@ -1353,17 +1355,36 @@ static int webp_decode_frame(AVCodecContext *avctx, 
void *data, int *got_frame,
 if (bytestream2_get_bytes_left(&gb) < 12)
 return AVERROR_INVALIDDATA;
 
-if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
-av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
-return AVERROR_INVALIDDATA;
-}
-
+chunk_type = bytestream2_get_le32(&gb);
 chunk_size = bytestream2_get_le32(&gb);
-if (bytestream2_get_bytes_left(&gb) < chunk_size)
-return AVERROR_INVALIDDATA;
 
-if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
-av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
+for (int i = 0; !s->read_header && i < 4; i++) {
+ff_lock_avformat();
+
+if (s->read_header) {
+ff_unlock_avformat();
+break;
+}
+
+if (chunk_type == MKTAG('R', 'I', 'F', 'F')) {
+int left = bytestream2_get_bytes_left(&gb);
+if (left < chunk_size && left != 22) {
+ff_unlock_avformat();
+return AVERROR_INVALIDDATA;
+}
+if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
+av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
+ff_unlock_avformat();
+return AVERROR_INVALIDDATA;
+}
+s->read_header = 1;
+}
+
+ff_unlock_avformat();
+}
+
+if (!s->read_header) {
+av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
 return AVERROR_INVALIDDATA;
 }
 
@@ -1416,6 +1437,8 @@ static int webp_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 ret = av_image_check_size(s->width, s->height, 0, avctx);
 if (ret < 0)
 return ret;
+if (bytestream2_get_bytes_left(&gb) == 0)
+return AVERROR(EAGAIN);
 break;
 case MKTAG('A', 'L', 'P', 'H'): {
 int alpha_header, filter_m, compression;
-- 
2.32.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 v3 2/4] avformat/webpdec: WebP demuxer implementation

2021-09-12 Thread Martin Reboredo
FFmpeg has the ability to mux encoded WebP packets, but it cannot demux the 
format.
The purpose of this patch is to add a way to extract pictures from a WebP 
stream.
Any other side data processing (mainly ICC profiles) is left up for later work.
Although we have a demuxer with `image2`, it doesn't have support for animated 
frames like this patch.

The WebP format is based on RIFF, and due to the charasteristics of the latter, 
I've took advantage from chunking for processing purposes.
Package reading is done by taking chunks in a specific way. Starts by splitting 
the `RIFF`/`WEBP` header, then it goes by any of the three
`VP8 ` (lossy)/`VP8L` (lossless)/`VP8X` (extended format). In the case of a 
`VP8X` chunk we check for relevant flags. We then follow by grabbing the
`VP8 `/`ALPH` (alpha frame) + `VP8 `/`VP8L` chunks accourdingly. If the 
container specifies that is an animated package we take `ANIM` for the animation
parameters and the many `ANMF` animation frames, which every of them contains 
an image chunk (`VP8 `/`ALPH` + `VP8 `/`VP8L`). Otherwise, if an unknown
chunk is found, we just simply ignore it.

Tested by remuxing WebP images (using `ffmpeg -i testa.webp -codec:v copy 
testb.webp`), viewed the images in my browser and compared the checksums.

Mostly followed the WebP container specification [1] for the implementation, 
the VP8 bitstream [2] and the WebP lossless [3] specs were used too.

Partially fixes #4907.

[1]: https://developers.google.com/speed/webp/docs/riff_container
[2]: https://datatracker.ietf.org/doc/html/rfc6386
[3]: 
https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification

Signed-off-by: Martin Reboredo 
---
 MAINTAINERS  |   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/riff.c   |   1 +
 libavformat/webpdec.c| 326 +++
 5 files changed, 330 insertions(+)
 create mode 100644 libavformat/webpdec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index dcac46003e..f2d8f5eb17 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -505,6 +505,7 @@ Muxers/Demuxers:
   wav.c Michael Niedermayer
   wc3movie.cMike Melanson
   webm dash (matroskaenc.c) Vignesh Venkatasubramanian
+  webp*.c   Martin Reboredo
   webvtt*   Matthew J Heaney
   westwood.cMike Melanson
   wtv.c Peter Ross
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f7e47563da..aec2833c52 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -581,6 +581,7 @@ OBJS-$(CONFIG_WEBM_MUXER)+= matroskaenc.o 
matroska.o \
 OBJS-$(CONFIG_WEBM_DASH_MANIFEST_MUXER)  += webmdashenc.o
 OBJS-$(CONFIG_WEBM_CHUNK_MUXER)  += webm_chunk.o
 OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o
+OBJS-$(CONFIG_WEBP_DEMUXER)  += webpdec.o
 OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o
 OBJS-$(CONFIG_WEBVTT_MUXER)  += webvttenc.o
 OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 5471f7c16f..55f3c9a956 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -473,6 +473,7 @@ extern const AVOutputFormat ff_webm_muxer;
 extern const AVInputFormat  ff_webm_dash_manifest_demuxer;
 extern const AVOutputFormat ff_webm_dash_manifest_muxer;
 extern const AVOutputFormat ff_webm_chunk_muxer;
+extern const AVInputFormat  ff_webp_demuxer;
 extern const AVOutputFormat ff_webp_muxer;
 extern const AVInputFormat  ff_webvtt_demuxer;
 extern const AVOutputFormat ff_webvtt_muxer;
diff --git a/libavformat/riff.c b/libavformat/riff.c
index 27a9706510..9bd940ba52 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -321,6 +321,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
 { AV_CODEC_ID_VP7,  MKTAG('V', 'P', '7', '1') },
 { AV_CODEC_ID_VP8,  MKTAG('V', 'P', '8', '0') },
 { AV_CODEC_ID_VP9,  MKTAG('V', 'P', '9', '0') },
+{ AV_CODEC_ID_WEBP, MKTAG('W', 'E', 'B', 'P') },
 { AV_CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
 { AV_CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
 { AV_CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
diff --git a/libavformat/webpdec.c b/libavformat/webpdec.c
new file mode 100644
index 00..e5c27231be
--- /dev/null
+++ b/libavformat/webpdec.c
@@ -0,0 +1,326 @@
+/*
+ * webp demuxer
+ * Copyright (c) 2021 Martin Reboredo 
+ *
+ * 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,

[FFmpeg-devel] [PATCH v3 3/4] avformat/webpenc: better detection of anim chunks

2021-09-12 Thread Martin Reboredo
Receiving RIFF chunks as `av_packet`s from `webpdec.c` in `webpenc.c` it wasn't 
doing proper animated frame detection/enumeration.
Check for `ANIM`/`ANMF` chunks to see if the package is an animated WebP packet 
and for the `ANMF`/`ALPH`/`VP8 `/`VP8L` chunks if it's an actual frame.

Signed-off-by: Martin Reboredo 
---
 libavformat/webpenc.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index 9599fe7b85..50bee91910 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -55,13 +55,18 @@ static int is_animated_webp_packet(AVPacket *pkt)
 {
 int skip = 0;
 unsigned flags = 0;
+int fourcc = AV_RL32(pkt->data);
 
 if (pkt->size < 4)
 return AVERROR_INVALIDDATA;
-if (AV_RL32(pkt->data) == AV_RL32("RIFF"))
+if (fourcc == AV_RL32("RIFF"))
 skip = 12;
+else if (fourcc == AV_RL32("ANIM"))
+return 1;
+else if (fourcc == AV_RL32("ANMF"))
+return 1;
 // Safe to do this as a valid WebP bitstream is >=30 bytes.
-if (pkt->size < skip + 4)
+if (pkt->size < skip + 4 && pkt->size != 12)
 return AVERROR_INVALIDDATA;
 if (AV_RL32(pkt->data + skip) == AV_RL32("VP8X")) {
 flags |= pkt->data[skip + 4 + 4];
@@ -143,6 +148,7 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 static int webp_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
 WebpContext *w = s->priv_data;
+int fourcc = AV_RL32(pkt->data);
 int ret;
 
 if (!pkt->size)
@@ -161,7 +167,9 @@ static int webp_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 return ret;
 av_packet_ref(&w->last_pkt, pkt);
 }
-++w->frame_count;
+if (fourcc == AV_RL32("ANMF") || fourcc == AV_RL32("ALPH") ||
+fourcc == AV_RL32("VP8 ") || fourcc == AV_RL32("VP8L"))
+++w->frame_count;
 
 return 0;
 }
-- 
2.32.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 v3 4/4] avcodec/libwebpdec: libwebp decoder implementation

2021-09-12 Thread Martin Reboredo
Followup of the webp demuxer implementation. As the demuxer sends RIFF packets, 
the decoder choses what to do with the arriving chunks.

Completely fixes #4907.

Signed-off-by: Martin Reboredo 
---
 configure   |   4 +-
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/libwebpdec.c | 419 
 4 files changed, 424 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libwebpdec.c

diff --git a/configure b/configure
index 98987ed186..73dc45fb0d 100755
--- a/configure
+++ b/configure
@@ -285,7 +285,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
-  --enable-libwebp enable WebP encoding via libwebp [no]
+  --enable-libwebp enable WebP de/encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
   --enable-libxavs enable AVS encoding via xavs [no]
@@ -3314,6 +3314,7 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libwebp_decoder_deps="libwebpdecoder"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -6518,6 +6519,7 @@ enabled libvpx&& {
 }
 
 enabled libwebp   && {
+enabled libwebp_decoder  && require_pkg_config libwebpdecoder 
"libwebpdecoder >= 0.2.0" webp/decode.h WebPGetDecoderVersion
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
 enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder 
"libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
 enabled libx264   && { check_pkg_config libx264 x264 "stdint.h x264.h" 
x264_encoder_encode ||
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 11873eecae..81936b9828 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1062,6 +1062,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
+OBJS-$(CONFIG_LIBWEBP_DECODER)+= libwebpdec.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index c42aba140d..223f8bbf15 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -768,6 +768,7 @@ extern AVCodec ff_libvpx_vp9_decoder;
 /* preferred over libwebp */
 extern const AVCodec ff_libwebp_anim_encoder;
 extern const AVCodec ff_libwebp_encoder;
+extern const AVCodec ff_libwebp_decoder;
 extern const AVCodec ff_libx262_encoder;
 #if CONFIG_LIBX264_ENCODER
 #include 
diff --git a/libavcodec/libwebpdec.c b/libavcodec/libwebpdec.c
new file mode 100644
index 00..c583f919e0
--- /dev/null
+++ b/libavcodec/libwebpdec.c
@@ -0,0 +1,419 @@
+/*
+ * WebP decoding support via libwebp
+ * Copyright (c) 2021 Martin Reboredo 
+ *
+ * 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
+ * WebP decoder using libwebp (WebPDecode API)
+ */
+
+#include 
+#include 
+
+#include "decode.h"
+#include "internal.h"
+#include "libavutil/colorspace.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/error.h"
+#include "libavutil/opt.h"
+
+struct WebPDecBgColor {
+uint8_t y;
+uint8_t u;
+uint8_t v;
+uint8_t a;
+};
+
+typedef struct LibWebPDecContext {
+AVClass *class; // class for AVOptions
+struct WebPDecBgColor bg_color; // background color for frame disposals
+int loop;   // number of times to loop all the 
pictures (0 means indefinitely)
+int bypass_filter;  // bypass filtering for decoded frames
+int flip;   // flip output imag

Re: [FFmpeg-devel] [PATCH v3 4/4] avcodec/libwebpdec: libwebp decoder implementation

2021-09-12 Thread Paul B Mahol
On Sun, Sep 12, 2021 at 10:21 PM Martin Reboredo  wrote:

> Followup of the webp demuxer implementation. As the demuxer sends RIFF
> packets, the decoder choses what to do with the arriving chunks.
>
> Completely fixes #4907.
>

I really doubt that.

>
> Signed-off-by: Martin Reboredo 
> ---
>  configure   |   4 +-
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/libwebpdec.c | 419 
>  4 files changed, 424 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libwebpdec.c
>
> diff --git a/configure b/configure
> index 98987ed186..73dc45fb0d 100755
> --- a/configure
> +++ b/configure
> @@ -285,7 +285,7 @@ External library support:
>--enable-libvorbis   enable Vorbis en/decoding via libvorbis,
> native implementation exists [no]
>--enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
> -  --enable-libwebp enable WebP encoding via libwebp [no]
> +  --enable-libwebp enable WebP de/encoding via libwebp [no]
>--enable-libx264 enable H.264 encoding via x264 [no]
>--enable-libx265 enable HEVC encoding via x265 [no]
>--enable-libxavs enable AVS encoding via xavs [no]
> @@ -3314,6 +3314,7 @@ libvpx_vp8_decoder_deps="libvpx"
>  libvpx_vp8_encoder_deps="libvpx"
>  libvpx_vp9_decoder_deps="libvpx"
>  libvpx_vp9_encoder_deps="libvpx"
> +libwebp_decoder_deps="libwebpdecoder"
>  libwebp_encoder_deps="libwebp"
>  libwebp_anim_encoder_deps="libwebp"
>  libx262_encoder_deps="libx262"
> @@ -6518,6 +6519,7 @@ enabled libvpx&& {
>  }
>
>  enabled libwebp   && {
> +enabled libwebp_decoder  && require_pkg_config libwebpdecoder
> "libwebpdecoder >= 0.2.0" webp/decode.h WebPGetDecoderVersion
>  enabled libwebp_encoder  && require_pkg_config libwebp "libwebp
> >= 0.2.0" webp/encode.h WebPGetEncoderVersion
>  enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder
> "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
>  enabled libx264   && { check_pkg_config libx264 x264 "stdint.h
> x264.h" x264_encoder_encode ||
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 11873eecae..81936b9828 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1062,6 +1062,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) +=
> libvpxdec.o
>  OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
>  OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o libvpx.o
>  OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o libvpx.o
> +OBJS-$(CONFIG_LIBWEBP_DECODER)+= libwebpdec.o
>  OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o
> libwebpenc.o
>  OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o
> libwebpenc_animencoder.o
>  OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index c42aba140d..223f8bbf15 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -768,6 +768,7 @@ extern AVCodec ff_libvpx_vp9_decoder;
>  /* preferred over libwebp */
>  extern const AVCodec ff_libwebp_anim_encoder;
>  extern const AVCodec ff_libwebp_encoder;
> +extern const AVCodec ff_libwebp_decoder;
>  extern const AVCodec ff_libx262_encoder;
>  #if CONFIG_LIBX264_ENCODER
>  #include 
> diff --git a/libavcodec/libwebpdec.c b/libavcodec/libwebpdec.c
> new file mode 100644
> index 00..c583f919e0
> --- /dev/null
> +++ b/libavcodec/libwebpdec.c
> @@ -0,0 +1,419 @@
> +/*
> + * WebP decoding support via libwebp
> + * Copyright (c) 2021 Martin Reboredo 
> + *
> + * 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
> + * WebP decoder using libwebp (WebPDecode API)
> + */
> +
> +#include 
> +#include 
> +
> +#include "decode.h"
> +#include "internal.h"
> +#include "libavutil/colorspace.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/error.h"
> +#include "libavutil/opt.h"
> +
> +struct WebPDecBgColor {
> +uint8_t y;
> +uint8_t u;
> +uint8_t v;
> +uint8_t a;
> +};
> +
> +typedef struct LibWebPDecContext {
> +AVClass *class; // class for 

Re: [FFmpeg-devel] [PATCH v3 1/4] avcodec/webp: compatibilize with avformat/webpdec

2021-09-12 Thread Andreas Rheinhardt
Martin Reboredo:
> The demuxer implementation splits some RIFF chunks (`RIFF`/`VP8X`/`ANMF` + 
> frame chunk) or sends the picture chunks separately.
> The internal WebP decoder waits for a complete file instead and by 
> consequence it needs to be modified to support this kind of fractioned input.
> 
> Fixes FATE tests with WebP.
> 
> Signed-off-by: Martin Reboredo 
> ---
>  libavcodec/webp.c | 41 -
>  1 file changed, 32 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
> index 3efd4438d9..7858d69481 100644
> --- a/libavcodec/webp.c
> +++ b/libavcodec/webp.c
> @@ -40,6 +40,7 @@
>   *   - XMP metadata
>   */
>  
> +#include "libavformat/internal.h"
>  #include "libavutil/imgutils.h"
>  
>  #define BITSTREAM_READER_LE
> @@ -191,6 +192,7 @@ typedef struct WebPContext {
>  AVFrame *alpha_frame;   /* AVFrame for alpha data 
> decompressed from VP8L */
>  AVPacket *pkt;  /* AVPacket to be passed to the 
> underlying VP8 decoder */
>  AVCodecContext *avctx;  /* parent AVCodecContext */
> +int read_header;/* RIFF header has been read */
>  int initialized;/* set once the VP8 context is 
> initialized */
>  int has_alpha;  /* has a separate alpha chunk */
>  enum AlphaCompression alpha_compression; /* compression type for alpha 
> chunk */
> @@ -1353,17 +1355,36 @@ static int webp_decode_frame(AVCodecContext *avctx, 
> void *data, int *got_frame,
>  if (bytestream2_get_bytes_left(&gb) < 12)
>  return AVERROR_INVALIDDATA;
>  
> -if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
> -av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
> -return AVERROR_INVALIDDATA;
> -}
> -
> +chunk_type = bytestream2_get_le32(&gb);
>  chunk_size = bytestream2_get_le32(&gb);
> -if (bytestream2_get_bytes_left(&gb) < chunk_size)
> -return AVERROR_INVALIDDATA;
>  
> -if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
> -av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
> +for (int i = 0; !s->read_header && i < 4; i++) {
> +ff_lock_avformat();

1. Why are you locking avformat? What is this lock supposed to guard?
2. You can't lock avformat from avcodec at all: The ff_-prefix means
that this function is intra-library (in this case libavformat) only. It
will work with static builds, but it won't work with shared builds.

> +
> +if (s->read_header) {
> +ff_unlock_avformat();
> +break;
> +}
> +
> +if (chunk_type == MKTAG('R', 'I', 'F', 'F')) {
> +int left = bytestream2_get_bytes_left(&gb);
> +if (left < chunk_size && left != 22) {
> +ff_unlock_avformat();
> +return AVERROR_INVALIDDATA;
> +}
> +if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
> +av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
> +ff_unlock_avformat();
> +return AVERROR_INVALIDDATA;
> +}
> +s->read_header = 1;
> +}
> +
> +ff_unlock_avformat();
> +}
> +
> +if (!s->read_header) {
> +av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
>  return AVERROR_INVALIDDATA;
>  }
>  
> @@ -1416,6 +1437,8 @@ static int webp_decode_frame(AVCodecContext *avctx, 
> void *data, int *got_frame,
>  ret = av_image_check_size(s->width, s->height, 0, avctx);
>  if (ret < 0)
>  return ret;
> +if (bytestream2_get_bytes_left(&gb) == 0)
> +return AVERROR(EAGAIN);
>  break;
>  case MKTAG('A', 'L', 'P', 'H'): {
>  int alpha_header, filter_m, compression;
> 

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

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


Re: [FFmpeg-devel] [PATCH v5 00/12] Subtitle Filtering

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Hendrik Leppkes
> Sent: Sunday, 12 September 2021 22:15
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v5 00/12] Subtitle Filtering
> 
> On Sun, Sep 12, 2021 at 10:07 PM Soft Works 
> wrote:
> >
> > All-in-all that doesn't seem to be worth all the hazzle. Again,
> > that brings me back to my original approach:
> >
> 
> It is for us, if its not for you, what can we say.
> The only approach to go forwards is to prepare proper, clean and
> fully
> featured integration that results in a clean API once the deprecation
> period is over and the old stuff can get removed. Anything else would
> be a hack and only serve your desired purpose, not the long-term API
> design of FFmpeg, which unfortunately is just not acceptable.
> If you are interested in doing it properly, we will listen and guide,
> but if not... thats the only way its going to get accepted.

There's no need to start talking like Nicolas, it would be nice
when we could talk about the subject itself instead.

Would you mind to elaborate on what is bad about AVSubtitle and 
attaching it to AVFrames?

Also could you please describe a bit more detailed how you would
envision the initial step to look like, based on my v5 patchset?

IIUC, that would be:

- Keep the added subtitle properties in AVFrame
- Also keep AVSubtitle
- Don't modify the subtitle encoders and decoders and keep them
  working with AVSubtitle
- In the internal ffmpeg processing:
  - without filtering, just forward AVSubtitle from the decoder
to the encoder
  - with filtering: Copy AVSubtitle properties to AVFrame for
filtergraph input, copy back to AVSubtitle at graph output
for feeding into encoders

So yes, please guide me in terms of what you're expecting, that
will be more productive than letting me guess :-)

Thanks,
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] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Nicolas George
Paul B Mahol (12021-09-12):
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |   7 ++
>  libavfilter/Makefile |   1 +
>  libavfilter/af_asdr.c| 197 +++
>  libavfilter/allfilters.c |   1 +
>  4 files changed, 206 insertions(+)
>  create mode 100644 libavfilter/af_asdr.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8f20ccf8c6..6af7344820 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2531,6 +2531,13 @@ noise removed from input signal.
>  
>  This filter supports the all above options as @ref{commands}.
>  
> +@section asdr
> +Measure Audio Signal-to-Distortion Ratio.
> +
> +This filter takes two audio streams for input, and outputs first
> +audio stream.
> +Results are in dB per channel at end of either input.
> +
>  @section asetnsamples
>  
>  Set the number of samples per each output audio frame.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 76c65c3f42..865252ef3f 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -82,6 +82,7 @@ OBJS-$(CONFIG_AREALTIME_FILTER)  += f_realtime.o
>  OBJS-$(CONFIG_ARESAMPLE_FILTER)  += af_aresample.o
>  OBJS-$(CONFIG_AREVERSE_FILTER)   += f_reverse.o
>  OBJS-$(CONFIG_ARNNDN_FILTER) += af_arnndn.o
> +OBJS-$(CONFIG_ASDR_FILTER)   += af_asdr.o
>  OBJS-$(CONFIG_ASEGMENT_FILTER)   += f_segment.o
>  OBJS-$(CONFIG_ASELECT_FILTER)+= f_select.o
>  OBJS-$(CONFIG_ASENDCMD_FILTER)   += f_sendcmd.o
> diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
> new file mode 100644
> index 00..25032445cd
> --- /dev/null
> +++ b/libavfilter/af_asdr.c
> @@ -0,0 +1,197 @@
> +/*
> + * Copyright (c) 2021 Paul B Mahol
> + *
> + * 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/channel_layout.h"
> +#include "libavutil/common.h"
> +#include "libavutil/opt.h"
> +
> +#include "audio.h"
> +#include "avfilter.h"
> +#include "formats.h"
> +#include "filters.h"
> +#include "internal.h"
> +
> +typedef struct AudioSDRContext {
> +int channels;
> +int64_t pts;
> +double *sum_u;
> +double *sum_uv;
> +
> +AVFrame *cache[2];
> +} AudioSDRContext;
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +static const enum AVSampleFormat sample_fmts[] = {
> +AV_SAMPLE_FMT_DBLP,
> +AV_SAMPLE_FMT_NONE
> +};
> +int ret = ff_set_common_all_channel_counts(ctx);
> +if (ret < 0)
> +return ret;
> +
> +ret = ff_set_common_formats_from_list(ctx, sample_fmts);
> +if (ret < 0)
> +return ret;
> +
> +return ff_set_common_all_samplerates(ctx);
> +}
> +
> +static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
> +{
> +AudioSDRContext *s = ctx->priv;
> +
> +for (int ch = 0; ch < u->channels; ch++) {
> +const double *const us = (double *)u->extended_data[ch];
> +const double *const vs = (double *)v->extended_data[ch];
> +double sum_uv = s->sum_uv[ch];
> +double sum_u = s->sum_u[ch];
> +
> +for (int n = 0; n < u->nb_samples; n++) {
> +sum_u  += us[n] * us[n];
> +sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
> +}
> +
> +s->sum_uv[ch] = sum_uv;
> +s->sum_u[ch]  = sum_u;
> +}
> +}
> +
> +static int activate(AVFilterContext *ctx)
> +{
> +AudioSDRContext *s = ctx->priv;
> +int ret, status;
> +int available;
> +int64_t pts;
> +
> +FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
> +
> +available = FFMIN(ff_inlink_queued_samples(ctx->inputs[0]), 
> ff_inlink_queued_samples(ctx->inputs[1]));
> +if (available > 0) {
> +AVFrame *out;
> +
> +for (int i = 0; i < 2; i++) {
> +ret = ff_inlink_consume_samples(ctx->inputs[i], available, 
> available, &s->cache[i]);
> +if (ret > 0) {
> +if (s->pts == AV_NOPTS_VALUE)
> +s->pts = s->cache[i]->pts;
> +}
> +}
> +
> +sdr(ctx, s->cache[0], s->cache[1]);
> +
> +av_frame_free(&s->cache[1]);
> +out = s->cache[0];
> +out->nb_samples =

Re: [FFmpeg-devel] [PATCH v3 1/4] avcodec/webp: compatibilize with avformat/webpdec

2021-09-12 Thread Martin Reboredo
Andreas Rheinhardt:
> Martin Reboredo:
> > The demuxer implementation splits some RIFF chunks (`RIFF`/`VP8X`/`ANMF` + 
> > frame chunk) or sends the picture chunks separately.
> > The internal WebP decoder waits for a complete file instead and by 
> > consequence it needs to be modified to support this kind of fractioned 
> > input.
> >
> > Fixes FATE tests with WebP.
> >
> > Signed-off-by: Martin Reboredo 
> > ---
> >  libavcodec/webp.c | 41 -
> >  1 file changed, 32 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavcodec/webp.c b/libavcodec/webp.c
> > index 3efd4438d9..7858d69481 100644
> > --- a/libavcodec/webp.c
> > +++ b/libavcodec/webp.c
> > @@ -40,6 +40,7 @@
> >   *   - XMP metadata
> >   */
> >  
> > +#include "libavformat/internal.h"
> >  #include "libavutil/imgutils.h"
> >  
> >  #define BITSTREAM_READER_LE
> > @@ -191,6 +192,7 @@ typedef struct WebPContext {
> >  AVFrame *alpha_frame;   /* AVFrame for alpha data 
> > decompressed from VP8L */
> >  AVPacket *pkt;  /* AVPacket to be passed to the 
> > underlying VP8 decoder */
> >  AVCodecContext *avctx;  /* parent AVCodecContext */
> > +int read_header;/* RIFF header has been read */
> >  int initialized;/* set once the VP8 context is 
> > initialized */
> >  int has_alpha;  /* has a separate alpha chunk */
> >  enum AlphaCompression alpha_compression; /* compression type for alpha 
> > chunk */
> > @@ -1353,17 +1355,36 @@ static int webp_decode_frame(AVCodecContext *avctx, 
> > void *data, int *got_frame,
> >  if (bytestream2_get_bytes_left(&gb) < 12)
> >  return AVERROR_INVALIDDATA;
> >  
> > -if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
> > -av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
> > -return AVERROR_INVALIDDATA;
> > -}
> > -
> > +chunk_type = bytestream2_get_le32(&gb);
> >  chunk_size = bytestream2_get_le32(&gb);
> > -if (bytestream2_get_bytes_left(&gb) < chunk_size)
> > -return AVERROR_INVALIDDATA;
> >  
> > -if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
> > -av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
> > +for (int i = 0; !s->read_header && i < 4; i++) {
> > +ff_lock_avformat();
> 
> 1. Why are you locking avformat? What is this lock supposed to guard?
> 2. You can't lock avformat from avcodec at all: The ff_-prefix means
> that this function is intra-library (in this case libavformat) only. It
> will work with static builds, but it won't work with shared builds.

The locking mechanism was meant for parsing the WebP header that is not a 
single image i.e. sending the animated packages. For simple files a situation 
like
this is not going to happen because the entire file was in the package, but for 
animations the parsing turns out to be difficult while using concurrency.
I could do a much better implementation, at the moment I don't have any better 
fixes for it.

As for the libavformat lock guard it was a _horrible_ production error from my 
side, I will submit the fix.

> > +
> > +if (s->read_header) {
> > +ff_unlock_avformat();
> > +break;
> > +}
> > +
> > +if (chunk_type == MKTAG('R', 'I', 'F', 'F')) {
> > +int left = bytestream2_get_bytes_left(&gb);
> > +if (left < chunk_size && left != 22) {
> > +ff_unlock_avformat();
> > +return AVERROR_INVALIDDATA;
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Paul B Mahol
On Sun, Sep 12, 2021 at 10:49 PM Nicolas George  wrote:

> Paul B Mahol (12021-09-12):
> > Signed-off-by: Paul B Mahol 
> > ---
> >  doc/filters.texi |   7 ++
> >  libavfilter/Makefile |   1 +
> >  libavfilter/af_asdr.c| 197 +++
> >  libavfilter/allfilters.c |   1 +
> >  4 files changed, 206 insertions(+)
> >  create mode 100644 libavfilter/af_asdr.c
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 8f20ccf8c6..6af7344820 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -2531,6 +2531,13 @@ noise removed from input signal.
> >
> >  This filter supports the all above options as @ref{commands}.
> >
> > +@section asdr
> > +Measure Audio Signal-to-Distortion Ratio.
> > +
> > +This filter takes two audio streams for input, and outputs first
> > +audio stream.
> > +Results are in dB per channel at end of either input.
> > +
> >  @section asetnsamples
> >
> >  Set the number of samples per each output audio frame.
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index 76c65c3f42..865252ef3f 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -82,6 +82,7 @@ OBJS-$(CONFIG_AREALTIME_FILTER)  +=
> f_realtime.o
> >  OBJS-$(CONFIG_ARESAMPLE_FILTER)  += af_aresample.o
> >  OBJS-$(CONFIG_AREVERSE_FILTER)   += f_reverse.o
> >  OBJS-$(CONFIG_ARNNDN_FILTER) += af_arnndn.o
> > +OBJS-$(CONFIG_ASDR_FILTER)   += af_asdr.o
> >  OBJS-$(CONFIG_ASEGMENT_FILTER)   += f_segment.o
> >  OBJS-$(CONFIG_ASELECT_FILTER)+= f_select.o
> >  OBJS-$(CONFIG_ASENDCMD_FILTER)   += f_sendcmd.o
> > diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
> > new file mode 100644
> > index 00..25032445cd
> > --- /dev/null
> > +++ b/libavfilter/af_asdr.c
> > @@ -0,0 +1,197 @@
> > +/*
> > + * Copyright (c) 2021 Paul B Mahol
> > + *
> > + * 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/channel_layout.h"
> > +#include "libavutil/common.h"
> > +#include "libavutil/opt.h"
> > +
> > +#include "audio.h"
> > +#include "avfilter.h"
> > +#include "formats.h"
> > +#include "filters.h"
> > +#include "internal.h"
> > +
> > +typedef struct AudioSDRContext {
> > +int channels;
> > +int64_t pts;
> > +double *sum_u;
> > +double *sum_uv;
> > +
> > +AVFrame *cache[2];
> > +} AudioSDRContext;
> > +
> > +static int query_formats(AVFilterContext *ctx)
> > +{
> > +static const enum AVSampleFormat sample_fmts[] = {
> > +AV_SAMPLE_FMT_DBLP,
> > +AV_SAMPLE_FMT_NONE
> > +};
> > +int ret = ff_set_common_all_channel_counts(ctx);
> > +if (ret < 0)
> > +return ret;
> > +
> > +ret = ff_set_common_formats_from_list(ctx, sample_fmts);
> > +if (ret < 0)
> > +return ret;
> > +
> > +return ff_set_common_all_samplerates(ctx);
> > +}
> > +
> > +static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame
> *v)
> > +{
> > +AudioSDRContext *s = ctx->priv;
> > +
> > +for (int ch = 0; ch < u->channels; ch++) {
> > +const double *const us = (double *)u->extended_data[ch];
> > +const double *const vs = (double *)v->extended_data[ch];
> > +double sum_uv = s->sum_uv[ch];
> > +double sum_u = s->sum_u[ch];
> > +
> > +for (int n = 0; n < u->nb_samples; n++) {
> > +sum_u  += us[n] * us[n];
> > +sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
> > +}
> > +
> > +s->sum_uv[ch] = sum_uv;
> > +s->sum_u[ch]  = sum_u;
> > +}
> > +}
> > +
> > +static int activate(AVFilterContext *ctx)
> > +{
> > +AudioSDRContext *s = ctx->priv;
> > +int ret, status;
> > +int available;
> > +int64_t pts;
> > +
> > +FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
> > +
> > +available = FFMIN(ff_inlink_queued_samples(ctx->inputs[0]),
> ff_inlink_queued_samples(ctx->inputs[1]));
> > +if (available > 0) {
> > +AVFrame *out;
> > +
> > +for (int i = 0; i < 2; i++) {
> > +ret = ff_inlink_consume_samples(ctx->inputs[i], available,
> available, &s

Re: [FFmpeg-devel] [PATCH] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Nicolas George
Paul B Mahol (12021-09-12):
> Yes, it is called down bellow few lines.

Indeed, but only if frame_wanted is set on the output. And it is conform
with all that is currently done, but there is something missing in all
filters with multiple inputs to make them work with a purely
input-driven scheme. I need to think about it. Do not consider this
blocking.

Regards,

-- 
  Nicolas George


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 v3 1/4] avcodec/webp: compatibilize with avformat/webpdec

2021-09-12 Thread Andreas Rheinhardt
Martin Reboredo:
> Andreas Rheinhardt:
>> Martin Reboredo:
>>> The demuxer implementation splits some RIFF chunks (`RIFF`/`VP8X`/`ANMF` + 
>>> frame chunk) or sends the picture chunks separately.
>>> The internal WebP decoder waits for a complete file instead and by 
>>> consequence it needs to be modified to support this kind of fractioned 
>>> input.
>>>
>>> Fixes FATE tests with WebP.

If this fixes fate tests, then you need to update the fate reference
files in the patch that changes fate output.

>>>
>>> Signed-off-by: Martin Reboredo 
>>> ---
>>>  libavcodec/webp.c | 41 -
>>>  1 file changed, 32 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
>>> index 3efd4438d9..7858d69481 100644
>>> --- a/libavcodec/webp.c
>>> +++ b/libavcodec/webp.c
>>> @@ -40,6 +40,7 @@
>>>   *   - XMP metadata
>>>   */
>>>  
>>> +#include "libavformat/internal.h"
>>>  #include "libavutil/imgutils.h"
>>>  
>>>  #define BITSTREAM_READER_LE
>>> @@ -191,6 +192,7 @@ typedef struct WebPContext {
>>>  AVFrame *alpha_frame;   /* AVFrame for alpha data 
>>> decompressed from VP8L */
>>>  AVPacket *pkt;  /* AVPacket to be passed to the 
>>> underlying VP8 decoder */
>>>  AVCodecContext *avctx;  /* parent AVCodecContext */
>>> +int read_header;/* RIFF header has been read */
>>>  int initialized;/* set once the VP8 context is 
>>> initialized */
>>>  int has_alpha;  /* has a separate alpha chunk */
>>>  enum AlphaCompression alpha_compression; /* compression type for alpha 
>>> chunk */
>>> @@ -1353,17 +1355,36 @@ static int webp_decode_frame(AVCodecContext *avctx, 
>>> void *data, int *got_frame,
>>>  if (bytestream2_get_bytes_left(&gb) < 12)
>>>  return AVERROR_INVALIDDATA;
>>>  
>>> -if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
>>> -av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
>>> -return AVERROR_INVALIDDATA;
>>> -}
>>> -
>>> +chunk_type = bytestream2_get_le32(&gb);
>>>  chunk_size = bytestream2_get_le32(&gb);
>>> -if (bytestream2_get_bytes_left(&gb) < chunk_size)
>>> -return AVERROR_INVALIDDATA;
>>>  
>>> -if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
>>> -av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
>>> +for (int i = 0; !s->read_header && i < 4; i++) {
>>> +ff_lock_avformat();
>>
>> 1. Why are you locking avformat? What is this lock supposed to guard?
>> 2. You can't lock avformat from avcodec at all: The ff_-prefix means
>> that this function is intra-library (in this case libavformat) only. It
>> will work with static builds, but it won't work with shared builds.
> 
> The locking mechanism was meant for parsing the WebP header that is not a 
> single image i.e. sending the animated packages. For simple files a situation 
> like
> this is not going to happen because the entire file was in the package, but 
> for animations the parsing turns out to be difficult while using concurrency.
> I could do a much better implementation, at the moment I don't have any 
> better fixes for it.
> 

This does not answer my first question at all: What is it supposed to
guard? What data race would there be if you didn't lock at all?
(I do not see why you need a lock at all.)

> As for the libavformat lock guard it was a _horrible_ production error from 
> my side, I will submit the fix.
> 
>>> +
>>> +if (s->read_header) {
>>> +ff_unlock_avformat();
>>> +break;
>>> +}
>>> +
>>> +if (chunk_type == MKTAG('R', 'I', 'F', 'F')) {
>>> +int left = bytestream2_get_bytes_left(&gb);
>>> +if (left < chunk_size && left != 22) {
>>> +ff_unlock_avformat();
>>> +return AVERROR_INVALIDDATA;
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Paul B Mahol
On Sun, Sep 12, 2021 at 11:06 PM Nicolas George  wrote:

> Paul B Mahol (12021-09-12):
> > Yes, it is called down bellow few lines.
>
> Indeed, but only if frame_wanted is set on the output. And it is conform
> with all that is currently done, but there is something missing in all
> filters with multiple inputs to make them work with a purely
> input-driven scheme. I need to think about it. Do not consider this
> blocking.
>

Why purely input-driven scheme is wanted/needed to be supported?


>
> Regards,
>
> --
>   Nicolas George
> ___
> 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 v5 10/12] avfilter/textmod: Add textmod filter

2021-09-12 Thread Andreas Rheinhardt
Soft Works:
> Signed-off-by: softworkz 
> ---
>  doc/filters.texi |  64 +++
>  libavfilter/Makefile |   3 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/sf_textmod.c | 381 +++
>  4 files changed, 449 insertions(+)
>  create mode 100644 libavfilter/sf_textmod.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 1d76461ada..9fd2876d63 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -25024,6 +25024,70 @@ existing filters using @code{--disable-filters}.
>  
>  Below is a description of the currently available subtitle filters.
>  
> +@section textmod
> +
> +Modify subtitle text in a number of ways.
> +
> +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 replace
> +Required for replace_chars and replace_words.
> +
> +@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
> +Mark the 100-pixel-wide region on the left edge of the frame as very
> +uninteresting (to be encoded at much lower quality than the rest of
> +the frame).
> +@example
> +addroi=0:0:100:ih:+1/5
> +@end example
> +@end itemize
> +
>  @section graphicsub2video
>  
>  Renders graphic subtitles as video frames. 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 0e752c5bf9..5a5a4be47e 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -534,6 +534,9 @@ OBJS-$(CONFIG_YUVTESTSRC_FILTER) += 
> vsrc_testsrc.o
>  
>  OBJS-$(CONFIG_NULLSINK_FILTER)   += vsink_nullsink.o
>  
> +# subtitle filters
> +OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
> +
>  # multimedia filters
>  OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
>  OBJS-$(CONFIG_ADRAWGRAPH_FILTER) += f_drawgraph.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 77463aa4c8..6d7a535ee8 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -524,6 +524,7 @@ extern const AVFilter ff_avf_showvolume;
>  extern const AVFilter ff_avf_showwaves;
>  extern const AVFilter ff_avf_showwavespic;
>  extern const AVFilter ff_vaf_spectrumsynth;
> +extern const AVFilter ff_sf_textmod;
>  extern const AVFilter ff_svf_graphicsub2video;
>  extern const AVFilter ff_svf_textsub2video;
>  
> diff --git a/libavfilter/sf_textmod.c b/libavfilter/sf_textmod.c
> new file mode 100644
> index 00..7c23ded9ef
> --- /dev/null
> +++ b/libavfilter/sf_textmod.c
> @@ -0,0 +1,381 @@
> +/*
> + * 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 WARRAN

Re: [FFmpeg-devel] [PATCH v5 02/12] global: Merge AVSubtitle into AVFrame

2021-09-12 Thread Andreas Rheinhardt
Soft Works:
> Signed-off-by: softworkz 
> ---

> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index ef2867d318..1855de9b3d 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -72,7 +72,12 @@ static void get_frame_defaults(AVFrame *frame)
>  frame->colorspace  = AVCOL_SPC_UNSPECIFIED;
>  frame->color_range = AVCOL_RANGE_UNSPECIFIED;
>  frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
> -frame->flags   = 0;
> +frame->subtitle_start_time = 0;
> +frame->subtitle_end_time   = 0;
> +frame->num_subtitle_rects  = 0;
> +frame->subtitle_rects  = NULL;
> +frame->subtitle_pts= 0;
> +frame->subtitle_header = NULL;
>  }
>  
>  static void free_side_data(AVFrameSideData **ptr_sd)
> @@ -306,6 +311,9 @@ static int frame_copy_props(AVFrame *dst, const AVFrame 
> *src, int force_copy)
>  dst->colorspace = src->colorspace;
>  dst->color_range= src->color_range;
>  dst->chroma_location= src->chroma_location;
> +dst->subtitle_start_time= src->subtitle_start_time;
> +dst->subtitle_end_time  = src->subtitle_end_time;
> +dst->subtitle_pts   = src->subtitle_pts;
>  
>  av_dict_copy(&dst->metadata, src->metadata, 0);
>  
> @@ -359,6 +367,19 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
>  if (ret < 0)
>  goto fail;
>  
> +/* duplicate subtitle rects */
> +dst->num_subtitle_rects = src->num_subtitle_rects;
> +
> +if (src->num_subtitle_rects) {
> +dst->subtitle_rects = av_malloc_array(src->num_subtitle_rects, 
> sizeof(AVSubtitleRect *));
> +
> +for (i = 0; i < src->num_subtitle_rects; i++) {
> +AVSubtitleRect *rect = src->subtitle_rects[i];
> +rect->nb_refs++;
> +dst->subtitle_rects[i] = rect;
> +}
> +}
> +
>  /* duplicate the frame data if it's not refcounted */
>  if (!src->buf[0]) {
>  ret = av_frame_get_buffer2(dst, 0);
> @@ -472,6 +493,24 @@ void av_frame_unref(AVFrame *frame)
>  av_buffer_unref(&frame->opaque_ref);
>  av_buffer_unref(&frame->private_ref);
>  
> +for (i = 0; i < frame->num_subtitle_rects; i++) {
> +AVSubtitleRect *rect = frame->subtitle_rects[i];
> +
> +if (rect && rect->nb_refs > 0)
> +rect->nb_refs--;
> +else {
> +av_freep(&rect->data[0]);
> +av_freep(&rect->data[1]);
> +av_freep(&rect->data[2]);
> +av_freep(&rect->data[3]);
> +av_freep(&rect->text);
> +av_freep(&rect->ass);
> +av_freep(&rect);

This should better be av_freep(&frame->subtitle_rects[i]);

> +}
> +}
> +
> +av_freep(&frame->subtitle_rects);
> +
>  get_frame_defaults(frame);
>  }
>  
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 005eed9d18..4e2cfe19b3 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"
>  
>  
> @@ -469,6 +470,17 @@ typedef struct AVFrame {
>   */
>  uint64_t channel_layout;
>  
> +uint32_t subtitle_start_time; /* display start time, relative to packet 
> pts, in ms */
> +uint32_t subtitle_end_time; /* display end time, relative to packet pts, 
> in ms */
> +unsigned num_subtitle_rects;
> +AVSubtitleRect **subtitle_rects;
> +int64_t subtitle_pts;///< Same as packet pts, in AV_TIME_BASE
> +
> +/**
> + * Header containing style information for text subtitles.
> + */
> +char *subtitle_header;
> +
>  /**
>   * 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
> diff --git a/libavutil/subfmt.c b/libavutil/subfmt.c
> new file mode 100644
> index 00..9a19d01aa3
> --- /dev/null
> +++ b/libavutil/subfmt.c
> @@ -0,0 +1,52 @@
> +/*
> + * 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 
> +#include "common.h"
> +#include "subfmt.h"
> +
> +typedef struct SubtitleFmtInfo {

Re: [FFmpeg-devel] [PATCH v5 01/12] avutil/frame: Subtitle Filtering - Add AVMediaType property to AVFrame

2021-09-12 Thread Andreas Rheinhardt
Soft Works:
> This is the root commit for adding subtitle filtering capabilities.
> Adding the media type property to AVFrame replaces the previous
> way of distinction which was based on checking width and height
> to determine whether a frame is audio or video.
> 
> Signed-off-by: softworkz 
> ---
>  libavutil/frame.c   | 85 -
>  libavutil/frame.h   | 39 +++--
>  libavutil/version.h |  2 +-
>  3 files changed, 106 insertions(+), 20 deletions(-)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index b0ceaf7145..ef2867d318 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -103,6 +103,7 @@ AVFrame *av_frame_alloc(void)
>  if (!frame)
>  return NULL;
>  
> +frame->type = AVMEDIA_TYPE_UNKNOWN;
>  frame->extended_data = NULL;
>  get_frame_defaults(frame);
>  
> @@ -244,22 +245,37 @@ static int get_audio_buffer(AVFrame *frame, int align)
>  }
>  
>  int av_frame_get_buffer(AVFrame *frame, int align)
> +{
> +if (frame->width > 0 && frame->height > 0)
> +frame->type = AVMEDIA_TYPE_VIDEO;
> +else if (frame->nb_samples > 0 && (frame->channel_layout || 
> frame->channels > 0))
> +frame->type = AVMEDIA_TYPE_AUDIO;
> +
> +return av_frame_get_buffer2(frame, align);
> +}
> +
> +int av_frame_get_buffer2(AVFrame *frame, int align)
>  {
>  if (frame->format < 0)
>  return AVERROR(EINVAL);
>  
> -if (frame->width > 0 && frame->height > 0)
> +switch(frame->type) {
> +case AVMEDIA_TYPE_VIDEO:
>  return get_video_buffer(frame, align);
> -else if (frame->nb_samples > 0 && (frame->channel_layout || 
> frame->channels > 0))
> +case AVMEDIA_TYPE_AUDIO:
>  return get_audio_buffer(frame, align);
> -
> -return AVERROR(EINVAL);
> +case AVMEDIA_TYPE_SUBTITLE:
> +return 0;

Making this a no-op (and keeping it a no-op in future commits) implies
that av_frame_make_writable() does not work for subtitles at all: It
just temporarily increments the refcount of all the AVSubtitleRects and
then decrements it again, so they are still shared. But it needs to do a
deep copy (in case the frame isn't writable).

> +default:
> +return AVERROR(EINVAL);
> +}
>  }
>  
>  static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
>  {
>  int ret, i;
>  
> +dst->type   = src->type;
>  dst->key_frame  = src->key_frame;
>  dst->pict_type  = src->pict_type;
>  dst->sample_aspect_ratio= src->sample_aspect_ratio;
> @@ -331,6 +347,7 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
>  av_assert1(dst->width == 0 && dst->height == 0);
>  av_assert1(dst->channels == 0);
>  
> +dst->type   = src->type;
>  dst->format = src->format;
>  dst->width  = src->width;
>  dst->height = src->height;
> @@ -344,7 +361,7 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
>  
>  /* duplicate the frame data if it's not refcounted */
>  if (!src->buf[0]) {
> -ret = av_frame_get_buffer(dst, 0);
> +ret = av_frame_get_buffer2(dst, 0);
>  if (ret < 0)
>  goto fail;
>  
> @@ -499,6 +516,7 @@ int av_frame_make_writable(AVFrame *frame)
>  return 0;
>  
>  memset(&tmp, 0, sizeof(tmp));
> +tmp.type   = frame->type;
>  tmp.format = frame->format;
>  tmp.width  = frame->width;
>  tmp.height = frame->height;
> @@ -509,7 +527,7 @@ int av_frame_make_writable(AVFrame *frame)
>  if (frame->hw_frames_ctx)
>  ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0);
>  else
> -ret = av_frame_get_buffer(&tmp, 0);
> +ret = av_frame_get_buffer2(&tmp, 0);
>  if (ret < 0)
>  return ret;
>  
> @@ -544,14 +562,22 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, 
> int plane)
>  uint8_t *data;
>  int planes, i;
>  
> -if (frame->nb_samples) {
> -int channels = frame->channels;
> -if (!channels)
> -return NULL;
> -CHECK_CHANNELS_CONSISTENCY(frame);
> -planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
> -} else
> +switch(frame->type) {
> +case AVMEDIA_TYPE_VIDEO:
>  planes = 4;
> +break;
> +case AVMEDIA_TYPE_AUDIO:
> +{
> +int channels = frame->channels;
> +if (!channels)
> +return NULL;
> +CHECK_CHANNELS_CONSISTENCY(frame);
> +planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
> +break;
> +}
> +default:
> +return NULL;
> +}
>  
>  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
>  return NULL;
> @@ -675,17 +701,42 @@ static int frame_copy_audio(AVFrame *dst, const AVFrame 
> *src)
>  return 0;
>  }
>  
> +static int frame_copy_subtitles(AVFrame 

Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add textmod filter

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Andreas Rheinhardt
> Sent: Sunday, 12 September 2021 23:56
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add
> textmod filter
> 
> Soft Works:
> > Signed-off-by: softworkz 
> > ---
> >  doc/filters.texi |  64 +++
> >  libavfilter/Makefile |   3 +
> >  libavfilter/allfilters.c |   1 +
> >  libavfilter/sf_textmod.c | 381
> +++
> >  4 files changed, 449 insertions(+)
> >  create mode 100644 libavfilter/sf_textmod.c
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 1d76461ada..9fd2876d63 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -25024,6 +25024,70 @@ existing filters using @code{--disable-
> filters}.

[...]

> > +static void uninit(AVFilterContext *ctx)
> > +{
> > +TextModContext *s = ctx->priv;
> > +int i;
> > +
> > +for (i = 0; i < s->nb_find_list; i++) {
> > +av_free(&s->find_list[i]);
> 
> This is completely wrong and will crash: You either want to do
> av_freep(&s->find_list[i]) or av_free(s->find_list[i]) if these
> strings
> were independently allocated; but looking at split_string() shows
> that
> they are not, they are substrings of s->find. Similar for the loop
> below.

You are right of course, thanks.

> > +}
> > +s->nb_find_list = 0;
> > +av_freep(&s->find_list);
> > +
> > +for (i = 0; i < s->nb_replace_list; i++) {
> > +av_free(&s->replace_list[i]);
> > +}
> > +s->nb_replace_list = 0;
> > +av_freep(&s->replace_list);
> > +}
> > +
> > +static int query_formats(AVFilterContext *ctx)
> > +{
> > +AVFilterFormats *formats;
> > +AVFilterLink *inlink = ctx->inputs[0];
> > +AVFilterLink *outlink = ctx->outputs[0];
> > +static const enum AVSubtitleType subtitle_fmts[] = {
> AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NONE };
> > +int ret;
> > +
> > +/* set input subtitle format */
> > +formats = ff_make_format_list(subtitle_fmts);
> > +if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) <
> 0)
> > +return ret;
> > +
> > +/* set output video format */
> > +if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) <
> 0)
> > +return ret;
> > +
> > +return 0;
> > +}
> > +
> > +static char *process_text(TextModContext *s, char *text)
> > +{
> > +const char *char_src = s->find;
> > +const char *char_dst = s->replace;
> > +char *result = NULL;
> > +int escape_level = 0, k = 0;
> > +
> > +switch (s->operation) {
> > +case OP_LEET:
> > +case OP_REPLACE_CHARS:
> > +
> > +if (s->operation == OP_LEET) {
> > +char_src = leet_src;
> > +char_dst = leet_dst;
> > +}
> > +
> > +result = av_strdup(text);
> > +if (!result)
> > +return NULL;
> > +
> > +for (size_t n = 0; n < strlen(result); n++) {
> > +if (result[n] == '{')
> > +escape_level++;
> > +
> > +if (!escape_level) {
> > +for (size_t t = 0; t < FF_ARRAY_ELEMS(char_src);
> t++) {
> > +if (result[n] == char_src[t]) {
> > +result[n] = char_dst[t];
> > +break;
> > +}
> > +}
> > +}
> > +
> > +if (result[n] == '}')
> > +escape_level--;
> > +}
> > +
> > +break;
> > +case OP_TO_UPPER:
> > +case OP_TO_LOWER:
> > +
> > +result = av_strdup(text);
> > +if (!result)
> > +return NULL;
> > +
> > +for (size_t n = 0; n < strlen(result); n++) {
> > +if (result[n] == '{')
> > +escape_level++;
> > +if (!escape_level)
> > +result[n] = s->operation == OP_TO_LOWER ?
> av_tolower(result[n]) : av_toupper(result[n]);
> > +if (result[n] == '}')
> > +escape_level--;
> > +}
> > +
> > +break;
> > +case OP_REMOVE_CHARS:
> > +
> > +result = av_strdup(text);
> > +if (!result)
> > +return NULL;
> > +
> > +for (size_t n = 0; n < strlen(result); n++) {
> > +int skip_char = 0;
> > +
> > +if (result[n] == '{')
> > +escape_level++;
> > +
> > +if (!escape_level) {
> > +for (size_t t = 0; t < FF_ARRAY_ELEMS(char_src);
> t++) {
> > +if (result[n] == char_src[t]) {
> > +skip_char = 1;
> > +break;
> > +}
> > +}
> > +}
> > +
> > +if (!skip_char)
> > +result[k++] = result[n];
> > +
> > +if (result[n] == '}')
> > +escape_level--;
> > +}
> > +
> > +result[k] = 0;
> > +
> > +break;
> > +case OP_REPLACE_WORDS:
> > +case OP_RE

Re: [FFmpeg-devel] [PATCH v3 1/4] avcodec/webp: compatibilize with avformat/webpdec

2021-09-12 Thread Martin Reboredo
Andreas Rheinhardt:
> Martin Reboredo:
> > Andreas Rheinhardt:
> >> Martin Reboredo:
> >>> The demuxer implementation splits some RIFF chunks (`RIFF`/`VP8X`/`ANMF` 
> >>> + frame chunk) or sends the picture chunks separately.
> >>> The internal WebP decoder waits for a complete file instead and by 
> >>> consequence it needs to be modified to support this kind of fractioned 
> >>> input.
> >>>
> >>> Fixes FATE tests with WebP.
> 
> If this fixes fate tests, then you need to update the fate reference
> files in the patch that changes fate output.
> 

In this case the fix was meant for passing FATE not fixing it by itself, I will 
clarify in the next update.

> >>>
> >>> Signed-off-by: Martin Reboredo 
> >>> ---
> >>>  libavcodec/webp.c | 41 -
> >>>  1 file changed, 32 insertions(+), 9 deletions(-)
> >>>
> >>> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
> >>> index 3efd4438d9..7858d69481 100644
> >>> --- a/libavcodec/webp.c
> >>> +++ b/libavcodec/webp.c
> >>> @@ -40,6 +40,7 @@
> >>>   *   - XMP metadata
> >>>   */
> >>>  
> >>> +#include "libavformat/internal.h"
> >>>  #include "libavutil/imgutils.h"
> >>>  
> >>>  #define BITSTREAM_READER_LE
> >>> @@ -191,6 +192,7 @@ typedef struct WebPContext {
> >>>  AVFrame *alpha_frame;   /* AVFrame for alpha data 
> >>> decompressed from VP8L */
> >>>  AVPacket *pkt;  /* AVPacket to be passed to the 
> >>> underlying VP8 decoder */
> >>>  AVCodecContext *avctx;  /* parent AVCodecContext */
> >>> +int read_header;/* RIFF header has been read */
> >>>  int initialized;/* set once the VP8 context is 
> >>> initialized */
> >>>  int has_alpha;  /* has a separate alpha chunk */
> >>>  enum AlphaCompression alpha_compression; /* compression type for 
> >>> alpha chunk */
> >>> @@ -1353,17 +1355,36 @@ static int webp_decode_frame(AVCodecContext 
> >>> *avctx, void *data, int *got_frame,
> >>>  if (bytestream2_get_bytes_left(&gb) < 12)
> >>>  return AVERROR_INVALIDDATA;
> >>>  
> >>> -if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
> >>> -av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
> >>> -return AVERROR_INVALIDDATA;
> >>> -}
> >>> -
> >>> +chunk_type = bytestream2_get_le32(&gb);
> >>>  chunk_size = bytestream2_get_le32(&gb);
> >>> -if (bytestream2_get_bytes_left(&gb) < chunk_size)
> >>> -return AVERROR_INVALIDDATA;
> >>>  
> >>> -if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
> >>> -av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
> >>> +for (int i = 0; !s->read_header && i < 4; i++) {
> >>> +ff_lock_avformat();
> >>
> >> 1. Why are you locking avformat? What is this lock supposed to guard?
> >> 2. You can't lock avformat from avcodec at all: The ff_-prefix means
> >> that this function is intra-library (in this case libavformat) only. It
> >> will work with static builds, but it won't work with shared builds.
> > 
> > The locking mechanism was meant for parsing the WebP header that is not a 
> > single image i.e. sending the animated packages. For simple files a 
> > situation like
> > this is not going to happen because the entire file was in the package, but 
> > for animations the parsing turns out to be difficult while using 
> > concurrency.
> > I could do a much better implementation, at the moment I don't have any 
> > better fixes for it.
> > 
>
> This does not answer my first question at all: What is it supposed to
> guard? What data race would there be if you didn't lock at all?
> (I do not see why you need a lock at all.)

The lock purpose was meant to synchronize the WebP header parsing with the 
arriving packages in the case of feeding an animated image (behaviour 
introduced by
my demuxer implementation).

Taking a better look on this makes me think that the internal codec 
(avcodec/webp) does an unnecessary parsing plus demuxing step that could be 
realized by
libavformat itself. A much better procedure might be achieved by sending only 
the RIFF chunks that contain decode parameters and/or frame data to the decoder
and omit sending the RIFF header altogether as we already know that the file is 
a valid WebP file to begin with. This of course involves tweaking
avformat/webpenc too (alongside my patchset of course). Any thoughts on this?

> > As for the libavformat lock guard it was a _horrible_ production error from 
> > my side, I will submit the fix.
> > 
> >>> +
> >>> +if (s->read_header) {
> >>> +ff_unlock_avformat();
> >>> +break;
> >>> +}
> >>> +
> >>> +if (chunk_type == MKTAG('R', 'I', 'F', 'F')) {
> >>> +int left = bytestream2_get_bytes_left(&gb);
> >>> +if (left < chunk_size && left != 22) {
> >>> +ff_unlock_avformat();
> >>> +return AVERROR_INVALIDDATA;

Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add textmod filter

2021-09-12 Thread Lynne
13 Sept 2021, 00:34 by softwo...@hotmail.com:

>
>
>> -Original Message-
>> From: ffmpeg-devel  On Behalf Of
>> Andreas Rheinhardt
>> Sent: Sunday, 12 September 2021 23:56
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add
>> textmod filter
>>
>> Soft Works:
>> > Signed-off-by: softworkz 
>> > ---
>> >  doc/filters.texi |  64 +++
>> >  libavfilter/Makefile |   3 +
>> >  libavfilter/allfilters.c |   1 +
>> >  libavfilter/sf_textmod.c | 381
>> +++
>> >  4 files changed, 449 insertions(+)
>> >  create mode 100644 libavfilter/sf_textmod.c
>> >
>> > diff --git a/doc/filters.texi b/doc/filters.texi
>> > index 1d76461ada..9fd2876d63 100644
>> > --- a/doc/filters.texi
>> > +++ b/doc/filters.texi
>> > @@ -25024,6 +25024,70 @@ existing filters using @code{--disable-
>> filters}.
>>
>
> [...]
>
>> > +static void uninit(AVFilterContext *ctx)
>> > +{
>> > +TextModContext *s = ctx->priv;
>> > +int i;
>> > +
>> > +for (i = 0; i < s->nb_find_list; i++) {
>> > +av_free(&s->find_list[i]);
>>
>> This is completely wrong and will crash: You either want to do
>> av_freep(&s->find_list[i]) or av_free(s->find_list[i]) if these
>> strings
>> were independently allocated; but looking at split_string() shows
>> that
>> they are not, they are substrings of s->find. Similar for the loop
>> below.
>>
>
> You are right of course, thanks.
>
>> > +}
>> > +s->nb_find_list = 0;
>> > +av_freep(&s->find_list);
>> > +
>> > +for (i = 0; i < s->nb_replace_list; i++) {
>> > +av_free(&s->replace_list[i]);
>> > +}
>> > +s->nb_replace_list = 0;
>> > +av_freep(&s->replace_list);
>> > +}
>> > +
>> > +static int query_formats(AVFilterContext *ctx)
>> > +{
>> > +AVFilterFormats *formats;
>> > +AVFilterLink *inlink = ctx->inputs[0];
>> > +AVFilterLink *outlink = ctx->outputs[0];
>> > +static const enum AVSubtitleType subtitle_fmts[] = {
>> AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NONE };
>> > +int ret;
>> > +
>> > +/* set input subtitle format */
>> > +formats = ff_make_format_list(subtitle_fmts);
>> > +if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) <
>> 0)
>> > +return ret;
>> > +
>> > +/* set output video format */
>> > +if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) <
>> 0)
>> > +return ret;
>> > +
>> > +return 0;
>> > +}
>> > +
>> > +static char *process_text(TextModContext *s, char *text)
>> > +{
>> > +const char *char_src = s->find;
>> > +const char *char_dst = s->replace;
>> > +char *result = NULL;
>> > +int escape_level = 0, k = 0;
>> > +
>> > +switch (s->operation) {
>> > +case OP_LEET:
>> > +case OP_REPLACE_CHARS:
>> > +
>> > +if (s->operation == OP_LEET) {
>> > +char_src = leet_src;
>> > +char_dst = leet_dst;
>> > +}
>> > +
>> > +result = av_strdup(text);
>> > +if (!result)
>> > +return NULL;
>> > +
>> > +for (size_t n = 0; n < strlen(result); n++) {
>> > +if (result[n] == '{')
>> > +escape_level++;
>> > +
>> > +if (!escape_level) {
>> > +for (size_t t = 0; t < FF_ARRAY_ELEMS(char_src);
>> t++) {
>> > +if (result[n] == char_src[t]) {
>> > +result[n] = char_dst[t];
>> > +break;
>> > +}
>> > +}
>> > +}
>> > +
>> > +if (result[n] == '}')
>> > +escape_level--;
>> > +}
>> > +
>> > +break;
>> > +case OP_TO_UPPER:
>> > +case OP_TO_LOWER:
>> > +
>> > +result = av_strdup(text);
>> > +if (!result)
>> > +return NULL;
>> > +
>> > +for (size_t n = 0; n < strlen(result); n++) {
>> > +if (result[n] == '{')
>> > +escape_level++;
>> > +if (!escape_level)
>> > +result[n] = s->operation == OP_TO_LOWER ?
>> av_tolower(result[n]) : av_toupper(result[n]);
>> > +if (result[n] == '}')
>> > +escape_level--;
>> > +}
>> > +
>> > +break;
>> > +case OP_REMOVE_CHARS:
>> > +
>> > +result = av_strdup(text);
>> > +if (!result)
>> > +return NULL;
>> > +
>> > +for (size_t n = 0; n < strlen(result); n++) {
>> > +int skip_char = 0;
>> > +
>> > +if (result[n] == '{')
>> > +escape_level++;
>> > +
>> > +if (!escape_level) {
>> > +for (size_t t = 0; t < FF_ARRAY_ELEMS(char_src);
>> t++) {
>> > +if (result[n] == char_src[t]) {
>> > +skip_char = 1;
>> > +break;
>> > +}
>> > +}
>> > +}
>> > +
>> > +if (!skip_char)
>> > +result[k++] = resu

Re: [FFmpeg-devel] [PATCH v3 4/4] avcodec/libwebpdec: libwebp decoder implementation

2021-09-12 Thread Lynne
12 Sept 2021, 22:20 by yakoy...@gmail.com:

> Followup of the webp demuxer implementation. As the demuxer sends RIFF 
> packets, the decoder choses what to do with the arriving chunks.
>
> Completely fixes #4907.
>

I'd really rather not merge this. Not when we have patches from last year[1] 
that implement
animated webp decoding. I approved them, but wanted another dev to take a look 
at them
as well, since it's not a small patchset.
I tried to find the original developer two or so months ago, but he's missing 
since the
Freenode death.

If it comes to it, I'll take over the patchset and make changes myself.

[1] - http://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/268820.html-
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add textmod filter

2021-09-12 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Lynne
> Sent: Monday, 13 September 2021 02:11
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add
> textmod filter
> 
> 13 Sept 2021, 00:34 by softwo...@hotmail.com:
> 
> >
> >
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf Of
> >> Andreas Rheinhardt
> >> Sent: Sunday, 12 September 2021 23:56
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [PATCH v5 10/12] avfilter/textmod: Add
> >> textmod filter

[..]

> >
> > One unsolved problem I have about dealing with AVSubtitleRect
> > as being part of AVFrame is that it's not possible to make a copy,
> > in a reliable way because the allocated sizes of the data[4]
> pointers
> > are not reliably known.
> >
> 
> We have cropping fields and cropping side data (IIRC) now,
> can they be used for this?
> 
> 
> > Usually, data[0] is the image and data[1] is the palette, but will
> > it always be like this? Then better not have a data array but
> > named pointer variables instead.
> >
> >
> > I was not sure what will be the general route: Merging AVSubtitle
> > into AVFrame or attaching AVSubtitle as a property to AVFrame.
> >
> 
> I think that's not really the best way to go. Subtitles ought to
> be contained in the data[] fields and described by the other
> fields like with audio and video.

You mean subtitle rects? Each AVSubtitle can include multiple
AVSubtitleRect(s)

Each bitmap subtitle rect has its own x,y,w and h as well as flags.
There are no existing fields to describe this. It would need 
an array of structs for these fields anyway (=> AVSubtitleRect), 
so why put the data in the data pointers then?
And in case of text subtitles, would the data[] fields contain
strings then?


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


[FFmpeg-devel] [PATCH] avformat/hlsenc: remove unnecessary http/https shutdown status operate

2021-09-12 Thread Steven Liu
there have been get http/https shutdown status in ffurl_shutdown.
so unnecessary http/https shutdown status operate.

Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7c37bc50b9..ad3800ecae 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -316,8 +316,7 @@ static int hlsenc_io_close(AVFormatContext *s, AVIOContext 
**pb, char *filename)
 URLContext *http_url_context = ffio_geturlcontext(*pb);
 av_assert0(http_url_context);
 avio_flush(*pb);
-ffurl_shutdown(http_url_context, AVIO_FLAG_WRITE);
-ret = ff_http_get_shutdown_status(http_url_context);
+ret = ffurl_shutdown(http_url_context, AVIO_FLAG_WRITE);
 #endif
 }
 return ret;
-- 
2.25.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 v2 4/5] libavfilter/x86/vf_gblur: add localbuf and ff_horiz_slice_avx2/512()

2021-09-12 Thread Wu, Jianhua

Zhao Zhili wrote:
> 
> Hi Wu,
> 
> > On Aug 4, 2021, at 10:06 AM, Wu Jianhua  wrote:
> >
> > We introduced a ff_horiz_slice_avx2/512() implemented on a new
> algorithm.
> > In a nutshell, the new algorithm does three things, gathering data
> > from
> > 8/16 rows, blurring data, and scattering data back to the image buffer.
> > Here we used a customized transpose 8x8/16x16 to avoid the huge
> > overhead brought by gather and scatter instructions, which is
> > dependent on the temporary buffer called localbuf added newly.
> >
> 
> I get fate error related to the patch:
> 
> make fate-checkasm-vf_gblur
> 
> checkasm: using random seed 227700911
> SSE:
>  - vf_gblur.postscale_slice [OK]
> SSE4.1:
>  - vf_gblur.horiz_slice [OK]
> test failed comparing 297.388 with 190 (abs diff=107.388 with EPS=0.01)
> AVX2:
>horiz_slice_avx2 (vf_gblur.c:47)
>  - vf_gblur.horiz_slice [FAILED]
>  - vf_gblur.postscale_slice [OK]
> src/tests/fate-run.sh: line 78: 40217 Illegal instruction: 4  $target_exec
> $target_path/"$@“
> 
> The last one "Illegal instruction: 4” exist before the patch.
> 
> I have tested on two macbook: mbp 2015 and MacBook Pro (16-inch, 2019).
> The test succeed on Ubuntu.
> 

Hi Zhili,

Thanks for the notice. I'll fix it once I get where the problem located.

Best regards,
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] libavutil/hwcontext_qsv: fix a bug for mapping qsv frame to vaapi

2021-09-12 Thread Chen, Wenbin
> On Fri, 2021-09-10 at 02:19 +, Chen, Wenbin wrote:
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of
> > > James Almer
> > > Sent: Thursday, September 9, 2021 8:48 PM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: fix a bug
> for
> > > mapping qsv frame to vaapi
> > >
> > > On 9/9/2021 6:13 AM, Wenbin Chen wrote:
> > > > Command below failed.
> > > > ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128
> > > > -init_hw_device qsv=qs@va -hwaccel qsv -hwaccel_device qs
> > > > -filter_hw_device va -c:v h264_qsv
> > > > -i 1080P.264 -vf "hwmap,format=vaapi" -c:v h264_vaapi output.264
> > > >
> > > > Cause: Assign pair->first directly to data[3] in vaapi frame.
> > > > pair->first is *VASurfaceID while data[3] in vaapi frame is
> > > > VASurfaceID. I fix this line of code. Now the command above works.
> > > >
> > > > Signed-off-by: Wenbin Chen 
> > > > ---
> > > >   libavutil/hwcontext_qsv.c | 2 +-
> > > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > > > index d431e71eab..6539cae619 100644
> > > > --- a/libavutil/hwcontext_qsv.c
> > > > +++ b/libavutil/hwcontext_qsv.c
> > > > @@ -781,7 +781,7 @@ static int qsv_map_from(AVHWFramesContext
> *ctx,
> > > >   case AV_HWDEVICE_TYPE_VAAPI:
> > > >   {
> > > >   mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
> > > > -child_data = pair->first;
> > > > +child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
> > >
> > > You can probably remove the intptr_t casting.
> >
> > If intptr_t is removed, it will report compile warning
> > "cast to pointer from integer of different size"
> 
> How about to add a comment here? If so, others can understand why this
> casting
> is needed.
> 
> Thanks
> Haihao

Ok, I will send path V2

> 
> 
> >
> > >
> > > Also, shouldn't this same fix be done for all three child device types
> > > used in this function? Which for that matter, child_data seems to be set
> > > for a d3d11va child device, but then never used.
> >
> > Dxva and d3d11 frames store the pointer to surface while vaapi frames
> store
> > surface,
> > so this part of code for dxva and d3d11va should be correct.
> >
> > D3d11 and dxva share dxva codec, the child_data is used in this part of
> code.
> > >
> > > >   break;
> > > >   }
> > > >   #endif
> > > >
> > >
> > > ___
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH V2] libavutil/hwcontext_qsv: fix a bug for mapping qsv frame to vaapi

2021-09-12 Thread Wenbin Chen
Command below failed.
ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128
-init_hw_device qsv=qs@va -hwaccel qsv -hwaccel_device qs
-filter_hw_device va -c:v h264_qsv
-i 1080P.264 -vf "hwmap,format=vaapi" -c:v h264_vaapi output.264

Cause: Assign pair->first directly to data[3] in vaapi frame.
pair->first is *VASurfaceID while data[3] in vaapi frame is
VASurfaceID. I fix this line of code. Now the command above works.

Signed-off-by: Wenbin Chen 
---
 libavutil/hwcontext_qsv.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index d431e71eab..b01236889e 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -781,7 +781,11 @@ static int qsv_map_from(AVHWFramesContext *ctx,
 case AV_HWDEVICE_TYPE_VAAPI:
 {
 mfxHDLPair *pair = (mfxHDLPair*)surf->Data.MemId;
-child_data = pair->first;
+/* pair->first is *VASurfaceID while data[3] in vaapi frame is 
VASurfaceID, so
+ * we need this casting for vaapi.
+ * Add intptr_t to force cast from VASurfaceID(uint) type to 
pointer(long) type
+ * to avoid compile warning */
+child_data = (uint8_t*)(intptr_t)*(VASurfaceID*)pair->first;
 break;
 }
 #endif
-- 
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] avfilter: add audio signal to distortion ratio filter

2021-09-12 Thread Nicolas George
Paul B Mahol (12021-09-12):
> Why purely input-driven scheme is wanted/needed to be supported?

Consider this:

input -> scale -> sink

If you add frames to the input, they will reach the sink. It can even be
something else than a buffersink and still work. No need to request a
frame on the sink.

OTOH:

input -> vstack -> sink
   /
testsrc --/

If you add frames to the input, they will accumulate in the link before
vstack, because no frame will be requested from the sink.

I think I forgot one rule for filters with multiple inputs: having
enough frames on one input should be considered a sign output is wanted,
and trigger requesting frames on other outputs.

But I am not 100% sure I did not already consider this and discard it
for a reason I forgot, so I need to think about it.

Regards,

-- 
  Nicolas George


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