Re: [FFmpeg-devel] [PATCH v2] avcodec/exr: output float pixels in float pixel format

2020-05-18 Thread Paul B Mahol
it looks fine to me.

On 5/19/20, Mark Reid  wrote:
> On Sun, May 10, 2020 at 12:40 AM Paul B Mahol  wrote:
>
>> On 5/10/20, Mark Reid  wrote:
>> > On Sat., May 9, 2020, 11:59 p.m. Paul B Mahol, 
>> > wrote:
>> >
>> >> Do we support these float formats in swscale?
>> >> If not, than patch is IMHO pointless.
>> >>
>> >
>> > Yes, my patches for swscale float support was merged a few days ago. I
>> also
>> > plan to try and add floating point support to some vf filters, namely
>> > lut3d.
>>
>> Great!
>>
>
> ping
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] drawtext: Allow textfile path to be expanded per frame

2020-05-18 Thread David Andreoletti
Hi ffmpeg maintainers / community,
New contributor here. The patch [0] for the drawtext filter was submitted some
time ago now but has been reviewed yet. It seems there is no official maintainer
for this filter (as per the MAINTAINERS file)
What should be done to have it reviewed ?

[0]
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200511143159.19390-1-da...@andreoletti.net/

Regards,
David Andreoletti  





On Mon, May 11, 2020 2:31 PM, David Andreoletti da...@andreoletti.net  wrote:
drawtext allows a file to be reloaded per frame. However,

the file to be reloaded is constant across frame. With

textfile now supporting text expansion, a different file can

be reloaded per frame. Eg: textfile=/path/fo/file{frame_num}.txt




Signed-off-by: David Andreoletti 

---

  doc/filters.texi | 16 +---

  libavfilter/vf_drawtext.c | 19 ---

  2 files changed, 29 insertions(+), 6 deletions(-)




diff --git a/doc/filters.texi b/doc/filters.texi

index d19fd346ae..460d65dd88 100644

--- a/doc/filters.texi

+++ b/doc/filters.texi

@@ -9659,13 +9659,13 @@ The default value of @var{borderw} is 0.

  Set the color to be used for drawing border around text. For the syntax of
this

  option, check the @ref{color syntax,,"Color" section in the ffmpeg-utils
manual,ffmpeg-utils}.

  

  The default value of @var{bordercolor} is "black".

  

  @item expansion

-Select how the @var{text} is expanded. Can be either @code{none},

+Select how the @var{text} and @var{textfile} are expanded. Can be either
@code{none},

  @code{strftime} (deprecated) or

  @code{normal} (default). See the @ref{drawtext_expansion, Text expansion}
section

  below for details.

  

  @item basetime

  Set a start time for the count. Value is in microseconds. Only applied

@@ -9786,15 +9786,19 @@ of UTF-8 encoded characters.

  

  This parameter is mandatory if no text string is specified with the

  parameter @var{text}.

  

  If both @var{text} and @var{textfile} are specified, an error is thrown.

  

+This parameter supports (per frame) variable expansion. Per frame variable 

+expansion requires @code{reload=1}. See @var{expansion} for details.

+

+

  @item reload

-If set to 1, the @var{textfile} will be reloaded before each frame.

-Be sure to update it atomically, or it may be read partially, or even fail.

+If set to 1, then before each frame, @var{textfile} file path will be expanded
and then the file at said path will be reloaded.

+Be sure to update the file atomically, or it may be read partially, or even
fail.

  

  @item x

  @item y

  The expressions which specify the offsets where text will be drawn

  within the video frame. They are relative to the top/left border of the

  output image.

@@ -10060,12 +10064,18 @@
drawtext="fontsize=15:fontfile=FreeSerif.ttf:text=LONG_LINE:y=h-line_h:x=-50*t"

  @item

  Show the content of file @file{CREDITS} off the bottom of the frame and scroll
up.

  @example

  drawtext="fontsize=20:fontfile=FreeSerif.ttf:textfile=CREDITS:y=h-20*t"

  @end example

  

+@item

+Each frame, reload a different text file at /path/to/frameX.txt, where X is
replaced with the frame number being processed by the filter

+@example

+drawtext="expansion:normal:textfile=/path/to/frame%@{frame_num@}.txt:reload=1"

+@end example

+

  @item

  Draw a single green letter "g", at the center of the input video.

  The glyph baseline is placed at half screen height.

  @example

 
drawtext="fontsize=60:fontfile=FreeSerif.ttf:fontcolor=green:text=g:x=(w-max_glyph_w)/2:y=h/2-ascent"

  @end example

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c

index abe1ca6c35..ffb1ff2330 100644

--- a/libavfilter/vf_drawtext.c

+++ b/libavfilter/vf_drawtext.c

@@ -152,13 +152,14 @@ typedef struct DrawTextContext {

  AVBPrint expanded_text; ///< used to contain the expanded text

  uint8_t *fontcolor_expr; ///< fontcolor expression to evaluate

  AVBPrint expanded_fontcolor; ///< used to contain the expanded fontcolor spec

  int ft_load_flags; ///< flags used for loading fonts, see FT_LOAD_*

  FT_Vector *positions; ///< positions for each element in the text

  size_t nb_positions; ///< number of elements of positions array

- char *textfile; ///< file with text to be drawn

+ char *textfile; ///< filename with text to be drawn

+ AVBPrint expanded_textfile; ///< Same as textfile, except the filename can be
expanded

  int x; ///< x position to start drawing text

  int y; ///< y position to start drawing text

  int max_glyph_w; ///< max glyph width

  int max_glyph_h; ///< max glyph height

  int shadowx, shadowy;

  int borderw; ///< border width

@@ -565,24 +566,33 @@ static int load_font(AVFilterContext *ctx)

  if (!err)

  return 0;

  #endif

  return err;

  }

  

+static int expand_text(AVFilterContext *ctx, char *text, AVBPrint *bp);

  static int load_textfile(AVFilterContext *ctx)

  {

  DrawTextContext *s = ctx->priv;

  int err;

  uint8_t *textbuf;

  uint8_t *t

Re: [FFmpeg-devel] [PATCH v2] avcodec: Add MediaFoundation encoder wrapper

2020-05-18 Thread Aman Gupta
On Fri, May 15, 2020 at 12:04 AM Martin Storsjö  wrote:

> On Tue, 12 May 2020, Martin Storsjö wrote:
>
> > From: wm4 
> >
> > This contains encoder wrappers for H264, HEVC, AAC, AC3 and MP3.
> >
> > This is based on top of an original patch by wm4
> > . The original patch supported both encoding
> > and decoding, but this patch only includes encoding.
> >
> > The patch contains further changes by Paweł Wegner
> >  (primarily for splitting out the encoding
> > parts of the original patch) and further cleanup, build compatibility
> > fixes and tweaks for use with Qualcomm encoders by Martin Storsjö.
> > ---
> > v2: Added AV_CODEC_CAP_HYBRID, removed a leftover unused AVBSFContext,
> > added changelog and encoders.text entries, renamed the configure option
> > and config item to "mediafoundation" instead of "mf", changed the
> > makefile to keep individual additions of object files for each
> > individual encoder (so that it isn't compiled if all encoders are
> > disabled, even if CONFIG_MEDIAFOUNDATION is enabled).
>
> Any further comments on this, or is it ok to be merged now?


+1 from me. We have been using the original patchset for quite a few years
now, and it will make things much easier if it is included upstream.

For encoding video, we found the mf apis work much more reliably across
different hardware (and versions of Windows) compared to using qsv directly.

Aman


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

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

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_lut3d: prelut support for 3d cinespace luts

2020-05-18 Thread mindmark
From: Mark Reid 

---
 libavfilter/vf_lut3d.c | 367 +++--
 1 file changed, 312 insertions(+), 55 deletions(-)

diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
index 482e2394a7..4067c4a60a 100644
--- a/libavfilter/vf_lut3d.c
+++ b/libavfilter/vf_lut3d.c
@@ -59,6 +59,15 @@ struct rgbvec {
 /* 3D LUT don't often go up to level 32, but it is common to have a Hald CLUT
  * of 512x512 (64x64x64) */
 #define MAX_LEVEL 256
+#define PRELUT_SIZE 65536
+
+typedef struct Lut3DPreLut {
+int size;
+float min[3];
+float max[3];
+float scale[3];
+float* lut[3];
+} Lut3DPreLut;
 
 typedef struct LUT3DContext {
 const AVClass *class;
@@ -71,6 +80,7 @@ typedef struct LUT3DContext {
 struct rgbvec *lut;
 int lutsize;
 int lutsize2;
+Lut3DPreLut prelut;
 #if CONFIG_HALDCLUT_FILTER
 uint8_t clut_rgba_map[4];
 int clut_step;
@@ -234,6 +244,31 @@ static inline struct rgbvec interp_tetrahedral(const 
LUT3DContext *lut3d,
 return c;
 }
 
+static inline float apply_prelut_channel(const LUT3DContext *lut3d, float x, 
int c)
+{
+
+x = (x - lut3d->prelut.min[c]) * lut3d->prelut.scale[c];
+x = av_clipf(x, 0.0f, lut3d->prelut.size-1);
+
+const float a = lut3d->prelut.lut[c][PREV(x)];
+const float b = lut3d->prelut.lut[c][(FFMIN((int)(x) + 1, 
lut3d->prelut.size - 1))];
+const float mix = x - (float)PREV(x);
+
+return lerpf(a, b, mix);
+}
+
+static inline struct rgbvec apply_prelut(const LUT3DContext *lut3d, const 
struct rgbvec *s)
+{
+if (lut3d->prelut.size <= 0)
+return *s;
+
+struct rgbvec c;
+c.r = apply_prelut_channel(lut3d, s->r, 0);
+c.g = apply_prelut_channel(lut3d, s->g, 1);
+c.b = apply_prelut_channel(lut3d, s->b, 2);
+return c;
+}
+
 #define DEFINE_INTERP_FUNC_PLANAR(name, nbits, depth)  
\
 static int interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, 
int jobnr, int nb_jobs) \
 {  
\
@@ -253,9 +288,11 @@ static int 
interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
 const uint8_t *srcbrow = in->data[1] + slice_start * in->linesize[1];  
\
 const uint8_t *srcrrow = in->data[2] + slice_start * in->linesize[2];  
\
 const uint8_t *srcarow = in->data[3] + slice_start * in->linesize[3];  
\
-const float scale_r = (lut3d->scale.r / ((1scale.g / ((1scale.b / ((1lutsize - 1;  
\
+const float scale_f = 1.0f / ((1scale.g * lut_max;
\
+const float scale_b = lut3d->scale.b * lut_max;
\

\
 for (y = slice_start; y < slice_end; y++) {
\
 uint##nbits##_t *dstg = (uint##nbits##_t *)grow;   
\
@@ -267,9 +304,13 @@ static int 
interp_##nbits##_##name##_p##depth(AVFilterContext *ctx, void *arg, i
 const uint##nbits##_t *srcr = (const uint##nbits##_t *)srcrrow;
\
 const uint##nbits##_t *srca = (const uint##nbits##_t *)srcarow;
\
 for (x = 0; x < in->width; x++) {  
\
-const struct rgbvec scaled_rgb = {srcr[x] * scale_r,   
\
-  srcg[x] * scale_g,   
\
-  srcb[x] * scale_b};  
\
+const struct rgbvec rgb = {srcr[x] * scale_f,  
\
+   srcg[x] * scale_f,  
\
+   srcb[x] * scale_f}; 
\
+const struct rgbvec prelut_rgb = apply_prelut(lut3d, &rgb);
\
+const struct rgbvec scaled_rgb = {av_clipf(prelut_rgb.r * scale_r, 
0, lut_max),\
+  av_clipf(prelut_rgb.g * scale_g, 
0, lut_max),\
+  av_clipf(prelut_rgb.b * 

[FFmpeg-devel] [PATCH 1/2] avfilter/vf_lut3d: initial float pixel format support

2020-05-18 Thread mindmark
From: Mark Reid 

---
 libavfilter/vf_lut3d.c | 207 +++--
 1 file changed, 201 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_lut3d.c b/libavfilter/vf_lut3d.c
index fda85b16b4..482e2394a7 100644
--- a/libavfilter/vf_lut3d.c
+++ b/libavfilter/vf_lut3d.c
@@ -24,9 +24,12 @@
  * 3D Lookup table filter
  */
 
+#include "float.h"
+
 #include "libavutil/opt.h"
 #include "libavutil/file.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/intfloat.h"
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/avstring.h"
@@ -73,6 +76,7 @@ typedef struct LUT3DContext {
 int clut_step;
 int clut_bits;
 int clut_planar;
+int clut_float;
 int clut_width;
 FFFrameSync fs;
 #endif
@@ -91,6 +95,30 @@ typedef struct ThreadData {
 { "tetrahedral", "interpolate values using a tetrahedron", 
   0, AV_OPT_TYPE_CONST, {.i64=INTERPOLATE_TETRAHEDRAL}, INT_MIN, INT_MAX, 
FLAGS, "interp_mode" }, \
 { NULL }
 
+#define EXPONENT_MASK 0x7F80
+#define MANTISSA_MASK 0x007F
+#define SIGN_MASK 0x7FFF
+
+static inline float sanitizef(float f)
+{
+union av_intfloat32 t;
+t.f = f;
+
+if ((t.i & EXPONENT_MASK) == EXPONENT_MASK) {
+if ((t.i & MANTISSA_MASK) != 0) {
+// NAN
+return 0.0f;
+} else if (t.i & SIGN_MASK) {
+// -INF
+return FLT_MIN;
+} else {
+// +INF
+return FLT_MAX;
+}
+}
+return f;
+}
+
 static inline float lerpf(float v0, float v1, float f)
 {
 return v0 + (v1 - v0) * f;
@@ -285,6 +313,66 @@ DEFINE_INTERP_FUNC_PLANAR(nearest, 16, 16)
 DEFINE_INTERP_FUNC_PLANAR(trilinear,   16, 16)
 DEFINE_INTERP_FUNC_PLANAR(tetrahedral, 16, 16)
 
+#define DEFINE_INTERP_FUNC_PLANAR_FLOAT(name, depth)   
\
+static int interp_##name##_pf##depth(AVFilterContext *ctx, void *arg, int 
jobnr, int nb_jobs)  \
+{  
\
+int x, y;  
\
+const LUT3DContext *lut3d = ctx->priv; 
\
+const ThreadData *td = arg;
\
+const AVFrame *in  = td->in;   
\
+const AVFrame *out = td->out;  
\
+const int direct = out == in;  
\
+const int slice_start = (in->height *  jobnr   ) / nb_jobs;
\
+const int slice_end   = (in->height * (jobnr+1)) / nb_jobs;
\
+uint8_t *grow = out->data[0] + slice_start * out->linesize[0]; 
\
+uint8_t *brow = out->data[1] + slice_start * out->linesize[1]; 
\
+uint8_t *rrow = out->data[2] + slice_start * out->linesize[2]; 
\
+uint8_t *arow = out->data[3] + slice_start * out->linesize[3]; 
\
+const uint8_t *srcgrow = in->data[0] + slice_start * in->linesize[0];  
\
+const uint8_t *srcbrow = in->data[1] + slice_start * in->linesize[1];  
\
+const uint8_t *srcrrow = in->data[2] + slice_start * in->linesize[2];  
\
+const uint8_t *srcarow = in->data[3] + slice_start * in->linesize[3];  
\
+const float lutsize = lut3d->lutsize - 1;  
\
+const float scale_r = lut3d->scale.r * lutsize;
\
+const float scale_g = lut3d->scale.g * lutsize;
\
+const float scale_b = lut3d->scale.b * lutsize;
\
+   
\
+for (y = slice_start; y < slice_end; y++) {
\
+float *dstg = (float *)grow;   
\
+float *dstb = (float *)brow;   
\
+float *dstr = (float *)rrow;   
\
+float *dsta = (float *)arow;   
\
+const float *srcg = (const float *)srcgrow;

Re: [FFmpeg-devel] [PATCH v2] avcodec/exr: output float pixels in float pixel format

2020-05-18 Thread Mark Reid
On Sun, May 10, 2020 at 12:40 AM Paul B Mahol  wrote:

> On 5/10/20, Mark Reid  wrote:
> > On Sat., May 9, 2020, 11:59 p.m. Paul B Mahol,  wrote:
> >
> >> Do we support these float formats in swscale?
> >> If not, than patch is IMHO pointless.
> >>
> >
> > Yes, my patches for swscale float support was merged a few days ago. I
> also
> > plan to try and add floating point support to some vf filters, namely
> > lut3d.
>
> Great!
>

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

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

Re: [FFmpeg-devel] [PATCH 2/2] Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.

2020-05-18 Thread Dale Curtis
On Mon, May 18, 2020 at 3:24 PM Dale Curtis  wrote:

> On Mon, May 18, 2020 at 2:22 PM Michael Niedermayer 
> wrote:
>
>>
>> > 38cfdcfc9d4fa1c1239dc01a766e369b20a0232a  sat_math_builtin_v5.patch
>>
>
> Latest upload is sat_math_builtin_v6.patch -- is that not showing up for
> you? I just tested and it applies cleanly to trunk.
>

Ahh, crap that one got eaten because I used the wrong e-mail address to
send it. Here's the latest one again from the right address this time.

- dale


sat_math_builtin_v6.patch
Description: Binary data
___
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] [mov] Free temp buffer upon negative sample_size error.

2020-05-18 Thread Dale Curtis
2d8d554f15a7a27cfeca81467cc9341a86f784e2 added a new error condition
to mov_read_stsz() but forgot to free a temporary buffer when it
occurs.

Signed-off-by: Dale Curtis 
---
 libavformat/mov.c | 1 +
 1 file changed, 1 insertion(+)


free_temp_v0.patch
Description: Binary data
___
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] Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.

2020-05-18 Thread Dale Curtis
On Mon, May 18, 2020 at 2:22 PM Michael Niedermayer 
wrote:

>
> > 38cfdcfc9d4fa1c1239dc01a766e369b20a0232a  sat_math_builtin_v5.patch
>

Latest upload is sat_math_builtin_v6.patch -- is that not showing up for
you? I just tested and it applies cleanly to trunk.


> > From 8ac3c2cea0d00c4aec2d1c6278462e6b0f1015b3 Mon Sep 17 00:00:00 2001
> > From: Dale Curtis 
> > Date: Fri, 1 May 2020 10:20:43 -0700
> > Subject: [PATCH] Use gcc/clang builtins for av_sat_(add|sub)_64_c if
> >  available.
>
> doesnt apply cleanly
>
> Applying: Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.
> error: patch failed: libavutil/common.h:299
> error: libavutil/common.h: patch does not apply
> Patch failed at 0001 Use gcc/clang builtins for av_sat_(add|sub)_64_c if
> available.
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
>
___
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] FFmpeg 4.2.3

2020-05-18 Thread Michael Niedermayer
Hi

Its quite a while since 4.2.2 so i intend to make 4.2.3 soon
if you want something backported, backport it now

thx


-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin


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 2/2] Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.

2020-05-18 Thread Michael Niedermayer
On Mon, May 04, 2020 at 11:40:47AM -0700, Dale Curtis wrote:
> On Mon, May 4, 2020 at 11:19 AM James Almer  wrote:
> 
> > On 5/4/2020 3:09 PM, Dale Curtis wrote:
> > > Bump. I have 5 integer overflow fuzzing issues awaiting our resolution of
> > > this discussion. Thanks.
> > >
> > > - dale
> >
> > What's the first version of clang with support for __builtin_*_overflow?
> > Because with your patch as is (Checking only __clang__), it's very
> > likely old clang builds could be broken. We have things like Clang 3 on
> > FATE right now.
> >
> 
> Clang 10.0 apparently:
> https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros -
> I'm fine with limiting support to where it works though. Attached patch
> does that.
> 
> 
> >
> > Also, does clang-cl define __clang__ and these builtins? Because maybe
> > we could remove that check and just keep the GCC + Intel one. The former
> > should in theory cover Clang builds that are reportedly compatible with
> > GCC >= 5.1
> >
> 
> Yes, clang-cl defines __clang__ and these builtins.
> 
> - dale

>  common.h |   10 ++
>  1 file changed, 10 insertions(+)
> 38cfdcfc9d4fa1c1239dc01a766e369b20a0232a  sat_math_builtin_v5.patch
> From 8ac3c2cea0d00c4aec2d1c6278462e6b0f1015b3 Mon Sep 17 00:00:00 2001
> From: Dale Curtis 
> Date: Fri, 1 May 2020 10:20:43 -0700
> Subject: [PATCH] Use gcc/clang builtins for av_sat_(add|sub)_64_c if
>  available.

doesnt apply cleanly

Applying: Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.
error: patch failed: libavutil/common.h:299
error: libavutil/common.h: patch does not apply
Patch failed at 0001 Use gcc/clang builtins for av_sat_(add|sub)_64_c if 
available.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


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] Open pull request to mitigate CVE-2020-12284 buffer overflow

2020-05-18 Thread Paul B Mahol
Already asked and answered several times.

On 5/18/20, Patrick Watts  wrote:
> All,
>
> Apologies in advance if this is not the correct forum. We're currently
> using FFmpeg in a production application, and our infosec folks have
> flagged it as a vulnerability.
>
> https://github.com/FFmpeg/FFmpeg/commit/1812352d767ccf5431aa440123e2e260a4db2726
>
> a) has anyone applied and implemented this patch in an upcoming version of
> FFmpeg?
> b) has anyone had to deal with mitigating this vulnerability in your
> production application, and can point us to a solution that doesn't force
> us to compromise functionality?
>
> CVE details: https://nvd.nist.gov/vuln/detail/CVE-2020-12284
>
> Private or public replies are welcome.
>
> Thanks!
>
>
> *Patrick Watts *Lead Business Analyst
> LifeWay Christian Resources
> (615) 251-5793
> Twitter: @patrickwatts 
>
>
> *We serve the Church in Her mission of making disciples.*
> *FREE resources from LifeWay for your church:*
> https://lifeway.com/coronavirus
>
>
>
> *Download a free sample at https://vbs.lifeway.com/free-sample/
> *
> ___
> 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 v6 7/9] libavfilter/qsvvpp: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/qsvvpp.c | 31 ++-
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8d5ff2eb65..0d3f7fb2f9 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -36,6 +36,7 @@
 
MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 typedef struct QSVFrame {
 AVFrame  *frame;
@@ -68,12 +69,6 @@ struct QSVVPPContext {
 int nb_ext_buffers;
 };
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static const AVRational default_tb = { 1, 9 };
 
 /* functions for frameAlloc */
@@ -129,7 +124,13 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
@@ -497,14 +498,18 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (ret == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
 if (ret != MFX_ERR_NONE) {
 av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 5/9] libavutil/hwcontext_qsv: enabling d3d11va usage by default, add usage child_device_type argument

2020-05-18 Thread artem . galin
From: Artem Galin 

Makes selection of d3d11va device type by default and over DirectX 9,
which might break users with older drivers/systems.
DCH driver with Gen6th support should be still fine.

Decode, encode, transcode have been validated.

child_device_type option is responsible for d3d11va/dxva2 device selection

Usage examples:

DirectX 11
-init_hw_device qsv:hw,child_device_type=d3d11va

DirectX 9 is still supported but requires explicit selection
-init_hw_device qsv:hw,child_device_type=dxva2

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 59 +--
 1 file changed, 45 insertions(+), 14 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index f6dba898b5..488655b686 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1439,28 +1439,59 @@ static int qsv_device_create(AVHWDeviceContext *ctx, 
const char *device,
 ctx->user_opaque = priv;
 ctx->free= qsv_device_free;
 
-e = av_dict_get(opts, "child_device", NULL, 0);
-
-child_device_opts = NULL;
-if (CONFIG_VAAPI) {
+e = av_dict_get(opts, "child_device_type", NULL, 0);
+if (e) {
+child_device_type = av_hwdevice_find_type_by_name(e ? e->value : NULL);
+if (child_device_type == AV_HWDEVICE_TYPE_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Unknown child device type "
+   "\"%s\".\n", e ? e->value : NULL);
+return AVERROR(EINVAL);
+}
+} else if (CONFIG_VAAPI) {
 child_device_type = AV_HWDEVICE_TYPE_VAAPI;
-// libmfx does not actually implement VAAPI properly, rather it
-// depends on the specific behaviour of a matching iHD driver when
-// used on recent Intel hardware.  Set options to the VAAPI device
-// creation so that we should pick a usable setup by default if
-// possible, even when multiple devices and drivers are available.
-av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
-av_dict_set(&child_device_opts, "driver","iHD",  0);
-} else if (CONFIG_DXVA2)
+} else if (CONFIG_D3D11VA) {
+child_device_type = AV_HWDEVICE_TYPE_D3D11VA;
+} else if (CONFIG_DXVA2) {
 child_device_type = AV_HWDEVICE_TYPE_DXVA2;
-else {
+} else {
 av_log(ctx, AV_LOG_ERROR, "No supported child device type is 
enabled\n");
 return AVERROR(ENOSYS);
 }
 
+child_device_opts = NULL;
+switch (child_device_type) {
+#if CONFIG_VAAPI
+case AV_HWDEVICE_TYPE_VAAPI:
+{
+// libmfx does not actually implement VAAPI properly, rather it
+// depends on the specific behaviour of a matching iHD driver when
+// used on recent Intel hardware.  Set options to the VAAPI device
+// creation so that we should pick a usable setup by default if
+// possible, even when multiple devices and drivers are available.
+av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
+av_dict_set(&child_device_opts, "driver","iHD",  0);
+}
+break;
+#endif
+#if CONFIG_D3D11VA
+case AV_HWDEVICE_TYPE_D3D11VA:
+break;
+#endif
+#if CONFIG_DXVA2
+case AV_HWDEVICE_TYPE_DXVA2:
+break;
+#endif
+default:
+{
+av_log(ctx, AV_LOG_ERROR, "No supported child device type is 
enabled\n");
+return AVERROR(ENOSYS);
+}
+break;
+}
+
+e = av_dict_get(opts, "child_device", NULL, 0);
 ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type,
  e ? e->value : NULL, child_device_opts, 0);
-
 av_dict_free(&child_device_opts);
 if (ret < 0)
 return ret;
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 8/9] libavfilter/vf_scale_qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/vf_scale_qsv.c | 43 +-
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 5064dcbb60..47701c20d0 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -70,6 +70,7 @@ enum var_name {
 };
 
 #define QSV_HAVE_SCALING_CONFIG  QSV_VERSION_ATLEAST(1, 19)
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 typedef struct QSVScaleContext {
 const AVClass *class;
@@ -264,16 +265,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static int init_out_session(AVFilterContext *ctx)
 {
 
@@ -292,28 +293,32 @@ static int init_out_session(AVFilterContext *ctx)
 mfxIMPL impl;
 mfxVideoParam par;
 mfxStatus err;
-int i;
+int ret, i;
 
 s->num_ext_buf = 0;
 
 /* extract the properties of the "master" session given to us */
-err = MFXQueryIMPL(device_hwctx->session, &impl);
-if (err == MFX_ERR_NONE)
-err = MFXQueryVersion(device_hwctx->session, &ver);
-if (err != MFX_ERR_NONE) {
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
-if (err != MFX_ERR_NONE) {
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
 }
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 9/9] libavfilter/vf_deinterlace_qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/vf_deinterlace_qsv.c | 44 ++--
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 80217c8419..f7f9d916db 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -42,6 +42,8 @@
 #include "internal.h"
 #include "video.h"
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 enum {
 QSVDEINT_MORE_OUTPUT = 1,
 QSVDEINT_MORE_INPUT,
@@ -157,16 +159,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static int init_out_session(AVFilterContext *ctx)
 {
 
@@ -183,26 +185,30 @@ static int init_out_session(AVFilterContext *ctx)
 mfxIMPL impl;
 mfxVideoParam par;
 mfxStatus err;
-int i;
+int ret, i;
 
 /* extract the properties of the "master" session given to us */
-err = MFXQueryIMPL(device_hwctx->session, &impl);
-if (err == MFX_ERR_NONE)
-err = MFXQueryVersion(device_hwctx->session, &ver);
-if (err != MFX_ERR_NONE) {
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
-if (err != MFX_ERR_NONE) {
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
 }
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 6/9] libavutil/hwcontext_qsv: pass vendor option to child device

2020-05-18 Thread artem . galin
From: Artem Galin 

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 488655b686..e75d4b7c24 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1475,6 +1475,11 @@ static int qsv_device_create(AVHWDeviceContext *ctx, 
const char *device,
 #endif
 #if CONFIG_D3D11VA
 case AV_HWDEVICE_TYPE_D3D11VA:
+{
+e = av_dict_get(opts, "vendor", NULL, 0);
+if(e)
+av_dict_set(&child_device_opts, "vendor", e->value, 0);
+}
 break;
 #endif
 #if CONFIG_DXVA2
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 4/9] libavutil/hwcontext_qsv: supporting d3d11va device type

2020-05-18 Thread artem . galin
From: Artem Galin 

This enables usage of non-powered/headless GPU, better HDR support.
Pool of resources is allocated as one texture with array of slices.

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 323 +++---
 1 file changed, 262 insertions(+), 61 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 4306c6e3b9..f6dba898b5 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -27,9 +27,13 @@
 #include 
 #endif
 
+#define COBJMACROS
 #if CONFIG_VAAPI
 #include "hwcontext_vaapi.h"
 #endif
+#if CONFIG_D3D11VA
+#include "hwcontext_d3d11va.h"
+#endif
 #if CONFIG_DXVA2
 #include "hwcontext_dxva2.h"
 #endif
@@ -48,6 +52,8 @@
 (MFX_VERSION_MAJOR > (MAJOR) || \
  MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 typedef struct QSVDevicePriv {
 AVBufferRef *child_device_ctx;
 } QSVDevicePriv;
@@ -74,6 +80,7 @@ typedef struct QSVFramesContext {
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
+mfxHDLPair *handle_pairs_internal;
 int nb_surfaces_used;
 
 // used in the frame allocator for non-opaque surfaces
@@ -85,20 +92,6 @@ typedef struct QSVFramesContext {
 mfxExtBuffer *ext_buffers[1];
 } QSVFramesContext;
 
-static const struct {
-mfxHandleType handle_type;
-enum AVHWDeviceType device_type;
-enum AVPixelFormat  pix_fmt;
-} supported_handle_types[] = {
-#if CONFIG_VAAPI
-{ MFX_HANDLE_VA_DISPLAY,  AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI 
},
-#endif
-#if CONFIG_DXVA2
-{ MFX_HANDLE_D3D9_DEVICE_MANAGER, AV_HWDEVICE_TYPE_DXVA2, 
AV_PIX_FMT_DXVA2_VLD },
-#endif
-{ 0 },
-};
-
 static const struct {
 enum AVPixelFormat pix_fmt;
 uint32_t   fourcc;
@@ -131,24 +124,11 @@ static int qsv_device_init(AVHWDeviceContext *ctx)
 {
 AVQSVDeviceContext *hwctx = ctx->hwctx;
 QSVDeviceContext   *s = ctx->internal->priv;
-
+int   hw_handle_supported = 0;
+mfxHandleType handle_type;
+enum AVHWDeviceType device_type;
+enum AVPixelFormat  pix_fmt;
 mfxStatus err;
-int i;
-
-for (i = 0; supported_handle_types[i].handle_type; i++) {
-err = MFXVideoCORE_GetHandle(hwctx->session, 
supported_handle_types[i].handle_type,
- &s->handle);
-if (err == MFX_ERR_NONE) {
-s->handle_type   = supported_handle_types[i].handle_type;
-s->child_device_type = supported_handle_types[i].device_type;
-s->child_pix_fmt = supported_handle_types[i].pix_fmt;
-break;
-}
-}
-if (!s->handle) {
-av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved 
"
-   "from the session\n");
-}
 
 err = MFXQueryIMPL(hwctx->session, &s->impl);
 if (err == MFX_ERR_NONE)
@@ -158,6 +138,41 @@ static int qsv_device_init(AVHWDeviceContext *ctx)
 return AVERROR_UNKNOWN;
 }
 
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_VAAPI
+handle_type = MFX_HANDLE_VA_DISPLAY;
+device_type = AV_HWDEVICE_TYPE_VAAPI;
+pix_fmt = AV_PIX_FMT_VAAPI;
+hw_handle_supported = 1;
+#endif
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_D3D11VA
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+device_type = AV_HWDEVICE_TYPE_D3D11VA;
+pix_fmt = AV_PIX_FMT_D3D11;
+hw_handle_supported = 1;
+#endif
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_DXVA2
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+device_type = AV_HWDEVICE_TYPE_DXVA2;
+pix_fmt = AV_PIX_FMT_DXVA2_VLD;
+hw_handle_supported = 1;
+#endif
+}
+
+if (hw_handle_supported) {
+err = MFXVideoCORE_GetHandle(hwctx->session, handle_type, &s->handle);
+if (err == MFX_ERR_NONE) {
+s->handle_type   = handle_type;
+s->child_device_type = device_type;
+s->child_pix_fmt = pix_fmt;
+}
+}
+if (!s->handle) {
+av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved 
"
+   "from the session\n");
+}
 return 0;
 }
 
@@ -187,6 +202,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 av_freep(&s->mem_ids);
 av_freep(&s->surface_ptrs);
 av_freep(&s->surfaces_internal);
+av_freep(&s->handle_pairs_internal);
 av_buffer_unref(&s->child_frames_ref);
 }
 
@@ -202,6 +218,8 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, int size)
 
 if (s->nb_surfaces_used < hwctx->nb_surfaces) {
 s->nb_surfaces_used++;
+av_buffer_create((uint8_t*)(s->handle_pairs_internal + 
s->nb_surfaces_used - 1),
+sizeof(*s->handle_pairs_internal), 
qsv_pool_release_dummy, NULL, 0);
 return av_buffer_create((uin

[FFmpeg-devel] [PATCH v6 3/9] libavutil/hwcontext_d3d11va: adding the vendor option to d3d11va device creation

2020-05-18 Thread artem . galin
From: Artem Galin 

Example: --init_hw_device d3d11va:,vendor=0x8086

qsv_device option is still works and has higher priority over vendor
option.

Signed-off-by: Artem Galin hwctx;
 
 HRESULT hr;
+AVDictionaryEntry *e;
 IDXGIAdapter   *pAdapter = NULL;
 ID3D10Multithread  *pMultithread;
 UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
+int adapter = -1;
+long int vendor_id = -1;
 int is_debug   = !!av_dict_get(opts, "debug", NULL, 0);
 int ret;
 
@@ -539,13 +542,45 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, 
const char *device,
 return AVERROR_UNKNOWN;
 }
 
+e = av_dict_get(opts, "vendor", NULL, 0);
+if (e) {
+vendor_id = strtol(e->value, NULL, 0);
+}
+
 if (device) {
+adapter = atoi(device);
+}
+
+if (adapter >= 0 || vendor_id != -1) {
 IDXGIFactory2 *pDXGIFactory;
 hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory);
 if (SUCCEEDED(hr)) {
-int adapter = atoi(device);
-if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, 
&pAdapter)))
+if (adapter < 0) {
+int adapter_cnt = 0;
+while (IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter_cnt++, 
&pAdapter) != DXGI_ERROR_NOT_FOUND) {
+DXGI_ADAPTER_DESC adapter_desc;
+hr = IDXGIAdapter2_GetDesc(pAdapter, &adapter_desc);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "IDXGIAdapter2_GetDesc 
returned error with adapter id %d\n", adapter_cnt);
+continue;
+}
+
+if (adapter_desc.VendorId == vendor_id) {
+break;
+}
+
+if (adapter)
+IDXGIAdapter_Release(pAdapter);
+}
+if (adapter_cnt < 0) {
+av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter 
by vendor id %ld\n", vendor_id);
+IDXGIFactory2_Release(pDXGIFactory);
+return AVERROR_UNKNOWN;
+}
+} else {
+if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, 
&pAdapter)))
 pAdapter = NULL;
+}
 IDXGIFactory2_Release(pDXGIFactory);
 }
 }
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v6 2/9] libavcodec/qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callbacks with
proper MediaSDK pair type support.

Extending structure for proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavcodec/qsv.c  | 53 ++-
 libavcodec/qsv_internal.h |  2 +-
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 17720070f1..ef57b92a9f 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -36,6 +36,8 @@
 #include "avcodec.h"
 #include "qsv_internal.h"
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfx/mfxvp8.h"
 #endif
@@ -239,7 +241,9 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame 
*frame)
 int i;
 for (i = 0; i < ctx->nb_mids; i++) {
 QSVMid *mid = &ctx->mids[i];
-if (mid->handle == frame->surface.Data.MemId)
+mfxHDLPair *pair = (mfxHDLPair*)frame->surface.Data.MemId;
+if ((mid->handle_pair.first == pair->first) &&
+(mid->handle_pair.second == pair->second))
 return i;
 }
 return AVERROR_BUG;
@@ -380,7 +384,11 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
  const char *load_plugins, int gpu_copy)
 {
+#if CONFIG_D3D11VA
+mfxIMPL  impl = MFX_IMPL_AUTO_ANY | MFX_IMPL_VIA_D3D11;
+#else
 mfxIMPL  impl = MFX_IMPL_AUTO_ANY;
+#endif
 mfxVersionver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
 mfxInitParam init_par = { MFX_IMPL_AUTO_ANY };
 
@@ -469,7 +477,7 @@ static AVBufferRef *qsv_create_mids(AVBufferRef 
*hw_frames_ref)
 
 for (i = 0; i < nb_surfaces; i++) {
 QSVMid *mid = &mids[i];
-mid->handle= frames_hwctx->surfaces[i].Data.MemId;
+mid->handle_pair   = 
*((mfxHDLPair*)frames_hwctx->surfaces[i].Data.MemId);
 mid->hw_frames_ref = hw_frames_ref1;
 }
 
@@ -646,7 +654,7 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 goto fail;
 
 qsv_mid->surf.Info = hw_frames_hwctx->surfaces[0].Info;
-qsv_mid->surf.Data.MemId = qsv_mid->handle;
+qsv_mid->surf.Data.MemId = &qsv_mid->handle_pair;
 
 /* map the data to the system memory */
 ret = av_hwframe_map(qsv_mid->locked_frame, qsv_mid->hw_frame,
@@ -679,7 +687,13 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId 
mid, mfxFrameData *ptr)
 static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
 QSVMid *qsv_mid = (QSVMid*)mid;
-*hdl = qsv_mid->handle;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)&qsv_mid->handle_pair;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
@@ -687,24 +701,19 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
AVBufferRef *device_ref, const char 
*load_plugins,
int gpu_copy)
 {
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
 AVHWDeviceContext*device_ctx = (AVHWDeviceContext*)device_ref->data;
 AVQSVDeviceContext *device_hwctx = device_ctx->hwctx;
 mfxSessionparent_session = device_hwctx->session;
 mfxInitParaminit_par = { MFX_IMPL_AUTO_ANY };
 mfxHDLhandle = NULL;
+int  hw_handle_supported = 0;
 
 mfxSessionsession;
 mfxVersionver;
 mfxIMPL   impl;
 mfxHandleType handle_type;
 mfxStatus err;
-
-int i, ret;
+int ret;
 
 err = MFXQueryIMPL(parent_session, &impl);
 if (err == MFX_ERR_NONE)
@@ -713,13 +722,23 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
 return ff_qsv_print_error(avctx, err,
   "Error querying the session attributes");
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+hw_handle_supported = 1;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+hw_handle_supported = 1;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+hw_handle_supported = 1;
+}
+
+if (hw_handle_supported) {
+err = MFXVideoCORE_GetHandle(parent_session, handle_ty

[FFmpeg-devel] [PATCH v6 1/9] fftools/qsv: add device initialization from string

2020-05-18 Thread artem . galin
From: Artem Galin 

Signed-off-by: Artem Galin 
---
 fftools/ffmpeg_opt.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 60bb437ea7..83f1b53e9d 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -558,7 +558,11 @@ static int opt_init_hw_device(void *optctx, const char 
*opt, const char *arg)
 printf("\n");
 exit_program(0);
 } else {
-return hw_device_init_from_string(arg, NULL);
+int err;
+if (!arg)
+return AVERROR(ENOMEM);
+err = hw_device_init_from_string(arg, NULL);
+return err;
 }
 }
 
-- 
2.26.2

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

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

Re: [FFmpeg-devel] [PATCH] avcodec/h264: support sps/pps AV_PKT_DATA_NEW_EXTRADATA

2020-05-18 Thread Olly Woodman
Do I need to do anything else for someone to take a look? It would be great
to get it merged, if possible, and I think the change itself is pretty
trivial. Apologies if this is being pinged too soon; I'm trying to follow
the guidance on the FFmpeg contributing page ("if some time passes without
reaction, send a reminder by email.").

Thanks!

On Fri, 8 May 2020 at 03:10, Oliver Woodman  wrote:

> https://github.com/FFmpeg/FFmpeg/commit/601c238 added support
> for AV_PKT_DATA_NEW_EXTRADATA, but only for avcC extradata.
> This commit adds support for sps/pps extradata as well. This
> makes support consistent for passing new extradata consistent
> with the types of extradata that can be passed when initializing
> the decoder.
>
> Signed-off-by: Oliver Woodman 
> ---
>  libavcodec/h264dec.c | 13 ++---
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> index 4c355feb18..c1d103a474 100644
> --- a/libavcodec/h264dec.c
> +++ b/libavcodec/h264dec.c
> @@ -829,7 +829,7 @@ static int output_frame(H264Context *h, AVFrame *dst,
> H264Picture *srcp)
>  return 0;
>  }
>
> -static int is_extra(const uint8_t *buf, int buf_size)
> +static int is_avcc_extradata(const uint8_t *buf, int buf_size)
>  {
>  int cnt= buf[5]&0x1f;
>  const uint8_t *p= buf+6;
> @@ -956,16 +956,15 @@ static int h264_decode_frame(AVCodecContext *avctx,
> void *data,
>  if (buf_size == 0)
>  return send_next_delayed_frame(h, pict, got_frame, 0);
>
> -if (h->is_avc && av_packet_get_side_data(avpkt,
> AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
> +if (av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
>  int side_size;
>  uint8_t *side = av_packet_get_side_data(avpkt,
> AV_PKT_DATA_NEW_EXTRADATA, &side_size);
> -if (is_extra(side, side_size))
> -ff_h264_decode_extradata(side, side_size,
> - &h->ps, &h->is_avc,
> &h->nal_length_size,
> - avctx->err_recognition, avctx);
> +ff_h264_decode_extradata(side, side_size,
> + &h->ps, &h->is_avc, &h->nal_length_size,
> + avctx->err_recognition, avctx);
>  }
>  if (h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 &&
> (buf[4]&0xFC)==0xFC) {
> -if (is_extra(buf, buf_size))
> +if (is_avcc_extradata(buf, buf_size))
>  return ff_h264_decode_extradata(buf, buf_size,
>  &h->ps, &h->is_avc,
> &h->nal_length_size,
>  avctx->err_recognition,
> avctx);
> --
> 2.26.0.110.g2183baf09c-goog
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH v5 1/9] fftools/qsv: add device initialization from string

2020-05-18 Thread artem . galin
From: Artem Galin 

Signed-off-by: Artem Galin 
---
 fftools/ffmpeg_opt.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 60bb437ea7..83f1b53e9d 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -558,7 +558,11 @@ static int opt_init_hw_device(void *optctx, const char 
*opt, const char *arg)
 printf("\n");
 exit_program(0);
 } else {
-return hw_device_init_from_string(arg, NULL);
+int err;
+if (!arg)
+return AVERROR(ENOMEM);
+err = hw_device_init_from_string(arg, NULL);
+return err;
 }
 }
 
-- 
2.26.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] [WIP] XComposite window capture demuxer (Linux)

2020-05-18 Thread Marton Balint



On Mon, 18 May 2020, Emanuele Oriani wrote:


Hi Marton/ffmpeg devs/all,

Haven't seen any response to the proposed XComposite windows capture.

As per below the reasoning for adding this code to libav*/ffmpeg is that 
seems to be better in quality than x11grab, although it uses more CPU in 
its current implementation (uses OpenGL and PBO - optional - to fetch 
XComposite windows).


Please let me know if it's still of interest and/or you have further 
technical feedback.

I've posted some performance tests in the thread below.

Here links of two captures (one with x11grab, the other with xcompgrab) 
and the sources:


https://send.firefox.com/download/df859689f4cc6429/#EN6w9upyIMHqO7n_1hMTaQ
https://github.com/Emanem/replayer/blob/master/src/xcompgrab.c

Thanks in advance for your time and feedback,


Thanks. I am not familiar with the details of opengl/compositing 
capturing, but here are a few questions coming into my mind. Not only for 
you, but for other developers as well:


- Is there a way to keep the captured textures as an 
OpenGL/VAAPI/NVenc/Vulkan object, so the frames can work as some kind of 
hwaccel frames? Can this improve performance?


- What can be the reason between the quality/smoothness difference of 
x11grab and the Compositor capturer?


As for the code, I only took a quick look, here are some comments

- probably GCC atomics should be replaced by  atomic 
functions.


- Unless there is a reason, I think av_malloc/av_free is preferred for 
memory alloc functions.


- Maybe some openGL glue can be shared with libavdevice/opengl_enc.c? Take 
a look, I am not sure, because that was implemented with SDL and cross 
platform capabilities in mind, but since your capture device is only for 
linux (or not?), then maybe it makes more sense to keep it separete?


- Can the Xlib functions replaced with xcb? I kind of think that would be 
preferable if it is a sensible thing to do.


And sorry, I cannot say how useful this would be, maybe now is the time 
for people to speak up if somebody is particularly against adding this for 
any reason.


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

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

[FFmpeg-devel] [PATCH v5 2/9] libavcodec/qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callbacks with
proper MediaSDK pair type support.

Extending structure for proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavcodec/qsv.c  | 53 ++-
 libavcodec/qsv_internal.h |  2 +-
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index db98c75073..cc427c6dfd 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -36,6 +36,8 @@
 #include "avcodec.h"
 #include "qsv_internal.h"
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 #if QSV_VERSION_ATLEAST(1, 12)
 #include "mfx/mfxvp8.h"
 #endif
@@ -221,7 +223,9 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame 
*frame)
 int i;
 for (i = 0; i < ctx->nb_mids; i++) {
 QSVMid *mid = &ctx->mids[i];
-if (mid->handle == frame->surface.Data.MemId)
+mfxHDLPair *pair = (mfxHDLPair*)frame->surface.Data.MemId;
+if ((mid->handle_pair.first == pair->first) &&
+(mid->handle_pair.second == pair->second))
 return i;
 }
 return AVERROR_BUG;
@@ -362,7 +366,11 @@ static int ff_qsv_set_display_handle(AVCodecContext 
*avctx, QSVSession *qs)
 int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
  const char *load_plugins, int gpu_copy)
 {
+#if CONFIG_D3D11VA
+mfxIMPL  impl = MFX_IMPL_AUTO_ANY | MFX_IMPL_VIA_D3D11;
+#else
 mfxIMPL  impl = MFX_IMPL_AUTO_ANY;
+#endif
 mfxVersionver = { { QSV_VERSION_MINOR, QSV_VERSION_MAJOR } };
 mfxInitParam init_par = { MFX_IMPL_AUTO_ANY };
 
@@ -451,7 +459,7 @@ static AVBufferRef *qsv_create_mids(AVBufferRef 
*hw_frames_ref)
 
 for (i = 0; i < nb_surfaces; i++) {
 QSVMid *mid = &mids[i];
-mid->handle= frames_hwctx->surfaces[i].Data.MemId;
+mid->handle_pair   = 
*((mfxHDLPair*)frames_hwctx->surfaces[i].Data.MemId);
 mid->hw_frames_ref = hw_frames_ref1;
 }
 
@@ -628,7 +636,7 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 goto fail;
 
 qsv_mid->surf.Info = hw_frames_hwctx->surfaces[0].Info;
-qsv_mid->surf.Data.MemId = qsv_mid->handle;
+qsv_mid->surf.Data.MemId = &qsv_mid->handle_pair;
 
 /* map the data to the system memory */
 ret = av_hwframe_map(qsv_mid->locked_frame, qsv_mid->hw_frame,
@@ -661,7 +669,13 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId 
mid, mfxFrameData *ptr)
 static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
 QSVMid *qsv_mid = (QSVMid*)mid;
-*hdl = qsv_mid->handle;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)&qsv_mid->handle_pair;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
@@ -669,24 +683,19 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
AVBufferRef *device_ref, const char 
*load_plugins,
int gpu_copy)
 {
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
 AVHWDeviceContext*device_ctx = (AVHWDeviceContext*)device_ref->data;
 AVQSVDeviceContext *device_hwctx = device_ctx->hwctx;
 mfxSessionparent_session = device_hwctx->session;
 mfxInitParaminit_par = { MFX_IMPL_AUTO_ANY };
 mfxHDLhandle = NULL;
+int  hw_handle_supported = 0;
 
 mfxSessionsession;
 mfxVersionver;
 mfxIMPL   impl;
 mfxHandleType handle_type;
 mfxStatus err;
-
-int i, ret;
+int ret;
 
 err = MFXQueryIMPL(parent_session, &impl);
 if (err == MFX_ERR_NONE)
@@ -695,13 +704,23 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
 return ff_qsv_print_error(avctx, err,
   "Error querying the session attributes");
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+hw_handle_supported = 1;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+hw_handle_supported = 1;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+hw_handle_supported = 1;
+}
+
+if (hw_handle_supported) {
+err = MFXVideoCORE_GetHandle(parent_session, handle_ty

[FFmpeg-devel] [PATCH v5 4/9] libavutil/hwcontext_qsv: supporting d3d11va device type

2020-05-18 Thread artem . galin
From: Artem Galin 

This enables usage of non-powered/headless GPU, better HDR support.
Pool of resources is allocated as one texture with array of slices.

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 323 +++---
 1 file changed, 262 insertions(+), 61 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b1b67400de..d289bed8ca 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -27,9 +27,13 @@
 #include 
 #endif
 
+#define COBJMACROS
 #if CONFIG_VAAPI
 #include "hwcontext_vaapi.h"
 #endif
+#if CONFIG_D3D11VA
+#include "hwcontext_d3d11va.h"
+#endif
 #if CONFIG_DXVA2
 #include "hwcontext_dxva2.h"
 #endif
@@ -44,6 +48,8 @@
 #include "pixdesc.h"
 #include "time.h"
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 typedef struct QSVDevicePriv {
 AVBufferRef *child_device_ctx;
 } QSVDevicePriv;
@@ -70,6 +76,7 @@ typedef struct QSVFramesContext {
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
+mfxHDLPair *handle_pairs_internal;
 int nb_surfaces_used;
 
 // used in the frame allocator for non-opaque surfaces
@@ -81,20 +88,6 @@ typedef struct QSVFramesContext {
 mfxExtBuffer *ext_buffers[1];
 } QSVFramesContext;
 
-static const struct {
-mfxHandleType handle_type;
-enum AVHWDeviceType device_type;
-enum AVPixelFormat  pix_fmt;
-} supported_handle_types[] = {
-#if CONFIG_VAAPI
-{ MFX_HANDLE_VA_DISPLAY,  AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI 
},
-#endif
-#if CONFIG_DXVA2
-{ MFX_HANDLE_D3D9_DEVICE_MANAGER, AV_HWDEVICE_TYPE_DXVA2, 
AV_PIX_FMT_DXVA2_VLD },
-#endif
-{ 0 },
-};
-
 static const struct {
 enum AVPixelFormat pix_fmt;
 uint32_t   fourcc;
@@ -119,24 +112,11 @@ static int qsv_device_init(AVHWDeviceContext *ctx)
 {
 AVQSVDeviceContext *hwctx = ctx->hwctx;
 QSVDeviceContext   *s = ctx->internal->priv;
-
+int   hw_handle_supported = 0;
+mfxHandleType handle_type;
+enum AVHWDeviceType device_type;
+enum AVPixelFormat  pix_fmt;
 mfxStatus err;
-int i;
-
-for (i = 0; supported_handle_types[i].handle_type; i++) {
-err = MFXVideoCORE_GetHandle(hwctx->session, 
supported_handle_types[i].handle_type,
- &s->handle);
-if (err == MFX_ERR_NONE) {
-s->handle_type   = supported_handle_types[i].handle_type;
-s->child_device_type = supported_handle_types[i].device_type;
-s->child_pix_fmt = supported_handle_types[i].pix_fmt;
-break;
-}
-}
-if (!s->handle) {
-av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved 
"
-   "from the session\n");
-}
 
 err = MFXQueryIMPL(hwctx->session, &s->impl);
 if (err == MFX_ERR_NONE)
@@ -146,6 +126,41 @@ static int qsv_device_init(AVHWDeviceContext *ctx)
 return AVERROR_UNKNOWN;
 }
 
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_VAAPI
+handle_type = MFX_HANDLE_VA_DISPLAY;
+device_type = AV_HWDEVICE_TYPE_VAAPI;
+pix_fmt = AV_PIX_FMT_VAAPI;
+hw_handle_supported = 1;
+#endif
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_D3D11VA
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+device_type = AV_HWDEVICE_TYPE_D3D11VA;
+pix_fmt = AV_PIX_FMT_D3D11;
+hw_handle_supported = 1;
+#endif
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(s->impl)) {
+#if CONFIG_DXVA2
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+device_type = AV_HWDEVICE_TYPE_DXVA2;
+pix_fmt = AV_PIX_FMT_DXVA2_VLD;
+hw_handle_supported = 1;
+#endif
+}
+
+if (hw_handle_supported) {
+err = MFXVideoCORE_GetHandle(hwctx->session, handle_type, &s->handle);
+if (err == MFX_ERR_NONE) {
+s->handle_type   = handle_type;
+s->child_device_type = device_type;
+s->child_pix_fmt = pix_fmt;
+}
+}
+if (!s->handle) {
+av_log(ctx, AV_LOG_VERBOSE, "No supported hw handle could be retrieved 
"
+   "from the session\n");
+}
 return 0;
 }
 
@@ -175,6 +190,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 av_freep(&s->mem_ids);
 av_freep(&s->surface_ptrs);
 av_freep(&s->surfaces_internal);
+av_freep(&s->handle_pairs_internal);
 av_buffer_unref(&s->child_frames_ref);
 }
 
@@ -190,6 +206,8 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, int size)
 
 if (s->nb_surfaces_used < hwctx->nb_surfaces) {
 s->nb_surfaces_used++;
+av_buffer_create((uint8_t*)(s->handle_pairs_internal + 
s->nb_surfaces_used - 1),
+sizeof(*s->handle_pairs_internal), 
qsv_pool_release_dummy, NULL, 0);
 return av_buffer_create((uint8_t*)(s->surfaces_internal + 
s->nb_surfaces_used - 1),
 

[FFmpeg-devel] [PATCH v5 6/9] libavutil/hwcontext_qsv: pass vendor option to child device

2020-05-18 Thread artem . galin
From: Artem Galin 

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 036dc94748..d84de696dd 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1451,6 +1451,11 @@ static int qsv_device_create(AVHWDeviceContext *ctx, 
const char *device,
 #endif
 #if CONFIG_D3D11VA
 case AV_HWDEVICE_TYPE_D3D11VA:
+{
+e = av_dict_get(opts, "vendor", NULL, 0);
+if(e)
+av_dict_set(&child_device_opts, "vendor", e->value, 0);
+}
 break;
 #endif
 #if CONFIG_DXVA2
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v5 7/9] libavfilter/qsvvpp: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/qsvvpp.c | 31 ++-
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8d5ff2eb65..0d3f7fb2f9 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -36,6 +36,7 @@
 
MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
 #define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
 #define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 typedef struct QSVFrame {
 AVFrame  *frame;
@@ -68,12 +69,6 @@ struct QSVVPPContext {
 int nb_ext_buffers;
 };
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static const AVRational default_tb = { 1, 9 };
 
 /* functions for frameAlloc */
@@ -129,7 +124,13 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
@@ -497,14 +498,18 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (ret == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
 if (ret != MFX_ERR_NONE) {
 av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v5 5/9] libavutil/hwcontext_qsv: enabling d3d11va usage by default, add usage child_device_type argument

2020-05-18 Thread artem . galin
From: Artem Galin 

Makes selection of d3d11va device type by default and over DirectX 9,
which might break users with older drivers/systems.
DCH driver with Gen6th support should be still fine.

Decode, encode, transcode have been validated.

child_device_type option is responsible for d3d11va/dxva2 device selection

Usage examples:

DirectX 11
-init_hw_device qsv:hw,child_device_type=d3d11va

DirectX 9 is still supported but requires explicit selection
-init_hw_device qsv:hw,child_device_type=dxva2

Signed-off-by: Artem Galin 
---
 libavutil/hwcontext_qsv.c | 59 +--
 1 file changed, 45 insertions(+), 14 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index d289bed8ca..036dc94748 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1415,28 +1415,59 @@ static int qsv_device_create(AVHWDeviceContext *ctx, 
const char *device,
 ctx->user_opaque = priv;
 ctx->free= qsv_device_free;
 
-e = av_dict_get(opts, "child_device", NULL, 0);
-
-child_device_opts = NULL;
-if (CONFIG_VAAPI) {
+e = av_dict_get(opts, "child_device_type", NULL, 0);
+if (e) {
+child_device_type = av_hwdevice_find_type_by_name(e ? e->value : NULL);
+if (child_device_type == AV_HWDEVICE_TYPE_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Unknown child device type "
+   "\"%s\".\n", e ? e->value : NULL);
+return AVERROR(EINVAL);
+}
+} else if (CONFIG_VAAPI) {
 child_device_type = AV_HWDEVICE_TYPE_VAAPI;
-// libmfx does not actually implement VAAPI properly, rather it
-// depends on the specific behaviour of a matching iHD driver when
-// used on recent Intel hardware.  Set options to the VAAPI device
-// creation so that we should pick a usable setup by default if
-// possible, even when multiple devices and drivers are available.
-av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
-av_dict_set(&child_device_opts, "driver","iHD",  0);
-} else if (CONFIG_DXVA2)
+} else if (CONFIG_D3D11VA) {
+child_device_type = AV_HWDEVICE_TYPE_D3D11VA;
+} else if (CONFIG_DXVA2) {
 child_device_type = AV_HWDEVICE_TYPE_DXVA2;
-else {
+} else {
 av_log(ctx, AV_LOG_ERROR, "No supported child device type is 
enabled\n");
 return AVERROR(ENOSYS);
 }
 
+child_device_opts = NULL;
+switch (child_device_type) {
+#if CONFIG_VAAPI
+case AV_HWDEVICE_TYPE_VAAPI:
+{
+// libmfx does not actually implement VAAPI properly, rather it
+// depends on the specific behaviour of a matching iHD driver when
+// used on recent Intel hardware.  Set options to the VAAPI device
+// creation so that we should pick a usable setup by default if
+// possible, even when multiple devices and drivers are available.
+av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
+av_dict_set(&child_device_opts, "driver","iHD",  0);
+}
+break;
+#endif
+#if CONFIG_D3D11VA
+case AV_HWDEVICE_TYPE_D3D11VA:
+break;
+#endif
+#if CONFIG_DXVA2
+case AV_HWDEVICE_TYPE_DXVA2:
+break;
+#endif
+default:
+{
+av_log(ctx, AV_LOG_ERROR, "No supported child device type is 
enabled\n");
+return AVERROR(ENOSYS);
+}
+break;
+}
+
+e = av_dict_get(opts, "child_device", NULL, 0);
 ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type,
  e ? e->value : NULL, child_device_opts, 0);
-
 av_dict_free(&child_device_opts);
 if (ret < 0)
 return ret;
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v5 9/9] libavfilter/vf_deinterlace_qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/vf_deinterlace_qsv.c | 44 ++--
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 80217c8419..f7f9d916db 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -42,6 +42,8 @@
 #include "internal.h"
 #include "video.h"
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 enum {
 QSVDEINT_MORE_OUTPUT = 1,
 QSVDEINT_MORE_INPUT,
@@ -157,16 +159,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static int init_out_session(AVFilterContext *ctx)
 {
 
@@ -183,26 +185,30 @@ static int init_out_session(AVFilterContext *ctx)
 mfxIMPL impl;
 mfxVideoParam par;
 mfxStatus err;
-int i;
+int ret, i;
 
 /* extract the properties of the "master" session given to us */
-err = MFXQueryIMPL(device_hwctx->session, &impl);
-if (err == MFX_ERR_NONE)
-err = MFXQueryVersion(device_hwctx->session, &ver);
-if (err != MFX_ERR_NONE) {
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
-if (err != MFX_ERR_NONE) {
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
 }
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v5 3/9] libavutil/hwcontext_d3d11va: adding the vendor option to d3d11va device creation

2020-05-18 Thread artem . galin
From: Artem Galin 

Example: --init_hw_device d3d11va:,vendor=0x8086

qsv_device option is still works and has higher priority over vendor
option.

Signed-off-by: Artem Galin hwctx;
 
 HRESULT hr;
+AVDictionaryEntry *e;
 IDXGIAdapter   *pAdapter = NULL;
 ID3D10Multithread  *pMultithread;
 UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
+int adapter = -1;
+long int vendor_id = -1;
 int is_debug   = !!av_dict_get(opts, "debug", NULL, 0);
 int ret;
 
@@ -539,13 +542,45 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, 
const char *device,
 return AVERROR_UNKNOWN;
 }
 
+e = av_dict_get(opts, "vendor", NULL, 0);
+if (e) {
+vendor_id = strtol(e->value, NULL, 0);
+}
+
 if (device) {
+adapter = atoi(device);
+}
+
+if (adapter >= 0 || vendor_id != -1) {
 IDXGIFactory2 *pDXGIFactory;
 hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory);
 if (SUCCEEDED(hr)) {
-int adapter = atoi(device);
-if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, 
&pAdapter)))
+if (adapter < 0) {
+int adapter_cnt = 0;
+while (IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter_cnt++, 
&pAdapter) != DXGI_ERROR_NOT_FOUND) {
+DXGI_ADAPTER_DESC adapter_desc;
+hr = IDXGIAdapter2_GetDesc(pAdapter, &adapter_desc);
+if (FAILED(hr)) {
+av_log(ctx, AV_LOG_ERROR, "IDXGIAdapter2_GetDesc 
returned error with adapter id %d\n", adapter_cnt);
+continue;
+}
+
+if (adapter_desc.VendorId == vendor_id) {
+break;
+}
+
+if (adapter)
+IDXGIAdapter_Release(pAdapter);
+}
+if (adapter_cnt < 0) {
+av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter 
by vendor id %ld\n", vendor_id);
+IDXGIFactory2_Release(pDXGIFactory);
+return AVERROR_UNKNOWN;
+}
+} else {
+if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, 
&pAdapter)))
 pAdapter = NULL;
+}
 IDXGIFactory2_Release(pDXGIFactory);
 }
 }
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH v5 8/9] libavfilter/vf_scale_qsv: enabling d3d11va support, added mfxhdlpair

2020-05-18 Thread artem . galin
From: Artem Galin 

Adding DX11 relevant device type checks and adjusting callback with
proper MediaSDK pair type support.

Signed-off-by: Artem Galin 
---
 libavfilter/vf_scale_qsv.c | 43 +-
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 5064dcbb60..47701c20d0 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -70,6 +70,7 @@ enum var_name {
 };
 
 #define QSV_HAVE_SCALING_CONFIG  QSV_VERSION_ATLEAST(1, 19)
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
 
 typedef struct QSVScaleContext {
 const AVClass *class;
@@ -264,16 +265,16 @@ static mfxStatus frame_unlock(mfxHDL pthis, mfxMemId mid, 
mfxFrameData *ptr)
 
 static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-*hdl = mid;
+mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
+mfxHDLPair *pair_src = (mfxHDLPair*)mid;
+
+pair_dst->first = pair_src->first;
+
+if (pair_src->second != (mfxMemId)MFX_INFINITE)
+pair_dst->second = pair_src->second;
 return MFX_ERR_NONE;
 }
 
-static const mfxHandleType handle_types[] = {
-MFX_HANDLE_VA_DISPLAY,
-MFX_HANDLE_D3D9_DEVICE_MANAGER,
-MFX_HANDLE_D3D11_DEVICE,
-};
-
 static int init_out_session(AVFilterContext *ctx)
 {
 
@@ -292,28 +293,32 @@ static int init_out_session(AVFilterContext *ctx)
 mfxIMPL impl;
 mfxVideoParam par;
 mfxStatus err;
-int i;
+int ret, i;
 
 s->num_ext_buf = 0;
 
 /* extract the properties of the "master" session given to us */
-err = MFXQueryIMPL(device_hwctx->session, &impl);
-if (err == MFX_ERR_NONE)
-err = MFXQueryVersion(device_hwctx->session, &ver);
-if (err != MFX_ERR_NONE) {
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes\n");
 return AVERROR_UNKNOWN;
 }
 
-for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) {
-err = MFXVideoCORE_GetHandle(device_hwctx->session, handle_types[i], 
&handle);
-if (err == MFX_ERR_NONE) {
-handle_type = handle_types[i];
-break;
-}
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(ctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
 }
 
-if (err != MFX_ERR_NONE) {
+ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
+if (ret != MFX_ERR_NONE) {
 av_log(ctx, AV_LOG_ERROR, "Error getting the session handle\n");
 return AVERROR_UNKNOWN;
 }
-- 
2.26.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 1/6] avutil/opt: add AV_OPT_FLAG_CHILD_CONSTS

2020-05-18 Thread Marton Balint



On Mon, 11 May 2020, Marton Balint wrote:


This will be used for AVCodecContext->profile. By specifying constants in the
encoders we won't have to use the common AVCodecContext options table and
different encoders can use the same profile name even with different values.

Signed-off-by: Marton Balint 
---
doc/APIchanges  | 3 +++
libavutil/opt.c | 3 ++-
libavutil/opt.h | 1 +
libavutil/version.h | 2 +-
4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 75cfdb08b0..235888c174 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21

API changes, most recent first:

+2020-05-xx - xx - lavu 56.44.101 - opt.h
+  Add AV_OPT_FLAG_CHILD_CONSTS.
+
2020-05-10 - xx - lavu 56.44.100 - hwcontext_vulkan.h
  Add enabled_inst_extensions, num_enabled_inst_extensions, 
enabled_dev_extensions
  and num_enabled_dev_extensions fields to AVVulkanDeviceContext
diff --git a/libavutil/opt.c b/libavutil/opt.c
index b792dec01c..423313bce2 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -256,11 +256,12 @@ static int set_string_number(void *obj, void *target_obj, 
const AVOption *o, con
}

{
-const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, 
o->unit, 0, 0);
int res;
int ci = 0;
double const_values[64];
const char * const_names[64];
+int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? 
AV_OPT_SEARCH_CHILDREN : 0;
+const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, 
o->unit, 0, search_flags);
if (o_named && o_named->type == AV_OPT_TYPE_CONST)
d = DEFAULT_NUMVAL(o_named);
else {
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 1969c984dd..e46119572a 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -291,6 +291,7 @@ typedef struct AVOption {
#define AV_OPT_FLAG_RUNTIME_PARAM   (1<<15) ///< a generic parameter which can 
be set by the user at runtime
#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can 
be set by the user for filtering
#define AV_OPT_FLAG_DEPRECATED  (1<<17) ///< set if option is deprecated, 
users should refer to AVOption.help text for more information
+#define AV_OPT_FLAG_CHILD_CONSTS(1<<18) ///< set if option constants can 
also reside in child objects
//FIXME think about enc-audio, ... style flags

/**
diff --git a/libavutil/version.h b/libavutil/version.h
index 48d8a38c42..c4946c1c7e 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@

#define LIBAVUTIL_VERSION_MAJOR  56
#define LIBAVUTIL_VERSION_MINOR  44
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101

#define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
   LIBAVUTIL_VERSION_MINOR, \



Ping for the series, is there anybody against the approach I took to move 
profile name constants to encoders?


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

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

Re: [FFmpeg-devel] [PATCH 6/6] avcodec: move mpeg4 profiles to profiles.h

2020-05-18 Thread Marton Balint



On Mon, 18 May 2020, Fu, Linjie wrote:


diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h
index d950971875..e414ea77a7 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -37,6 +37,12 @@
 FF_AVCTX_PROFILE_OPTION("mpeg2_aac_low", NULL, AUDIO,
FF_PROFILE_MPEG2_AAC_LOW)\
 FF_AVCTX_PROFILE_OPTION("mpeg2_aac_he",  NULL, AUDIO,
FF_PROFILE_MPEG2_AAC_HE)\

+#define FF_MPEG4_PROFILE_OPTS \
+FF_AVCTX_PROFILE_OPTION("mpeg4_sp",  NULL, VIDEO,
FF_PROFILE_MPEG4_SIMPLE)\
+FF_AVCTX_PROFILE_OPTION("mpeg4_core",NULL, VIDEO,
FF_PROFILE_MPEG4_CORE)\
+FF_AVCTX_PROFILE_OPTION("mpeg4_main",NULL, VIDEO,
FF_PROFILE_MPEG4_MAIN)\
+FF_AVCTX_PROFILE_OPTION("mpeg4_asp", NULL, VIDEO,
FF_PROFILE_MPEG4_ADVANCED_SIMPLE)\
+

Since it's now searchable according to the AVClass, we may not need
the prefix anymore. (for now it's necessary for the ABI)

Hence would it be better to add some deprecated flags for them and
remove the prefix in future  when avcodec version increase?
(something like FF_API_NEXT)


Yes, can be done later, but this patch is only about moving existing 
option names, not deprecating existing ones and adding new names.


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

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

Re: [FFmpeg-devel] [RFC] encoder profile validation

2020-05-18 Thread Marton Balint



On Mon, 18 May 2020, Anton Khirnov wrote:


Quoting Marton Balint (2020-05-16 15:52:22)

Hi,

As you may know, a recent patchset enabled AVCodecContext->profile 
constants to reside in encoders.


In order to make a full transition to avctx->profile even in existing 
encoders which might use a private profile setting, we have to make sure 
only supported avctx->profile values are passed to encoders.


The fact that avctx->profile is not validated is already an issue, and 
assertions/segmentation faults can already happen in existing encoders 
(e.g.: aac, mpeg) if unsupported values are passed.


AVCodec have a .profiles attribute which supposed to contain the list of 
supported profiles. However this is problematic because

- AVCodecContext->profile is not validated against this list
- not all encoders define the list
- even if there is a list it might be defined as NULL_IF_CONFIG_SMALL
- some encoders support more or less than its currently defined list


All of these sound like bugs that can and should be fixed.


- AVCodec->profiles contains AVProfiles which supposed to have a textual
   representation of each profile, which can cause profile name
   duplications/inconsistencies against libavcodec/profiles.c if the list
   is different to the one in codecs profile list.


Why should it be different? Isn't that a bug that should be fixed?


The list can be different because possibly not all the profiles which are 
recognized by the decoder is supported by the encoder. Also the encoder 
can define pseudo profiles which it can support, for example the AAC 
encoders have support for FF_PROFILE_MPEG2_AAC_LOW which is LC profile 
with some features disabled.






So I'd rather not user AVCodec->profiles for this validation. I am 
thinking about two possible solutions:


It seems preferable to me to fix the above issues and not have multiple
fields with subtly different meanings that are just bound to cause
confusion and bugs.


I agree that having the list of suppored profiles in two places is wrong, 
so in the long run, I would simply deprecate AVCodec->profiles, and use 
only the AVOptions to list the supported profiles. Also see my previous 
patchset which moves profile names directly to encoders:


https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1193

So the supported profiles would be contained in one place, AVOptions.
Even querying the list should be doable, if needed, and 
av_get_profile_name can also be modified to get the profile name from the 
AVOptions.


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

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

Re: [FFmpeg-devel] [PATCH 2/2] Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.

2020-05-18 Thread Dale Curtis
The C versions of these functions have landed. Michael, did you intend to
land this one too?

- dale

On Thu, May 14, 2020 at 12:47 PM Dale Curtis  wrote:

> Rebased.
>
> On Mon, May 4, 2020 at 11:47 AM James Almer  wrote:
>
>> On 5/4/2020 3:40 PM, Dale Curtis wrote:
>> > On Mon, May 4, 2020 at 11:19 AM James Almer  wrote:
>> >
>> >> On 5/4/2020 3:09 PM, Dale Curtis wrote:
>> >>> Bump. I have 5 integer overflow fuzzing issues awaiting our
>> resolution of
>> >>> this discussion. Thanks.
>> >>>
>> >>> - dale
>> >>
>> >> What's the first version of clang with support for
>> __builtin_*_overflow?
>> >> Because with your patch as is (Checking only __clang__), it's very
>> >> likely old clang builds could be broken. We have things like Clang 3 on
>> >> FATE right now.
>> >>
>> >
>> > Clang 10.0 apparently:
>> >
>> https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
>> -
>> > I'm fine with limiting support to where it works though. Attached patch
>> > does that.
>> >
>> >
>> >>
>> >> Also, does clang-cl define __clang__ and these builtins? Because maybe
>> >> we could remove that check and just keep the GCC + Intel one. The
>> former
>> >> should in theory cover Clang builds that are reportedly compatible with
>> >> GCC >= 5.1
>> >>
>> >
>> > Yes, clang-cl defines __clang__ and these builtins.
>> >
>> > - dale
>>
>> Ok, if __has_builtin() works for these then this patch LGTM, but I'd
>> prefer to first hear Michael's opinion about your reply to his question.
>> ___
>> 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] Open pull request to mitigate CVE-2020-12284 buffer overflow

2020-05-18 Thread Patrick Watts
All,

Apologies in advance if this is not the correct forum. We're currently
using FFmpeg in a production application, and our infosec folks have
flagged it as a vulnerability.

https://github.com/FFmpeg/FFmpeg/commit/1812352d767ccf5431aa440123e2e260a4db2726

a) has anyone applied and implemented this patch in an upcoming version of
FFmpeg?
b) has anyone had to deal with mitigating this vulnerability in your
production application, and can point us to a solution that doesn't force
us to compromise functionality?

CVE details: https://nvd.nist.gov/vuln/detail/CVE-2020-12284

Private or public replies are welcome.

Thanks!


*Patrick Watts *Lead Business Analyst
LifeWay Christian Resources
(615) 251-5793
Twitter: @patrickwatts 


*We serve the Church in Her mission of making disciples.*
*FREE resources from LifeWay for your church:*
https://lifeway.com/coronavirus



*Download a free sample at https://vbs.lifeway.com/free-sample/
*
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 2/3] fftools/cmdutils: remove lossless and intra only capability entries from print_codec()

2020-05-18 Thread James Almer
They are codec properties, not encoder capabilities.

Signed-off-by: James Almer 
---
 fftools/cmdutils.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 7f5a5ca664..7bec1db18b 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1423,10 +1423,6 @@ static void print_codec(const AVCodec *c)
 printf("threads ");
 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
 printf("avoidprobe ");
-if (c->capabilities & AV_CODEC_CAP_INTRA_ONLY)
-printf("intraonly ");
-if (c->capabilities & AV_CODEC_CAP_LOSSLESS)
-printf("lossless ");
 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
 printf("hardware ");
 if (c->capabilities & AV_CODEC_CAP_HYBRID)
-- 
2.26.2

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

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

[FFmpeg-devel] [PATCH 3/3] avcodec: deprecate Lossless and Intra Only encoder capabilites

2020-05-18 Thread James Almer
Both are codec properties and not encoder capabilities. The relevant
AVCodecDescriptor.props flags exist for this purpose.

Signed-off-by: James Almer 
---
 doc/APIchanges  | 3 +++
 libavcodec/audiotoolboxenc.c| 2 +-
 libavcodec/avcodec.h| 7 +--
 libavcodec/avuienc.c| 2 +-
 libavcodec/dnxhdenc.c   | 2 +-
 libavcodec/dvenc.c  | 2 +-
 libavcodec/flacenc.c| 2 +-
 libavcodec/huffyuvenc.c | 4 ++--
 libavcodec/jpeglsenc.c  | 2 +-
 libavcodec/lclenc.c | 2 +-
 libavcodec/libopenjpegenc.c | 2 +-
 libavcodec/librsvgdec.c | 2 +-
 libavcodec/ljpegenc.c   | 2 +-
 libavcodec/magicyuvenc.c| 2 +-
 libavcodec/mjpegenc.c   | 2 +-
 libavcodec/pngenc.c | 2 +-
 libavcodec/proresenc_anatoliy.c | 4 ++--
 libavcodec/proresenc_kostya.c   | 2 +-
 libavcodec/r210enc.c| 3 ---
 libavcodec/tiffenc.c| 2 +-
 libavcodec/ttaenc.c | 2 +-
 libavcodec/utvideoenc.c | 2 +-
 libavcodec/v308enc.c| 1 -
 libavcodec/v408enc.c| 2 --
 libavcodec/vaapi_encode_mjpeg.c | 3 +--
 libavcodec/version.h| 5 -
 libavcodec/xfaceenc.c   | 1 -
 libavcodec/y41penc.c| 1 -
 libavcodec/yuv4enc.c| 1 -
 29 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 986ca9f206..39428308c4 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2020-05-xx - xx - lavc 56.85.100 - avcodec.h
+  Deprecated AV_CODEC_CAP_INTRA_ONLY and AV_CODEC_CAP_LOSSLESS.
+
 2020-05-xx - xx - lavu 56.46.100 - common.h
   Add av_sat_add64() and av_sat_sub64()
 
diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c
index 27632decf5..e8748b3c68 100644
--- a/libavcodec/audiotoolboxenc.c
+++ b/libavcodec/audiotoolboxenc.c
@@ -656,7 +656,7 @@ static const uint64_t aac_at_channel_layouts[] = {
 
 FFAT_ENC(aac,  AV_CODEC_ID_AAC,  aac_profiles, , 
.channel_layouts = aac_at_channel_layouts)
 //FFAT_ENC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT, NULL)
-FFAT_ENC(alac, AV_CODEC_ID_ALAC, NULL, | 
AV_CODEC_CAP_VARIABLE_FRAME_SIZE | AV_CODEC_CAP_LOSSLESS)
+FFAT_ENC(alac, AV_CODEC_ID_ALAC, NULL, | 
AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
 FFAT_ENC(ilbc, AV_CODEC_ID_ILBC, NULL)
 FFAT_ENC(pcm_alaw, AV_CODEC_ID_PCM_ALAW, NULL)
 FFAT_ENC(pcm_mulaw,AV_CODEC_ID_PCM_MULAW,NULL)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c9baf859ac..4d04787b2d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -483,14 +483,17 @@ typedef struct RcOverride{
  * choice for probing.
  */
 #define AV_CODEC_CAP_AVOID_PROBING   (1 << 17)
+
+#if FF_API_UNUSED_CODEC_CAPS
 /**
- * Codec is intra only.
+ * Deprecated and unused. Use AVCodecDescriptor.props instead
  */
 #define AV_CODEC_CAP_INTRA_ONLY   0x4000
 /**
- * Codec is lossless.
+ * Deprecated and unused. Use AVCodecDescriptor.props instead
  */
 #define AV_CODEC_CAP_LOSSLESS 0x8000
+#endif
 
 /**
  * Codec is backed by a hardware implementation. Typically used to
diff --git a/libavcodec/avuienc.c b/libavcodec/avuienc.c
index b219906706..2091309e7e 100644
--- a/libavcodec/avuienc.c
+++ b/libavcodec/avuienc.c
@@ -98,6 +98,6 @@ AVCodec ff_avui_encoder = {
 .id   = AV_CODEC_ID_AVUI,
 .init = avui_encode_init,
 .encode2  = avui_encode_frame,
-.capabilities = AV_CODEC_CAP_EXPERIMENTAL | AV_CODEC_CAP_INTRA_ONLY,
+.capabilities = AV_CODEC_CAP_EXPERIMENTAL,
 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_UYVY422, 
AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 32ac90f751..fad8400c21 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -1396,7 +1396,7 @@ AVCodec ff_dnxhd_encoder = {
 .init   = dnxhd_encode_init,
 .encode2= dnxhd_encode_picture,
 .close  = dnxhd_encode_end,
-.capabilities   = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS 
| AV_CODEC_CAP_INTRA_ONLY,
+.capabilities   = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]) {
 AV_PIX_FMT_YUV422P,
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index dca57feb4f..3e98d1b38c 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -1220,7 +1220,7 @@ AVCodec ff_dvvideo_encoder = {
 .priv_data_size = sizeof(DVVideoContext),
 .init   = dvvideo_encode_init,
 .encode2= dvvideo_encode_frame,
-.capabilities   = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS 
| AV_CODEC_CAP_INTRA_ONLY,
+.capabilities   = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
 .pix_fmts  

[FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_filter: check the codec's descriptor to see if it's lossless

2020-05-18 Thread James Almer
Signed-off-by: James Almer 
---
 fftools/ffmpeg_filter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 8b5b157be7..422e1268e9 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -99,7 +99,8 @@ void choose_sample_fmt(AVStream *st, AVCodec *codec)
 break;
 }
 if (*p == -1) {
-if((codec->capabilities & AV_CODEC_CAP_LOSSLESS) && 
av_get_sample_fmt_name(st->codecpar->format) > 
av_get_sample_fmt_name(codec->sample_fmts[0]))
+const AVCodecDescriptor *desc = avcodec_descriptor_get(codec->id);
+if(desc && (desc->props & AV_CODEC_PROP_LOSSLESS) && 
av_get_sample_fmt_name(st->codecpar->format) > 
av_get_sample_fmt_name(codec->sample_fmts[0]))
 av_log(NULL, AV_LOG_ERROR, "Conversion will not be 
lossless.\n");
 if(av_get_sample_fmt_name(st->codecpar->format))
 av_log(NULL, AV_LOG_WARNING,
-- 
2.26.2

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: export frame sample aspect ratio

2020-05-18 Thread James Almer
On 5/18/2020 12:16 PM, Anton Khirnov wrote:
> Quoting James Almer (2020-05-11 16:27:56)
>> Signed-off-by: James Almer 
>> ---
>>  libavcodec/libdav1d.c | 6 ++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
>> index 72f06c550e..a265a487d8 100644
>> --- a/libavcodec/libdav1d.c
>> +++ b/libavcodec/libdav1d.c
>> @@ -335,6 +335,12 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
>> AVFrame *frame)
>>  goto fail;
>>  }
>>  
>> +av_reduce(&frame->sample_aspect_ratio.num,
>> +  &frame->sample_aspect_ratio.den,
>> +  frame->height * (int64_t)p->frame_hdr->render_width,
>> +  frame->width  * (int64_t)p->frame_hdr->render_height,
>> +  INT_MAX);
> 
> Wondered whether av_div_q might make it look better, but probably not by
> much.
> 
> Patch looks ok.

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

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

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: export frame sample aspect ratio

2020-05-18 Thread Anton Khirnov
Quoting James Almer (2020-05-11 16:27:56)
> Signed-off-by: James Almer 
> ---
>  libavcodec/libdav1d.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index 72f06c550e..a265a487d8 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -335,6 +335,12 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
> AVFrame *frame)
>  goto fail;
>  }
>  
> +av_reduce(&frame->sample_aspect_ratio.num,
> +  &frame->sample_aspect_ratio.den,
> +  frame->height * (int64_t)p->frame_hdr->render_width,
> +  frame->width  * (int64_t)p->frame_hdr->render_height,
> +  INT_MAX);

Wondered whether av_div_q might make it look better, but probably not by
much.

Patch looks ok.

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

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

Re: [FFmpeg-devel] [PATCH] avcodec/frame_thread_encoder: check for frame threading codec cap instead of intra only

2020-05-18 Thread James Almer
On 5/18/2020 11:36 AM, Anton Khirnov wrote:
> Quoting James Almer (2020-05-18 15:56:36)
>> It's the correct dedicated capability reported by supported encoders.
>> Otherwise, the frame thread path will be used for unsupported encoders
>> like r210 for no gain.
>>
>> Signed-off-by: James Almer 
>> ---
> 
> Looks ok.
> 
> Also, this capability looks like it should not exist since it's not an
> encoder capability, it's a codec property. Same for CAP_LOSSLESS.

True. There's a AVCodecDescriptor.props flag for both of them after all.

Also, after this change AV_CODEC_CAP_INTRA_ONLY is unused (not counting
cmdutils.c where it's used to print an entry in a log message), so we
could safely deprecate it and remove it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libdav1d: try to set decoder context parameters during init()

2020-05-18 Thread James Almer
On 5/18/2020 11:43 AM, Anton Khirnov wrote:
> Quoting James Almer (2020-05-11 16:27:55)
>> If extradata is available, use it to initialize the AVCodecContext before
>> packet data is seen. Also, don't constantly overwrite it after it's set.
>>
>> Signed-off-by: James Almer 
>> ---
>> The main benefit from this is using ff_decode_frame_props() to fill frame
>> props, which includes copying any relevant side data that may be present in
>> packets, like for example container mastering metadata propagated by a 
>> demuxer.
>>
>>  libavcodec/libdav1d.c | 102 +-
>>  1 file changed, 71 insertions(+), 31 deletions(-)
>>
>> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
>> index 5248e3f9f5..72f06c550e 100644
>> --- a/libavcodec/libdav1d.c
>> +++ b/libavcodec/libdav1d.c
>> @@ -42,6 +42,8 @@ typedef struct Libdav1dContext {
>>  int apply_grain;
>>  int operating_point;
>>  int all_layers;
>> +
>> +int inited;
>>  } Libdav1dContext;
>>  
>>  static const enum AVPixelFormat pix_fmt[][3] = {
>> @@ -117,9 +119,59 @@ static void libdav1d_picture_release(Dav1dPicture *p, 
>> void *cookie)
>>  av_buffer_unref(&buf);
>>  }
>>  
>> +static int libdav1d_init_params(AVCodecContext *c, Dav1dSequenceHeader *seq)
>> +{
>> +Libdav1dContext *dav1d = c->priv_data;
>> +int res;
>> +
>> +if (dav1d->inited)
>> +return 0;
> 
> Changing parameters mid-stream is not supported?

Sequence Headers are not meant to change within a video sequence. Afaik,
the only params that can change between frames are its dimensions, and
that's already handled by looking at the values on a given Dav1dPicture.
But libdav1d does seem to gracefully handle changes in seq headers by
assuming it's a new sequence and resetting its internal state, so i
guess I'll remove it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libdav1d: try to set decoder context parameters during init()

2020-05-18 Thread Anton Khirnov
Quoting James Almer (2020-05-11 16:27:55)
> If extradata is available, use it to initialize the AVCodecContext before
> packet data is seen. Also, don't constantly overwrite it after it's set.
> 
> Signed-off-by: James Almer 
> ---
> The main benefit from this is using ff_decode_frame_props() to fill frame
> props, which includes copying any relevant side data that may be present in
> packets, like for example container mastering metadata propagated by a 
> demuxer.
> 
>  libavcodec/libdav1d.c | 102 +-
>  1 file changed, 71 insertions(+), 31 deletions(-)
> 
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index 5248e3f9f5..72f06c550e 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -42,6 +42,8 @@ typedef struct Libdav1dContext {
>  int apply_grain;
>  int operating_point;
>  int all_layers;
> +
> +int inited;
>  } Libdav1dContext;
>  
>  static const enum AVPixelFormat pix_fmt[][3] = {
> @@ -117,9 +119,59 @@ static void libdav1d_picture_release(Dav1dPicture *p, 
> void *cookie)
>  av_buffer_unref(&buf);
>  }
>  
> +static int libdav1d_init_params(AVCodecContext *c, Dav1dSequenceHeader *seq)
> +{
> +Libdav1dContext *dav1d = c->priv_data;
> +int res;
> +
> +if (dav1d->inited)
> +return 0;

Changing parameters mid-stream is not supported?

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

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

Re: [FFmpeg-devel] [PATCH] avcodec/frame_thread_encoder: check for frame threading codec cap instead of intra only

2020-05-18 Thread Anton Khirnov
Quoting James Almer (2020-05-18 15:56:36)
> It's the correct dedicated capability reported by supported encoders.
> Otherwise, the frame thread path will be used for unsupported encoders
> like r210 for no gain.
> 
> Signed-off-by: James Almer 
> ---

Looks ok.

Also, this capability looks like it should not exist since it's not an
encoder capability, it's a codec property. Same for CAP_LOSSLESS.

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

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

[FFmpeg-devel] [PATCH] Stop hardcoding align=32 in av_frame_get_buffer() calls.

2020-05-18 Thread Anton Khirnov
Use 0, which selects the alignment automatically.
---
 doc/examples/encode_video.c| 2 +-
 doc/examples/muxing.c  | 2 +-
 doc/examples/vaapi_encode.c| 2 +-
 fftools/ffmpeg.c   | 2 +-
 fftools/ffmpeg_videotoolbox.c  | 2 +-
 libavcodec/asvenc.c| 2 +-
 libavcodec/encode.c| 2 +-
 libavcodec/libwebpenc_common.c | 2 +-
 libavcodec/mpegvideo_enc.c | 2 +-
 libavcodec/pngenc.c| 4 ++--
 libavcodec/tdsc.c  | 2 +-
 libavfilter/af_compand.c   | 2 +-
 libavfilter/af_compensationdelay.c | 2 +-
 libavfilter/avf_showcqt.c  | 2 +-
 libavfilter/vf_find_rect.c | 2 +-
 libavfilter/vf_signalstats.c   | 2 +-
 libavutil/frame.c  | 4 ++--
 libavutil/hwcontext.c  | 2 +-
 libavutil/hwcontext_qsv.c  | 2 +-
 tests/api/api-flac-test.c  | 2 +-
 tests/api/api-threadmessage-test.c | 2 +-
 21 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
index d9ab409908..908eb203d5 100644
--- a/doc/examples/encode_video.c
+++ b/doc/examples/encode_video.c
@@ -145,7 +145,7 @@ int main(int argc, char **argv)
 frame->width  = c->width;
 frame->height = c->height;
 
-ret = av_frame_get_buffer(frame, 32);
+ret = av_frame_get_buffer(frame, 0);
 if (ret < 0) {
 fprintf(stderr, "Could not allocate the video frame data\n");
 exit(1);
diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index c1d42303af..bd16486a24 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -396,7 +396,7 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, 
int width, int height)
 picture->height = height;
 
 /* allocate the buffers for the frame data */
-ret = av_frame_get_buffer(picture, 32);
+ret = av_frame_get_buffer(picture, 0);
 if (ret < 0) {
 fprintf(stderr, "Could not allocate frame data.\n");
 exit(1);
diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
index 98fd5d3b51..707939db37 100644
--- a/doc/examples/vaapi_encode.c
+++ b/doc/examples/vaapi_encode.c
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
 sw_frame->width  = width;
 sw_frame->height = height;
 sw_frame->format = AV_PIX_FMT_NV12;
-if ((err = av_frame_get_buffer(sw_frame, 32)) < 0)
+if ((err = av_frame_get_buffer(sw_frame, 0)) < 0)
 goto close;
 if ((err = fread((uint8_t*)(sw_frame->data[0]), size, 1, fin)) <= 0)
 break;
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f697460a30..ad95a0e417 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -182,7 +182,7 @@ static int sub2video_get_blank_frame(InputStream *ist)
 ist->sub2video.frame->width  = ist->dec_ctx->width  ? ist->dec_ctx->width  
: ist->sub2video.w;
 ist->sub2video.frame->height = ist->dec_ctx->height ? ist->dec_ctx->height 
: ist->sub2video.h;
 ist->sub2video.frame->format = AV_PIX_FMT_RGB32;
-if ((ret = av_frame_get_buffer(frame, 32)) < 0)
+if ((ret = av_frame_get_buffer(frame, 0)) < 0)
 return ret;
 memset(frame->data[0], 0, frame->height * frame->linesize[0]);
 return 0;
diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
index 628fb5e32c..a6b78d0f7d 100644
--- a/fftools/ffmpeg_videotoolbox.c
+++ b/fftools/ffmpeg_videotoolbox.c
@@ -67,7 +67,7 @@ static int videotoolbox_retrieve_data(AVCodecContext *s, 
AVFrame *frame)
 
 vt->tmp_frame->width  = frame->width;
 vt->tmp_frame->height = frame->height;
-ret = av_frame_get_buffer(vt->tmp_frame, 32);
+ret = av_frame_get_buffer(vt->tmp_frame, 0);
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index 3cc94bf91a..c2c940f365 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -228,7 +228,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 clone->format = pict->format;
 clone->width  = FFALIGN(pict->width, 16);
 clone->height = FFALIGN(pict->height, 16);
-ret = av_frame_get_buffer(clone, 32);
+ret = av_frame_get_buffer(clone, 0);
 if (ret < 0) {
 av_frame_free(&clone);
 return ret;
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 9ed2cf0f59..03d579fd4e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -90,7 +90,7 @@ static int pad_last_frame(AVCodecContext *s, AVFrame **dst, 
const AVFrame *src)
 frame->channel_layout = src->channel_layout;
 frame->channels   = src->channels;
 frame->nb_samples = s->frame_size;
-ret = av_frame_get_buffer(frame, 32);
+ret = av_frame_get_buffer(frame, 0);
 if (ret < 0)
 goto fail;
 
diff --git a/libavcodec/libwebpenc_common.c b/libavcodec/libwebpenc_common.c
index 21d7adaf56..3c4c3e2294 100644
--- a/libavcodec/libwebpenc_common.c
+++ b/li

[FFmpeg-devel] [PATCH] cmdutils: drop libavformat/network.h include

2020-05-18 Thread Anton Khirnov
It is not a public header and has not been used since
10173c0e58e557582dbd659f42c6aa164a8682db
---
 fftools/cmdutils.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 7f5a5ca664..b4fd44555b 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -55,9 +55,6 @@
 #include "libavutil/ffversion.h"
 #include "libavutil/version.h"
 #include "cmdutils.h"
-#if CONFIG_NETWORK
-#include "libavformat/network.h"
-#endif
 #if HAVE_SYS_RESOURCE_H
 #include 
 #include 
-- 
2.25.1

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

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

[FFmpeg-devel] [PATCH v3 5/5] avfilter/vf_libopencv: add opencv drawbox filter

2020-05-18 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
depend on below patchset:
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1212

 doc/filters.texi   |  21 ++
 libavfilter/vf_libopencv.c | 147 +++--
 2 files changed, 162 insertions(+), 6 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index e12c667348..cac204fd81 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14219,6 +14219,27 @@ Display width and height of every faces, face_id is 
the face index
 which is range from [0, nb_faces-1]
 @end table
 
+@subsection drawbox
+draw all boxes by the detected metadata results of the ocv filter's
+facedetect mode. If no face detection metadata exists, then the filter
+will do nothing.
+
+The filter takes the following parameters:
+@var{color}|@var{thickness}|@var{line_type}|@var{shift}.
+
+@var{color} Specify the color of the box to write. For the general syntax of 
this option,
+check the @ref{color syntax,,"Color" section in the ffmpeg-utils 
manual,ffmpeg-utils}.
+
+@var{thickness}
+Set the thickness of the box edge. Default value is @code{1}.
+Negative values, like -1, mean that the function has to draw a filled 
rectangle.
+
+@var{line_type}
+Set the line type of the box boundary. Default value is @code{8}.
+
+@var{shift}
+Set the number of fractional bits in the point coordinates. Default value is 
@code{0}.
+
 @section oscilloscope
 
 2D Video Oscilloscope.
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index c70c4dc8b9..2e23222cb4 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -42,6 +42,7 @@
 #include "libavutil/common.h"
 #include "libavutil/file.h"
 #include "libavutil/opt.h"
+#include "libavutil/parseutils.h"
 #include "avfilter.h"
 #include "formats.h"
 #include "internal.h"
@@ -90,6 +91,7 @@ typedef struct OCVContext {
 void (*uninit)(AVFilterContext *ctx);
 void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage 
*outimg);
 void (*postprocess)(AVFilterContext *ctx, AVFrame *out);
+void (*preprocess)(AVFilterContext *ctx, AVFrame *in);
 void *priv;
 } OCVContext;
 
@@ -466,6 +468,127 @@ static void facedetect_postprocess(AVFilterContext *ctx, 
AVFrame *out)
 }
 }
 
+typedef struct DrawboxContext {
+CvScalar color;
+int thickness;
+int line_type;
+int shift;
+
+int nb_faces;
+CvRect *faces[1024];
+} DrawboxContext;
+
+static av_cold int drawbox_init(AVFilterContext *ctx, const char *args)
+{
+OCVContext *s = ctx->priv;
+DrawboxContext *drawbox = s->priv;
+const char *buf = args;
+int ret;
+uint8_t rgba[4] = { 255, 0, 0, 255};
+char color_str[32] = "Red";
+
+drawbox->thickness = 1;
+drawbox->line_type = 8;
+drawbox->shift = 0;
+if (args) {
+sscanf(args, "%32[^|]|%d|%d|%d", color_str, &drawbox->thickness, 
&drawbox->line_type, &drawbox->shift);
+}
+
+if (av_parse_color(rgba, color_str, -1, ctx) < 0) {
+av_log(ctx, AV_LOG_ERROR, "failed to get color \n");
+return AVERROR(EINVAL);
+}
+drawbox->color = cvScalar(rgba[0], rgba[1], rgba[2], rgba[3]);
+
+av_log(ctx, AV_LOG_TRACE, "rgba: %d:%d:%d:%d, thickness: %d, line_type: 
%d, shift: %d \n",
+rgba[0], rgba[1], rgba[2], rgba[3], drawbox->thickness, 
drawbox->line_type, drawbox->shift);
+
+return 0;
+}
+
+static void drawbox_preprocess(AVFilterContext *ctx, AVFrame *in)
+{
+OCVContext *s = ctx->priv;
+DrawboxContext *drawbox = s->priv;
+AVDictionaryEntry *ef, *ex, *ey, *ew, *eh;
+char key2[128];
+AVDictionary *metadata = in->metadata;
+int nb_faces = 0;
+
+ef = av_dict_get(metadata, "lavfi.facedetect.nb_faces", NULL, 
AV_DICT_MATCH_CASE);
+if (ef) {
+nb_faces = strtol(ef->value, NULL, 10);
+}
+
+if (nb_faces > 0) {
+drawbox->nb_faces = nb_faces;
+for (int i = 0; i < nb_faces && i < sizeof(drawbox->faces); i++ ) {
+CvRect *tmp;
+
+tmp =  av_realloc(drawbox->faces[i], sizeof(*tmp));
+if (!tmp)
+return AVERROR(ENOMEM);
+drawbox->faces[i] = tmp;
+
+snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", i, "x");
+ex = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE);
+
+snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", i, "y");
+ey = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE);
+
+snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", i, "w");
+ew = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE);
+
+snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", i, "h");
+eh = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE);
+
+if (ex && ey && ew && eh) {
+tmp->x  = strtol(ex->value, NULL, 10);
+tmp->y  = strtol(ey->value, NULL, 10);
+tmp->width  = strtol(ew->value, NULL

Re: [FFmpeg-devel] [PATCH v3 2/5] avfilter/vf_libopencv: add opencv HaarCascade classifier simple face detection filter

2020-05-18 Thread lance . lmwang
On Mon, May 18, 2020 at 01:11:12PM +0200, Paul B Mahol wrote:
> This opencv module is obsolete for latest opencv.
> 
> Instead there should be C++ wrapper.

Sorry, where is the C++ wrapper? Now Opencv 2.x and 3.x is good
to use for my current function. By my initial testing, the performance is
very good, we can easily to get realtime for HD, the drawbacks are: 
1. The face is not directly opposite and cannot be recognized.
2. there are some false detect for video.

If have any old discussion for that, please give the discussion link for 
reference. I'm not keep track of the ML before.


> 
> On 5/18/20, lance.lmw...@gmail.com  wrote:
> > From: Limin Wang 
> >
> > Signed-off-by: Limin Wang 
> > ---
> > change the update_metadata() to postprocess() only, I'll add opencv drawbox
> > filter and it need preprocess() to get the meta, so I prefer to change the
> > function name for better readablity, in future, it may have other processing
> > than metadata only.
> >
> >  configure  |   1 +
> >  doc/filters.texi   |  29 +++
> >  libavfilter/vf_libopencv.c | 164 -
> >  3 files changed, 191 insertions(+), 3 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 34afdaad28..281b67efc4 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2123,6 +2123,7 @@ HEADERS_LIST="
> >  machine_ioctl_meteor_h
> >  malloc_h
> >  opencv2_core_core_c_h
> > +opencv2_objdetect_objdetect_c_h
> >  OpenGL_gl3_h
> >  poll_h
> >  sys_param_h
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index d9ba0fffa1..f938dd04de 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -14177,6 +14177,35 @@ other parameters is 0.
> >  These parameters correspond to the parameters assigned to the
> >  libopencv function @code{cvSmooth}.
> >
> > +@subsection facedetect
> > +Face detection using Haar Feature-based Cascade Classifiers.
> > +
> > +The filter takes the following parameters:
> > +@var{xml_model}|@var{qoffset}.
> > +
> > +@var{xml_model} is the path of pre-trained classifiers, The C API still
> > +does not support the newer cascade format, please use the old format
> > +haarcascade_frontalface_alt.xml which type_id is opencv-haar-classifier.
> > +
> > +@var{qoffset}
> > +If you want export the detected faces by ROI side data in frame, please set
> > the
> > +parameters, See also the @ref{addroi} filter. The range of qoffset is from
> > [-1.0, 1.0]
> > +
> > +By default the filter will report these metadata values if face are
> > +detected:
> > +@table @option
> > +@item lavfi.facedetect.nb_faces
> > +Display the detected face number
> > +
> > +@item lavfi.facedetect.face_id.x, lavfi.facedetect.face_id.y
> > +Display x and y of every faces, face_id is the face index which is range
> > +from [0, nb_faces-1]
> > +
> > +@item lavfi.facedetect.face_id.w, lavfi.facedetect.face_id.h
> > +Display width and height of every faces, face_id is the face index
> > +which is range from [0, nb_faces-1]
> > +@end table
> > +
> >  @section oscilloscope
> >
> >  2D Video Oscilloscope.
> > diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
> > index 8128030b8c..b2d19bb241 100644
> > --- a/libavfilter/vf_libopencv.c
> > +++ b/libavfilter/vf_libopencv.c
> > @@ -1,5 +1,6 @@
> >  /*
> >   * Copyright (c) 2010 Stefano Sabatini
> > + * Copyright (c) 2020 Limin Wang
> >   *
> >   * This file is part of FFmpeg.
> >   *
> > @@ -27,10 +28,16 @@
> >  #if HAVE_OPENCV2_CORE_CORE_C_H
> >  #include 
> >  #include 
> > +#if HAVE_OPENCV2_OBJECTDETECT_OBJECTDETECT_C_H
> > +#include 
> > +#else
> > +#include 
> > +#endif
> >  #else
> >  #include 
> >  #include 
> >  #endif
> > +
> >  #include "libavutil/avstring.h"
> >  #include "libavutil/common.h"
> >  #include "libavutil/file.h"
> > @@ -82,6 +89,7 @@ typedef struct OCVContext {
> >  int (*init)(AVFilterContext *ctx, const char *args);
> >  void (*uninit)(AVFilterContext *ctx);
> >  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg,
> > IplImage *outimg);
> > +void (*postprocess)(AVFilterContext *ctx, AVFrame *out);
> >  void *priv;
> >  } OCVContext;
> >
> > @@ -326,18 +334,152 @@ static void erode_end_frame_filter(AVFilterContext
> > *ctx, IplImage *inimg, IplIma
> >  cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
> >  }
> >
> > +typedef struct FaceDetectContext {
> > +char *xml_model;
> > +CvHaarClassifierCascade* cascade;
> > +CvMemStorage* storage;
> > +int nb_faces;
> > +CvSeq *faces;
> > +int add_roi;
> > +AVRational qoffset;
> > +} FaceDetectContext;
> > +
> > +static av_cold int facedetect_init(AVFilterContext *ctx, const char *args)
> > +{
> > +OCVContext *s = ctx->priv;
> > +FaceDetectContext *facedetect = s->priv;
> > +const char *buf = args;
> > +double qoffset;
> > +
> > +if (args) {
> > +facedetect->xml_model = av_get_token(&buf, "|");
> > +if (!facedetect->x

[FFmpeg-devel] [PATCH] avcodec/frame_thread_encoder: check for frame threading codec cap instead of intra only

2020-05-18 Thread James Almer
It's the correct dedicated capability reported by supported encoders.
Otherwise, the frame thread path will be used for unsupported encoders
like r210 for no gain.

Signed-off-by: James Almer 
---
 libavcodec/frame_thread_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/frame_thread_encoder.c 
b/libavcodec/frame_thread_encoder.c
index 949bc69f81..bb4b5d7341 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -120,7 +120,7 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, 
AVDictionary *options){
 
 
 if(   !(avctx->thread_type & FF_THREAD_FRAME)
-   || !(avctx->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY))
+   || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
 return 0;
 
 if(   !avctx->thread_count
-- 
2.26.2

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

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

Re: [FFmpeg-devel] [PATCH 2/4] avcodec.h: split AVCodecParameters API into its own header

2020-05-18 Thread Anton Khirnov
Quoting James Almer (2020-04-11 17:44:51)
> On 4/10/2020 12:41 PM, Anton Khirnov wrote:
> > ---
> > Not sure what to do with AVFieldOrder. It gets moved to codec_par.h
> > since it is used in AVCodecParameters, but it isn't precisely the right
> > place for it, though it's not horribly wrong either.
> 
> How about moving it to lavu's pixfmt.h, alongside other format definitions?

It's a property of a coded bitstream, so pixfmt seems like the wrong
place for it.

> 
> > 
> > Least bad solution I've come up with is making a separate header for
> > "misc small types used in lavc" and move there:
> > - AVFieldOrder
> > - AVAudioServiceType
> > - AVPanScan
> > - AVCPBProperties
> > - AVProducerReferenceTime
> > - AVProfile
> > - AVPictureStructure
> > 
> > but
> > - it's a "misc" header and misc headers are evil
> > - I can't come up with a good name for it
> > 
> > Suggestions?
> 
> AVCPBProperties and AVProducerReferenceTime are both packet or codec
> coded side data, so maybe they could be moved to packet.h, or to codec_par.h
> AVProfile is used by AVCodec only, AVAudioServiceType by AVCodecContext
> only, and AVPictureStructure by AVCodecParserContext only, so IMO they
> should be in the same header as their users.

They are used by those structs *now*. That can change in the future.

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

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

[FFmpeg-devel] [PATCH 3/3] avcodec/h264dec: Add FF_CODEC_CAP_INIT_CLEANUP

2020-05-18 Thread lance . lmwang
From: Limin Wang 

then ff_h264_free_tables() and h264_decode_end() can be removed
in h264_decode_init() if it's failed.

The FF_CODEC_CAP_INIT_CLEANUP flag is need for single thread, For multithread,
it'll be cleanup still by AV_CODEC_CAP_FRAME_THREADS flag if have.

Signed-off-by: Limin Wang 
---
 libavcodec/h264dec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 4c355fe..3478b38 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -226,7 +226,6 @@ int ff_h264_alloc_tables(H264Context *h)
 return 0;
 
 fail:
-ff_h264_free_tables(h);
 return AVERROR(ENOMEM);
 }
 
@@ -418,7 +417,6 @@ static av_cold int h264_decode_init(AVCodecContext *avctx)
av_log(avctx, explode ? AV_LOG_ERROR: AV_LOG_WARNING,
   "Error decoding the extradata\n");
if (explode) {
-   h264_decode_end(avctx);
return ret;
}
ret = 0;
@@ -1036,7 +1034,7 @@ AVCodec ff_h264_decoder = {
 .decode= h264_decode_frame,
 .capabilities  = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ 
AV_CODEC_CAP_DR1 |
  AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
- AV_CODEC_CAP_FRAME_THREADS,
+ AV_CODEC_CAP_FRAME_THREADS | 
FF_CODEC_CAP_INIT_CLEANUP,
 .hw_configs= (const AVCodecHWConfigInternal*[]) {
 #if CONFIG_H264_DXVA2_HWACCEL
HWACCEL_DXVA2(h264),
-- 
2.6.4

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

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

Re: [FFmpeg-devel] [PATCH v3 2/5] avfilter/vf_libopencv: add opencv HaarCascade classifier simple face detection filter

2020-05-18 Thread Paul B Mahol
This opencv module is obsolete for latest opencv.

Instead there should be C++ wrapper.

On 5/18/20, lance.lmw...@gmail.com  wrote:
> From: Limin Wang 
>
> Signed-off-by: Limin Wang 
> ---
> change the update_metadata() to postprocess() only, I'll add opencv drawbox
> filter and it need preprocess() to get the meta, so I prefer to change the
> function name for better readablity, in future, it may have other processing
> than metadata only.
>
>  configure  |   1 +
>  doc/filters.texi   |  29 +++
>  libavfilter/vf_libopencv.c | 164 -
>  3 files changed, 191 insertions(+), 3 deletions(-)
>
> diff --git a/configure b/configure
> index 34afdaad28..281b67efc4 100755
> --- a/configure
> +++ b/configure
> @@ -2123,6 +2123,7 @@ HEADERS_LIST="
>  machine_ioctl_meteor_h
>  malloc_h
>  opencv2_core_core_c_h
> +opencv2_objdetect_objdetect_c_h
>  OpenGL_gl3_h
>  poll_h
>  sys_param_h
> diff --git a/doc/filters.texi b/doc/filters.texi
> index d9ba0fffa1..f938dd04de 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -14177,6 +14177,35 @@ other parameters is 0.
>  These parameters correspond to the parameters assigned to the
>  libopencv function @code{cvSmooth}.
>
> +@subsection facedetect
> +Face detection using Haar Feature-based Cascade Classifiers.
> +
> +The filter takes the following parameters:
> +@var{xml_model}|@var{qoffset}.
> +
> +@var{xml_model} is the path of pre-trained classifiers, The C API still
> +does not support the newer cascade format, please use the old format
> +haarcascade_frontalface_alt.xml which type_id is opencv-haar-classifier.
> +
> +@var{qoffset}
> +If you want export the detected faces by ROI side data in frame, please set
> the
> +parameters, See also the @ref{addroi} filter. The range of qoffset is from
> [-1.0, 1.0]
> +
> +By default the filter will report these metadata values if face are
> +detected:
> +@table @option
> +@item lavfi.facedetect.nb_faces
> +Display the detected face number
> +
> +@item lavfi.facedetect.face_id.x, lavfi.facedetect.face_id.y
> +Display x and y of every faces, face_id is the face index which is range
> +from [0, nb_faces-1]
> +
> +@item lavfi.facedetect.face_id.w, lavfi.facedetect.face_id.h
> +Display width and height of every faces, face_id is the face index
> +which is range from [0, nb_faces-1]
> +@end table
> +
>  @section oscilloscope
>
>  2D Video Oscilloscope.
> diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
> index 8128030b8c..b2d19bb241 100644
> --- a/libavfilter/vf_libopencv.c
> +++ b/libavfilter/vf_libopencv.c
> @@ -1,5 +1,6 @@
>  /*
>   * Copyright (c) 2010 Stefano Sabatini
> + * Copyright (c) 2020 Limin Wang
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -27,10 +28,16 @@
>  #if HAVE_OPENCV2_CORE_CORE_C_H
>  #include 
>  #include 
> +#if HAVE_OPENCV2_OBJECTDETECT_OBJECTDETECT_C_H
> +#include 
> +#else
> +#include 
> +#endif
>  #else
>  #include 
>  #include 
>  #endif
> +
>  #include "libavutil/avstring.h"
>  #include "libavutil/common.h"
>  #include "libavutil/file.h"
> @@ -82,6 +89,7 @@ typedef struct OCVContext {
>  int (*init)(AVFilterContext *ctx, const char *args);
>  void (*uninit)(AVFilterContext *ctx);
>  void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg,
> IplImage *outimg);
> +void (*postprocess)(AVFilterContext *ctx, AVFrame *out);
>  void *priv;
>  } OCVContext;
>
> @@ -326,18 +334,152 @@ static void erode_end_frame_filter(AVFilterContext
> *ctx, IplImage *inimg, IplIma
>  cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
>  }
>
> +typedef struct FaceDetectContext {
> +char *xml_model;
> +CvHaarClassifierCascade* cascade;
> +CvMemStorage* storage;
> +int nb_faces;
> +CvSeq *faces;
> +int add_roi;
> +AVRational qoffset;
> +} FaceDetectContext;
> +
> +static av_cold int facedetect_init(AVFilterContext *ctx, const char *args)
> +{
> +OCVContext *s = ctx->priv;
> +FaceDetectContext *facedetect = s->priv;
> +const char *buf = args;
> +double qoffset;
> +
> +if (args) {
> +facedetect->xml_model = av_get_token(&buf, "|");
> +if (!facedetect->xml_model) {
> +av_log(ctx, AV_LOG_ERROR, "failed to get %s, %s\n", args,
> facedetect->xml_model);
> +return AVERROR(EINVAL);
> +}
> +
> +if (buf && sscanf(buf, "|%lf", &qoffset) == 1) {
> +if (qoffset < -1.0 || qoffset > 1.0) {
> +av_log(ctx, AV_LOG_ERROR, "failed to get valid
> qoffset(%f))\n", qoffset);
> +return AVERROR(EINVAL);
> +}
> +facedetect->add_roi = 1;
> +facedetect->qoffset = av_d2q(qoffset, 255);
> +}
> +} else {
> +av_log(ctx, AV_LOG_ERROR, "failed to get
> haarcascade_frontalface_alt.xml model file\n");
> +return AVERROR(EINVAL);
> +}
> +
> +av_log(ctx, AV_LOG_VERBOSE, "xml_model: %s add_ro

[FFmpeg-devel] [PATCH 2/3] avcodec: Add FF_CODEC_CAP_INIT_CLEANUP

2020-05-18 Thread lance . lmwang
From: Limin Wang 

then ff_mpv_encode_end() will be unnecessary in ff_mpv_encode_init() 
if it's failed.

The FF_CODEC_CAP_INIT_CLEANUP flag is need for single thread, For multithread,
it'll be cleanup still by AV_CODEC_CAP_FRAME_THREADS flag if have.


Signed-off-by: Limin Wang 
---
 libavcodec/flvenc.c| 1 +
 libavcodec/h261enc.c   | 1 +
 libavcodec/mjpegenc.c  | 2 ++
 libavcodec/mpeg4videoenc.c | 2 +-
 libavcodec/mpegvideo_enc.c | 7 +--
 libavcodec/rv10enc.c   | 1 +
 libavcodec/rv20enc.c   | 1 +
 libavcodec/wmv2enc.c   | 1 +
 8 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 15f794e..c122727 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -107,6 +107,7 @@ AVCodec ff_flv_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
  AV_PIX_FMT_NONE},
 .priv_class = &flv_class,
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 315762c..196c37b 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -394,6 +394,7 @@ AVCodec ff_h261_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
  AV_PIX_FMT_NONE },
 .priv_class = &h261_class,
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 0ea7bd3..02cc4b0 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -415,6 +415,7 @@ AVCodec ff_mjpeg_encoder = {
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
 .capabilities   = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS 
| AV_CODEC_CAP_INTRA_ONLY,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]) {
 AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, 
AV_PIX_FMT_NONE
 },
@@ -440,6 +441,7 @@ AVCodec ff_amv_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= amv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]) {
 AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_NONE
 },
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 2cd5a8c..d258eb5 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1396,6 +1396,6 @@ AVCodec ff_mpeg4_encoder = {
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
 .pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_NONE },
-.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | 
FF_CODEC_CAP_INIT_CLEANUP,
 .priv_class = &mpeg4enc_class,
 };
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 50ae57e..7420b7b 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1060,7 +1060,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 return 0;
 fail:
-ff_mpv_encode_end(avctx);
 return AVERROR_UNKNOWN;
 }
 
@@ -4743,6 +4742,7 @@ AVCodec ff_h263_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts= (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_NONE},
 .priv_class = &h263_class,
 };
@@ -4771,7 +4771,7 @@ AVCodec ff_h263p_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
-.capabilities   = AV_CODEC_CAP_SLICE_THREADS,
+.capabilities   = AV_CODEC_CAP_SLICE_THREADS | FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_NONE },
 .priv_class = &h263p_class,
 };
@@ -4792,6 +4792,7 @@ AVCodec ff_msmpeg4v2_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, 
AV_PIX_FMT_NONE },
 .priv_class = &msmpeg4v2_class,
 };
@@ -4812,6 +4813,7 @@ AVCodec ff_msmpeg4v3_encoder = {
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 .pix_fmts   = (con

[FFmpeg-devel] [PATCH 1/3] avcodec/adpcmenc: Add FF_CODEC_CAP_INIT_CLEANUP

2020-05-18 Thread lance . lmwang
From: Limin Wang 

then we can remove adpcm_encode_close() in adpcm_encode_init() if have failed.
so the goto error lable wlll be unnecessary and can be removed later. 

Signed-off-by: Limin Wang 
---
 libavcodec/adpcmenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 668939c..1c84561 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -146,7 +146,6 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
 
 return 0;
 error:
-adpcm_encode_close(avctx);
 return ret;
 }
 
@@ -717,6 +716,7 @@ AVCodec ff_ ## name_ ## _encoder = {
\
 .encode2= adpcm_encode_frame,   \
 .close  = adpcm_encode_close,   \
 .sample_fmts= sample_fmts_, \
+.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,\
 }
 
 ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT,  adpcm_ima_qt,  sample_fmts_p, "ADPCM 
IMA QuickTime");
-- 
2.6.4

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

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

Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add shift option

2020-05-18 Thread lance . lmwang
On Mon, May 18, 2020 at 11:34:03AM +0200, Manolis Stamatogiannakis wrote:
> Bumping this up after 10 days without a comment.
> 
> On Fri, 8 May 2020 at 13:14, Manolis Stamatogiannakis 
> wrote:
> 
> > Allows shifting of subtitle display times to align them with the video.
> > This avoids having to rewrite the subtitle file in order to display
> > subtitles correctly when input is seeked (-ss).
> > Also handy for minor subtitle timing corrections without rewriting the
> > subtitles file.
> >
> > Signed-off-by: Manolis Stamatogiannakis 
> > ---
> >  doc/filters.texi   |  8 
> >  libavfilter/vf_subtitles.c | 29 +++--
> >  2 files changed, 35 insertions(+), 2 deletions(-)
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index d19fd346ae..94323495f0 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -17851,6 +17851,9 @@ The filter accepts the following options:
> >  @item filename, f
> >  Set the filename of the subtitle file to read. It must be specified.
> >
> > +@item shift
> > +Shift subtitles timings by the specified amount.
> > +
> >  @item original_size
> >  Specify the size of the original video, the video for which the ASS file
> >  was composed. For the syntax of this option, check the
> > @@ -17907,6 +17910,11 @@ To make the subtitles stream from @file{sub.srt}
> > appear in 80% transparent blue
> >  subtitles=sub.srt:force_style='FontName=DejaVu
> > Serif,PrimaryColour=&HCCFF'
> >  @end example
> >
> > +To re-sync subtitles after seeking the input e.g. with @code{-ss 20:20},
> > use:
> > +@example
> > +subtitles=filename=sub.srt:shift=-20\:20
> > +@end example
> > +
> >  @section super2xsai
> >
> >  Scale the input by 2x and smooth using the Super2xSaI (Scale and
> > diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> > index a3b4029af4..47a38b55b1 100644
> > --- a/libavfilter/vf_subtitles.c
> > +++ b/libavfilter/vf_subtitles.c
> > @@ -52,6 +52,8 @@ typedef struct AssContext {
> >  char *filename;
> >  char *fontsdir;
> >  char *charenc;
> > +int64_t shift;
> > +char *shift_opt;
> >  char *force_style;
> >  int stream_index;
> >  int alpha;
> > @@ -68,6 +70,7 @@ typedef struct AssContext {
> >  #define COMMON_OPTIONS \
> >  {"filename",   "set the filename of file to read",
> >  OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> > FLAGS }, \
> >  {"f",  "set the filename of file to read",
> >  OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> > FLAGS }, \
> > +{"shift",  "shift the timing of the subtitles",
> >   OFFSET(shift_opt),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> > FLAGS }, \

I can't give comments for the function, but here It's better to use 
AV_OPT_TYPE_DURATION type
for the timing shift, then you can use shift directly and shift_opt isn't 
necessary anymore.


> >  {"original_size",  "set the size of the original video (used to scale
> > fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  0, 0,
> > FLAGS }, \
> >  {"fontsdir",   "set the directory containing the fonts to read",
> >  OFFSET(fontsdir),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> > FLAGS }, \
> >  {"alpha",  "enable processing of alpha channel",
> >  OFFSET(alpha),  AV_OPT_TYPE_BOOL,   {.i64 = 0   },
> >  0,1, FLAGS }, \
> > @@ -103,6 +106,16 @@ static av_cold int init(AVFilterContext *ctx)
> >  return AVERROR(EINVAL);
> >  }
> >
> > +if (ass->shift_opt) {
> > +if (av_parse_time(&ass->shift, ass->shift_opt, 1) < 0) {
> > +av_log(ctx, AV_LOG_ERROR, "Invalid subtitles shift: %s\n",
> > +   ass->shift_opt);
> > +return AVERROR(EINVAL);
> > +}
> > +ass->shift = av_rescale_q(ass->shift, AV_TIME_BASE_Q,
> > av_make_q(1, 1000));
> > +av_log(ctx, AV_LOG_DEBUG, "Shifting subtitles by %0.3fsec.\n",
> > ass->shift/1000.0);
> > +}
> > +
> >  ass->library = ass_library_init();
> >  if (!ass->library) {
> >  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
> > @@ -297,7 +310,7 @@ AVFILTER_DEFINE_CLASS(subtitles);
> >
> >  static av_cold int init_subtitles(AVFilterContext *ctx)
> >  {
> > -int j, ret, sid;
> > +int j, ret, sid, nskip;
> >  int k = 0;
> >  AVDictionary *codec_opts = NULL;
> >  AVFormatContext *fmt = NULL;
> > @@ -448,6 +461,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
> >  av_init_packet(&pkt);
> >  pkt.data = NULL;
> >  pkt.size = 0;
> > +nskip = 0;
> >  while (av_read_frame(fmt, &pkt) >= 0) {
> >  int i, got_subtitle;
> >  AVSubtitle sub = {0};
> > @@ -458,8 +472,17 @@ static av_cold int init_subtitles(AVFilterContext
> > *ctx)
> >  av_log(ctx, AV_LOG_WARNING, "Error decoding: %s
> > (ignored)\n",
> >   

Re: [FFmpeg-devel] [PATCH v3] libavformat/flacdec: Workaround for truncated metadata picture size

2020-05-18 Thread Mattias Wadman
On Sat, May 16, 2020 at 9:59 PM Andreas Rheinhardt
 wrote:
>
> Mattias Wadman:
> > lavf flacenc could previously write truncated metadata picture size if
> > the picture data did not fit in 24 bits. Detect this by truncting the
> > size found inside the picture block and if it matches the block size
> > use it and read rest of picture data.
> >
> > Also only enable this workaround flac files and not ogg files with flac
> > METADATA_BLOCK_PICTURE comment.
> >
> > flacenc was fixed in e447a4d112bcfee10126c54eb4481fa8712957c8
> > before the fix a broken flac for reproduction could be generated with:
> > ffmpeg -f lavfi -i sine -f lavfi -i color=red:size=2400x2400 -map 0:0 -map 
> > 1:0 -c:v:0 bmp -disposition:1 attached_pic -t 1 test.flac
> >
> > Fixes ticket 6333
> > ---
> >  libavformat/flac_picture.c   | 35 +++
> >  libavformat/flac_picture.h   |  2 +-
> >  libavformat/flacdec.c|  2 +-
> >  libavformat/oggparsevorbis.c |  2 +-
> >  4 files changed, 30 insertions(+), 11 deletions(-)
> >
> > diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
> > index 81ddf80465..61277e9dee 100644
> > --- a/libavformat/flac_picture.c
> > +++ b/libavformat/flac_picture.c
> > @@ -27,7 +27,7 @@
> >  #include "id3v2.h"
> >  #include "internal.h"
> >
> > -int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
> > +int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, 
> > int truncate_workaround)
> >  {
> >  const CodecMime *mime = ff_id3v2_mime_tags;
> >  enum AVCodecID id = AV_CODEC_ID_NONE;
> > @@ -36,7 +36,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
> > *buf, int buf_size)
> >  GetByteContext g;
> >  AVStream *st;
> >  int width, height, ret = 0;
> > -unsigned int len, type;
> > +unsigned int type;
> > +uint32_t len, left, trunclen = 0;
> >
> >  if (buf_size < 34) {
> >  av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > @@ -114,16 +115,34 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
> > *buf, int buf_size)
> >
> >  /* picture data */
> >  len = bytestream2_get_be32u(&g);
> > -if (len <= 0 || len > bytestream2_get_bytes_left(&g)) {
> > -av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > -if (s->error_recognition & AV_EF_EXPLODE)
> > -ret = AVERROR_INVALIDDATA;
> > -goto fail;
> > +
> > +left = bytestream2_get_bytes_left(&g);
> > +if (len <= 0 || len > left) {
> > +// Workaround lavf flacenc bug that allowed writing truncated 
> > metadata picture block size if
>
> I have not found the typical lavf metadata in the file from #6333, so it
> seems we are not the only tool that created such out-of-spec files. This
> should be reflected in the comment.

Good point, have been clarified.

>
> > +// picture size did not fit in 24 bits
> > +if (truncate_workaround && len > left && (len & 0xff) == left) 
> > {
>
> There should be a way to disable this workaround; after all, there'd be
> no remedy if the 32bit len field is bogus. Maybe check
> strict_std_compliance for being >= FF_COMPLIANCE_STRICT.

Fixed. Made it fail if strict level it above normal.

>
> > +av_log(s, AV_LOG_INFO, "Correcting truncated metadata picture 
> > size from %d to %d\n", left, len);
> > +trunclen = len - left;
> > +} else {
> > +av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
> > short\n");
> > +if (s->error_recognition & AV_EF_EXPLODE)
> > +ret = AVERROR_INVALIDDATA;
> > +goto fail;
> > +}
> >  }
> >  if (!(data = av_buffer_alloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
>
> av_buffer_alloc() takes an int as its size argument. len +
> AV_INPUT_BUFFER_PADDING_SIZE can be anything here; it can be positive or
> negative. It can even be wrapped around. You need to check len for being
> < INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE. I wonder whether it should not
> be restricted even more (otherwise it would be easy to force an
> allocation of close to 2GiB).

Fixed. Fails if >500MB or INT_MAX overflow.

>
> >  RETURN_ERROR(AVERROR(ENOMEM));
> >  }
> > -bytestream2_get_bufferu(&g, data->data, len);
> > +
> > +if (trunclen == 0) {
> > +bytestream2_get_bufferu(&g, data->data, len);
> > +} else {
> > +// If truncation was detect copy all data from block and read 
> > missing bytes
>
> was detected

Fixed.

>
> > +// not included in the block size
> > +bytestream2_get_bufferu(&g, data->data, left);
> > +if (avio_read(s->pb, data->data + len - trunclen, trunclen) < 
> > trunclen)
> > +RETURN_ERROR(AVERROR_INVALIDDATA);
> > +}
> >  memset(data->data + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> >
> >  if (AV_RB64(data->data) == PNGSIG)
> > diff --git a/libavformat/flac_pict

[FFmpeg-devel] [PATCH v3 2/5] avfilter/vf_libopencv: add opencv HaarCascade classifier simple face detection filter

2020-05-18 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
change the update_metadata() to postprocess() only, I'll add opencv drawbox
filter and it need preprocess() to get the meta, so I prefer to change the
function name for better readablity, in future, it may have other processing
than metadata only.

 configure  |   1 +
 doc/filters.texi   |  29 +++
 libavfilter/vf_libopencv.c | 164 -
 3 files changed, 191 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 34afdaad28..281b67efc4 100755
--- a/configure
+++ b/configure
@@ -2123,6 +2123,7 @@ HEADERS_LIST="
 machine_ioctl_meteor_h
 malloc_h
 opencv2_core_core_c_h
+opencv2_objdetect_objdetect_c_h
 OpenGL_gl3_h
 poll_h
 sys_param_h
diff --git a/doc/filters.texi b/doc/filters.texi
index d9ba0fffa1..f938dd04de 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -14177,6 +14177,35 @@ other parameters is 0.
 These parameters correspond to the parameters assigned to the
 libopencv function @code{cvSmooth}.
 
+@subsection facedetect
+Face detection using Haar Feature-based Cascade Classifiers.
+
+The filter takes the following parameters:
+@var{xml_model}|@var{qoffset}.
+
+@var{xml_model} is the path of pre-trained classifiers, The C API still
+does not support the newer cascade format, please use the old format
+haarcascade_frontalface_alt.xml which type_id is opencv-haar-classifier.
+
+@var{qoffset}
+If you want export the detected faces by ROI side data in frame, please set the
+parameters, See also the @ref{addroi} filter. The range of qoffset is from 
[-1.0, 1.0]
+
+By default the filter will report these metadata values if face are
+detected:
+@table @option
+@item lavfi.facedetect.nb_faces
+Display the detected face number
+
+@item lavfi.facedetect.face_id.x, lavfi.facedetect.face_id.y
+Display x and y of every faces, face_id is the face index which is range
+from [0, nb_faces-1]
+
+@item lavfi.facedetect.face_id.w, lavfi.facedetect.face_id.h
+Display width and height of every faces, face_id is the face index
+which is range from [0, nb_faces-1]
+@end table
+
 @section oscilloscope
 
 2D Video Oscilloscope.
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index 8128030b8c..b2d19bb241 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2010 Stefano Sabatini
+ * Copyright (c) 2020 Limin Wang
  *
  * This file is part of FFmpeg.
  *
@@ -27,10 +28,16 @@
 #if HAVE_OPENCV2_CORE_CORE_C_H
 #include 
 #include 
+#if HAVE_OPENCV2_OBJECTDETECT_OBJECTDETECT_C_H
+#include 
+#else
+#include 
+#endif
 #else
 #include 
 #include 
 #endif
+
 #include "libavutil/avstring.h"
 #include "libavutil/common.h"
 #include "libavutil/file.h"
@@ -82,6 +89,7 @@ typedef struct OCVContext {
 int (*init)(AVFilterContext *ctx, const char *args);
 void (*uninit)(AVFilterContext *ctx);
 void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage 
*outimg);
+void (*postprocess)(AVFilterContext *ctx, AVFrame *out);
 void *priv;
 } OCVContext;
 
@@ -326,18 +334,152 @@ static void erode_end_frame_filter(AVFilterContext *ctx, 
IplImage *inimg, IplIma
 cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
 }
 
+typedef struct FaceDetectContext {
+char *xml_model;
+CvHaarClassifierCascade* cascade;
+CvMemStorage* storage;
+int nb_faces;
+CvSeq *faces;
+int add_roi;
+AVRational qoffset;
+} FaceDetectContext;
+
+static av_cold int facedetect_init(AVFilterContext *ctx, const char *args)
+{
+OCVContext *s = ctx->priv;
+FaceDetectContext *facedetect = s->priv;
+const char *buf = args;
+double qoffset;
+
+if (args) {
+facedetect->xml_model = av_get_token(&buf, "|");
+if (!facedetect->xml_model) {
+av_log(ctx, AV_LOG_ERROR, "failed to get %s, %s\n", args, 
facedetect->xml_model);
+return AVERROR(EINVAL);
+}
+
+if (buf && sscanf(buf, "|%lf", &qoffset) == 1) {
+if (qoffset < -1.0 || qoffset > 1.0) {
+av_log(ctx, AV_LOG_ERROR, "failed to get valid 
qoffset(%f))\n", qoffset);
+return AVERROR(EINVAL);
+}
+facedetect->add_roi = 1;
+facedetect->qoffset = av_d2q(qoffset, 255);
+}
+} else {
+av_log(ctx, AV_LOG_ERROR, "failed to get 
haarcascade_frontalface_alt.xml model file\n");
+return AVERROR(EINVAL);
+}
+
+av_log(ctx, AV_LOG_VERBOSE, "xml_model: %s add_roi: %d qoffset: %d/%d\n",
+   facedetect->xml_model, facedetect->add_roi, 
facedetect->qoffset.num, facedetect->qoffset.den);
+
+facedetect->storage = cvCreateMemStorage(0);
+if (!facedetect->storage) {
+av_log(ctx, AV_LOG_ERROR, "cvCreateMemStorage() failed\n");
+return AVERROR(EINVAL);
+}
+cvClearMemStorage(facedetect->storage);
+
+facedetect->cascade = (CvHaarClassifie

[FFmpeg-devel] [PATCH v4] libavformat/flacdec: Workaround for truncated metadata picture size

2020-05-18 Thread Mattias Wadman
Some flac muxers write truncated metadata picture size if the picture
data do not fit in 24 bits. Detect this by truncting the size found inside
the picture block and if it matches the block size use it and read rest
of picture data.

Used to be an issue with lavf flacenc that was fixed in 
e447a4d112bcfee10126c54eb4481fa8712957c8
but based on exiting broken files other unknown flac muxers seems to do it also.
Before the fix a broken flac for reproduction could be generated with:
ffmpeg -f lavfi -i sine -f lavfi -i color=red:size=2400x2400 -map 0:0 -map 1:0 
-c:v:0 bmp -disposition:1 attached_pic -t 1 test.flac

Also only enable this workaround flac files and not ogg files with flac
METADATA_BLOCK_PICTURE comment.

Can be disabled with strict level above normal and correctly there is a 500MB 
limit
on truncate size to protect from large memory allocations.

Fixes ticket 6333
---
 libavformat/flac_picture.c   | 47 ++--
 libavformat/flac_picture.h   |  2 +-
 libavformat/flacdec.c|  2 +-
 libavformat/oggparsevorbis.c |  2 +-
 4 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index 81ddf80465..349f2067aa 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -27,7 +27,9 @@
 #include "id3v2.h"
 #include "internal.h"
 
-int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
+#define MAX_TRUNC_PICTURE_SIZE (500 * 1024 * 1024)
+
+int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int 
truncate_workaround)
 {
 const CodecMime *mime = ff_id3v2_mime_tags;
 enum AVCodecID id = AV_CODEC_ID_NONE;
@@ -36,7 +38,8 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, 
int buf_size)
 GetByteContext g;
 AVStream *st;
 int width, height, ret = 0;
-unsigned int len, type;
+unsigned int type;
+uint32_t len, left, trunclen = 0;
 
 if (buf_size < 34) {
 av_log(s, AV_LOG_ERROR, "Attached picture metadata block too short\n");
@@ -114,16 +117,44 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t 
*buf, int buf_size)
 
 /* picture data */
 len = bytestream2_get_be32u(&g);
-if (len <= 0 || len > bytestream2_get_bytes_left(&g)) {
-av_log(s, AV_LOG_ERROR, "Attached picture metadata block too short\n");
-if (s->error_recognition & AV_EF_EXPLODE)
-ret = AVERROR_INVALIDDATA;
-goto fail;
+
+left = bytestream2_get_bytes_left(&g);
+if (len <= 0 || len > left) {
+if (len > MAX_TRUNC_PICTURE_SIZE || len >= INT_MAX - 
AV_INPUT_BUFFER_PADDING_SIZE) {
+av_log(s, AV_LOG_ERROR, "Attached picture metadata block too big 
%u\n", len);
+if (s->error_recognition & AV_EF_EXPLODE)
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
+// Workaround bug for flac muxers that writs truncated metadata 
picture block size if
+// the picture size do not fit in 24 bits. lavf flacenc used to have 
the issue and based
+// on broken files some other unknown flac muxer seems to do it also.
+if (truncate_workaround &&
+s->strict_std_compliance <= FF_COMPLIANCE_NORMAL &&
+len > left && (len & 0xff) == left) {
+av_log(s, AV_LOG_INFO, "Correcting truncated metadata picture size 
from %u to %u\n", left, len);
+trunclen = len - left;
+} else {
+av_log(s, AV_LOG_ERROR, "Attached picture metadata block too 
short\n");
+if (s->error_recognition & AV_EF_EXPLODE)
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
 }
 if (!(data = av_buffer_alloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
 RETURN_ERROR(AVERROR(ENOMEM));
 }
-bytestream2_get_bufferu(&g, data->data, len);
+
+if (trunclen == 0) {
+bytestream2_get_bufferu(&g, data->data, len);
+} else {
+// If truncation was detected copy all data from block and read 
missing bytes
+// not included in the block size
+bytestream2_get_bufferu(&g, data->data, left);
+if (avio_read(s->pb, data->data + len - trunclen, trunclen) < trunclen)
+RETURN_ERROR(AVERROR_INVALIDDATA);
+}
 memset(data->data + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
 if (AV_RB64(data->data) == PNGSIG)
diff --git a/libavformat/flac_picture.h b/libavformat/flac_picture.h
index 4374b6f4f6..61fd0c8806 100644
--- a/libavformat/flac_picture.h
+++ b/libavformat/flac_picture.h
@@ -26,6 +26,6 @@
 
 #define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
 
-int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size);
+int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int 
truncate_workaround);
 
 #endif /* AVFORMAT_FLAC_PICTURE_H */
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index cb516fb1f3..79c05f14bf 100644
--- a/libavformat/flacdec.

Re: [FFmpeg-devel] [PATCH 4/4] lavfi/tests/formats: reindent.

2020-05-18 Thread Nicolas George
Nicolas George (12020-04-16):
> Signed-off-by: Nicolas George 
> ---
>  libavfilter/tests/formats.c | 136 ++--
>  1 file changed, 68 insertions(+), 68 deletions(-)

I indent to push this soon, so that I can push vf_untile too.

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 1/2] lavu: add av_gcd_q().

2020-05-18 Thread Nicolas George
Nicolas George (12020-04-16):
> TODO APIchanges and minor bump.
> 
> Signed-off-by: Nicolas George 
> ---
>  libavutil/rational.c | 9 +
>  libavutil/rational.h | 6 ++
>  2 files changed, 15 insertions(+)
> 
> 
> This one too, I need for the code I am writing.
> And lavfi/avf_concat could use it too to choose a better time base.

I intend to push this 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] [RFC]separation of multiple outputs' encoding

2020-05-18 Thread Kieran Kunhya
On Mon, 18 May 2020 at 09:33, Anton Khirnov  wrote:

> Quoting Tao Zhang (2020-05-18 08:00:55)
> > If no more comments, I will try to code something to create a pseudo
> > encoder which run the actual encoding in the separate thread. Thanks
>
> I do not think it is a good idea to have the library compensate for
> deficiencies in the calling program.
>

Agreed, what is proposed is a huge hack.

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

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

[FFmpeg-devel] [PATCH 1/2] h264dec: support exporting QP tables through the AVVideoEncParams API

2020-05-18 Thread Anton Khirnov
---
 libavcodec/h264_picture.c|  8 ++-
 libavcodec/h264_slice.c  |  9 +++
 libavcodec/h264dec.c | 46 
 libavcodec/h264dec.h |  6 +
 libavutil/video_enc_params.h | 13 ++
 5 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index 2113947d1d..eec5e9fb9a 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -54,6 +54,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
 
 av_buffer_unref(&pic->qscale_table_buf);
 av_buffer_unref(&pic->mb_type_buf);
+av_buffer_unref(&pic->pps_buf);
 for (i = 0; i < 2; i++) {
 av_buffer_unref(&pic->motion_val_buf[i]);
 av_buffer_unref(&pic->ref_index_buf[i]);
@@ -77,12 +78,14 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, 
H264Picture *src)
 
 dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf);
 dst->mb_type_buf  = av_buffer_ref(src->mb_type_buf);
-if (!dst->qscale_table_buf || !dst->mb_type_buf) {
+dst->pps_buf  = av_buffer_ref(src->pps_buf);
+if (!dst->qscale_table_buf || !dst->mb_type_buf || !dst->pps_buf) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 dst->qscale_table = src->qscale_table;
 dst->mb_type  = src->mb_type;
+dst->pps  = src->pps;
 
 for (i = 0; i < 2; i++) {
 dst->motion_val_buf[i] = av_buffer_ref(src->motion_val_buf[i]);
@@ -120,6 +123,9 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, 
H264Picture *src)
 dst->recovered = src->recovered;
 dst->invalid_gap   = src->invalid_gap;
 dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt;
+dst->mb_width  = src->mb_width;
+dst->mb_height = src->mb_height;
+dst->mb_stride = src->mb_stride;
 
 return 0;
 fail:
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 5a8a4a7f86..713953778a 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -243,6 +243,15 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
 pic->ref_index[i]  = pic->ref_index_buf[i]->data;
 }
 
+pic->pps_buf = av_buffer_ref(h->ps.pps_ref);
+if (!pic->pps_buf)
+goto fail;
+pic->pps = (const PPS*)pic->pps_buf->data;
+
+pic->mb_width  = h->mb_width;
+pic->mb_height = h->mb_height;
+pic->mb_stride = h->mb_stride;
+
 return 0;
 fail:
 ff_h264_unref_picture(h, pic);
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 4c355feb18..f784ac4c0d 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -32,6 +32,8 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/video_enc_params.h"
+
 #include "internal.h"
 #include "bytestream.h"
 #include "cabac.h"
@@ -812,6 +814,41 @@ static int get_consumed_bytes(int pos, int buf_size)
 return pos;
 }
 
+static int h264_export_enc_params(AVFrame *f, H264Picture *p)
+{
+AVVideoEncParams *par;
+unsigned int nb_mb = p->mb_height * p->mb_width;
+unsigned int x, y;
+
+par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_H264, 
nb_mb);
+if (!par)
+return AVERROR(ENOMEM);
+
+par->qp = p->pps->init_qp;
+
+par->delta_qp[1][0] = p->pps->chroma_qp_index_offset[0];
+par->delta_qp[1][1] = p->pps->chroma_qp_index_offset[0];
+par->delta_qp[2][0] = p->pps->chroma_qp_index_offset[1];
+par->delta_qp[2][1] = p->pps->chroma_qp_index_offset[1];
+
+for (y = 0; y < p->mb_height; y++)
+for (x = 0; x < p->mb_width; x++) {
+const unsigned int block_idx = y * p->mb_width + x;
+const unsigned int mb_xy = y * p->mb_stride + x;
+AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
+
+b->src_x = x * 16;
+b->src_y = y * 16;
+b->w = 16;
+b->h = 16;
+
+b->delta_qp = p->qscale_table[mb_xy] - par->qp;
+}
+
+
+return 0;
+}
+
 static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
 {
 AVFrame *src = srcp->f;
@@ -826,7 +863,16 @@ static int output_frame(H264Context *h, AVFrame *dst, 
H264Picture *srcp)
 if (srcp->sei_recovery_frame_cnt == 0)
 dst->key_frame = 1;
 
+if (h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
+ret = h264_export_enc_params(dst, srcp);
+if (ret < 0)
+goto fail;
+}
+
 return 0;
+fail:
+av_frame_unref(dst);
+return ret;
 }
 
 static int is_extra(const uint8_t *buf, int buf_size)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 530e2d4071..29c4d4e42c 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -161,6 +161,12 @@ typedef struct H264Picture {
 int recovered;  ///< picture at IDR or recovery point + recovery 
count
 int invalid_gap;
 int sei_recov

[FFmpeg-devel] [PATCH 2/2] fate: add tests for h264 and vp9 video enc parameters export

2020-05-18 Thread Anton Khirnov
---
 libavformat/Makefile  |   1 +
 tests/Makefile|   1 +
 tests/fate-run.sh |   7 +
 tests/fate/h264.mak   |   6 +-
 tests/fate/vpx.mak|   5 +
 tests/ref/fate/h264-encparams | 404 +++
 tests/ref/fate/vp9-encparams  | 937 ++
 tools/venc_data_dump.c| 195 +++
 8 files changed, 1555 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/h264-encparams
 create mode 100644 tests/ref/fate/vp9-encparams
 create mode 100644 tools/venc_data_dump.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5fa24cef16..67778ff798 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -670,3 +670,4 @@ TOOLS = aviocat 
\
 probetest   \
 seek_print  \
 sidxindex   \
+venc_data_dump
diff --git a/tests/Makefile b/tests/Makefile
index ab3c235f25..7844901e53 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -221,6 +221,7 @@ $(FATE_FFMPEG) $(FATE_FFMPEG_FFPROBE) 
$(FATE_SAMPLES_AVCONV) $(FATE_SAMPLES_FFMP
 $(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) 
$(FATE_SAMPLES_FFMPEG_FFPROBE): ffprobe$(PROGSSUF)$(EXESUF)
 
 $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF)
+$(FATE_SAMPLES_DUMP_DATA): tools/venc_data_dump$(EXESUF)
 
 ifdef SAMPLES
 FATE += $(FATE_EXTERN)
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 7c6d753261..07296d93f9 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -487,6 +487,13 @@ concat(){
 fi
 }
 
+venc_data(){
+file=$1
+stream=$2
+frames=$3
+tools/venc_data_dump${EXECSUF} ${file} ${stream} ${frames} ${threads} 
${thread_type}
+}
+
 null(){
 :
 }
diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index f14b46c6e0..13a596e52b 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -196,7 +196,8 @@ FATE_H264  := $(FATE_H264:%=fate-h264-conformance-%)
\
   fate-h264-3386\
   fate-h264-missing-frame   \
   fate-h264-ref-pic-mod-overflow\
-  fate-h264-timecode
+  fate-h264-timecode\
+  fate-h264-encparams
 
 FATE_H264-$(call DEMDEC, H264, H264) += $(FATE_H264)
 FATE_H264-$(call DEMDEC,  MOV, H264) += fate-h264-crop-to-container
@@ -446,3 +447,6 @@ fate-h264-timecode:   CMD = 
framecrc -i $(TARGET_SAM
 fate-h264-reinit-%:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/$(@:fate-h264-%=%).h264 -vf 
format=yuv444p10le,scale=w=352:h=288
 
 fate-h264-dts_5frames:CMD = probeframes 
$(TARGET_SAMPLES)/h264/dts_5frames.mkv
+
+fate-h264-encparams: CMD = venc_data 
$(TARGET_SAMPLES)/h264-conformance/FRext/FRExt_MMCO4_Sony_B.264 0 1
+FATE_SAMPLES_DUMP_DATA += fate-h264-encparams
diff --git a/tests/fate/vpx.mak b/tests/fate/vpx.mak
index c65959f133..88ccc70a5a 100644
--- a/tests/fate/vpx.mak
+++ b/tests/fate/vpx.mak
@@ -163,5 +163,10 @@ FATE_VP9-$(CONFIG_IVF_DEMUXER) += fate-vp9-05-resize
 fate-vp9-05-resize: CMD = framemd5 -i 
$(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-05-resize.ivf -s 352x288 -sws_flags 
bitexact+bilinear
 fate-vp9-05-resize: REF = $(SRC_PATH)/tests/ref/fate/vp9-05-resize
 
+fate-vp9-encparams: CMD = venc_data 
$(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-segmentation-aq-akiyo.webm 0 5
+FATE_SAMPLES_DUMP_DATA += fate-vp9-encparams
+
+FATE_VP9-$(CONFIG_MATROSKA_DEMUXER) += fate-vp9-encparams
+
 FATE_SAMPLES_AVCONV-$(CONFIG_VP9_DECODER) += $(FATE_VP9-yes)
 fate-vp9: $(FATE_VP9-yes)
diff --git a/tests/ref/fate/h264-encparams b/tests/ref/fate/h264-encparams
new file mode 100644
index 00..8dd5e86b74
--- /dev/null
+++ b/tests/ref/fate/h264-encparams
@@ -0,0 +1,404 @@
+frame 0
+AVVideoEncParams 1
+qp 28
+delta_qp[1][0] 3
+delta_qp[1][1] 3
+delta_qp[2][0] -2
+delta_qp[2][1] -2
+nb_blocks 396
+block 0 0:0 16x16 0
+block 1 16:0 16x16 0
+block 2 32:0 16x16 0
+block 3 48:0 16x16 0
+block 4 64:0 16x16 0
+block 5 80:0 16x16 0
+block 6 96:0 16x16 0
+block 7 112:0 16x16 0
+block 8 128:0 16x16 0
+block 9 144:0 16x16 0
+block 10 160:0 16x16 0
+block 11 176:0 16x16 0
+block 12 192:0 16x16 0
+block 13 208:0 16x16 0
+block 14 224:0 16x16 0
+block 15 240:0 16x16 0
+block 16 256:0 16x16 0
+block 17 272:0 16x16 0
+block 18 288:0 16x16 0
+block 19 304:0 16x16 0
+block 20 320:0 16x16 0
+block 21 336:0 16x16 0
+block 22 0:16 16x16 0
+block 23 16:16 16x16 0
+block 24 32:16 16x16 0
+block 25 48:16 16x16 0
+block 26 64:16 16x16 0
+block 27 80:16 16x16 0
+block 28 96:16 16x16 0
+block 29 112:16 16x16 0
+block 30 128:16 16x16 0
+block 31 144:16 16x16 0
+block 32 160:16 16x16

Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: add shift option

2020-05-18 Thread Manolis Stamatogiannakis
Bumping this up after 10 days without a comment.

On Fri, 8 May 2020 at 13:14, Manolis Stamatogiannakis 
wrote:

> Allows shifting of subtitle display times to align them with the video.
> This avoids having to rewrite the subtitle file in order to display
> subtitles correctly when input is seeked (-ss).
> Also handy for minor subtitle timing corrections without rewriting the
> subtitles file.
>
> Signed-off-by: Manolis Stamatogiannakis 
> ---
>  doc/filters.texi   |  8 
>  libavfilter/vf_subtitles.c | 29 +++--
>  2 files changed, 35 insertions(+), 2 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index d19fd346ae..94323495f0 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -17851,6 +17851,9 @@ The filter accepts the following options:
>  @item filename, f
>  Set the filename of the subtitle file to read. It must be specified.
>
> +@item shift
> +Shift subtitles timings by the specified amount.
> +
>  @item original_size
>  Specify the size of the original video, the video for which the ASS file
>  was composed. For the syntax of this option, check the
> @@ -17907,6 +17910,11 @@ To make the subtitles stream from @file{sub.srt}
> appear in 80% transparent blue
>  subtitles=sub.srt:force_style='FontName=DejaVu
> Serif,PrimaryColour=&HCCFF'
>  @end example
>
> +To re-sync subtitles after seeking the input e.g. with @code{-ss 20:20},
> use:
> +@example
> +subtitles=filename=sub.srt:shift=-20\:20
> +@end example
> +
>  @section super2xsai
>
>  Scale the input by 2x and smooth using the Super2xSaI (Scale and
> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> index a3b4029af4..47a38b55b1 100644
> --- a/libavfilter/vf_subtitles.c
> +++ b/libavfilter/vf_subtitles.c
> @@ -52,6 +52,8 @@ typedef struct AssContext {
>  char *filename;
>  char *fontsdir;
>  char *charenc;
> +int64_t shift;
> +char *shift_opt;
>  char *force_style;
>  int stream_index;
>  int alpha;
> @@ -68,6 +70,7 @@ typedef struct AssContext {
>  #define COMMON_OPTIONS \
>  {"filename",   "set the filename of file to read",
>  OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> FLAGS }, \
>  {"f",  "set the filename of file to read",
>  OFFSET(filename),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> FLAGS }, \
> +{"shift",  "shift the timing of the subtitles",
>   OFFSET(shift_opt),  AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> FLAGS }, \
>  {"original_size",  "set the size of the original video (used to scale
> fonts)", OFFSET(original_w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL},  0, 0,
> FLAGS }, \
>  {"fontsdir",   "set the directory containing the fonts to read",
>  OFFSET(fontsdir),   AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,
> FLAGS }, \
>  {"alpha",  "enable processing of alpha channel",
>  OFFSET(alpha),  AV_OPT_TYPE_BOOL,   {.i64 = 0   },
>  0,1, FLAGS }, \
> @@ -103,6 +106,16 @@ static av_cold int init(AVFilterContext *ctx)
>  return AVERROR(EINVAL);
>  }
>
> +if (ass->shift_opt) {
> +if (av_parse_time(&ass->shift, ass->shift_opt, 1) < 0) {
> +av_log(ctx, AV_LOG_ERROR, "Invalid subtitles shift: %s\n",
> +   ass->shift_opt);
> +return AVERROR(EINVAL);
> +}
> +ass->shift = av_rescale_q(ass->shift, AV_TIME_BASE_Q,
> av_make_q(1, 1000));
> +av_log(ctx, AV_LOG_DEBUG, "Shifting subtitles by %0.3fsec.\n",
> ass->shift/1000.0);
> +}
> +
>  ass->library = ass_library_init();
>  if (!ass->library) {
>  av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
> @@ -297,7 +310,7 @@ AVFILTER_DEFINE_CLASS(subtitles);
>
>  static av_cold int init_subtitles(AVFilterContext *ctx)
>  {
> -int j, ret, sid;
> +int j, ret, sid, nskip;
>  int k = 0;
>  AVDictionary *codec_opts = NULL;
>  AVFormatContext *fmt = NULL;
> @@ -448,6 +461,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
>  av_init_packet(&pkt);
>  pkt.data = NULL;
>  pkt.size = 0;
> +nskip = 0;
>  while (av_read_frame(fmt, &pkt) >= 0) {
>  int i, got_subtitle;
>  AVSubtitle sub = {0};
> @@ -458,8 +472,17 @@ static av_cold int init_subtitles(AVFilterContext
> *ctx)
>  av_log(ctx, AV_LOG_WARNING, "Error decoding: %s
> (ignored)\n",
> av_err2str(ret));
>  } else if (got_subtitle) {
> -const int64_t start_time = av_rescale_q(sub.pts,
> AV_TIME_BASE_Q, av_make_q(1, 1000));
> +const int64_t start_time = av_rescale_q(sub.pts,
> AV_TIME_BASE_Q, av_make_q(1, 1000)) + ass->shift;
>  const int64_t duration   = sub.end_display_time;
> +
> +if (start_time + duration < 0) {
> +nskip++;
> +goto pkt_end;
> + 

Re: [FFmpeg-devel] [RFC] encoder profile validation

2020-05-18 Thread Anton Khirnov
Quoting Marton Balint (2020-05-16 15:52:22)
> Hi,
> 
> As you may know, a recent patchset enabled AVCodecContext->profile 
> constants to reside in encoders.
> 
> In order to make a full transition to avctx->profile even in existing 
> encoders which might use a private profile setting, we have to make sure 
> only supported avctx->profile values are passed to encoders.
> 
> The fact that avctx->profile is not validated is already an issue, and 
> assertions/segmentation faults can already happen in existing encoders 
> (e.g.: aac, mpeg) if unsupported values are passed.
> 
> AVCodec have a .profiles attribute which supposed to contain the list of 
> supported profiles. However this is problematic because
> - AVCodecContext->profile is not validated against this list
> - not all encoders define the list
> - even if there is a list it might be defined as NULL_IF_CONFIG_SMALL
> - some encoders support more or less than its currently defined list

All of these sound like bugs that can and should be fixed.

> - AVCodec->profiles contains AVProfiles which supposed to have a textual
>representation of each profile, which can cause profile name
>duplications/inconsistencies against libavcodec/profiles.c if the list
>is different to the one in codecs profile list.

Why should it be different? Isn't that a bug that should be fixed?

> 
> So I'd rather not user AVCodec->profiles for this validation. I am 
> thinking about two possible solutions:

It seems preferable to me to fix the above issues and not have multiple
fields with subtly different meanings that are just bound to cause
confusion and bugs.

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

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

Re: [FFmpeg-devel] [RFC]separation of multiple outputs' encoding

2020-05-18 Thread Anton Khirnov
Quoting Tao Zhang (2020-05-18 08:00:55)
> If no more comments, I will try to code something to create a pseudo
> encoder which run the actual encoding in the separate thread. Thanks

I do not think it is a good idea to have the library compensate for
deficiencies in the calling program.

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

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

Re: [FFmpeg-devel] [PATCH 00/10] Vulkan code general/performance improvements

2020-05-18 Thread Anton Khirnov
Quoting James Almer (2020-05-15 20:47:56)
> On 5/15/2020 3:36 PM, Lynne wrote:
> > Just posting this as a single email not to spam the ML too much.
> > Going to push this sometime over the weekend alongside the other 3 patches 
> > to finish
> > all work on Vulkan before the next release.
> 
> The new release is not going to happen tomorrow or even next week, so
> you could give people more than two days to look at a dozen patches...

I'd add that individual emails are a lot easier to read/review. And if
you send them as a thread, which git-send-email does by default, it
doesn't really spam the ML any more than a single mail in any sane MUA.

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

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

[FFmpeg-devel] [PATCH] avcodec/nvenc: set average and max bitrate values to zero when in CQ rate control mode

2020-05-18 Thread Roman Arzumanyan
Hello,
The patch fixes bug with CQ RC mode: max and average bitrate values were not 
set to zero.

How to reproduce:
#CQ 30 file
ffmpeg \
  -i big_buck_bunny_1080p_h264.mov -c:v h264_nvenc -preset medium \
  -cq 30 -y output_cq30.mp4

#CQ 10 file
ffmpeg \
  -i big_buck_bunny_1080p_h264.mov -c:v h264_nvenc -preset medium \
  -cq 10 -y output_cq10.mp4

Before the patch, both output_cq30.mp4  and output_cq10.mp4  were of same size.
After the patch, output_cq10.mp4 file has higher quality and bigger size.

--
BR, Roman Arzumanyan


---
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
---


0001-fixing-CQ-mode-avg-max-bitrate-settings.patch
Description: 0001-fixing-CQ-mode-avg-max-bitrate-settings.patch
___
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: add NotchLC decoder

2020-05-18 Thread Paul B Mahol
Will apply soon.

On 5/14/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/codec_desc.c |   7 +
>  libavcodec/codec_id.h   |   1 +
>  libavcodec/notchlc.c| 461 
>  libavformat/isom.c  |   2 +
>  libavformat/riff.c  |   1 +
>  7 files changed, 474 insertions(+)
>  create mode 100644 libavcodec/notchlc.c
>
___
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 gradients source video filter

2020-05-18 Thread Paul B Mahol
Will apply soon.

On 5/15/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  doc/filters.texi |  27 
>  libavfilter/Makefile |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vsrc_gradients.c | 290 +++
>  4 files changed, 319 insertions(+)
>  create mode 100644 libavfilter/vsrc_gradients.c
>
___
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] [WIP] XComposite window capture demuxer (Linux)

2020-05-18 Thread Emanuele Oriani

Hi Marton/ffmpeg devs/all,

Haven't seen any response to the proposed XComposite windows capture.

As per below the reasoning for adding this code to libav*/ffmpeg is that 
seems to be better in quality than x11grab, although it uses more CPU in 
its current implementation (uses OpenGL and PBO - optional - to fetch 
XComposite windows).


Please let me know if it's still of interest and/or you have further 
technical feedback.

I've posted some performance tests in the thread below.

Here links of two captures (one with x11grab, the other with xcompgrab) 
and the sources:


https://send.firefox.com/download/df859689f4cc6429/#EN6w9upyIMHqO7n_1hMTaQ
https://github.com/Emanem/replayer/blob/master/src/xcompgrab.c

Thanks in advance for your time and feedback,
Emanuele

Ps. Apologies if I've missed reposes on this list

On 10/05/2020 19:01, Emanuele Oriani wrote:

Hi Marton/all,

I've re-uploaded the firefox send link (expired) with some sample 
capture at 60 FPS:


https://send.firefox.com/download/51b45decae720c08/#r5o4J2SgCJZndRdMOxxRBg

Please note I have integrated usage of OpenGL's Pixel Buffer Objects - 
now the memory management of the captured framed can be managed by the 
drivers and hopefully should be DMA and less memory hops.

This new code works on both Nvidia and AMD.

CPU usage is still higher than x11grab (similar levels as below).

Let me know your thoughts.

Thanks,
Emanuele

Ps. quick link to demuxer: 
https://github.com/Emanem/replayer/blob/master/src/xcompgrab.c


On 08/05/2020 11:43, Emanuele Oriani wrote:

Hi Marton,

Capturing at 60 FPS 1920x1080, the difference is even more noticeable: 
x11grab is choppy, xcompgrab is smooth (this time I used H264 
ultrafast to encode).


https://send.firefox.com/download/17001ef60837a5ec/#FaQTa-dP4MB28YfPNMXxuw 



CPU performance:

  real    user   sys
- xcompgrab: 10.32s, 18.2s, 0.38s
- x11grab:   10.20s, 11.6s, 0.22s

Definitely much more CPU usage, but the output quality can't be compared.
Please note no frames were lost/skipped, everything was processed on 
time for both tests.


Thanks,
Emanuele

On 08/05/2020 11:05, Emanuele Oriani wrote:

Hi Marton,

TL;DR
xcompgrab uses more CPU but produces much better streams than x11grab.

I have the following CPU usage performance report (on my i7-8700k, 
Nvidia 2080 Ti RTX, governor set to 'performance', on Ubuntu 18.04 
using Gnome shell).
The capture has been a surface area of  1720x1376 for 10 seconds at 
30 FPS, only getting the frames, not trying to encode them into a file:


  real    user   sys
- xcompgrab: 10.13s, 2.06s, 0.085s
- x11grab:   10.05s, 0.20s, 0.035s

from a first outlook x11grab is much more CPU efficient, almost 90% 
less CPU usage, but upon starting to record the video, it feels like 
it's 'choppier' and loses frames.


Below videos have been captured at 1920x1080, the encoder is exactly 
the same with same settings and the total CPU time is greater for 
xcompgrab (as expected).


But if you look at both, the xcompgrab doesn't lose frames/is not 
choppier, instead x11grab seems to be much worse.


I've uploaded both 10 secs segments at:
https://send.firefox.com/download/0cbf01f9126519c7/#DPKzIfjemAFm263ZSdMOBw 



The code used to grab and encode is 
https://github.com/Emanem/replayer again very simple, one thread gets 
the packets/frames, the other picks the frames and encodes them.


Performance of this run has been:

  real    user   sys
- xcompgrab: 10.42s, 12.5s, 0.22s
- x11grab:   10.21s, 8.90s, 0.31s

As expected x11grab yields better CPU usage but the quality of output 
is somehow lacking.


Let me know your thoughts.

Thanks,
Emanuele

On 07/05/2020 19:52, Marton Balint wrote:



On Thu, 7 May 2020, Emanuele Oriani wrote:


Hi FFMPEG devel,

I have been writing a simple XComposite window capture demuxer, 
heavily inspired from x11grab sources and OBS Window capture 
logic/code.


Have you compared performance to x11grab for various resolutions and 
frame rates? Do you have some numbers?


Thanks,
Marton



I would like to give back to the community and share the sources; 
before I would formally submit for a review/patch, I would really 
appreciate if someone could have a high level pass at the code 
(it's relatively simple actually) and point out any major 
issues/problems/...


The code is available as part of a simple test application on 
github, at:


https://github.com/Emanem/replayer/blob/master/src/xcompgrab.c

Being the author of the code I would be happy to re-license it to 
be used in ffmpeg/libav* mainline once I get the OK from you.
In order to compile/execute this code, one needs the following dev 
packages:


libav*-dev, libx11-dev, libxcomposite-dev, OpenGL headers/libs.

Libraries to be linked are:

-lavcodec -lavformat -lavdevice -lavutil -lswscale -lX11 
-lXcomposite -lGL


I've tested it and it's working fine on both AMD and Nvidia hardware.

Let me know if this is of interest, otherwise no worries and thanks 
again f

Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_chromakey: fix formula for calculation of difference

2020-05-18 Thread Paul B Mahol
Will apply soon.

On 5/16/20, Paul B Mahol  wrote:
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_chromakey.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/vf_chromakey.c b/libavfilter/vf_chromakey.c
> index ce8003657c..4b1669d084 100644
> --- a/libavfilter/vf_chromakey.c
> +++ b/libavfilter/vf_chromakey.c
> @@ -56,7 +56,7 @@ static uint8_t do_chromakey_pixel(ChromakeyContext *ctx,
> uint8_t u[9], uint8_t v
>  du = (int)u[i] - ctx->chromakey_uv[0];
>  dv = (int)v[i] - ctx->chromakey_uv[1];
>
> -diff += sqrt((du * du + dv * dv) / (255.0 * 255.0));
> +diff += sqrt((du * du + dv * dv) / (255.0 * 255.0 * 2));
>  }
>
>  diff /= 9.0;
> @@ -78,7 +78,7 @@ static uint16_t do_chromakey_pixel16(ChromakeyContext
> *ctx, uint16_t u[9], uint1
>  du = (int)u[i] - ctx->chromakey_uv[0];
>  dv = (int)v[i] - ctx->chromakey_uv[1];
>
> -diff += sqrt((du * du + dv * dv) / (max * max));
> +diff += sqrt((du * du + dv * dv) / (max * max * 2));
>  }
>
>  diff /= 9.0;
> --
> 2.17.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 2/2] lavc/hevc_refs: Fix the logic of find_ref_idx()

2020-05-18 Thread Fu, Linjie
> From: Fu, Linjie 
> Sent: Tuesday, May 12, 2020 21:44
> To: ffmpeg-devel@ffmpeg.org
> Cc: Xu, Guangxin ; Fu, Linjie 
> Subject: [PATCH 2/2] lavc/hevc_refs: Fix the logic of find_ref_idx()
> 
> From: Xu Guangxin 
> 
> Currently find_ref_idx() would trigger 2 scans in DPB to find the
> requested POC:
> 1. Firstly, ignore MSB of ref->poc and search for the requested POC;
> 2. Secondly, compare the entire ref->poc with requested POC;
> 
> For long term reference, we are able to only check LSB if MSB is not
> presented(e.g. delta_poc_msb_present_flag == 0). However, for short
> term reference, we should never ignore poc's MSB and it should be
> kind of bit-exact. (Details in 8.3.2)
> 
> Otherwise this leads to decoding failures like:
> [hevc @ 0x5638f4328600] Error constructing the frame RPS.
> [hevc @ 0x5638f4328600] Error parsing NAL unit #2.
> [hevc @ 0x5638f4338a80] Could not find ref with POC 21
> Error while decoding stream #0:0: Invalid data found when processing input
> 
> Search the requested POC based on whether MSB is used, and avoid
> the 2-times scan for DPB buffer. This benefits both native HEVC
> decoder and integrated HW decoders.
> 
> Signed-off-by: Linjie Fu 
> ---
> 
> Since it's kind of difficult to generate an identical bitstream for
> fate or test, I'd like to elaborate more about one of the failures:
> 
> requested POC = 5;
> LtMask = (1 << 4) - 1 = 15;
> ref[0]->poc = 21; // unexpected ref for poc = 5 (short term)
> ref[1]->poc = 5;  // expected ref for poc = 5 (short term)
> 
> Hence find_ref_idx() would wrongly return a ref with poc = 21, which
> leads to the decoding error.
> 
>  libavcodec/hevc_refs.c | 38 --
>  1 file changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index 7870a72..73aa6d8 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -358,24 +358,26 @@ int ff_hevc_slice_rpl(HEVCContext *s)
>  return 0;
>  }
> 
> -static HEVCFrame *find_ref_idx(HEVCContext *s, int poc)
> +static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb)
>  {
>  int i;
> -int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1;
> 
> -for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> -HEVCFrame *ref = &s->DPB[i];
> -if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) {
> -if ((ref->poc & LtMask) == poc)
> -return ref;
> +if (use_msb) {
> +for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> +HEVCFrame *ref = &s->DPB[i];
> +if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) {
> +if (ref->poc == poc)
> +return ref;
> +}
>  }
> -}
> -
> -for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> -HEVCFrame *ref = &s->DPB[i];
> -if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
> -if (ref->poc == poc || (ref->poc & LtMask) == poc)
> -return ref;
> +} else {
> +int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1;
> +for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
> +HEVCFrame *ref = &s->DPB[i];
> +if (ref->frame->buf[0] && ref->sequence == s->seq_decode) {
> +if ((ref->poc & LtMask) == poc)
> +return ref;
> +}
>  }
>  }
> 
> @@ -427,9 +429,9 @@ static HEVCFrame
> *generate_missing_ref(HEVCContext *s, int poc)
> 
>  /* add a reference with the given poc to the list and mark it as used in DPB
> */
>  static int add_candidate_ref(HEVCContext *s, RefPicList *list,
> - int poc, int ref_flag)
> + int poc, int ref_flag, uint8_t use_msb)
>  {
> -HEVCFrame *ref = find_ref_idx(s, poc);
> +HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
> 
>  if (ref == s->ref || list->nb_refs >= HEVC_MAX_REFS)
>  return AVERROR_INVALIDDATA;
> @@ -485,7 +487,7 @@ int ff_hevc_frame_rps(HEVCContext *s)
>  else
>  list = ST_CURR_AFT;
> 
> -ret = add_candidate_ref(s, &rps[list], poc,
> HEVC_FRAME_FLAG_SHORT_REF);
> +ret = add_candidate_ref(s, &rps[list], poc,
> HEVC_FRAME_FLAG_SHORT_REF, 1);
>  if (ret < 0)
>  goto fail;
>  }
> @@ -495,7 +497,7 @@ int ff_hevc_frame_rps(HEVCContext *s)
>  int poc  = long_rps->poc[i];
>  int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
> 
> -ret = add_candidate_ref(s, &rps[list], poc,
> HEVC_FRAME_FLAG_LONG_REF);
> +ret = add_candidate_ref(s, &rps[list], poc,
> HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]);
>  if (ret < 0)
>  goto fail;
>  }
> --
> 2.7.4

Ping for this patch set.
Verified with 1000 + decoding conformance cases including 8/10 bit, no 
regression observed.

 - Linjie
___
ffmpeg-devel mailing l

Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: Async the encoding and output procedure of encoder

2020-05-18 Thread Fu, Linjie
> Mark Thompson:
> Sent: Monday, November 18, 2019 07:14
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: Async the
> encoding and output procedure of encoder
> 
> On 07/11/2019 16:32, Linjie Fu wrote:
> > Currently, vaapi encodes a pic if all its references are ready,
> > and then outputs it immediately by calling vaapi_encode_output.
> >
> > However, while working on output procedure, hardware is be able to
> > cope with encoding tasks in the meantime to have the better performance.
> >
> > So a more efficient way is to send all the pics with available refs to
> > hardware to allow encoding while output.
> >
> > It's what vaapi originally did before the regression, and the performance
> > could be improved for ~20%.
> >
> > CMD:
> > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128
> > -hwaccel_output_format vaapi -i
> bbb_sunflower_1080p_30fps_normal.mp4
> > -c:v h264_vaapi -f h264 -y /dev/null
> >
> > Source:
> > https://download.blender.org/demo/movies/BBB/
> >
> > Before:
> > ~164 fps
> > After:
> > ~198 fps
> >
> > Fix #7706.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> 
> The sync in the same receive call here is required for correctness because of
> the how VAAPI syncs to the input surface (consider the interactions of a split
> followed by two encoders using the same surfaces).  I didn't realise that for 
> a
> long time, hence the error existing in earlier versions.

Indeed, you're right 1:N encoding procedure suffered from this. And the proper
fix is to provide a new API to sync the coded buffer which is independent for 
each
encoding task, instead of syncing the shared input surface. (See comments below)

> 
> Relatedly, this change would significantly increase latency on Intel platforms
> because vaEndPicture() is mostly synchronous there, and you're now calling
> it multiple times before returning anything.

As the the latency, how about adding an option like "-async 0/1" to specify the
user requirement:
For live streaming, user may use -async 0 to minimize the latency;
For video on demand, user may use -async 1 to maximize the performance.

> 
> More generally, though, the API definition here is just really stupid.  If 
> you're
> interested it would be much better to fix this in the API - sync-to-output of
> some kind would make far more sense, as would some kind of event-based
> system (extra points if it can interop via fds to normal poll() and Vulkan).
> 
We have a proposal[1] to libva to introduce the new function to make encoder
synchronization by output bitstream., and looking forward to your comments.

- Linjie

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