[FFmpeg-devel] [PATCH V5 1/2] lavfi/colorlevels: Add slice threading support

2019-05-31 Thread Jun Zhao
From: Jun Zhao 

Add slice threading support, use the command like:

./ffmpeg -i input -vf colorlevels -f null /dev/null

with 1080p h264 clip, the fps from 39 fps to 79 fps
in the local(Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz)

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_colorlevels.c |  110 ++---
 1 files changed, 91 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_colorlevels.c b/libavfilter/vf_colorlevels.c
index 5385a5e..fadb39e 100644
--- a/libavfilter/vf_colorlevels.c
+++ b/libavfilter/vf_colorlevels.c
@@ -105,6 +105,68 @@ static int config_input(AVFilterLink *inlink)
 return 0;
 }
 
+struct thread_data {
+const uint8_t *srcrow;
+uint8_t *dstrow;
+int dst_linesize;
+int src_linesize;
+
+double coeff;
+uint8_t offset;
+
+int h;
+
+int imin;
+int omin;
+};
+
+#define LOAD_COMMON\
+ColorLevelsContext *s = ctx->priv;\
+const struct thread_data *td = arg;\
+\
+int process_h = td->h;\
+const int slice_start = (process_h *  jobnr   ) / nb_jobs;\
+const int slice_end   = (process_h * (jobnr+1)) / nb_jobs;\
+int x, y;\
+const uint8_t *srcrow = td->srcrow;\
+uint8_t *dstrow = td->dstrow;\
+const int step = s->step;\
+const uint8_t offset = td->offset;\
+\
+int imin = td->imin;\
+int omin = td->omin;\
+double coeff = td->coeff;\
+
+static int colorlevel_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+LOAD_COMMON
+
+for (y = slice_start; y < slice_end; y++) {
+const uint8_t *src = srcrow + y * td->src_linesize;
+uint8_t *dst = dstrow + y * td->dst_linesize;
+
+for (x = 0; x < s->linesize; x += step)
+dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * coeff + 
omin);
+}
+
+return 0;
+}
+
+static int colorlevel_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+LOAD_COMMON
+
+for (y = slice_start; y < slice_end; y++) {
+const uint16_t *src = (const uint16_t *)(srcrow + y * 
td->src_linesize);
+uint16_t *dst = (uint16_t *)(dstrow + y * td->dst_linesize);
+
+for (x = 0; x < s->linesize; x += step)
+dst[x + offset] = av_clip_uint16((src[x + offset] - imin) * coeff 
+ omin);
+}
+
+return 0;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -137,6 +199,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 int omin = lrint(r->out_min * UINT8_MAX);
 int omax = lrint(r->out_max * UINT8_MAX);
 double coeff;
+struct thread_data td;
 
 if (imin < 0) {
 imin = UINT8_MAX;
@@ -162,15 +225,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 srcrow = in->data[0];
 coeff = (omax - omin) / (double)(imax - imin);
-for (y = 0; y < inlink->h; y++) {
-const uint8_t *src = srcrow;
-uint8_t *dst = dstrow;
-
-for (x = 0; x < s->linesize; x += step)
-dst[x + offset] = av_clip_uint8((src[x + offset] - imin) * 
coeff + omin);
-dstrow += out->linesize[0];
-srcrow += in->linesize[0];
-}
+
+td.srcrow= srcrow;
+td.dstrow= dstrow;
+td.dst_linesize  = out->linesize[0];
+td.src_linesize  = in->linesize[0];
+td.coeff = coeff;
+td.offset= offset;
+td.h = inlink->h;
+td.imin  = imin;
+td.omin  = omin;
+
+ctx->internal->execute(ctx, colorlevel_slice_8, , NULL,
+   FFMIN(inlink->h, 
ff_filter_get_nb_threads(ctx)));
 }
 break;
 case 2:
@@ -184,6 +251,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 int omin = lrint(r->out_min * UINT16_MAX);
 int omax = lrint(r->out_max * UINT16_MAX);
 double coeff;
+struct thread_data td;
 
 if (imin < 0) {
 imin = UINT16_MAX;
@@ -209,15 +277,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 srcrow = in->data[0];
 coeff = (omax - omin) / (double)(imax - imin);
-for (y = 0; y < inlink->h; y++) {
-const uint16_t *src = (const uint16_t*)srcrow;
-uint16_t *dst = (uint16_t *)dstrow;
-
-for (x = 0; x < s->linesize; x += step)
-dst[x + offset] = av_clip_uint16((src[x + offset] - imin) 
* coeff + omin);
-dstrow += out->linesize[0];
-srcrow += in->linesize[0];
-}
+
+td.srcrow= srcrow;
+td.dstrow= dstrow;
+td.dst_linesize  = out->linesize[0];
+td.src_linesize  = in->linesize[0];
+  

[FFmpeg-devel] [PATCH V5 2/2] lavfi/lut: Add slice threading support

2019-05-31 Thread Jun Zhao
From: Jun Zhao 

Used the command for 1080p h264 clip as follow:

a). ffmpeg -i input -vf lutyuv="u=128:v=128" -f null /dev/null
b). ffmpeg -i input -vf lutrgb="g=0:b=0" -f null /dev/null

after enabled the slice threading, the fps change from:

a). 144fps to 258fps (lutyuv)
b). 94fps  to 153fps (lutrgb)

in Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_lut.c |  310 --
 1 files changed, 197 insertions(+), 113 deletions(-)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index c815ddc..90998e6 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -337,13 +337,194 @@ static int config_props(AVFilterLink *inlink)
 return 0;
 }
 
+struct thread_data {
+AVFrame *in;
+AVFrame *out;
+
+int w;
+int h;
+};
+
+#define LOAD_PACKED_COMMON\
+LutContext *s = ctx->priv;\
+const struct thread_data *td = arg;\
+\
+int i, j;\
+const int w = td->w;\
+const int h = td->h;\
+AVFrame *in = td->in;\
+AVFrame *out = td->out;\
+const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;\
+const int step = s->step;\
+\
+const int slice_start = (h *  jobnr   ) / nb_jobs;\
+const int slice_end   = (h * (jobnr+1)) / nb_jobs;\
+
+/* packed, 16-bit */
+static int lut_packed_16bits(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+LOAD_PACKED_COMMON
+
+uint16_t *inrow, *outrow, *inrow0, *outrow0;
+const int in_linesize  =  in->linesize[0] / 2;
+const int out_linesize = out->linesize[0] / 2;
+inrow0  = (uint16_t *)in ->data[0];
+outrow0 = (uint16_t *)out->data[0];
+
+for (i = slice_start; i < slice_end; i++) {
+inrow  = inrow0 + i * in_linesize;
+outrow = outrow0 + i * out_linesize;
+for (j = 0; j < w; j++) {
+
+switch (step) {
+#if HAVE_BIGENDIAN
+case 4:  outrow[3] = av_bswap16(tab[3][av_bswap16(inrow[3])]); // 
Fall-through
+case 3:  outrow[2] = av_bswap16(tab[2][av_bswap16(inrow[2])]); // 
Fall-through
+case 2:  outrow[1] = av_bswap16(tab[1][av_bswap16(inrow[1])]); // 
Fall-through
+default: outrow[0] = av_bswap16(tab[0][av_bswap16(inrow[0])]);
+#else
+case 4:  outrow[3] = tab[3][inrow[3]]; // Fall-through
+case 3:  outrow[2] = tab[2][inrow[2]]; // Fall-through
+case 2:  outrow[1] = tab[1][inrow[1]]; // Fall-through
+default: outrow[0] = tab[0][inrow[0]];
+#endif
+}
+outrow += step;
+inrow  += step;
+}
+}
+
+return 0;
+}
+
+/* packed, 8-bit */
+static int lut_packed_8bits(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+LOAD_PACKED_COMMON
+
+uint8_t *inrow, *outrow, *inrow0, *outrow0;
+const int in_linesize  =  in->linesize[0];
+const int out_linesize = out->linesize[0];
+inrow0  = in ->data[0];
+outrow0 = out->data[0];
+
+for (i = slice_start; i < slice_end; i++) {
+inrow  = inrow0 + i * in_linesize;
+outrow = outrow0 + i * out_linesize;
+for (j = 0; j < w; j++) {
+switch (step) {
+case 4:  outrow[3] = tab[3][inrow[3]]; // Fall-through
+case 3:  outrow[2] = tab[2][inrow[2]]; // Fall-through
+case 2:  outrow[1] = tab[1][inrow[1]]; // Fall-through
+default: outrow[0] = tab[0][inrow[0]];
+}
+outrow += step;
+inrow  += step;
+}
+}
+
+return 0;
+}
+
+#define LOAD_PLANAR_COMMON\
+LutContext *s = ctx->priv;\
+const struct thread_data *td = arg;\
+int i, j, plane;\
+AVFrame *in = td->in;\
+AVFrame *out = td->out;\
+
+#define PLANAR_COMMON\
+int vsub = plane == 1 || plane == 2 ? s->vsub : 0;\
+int hsub = plane == 1 || plane == 2 ? s->hsub : 0;\
+int h = AV_CEIL_RSHIFT(td->h, vsub);\
+int w = AV_CEIL_RSHIFT(td->w, hsub);\
+const uint16_t *tab = s->lut[plane];\
+\
+const int slice_start = (h *  jobnr   ) / nb_jobs;\
+const int slice_end   = (h * (jobnr+1)) / nb_jobs;\
+
+/* planar >8 bit depth */
+static int lut_planar_16bits(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+LOAD_PLANAR_COMMON
+
+uint16_t *inrow, *outrow;
+
+for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; 
plane++) {
+PLANAR_COMMON
+
+const int in_linesize  =  in->linesize[plane] / 2;
+const int out_linesize = out->linesize[plane] / 2;
+
+inrow  = (uint16_t *)(in ->data[plane] + slice_start * in_linesize);
+outrow = (uint16_t *)(out->data[plane] + slice_start * out_linesize);
+
+for (i = slice_start; i < slice_end; i++) {
+for (j = 0; j < w; j++) {
+#if HAVE_BIGENDIAN
+outrow[j] = av_bswap16(tab[av_bswap16(inrow[j])]);
+#else
+outrow[j] = tab[inrow[j]];
+#endif
+}
+inrow  

[FFmpeg-devel] [PATCH V5 0/2] Add slice threading support

2019-05-31 Thread Jun Zhao
V5: - Using Macros for redundant code, don't use the is_16bit check in the 
  thread exec callback to avoid potential performance issues, Thanks 
  Ruiling Song, ZhongLi and Paul B Mahol review/comments/suggestion.

Jun Zhao (2):
  lavfi/colorlevels: Add slice threading support
  lavfi/lut: Add slice threading support

 libavfilter/vf_colorlevels.c |  110 ---
 libavfilter/vf_lut.c |  310 +++---
 2 files changed, 288 insertions(+), 132 deletions(-)

___
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 V1 2/3] lavf/sr: Don't need to check NULL before sws_freeContext

2019-05-31 Thread Jun Zhao
From: Jun Zhao 

sws_freeContext have check the NULL pointer, so don't need to check
NULL before sws_freeContext.

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_sr.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
index a371e44..0be572f 100644
--- a/libavfilter/vf_sr.c
+++ b/libavfilter/vf_sr.c
@@ -286,9 +286,7 @@ static av_cold void uninit(AVFilterContext *context)
 }
 
 for (i = 0; i < 3; ++i){
-if (sr_context->sws_contexts[i]){
-sws_freeContext(sr_context->sws_contexts[i]);
-}
+sws_freeContext(sr_context->sws_contexts[i]);
 }
 }
 
-- 
1.7.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 V1 3/3] lavf/sr: Refine the coding style for init

2019-05-31 Thread Jun Zhao
From: Jun Zhao 

We perfer the coding style like:

/* some stuff */
if (error) {
/* error handling */
return -(errorcode);
}
/* normal actions */
do_something()

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_sr.c |   13 ++---
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
index 0be572f..0433246 100644
--- a/libavfilter/vf_sr.c
+++ b/libavfilter/vf_sr.c
@@ -72,17 +72,16 @@ static av_cold int init(AVFilterContext *context)
 av_log(context, AV_LOG_ERROR, "could not create DNN module for 
requested backend\n");
 return AVERROR(ENOMEM);
 }
+
 if (!sr_context->model_filename){
 av_log(context, AV_LOG_ERROR, "model file for network was not 
specified\n");
 return AVERROR(EIO);
-} else {
-if (!sr_context->dnn_module->load_model) {
-av_log(context, AV_LOG_ERROR, "load_model for network was not 
specified\n");
-return AVERROR(EIO);
-} else {
-sr_context->model = 
(sr_context->dnn_module->load_model)(sr_context->model_filename);
-}
 }
+if (!sr_context->dnn_module->load_model) {
+av_log(context, AV_LOG_ERROR, "load_model for network was not 
specified\n");
+return AVERROR(EIO);
+}
+sr_context->model = 
(sr_context->dnn_module->load_model)(sr_context->model_filename);
 if (!sr_context->model){
 av_log(context, AV_LOG_ERROR, "could not load DNN model\n");
 return AVERROR(EIO);
-- 
1.7.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 V1 0/3] Refine SR filter

2019-05-31 Thread Jun Zhao
V1: - Dump input pixel format in error message
- Remove NULL check before call sws_freeContext
- Refine the error handling coding logic for init 

Jun Zhao (3):
  lavf/sr: Dump input pixel format in error message
  lavf/sr: Don't need to check NULL before sws_freeContext
  lavf/sr: Refine the coding style for init

 libavfilter/vf_sr.c |   22 +++---
 1 files changed, 11 insertions(+), 11 deletions(-)

___
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 V1 1/3] lavf/sr: Dump input pixel format in error message

2019-05-31 Thread Jun Zhao
From: Jun Zhao 

Dump input pixel format in error message, it's will help to debugging

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_sr.c |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/libavfilter/vf_sr.c b/libavfilter/vf_sr.c
index 86dc551..a371e44 100644
--- a/libavfilter/vf_sr.c
+++ b/libavfilter/vf_sr.c
@@ -29,6 +29,7 @@
 #include "formats.h"
 #include "internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "libavformat/avio.h"
 #include "libswscale/swscale.h"
 #include "dnn_interface.h"
@@ -205,7 +206,9 @@ static int config_props(AVFilterLink *inlink)
 sws_dst_w = AV_CEIL_RSHIFT(sws_dst_w, 2);
 break;
 default:
-av_log(context, AV_LOG_ERROR, "could not create SwsContext for 
scaling for given input pixel format");
+av_log(context, AV_LOG_ERROR,
+   "could not create SwsContext for scaling for given 
input pixel format: %s\n",
+   av_get_pix_fmt_name(inlink->format));
 return AVERROR(EIO);
 }
 sr_context->sws_contexts[0] = sws_getContext(sws_src_w, sws_src_h, 
AV_PIX_FMT_GRAY8,
-- 
1.7.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 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Gyan



On 01-06-2019 02:06 AM, Carl Eugen Hoyos wrote:

Am Fr., 31. Mai 2019 um 16:40 Uhr schrieb Lynne :


Number of threads should not have any impact at all on quality ever.

Afair, it has for x264...
(not necessarily related to this patch though)
Definitely x265: 
https://bitbucket.org/multicoreware/x265/issues/449/distortion-in-idr-frame-higher-ratefactor


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

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

Re: [FFmpeg-devel] [PATCH v6 1/2] lavf/vf_transpose: add exif orientation support

2019-05-31 Thread Jun Li
On Thu, May 30, 2019 at 5:29 PM Jun Li  wrote:

> Add exif orientation support and expose an option.
> ---
>  libavfilter/hflip.h|   2 +
>  libavfilter/transpose.h|  14 
>  libavfilter/vf_hflip.c |  40 ++---
>  libavfilter/vf_transpose.c | 161 -
>  4 files changed, 185 insertions(+), 32 deletions(-)
>
> diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h
> index 204090dbb4..4e89bae3fc 100644
> --- a/libavfilter/hflip.h
> +++ b/libavfilter/hflip.h
> @@ -35,5 +35,7 @@ typedef struct FlipContext {
>
>  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes);
>  void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes);
> +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink);
> +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> job, int nb_jobs, int vlifp);
>
>  #endif /* AVFILTER_HFLIP_H */
> diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h
> index aa262b9487..5da08bddc0 100644
> --- a/libavfilter/transpose.h
> +++ b/libavfilter/transpose.h
> @@ -34,4 +34,18 @@ enum TransposeDir {
>  TRANSPOSE_VFLIP,
>  };
>
> +enum OrientationType {
> +ORIENTATION_AUTO_TRANSPOSE = -2,
> +ORIENTATION_AUTO_FLIP = -1,
> +ORIENTATION_NONE = 0,
> +ORIENTATION_NORMAL,
> +ORIENTATION_HFLIP,
> +ORIENTATION_ROTATE180,
> +ORIENTATION_VFLIP,
> +ORIENTATION_HFLIP_ROTATE270CW,
> +ORIENTATION_ROTATE90CW,
> +ORIENTATION_HFLIP_ROTATE90CW,
> +ORIENTATION_ROTATE270CW
> +};
> +
>  #endif
> diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c
> index b77afc77fc..d24ca5c2e7 100644
> --- a/libavfilter/vf_hflip.c
> +++ b/libavfilter/vf_hflip.c
> @@ -125,9 +125,8 @@ static void hflip_qword_c(const uint8_t *ssrc, uint8_t
> *ddst, int w)
>  dst[j] = src[-j];
>  }
>
> -static int config_props(AVFilterLink *inlink)
> +int ff_hflip_config_props(FlipContext* s, AVFilterLink *inlink)
>  {
> -FlipContext *s = inlink->dst->priv;
>  const AVPixFmtDescriptor *pix_desc =
> av_pix_fmt_desc_get(inlink->format);
>  const int hsub = pix_desc->log2_chroma_w;
>  const int vsub = pix_desc->log2_chroma_h;
> @@ -144,6 +143,12 @@ static int config_props(AVFilterLink *inlink)
>  return ff_hflip_init(s, s->max_step, nb_planes);
>  }
>
> +static int config_props(AVFilterLink *inlink)
> +{
> +FlipContext *s = inlink->dst->priv;
> +return ff_hflip_config_props(s, inlink);
> +}
> +
>  int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
>  {
>  int i;
> @@ -170,14 +175,10 @@ typedef struct ThreadData {
>  AVFrame *in, *out;
>  } ThreadData;
>
> -static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> nb_jobs)
> +int ff_hflip_filter_slice(FlipContext *s, AVFrame *in, AVFrame *out, int
> job, int nb_jobs, int vflip)
>  {
> -FlipContext *s = ctx->priv;
> -ThreadData *td = arg;
> -AVFrame *in = td->in;
> -AVFrame *out = td->out;
>  uint8_t *inrow, *outrow;
> -int i, plane, step;
> +int i, plane, step, outlinesize;
>
>  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane];
> plane++) {
>  const int width  = s->planewidth[plane];
> @@ -187,19 +188,36 @@ static int filter_slice(AVFilterContext *ctx, void
> *arg, int job, int nb_jobs)
>
>  step = s->max_step[plane];
>
> -outrow = out->data[plane] + start * out->linesize[plane];
> -inrow  = in ->data[plane] + start * in->linesize[plane] + (width
> - 1) * step;
> +if (vflip) {
> +outrow = out->data[plane] + (height - start - 1)*
> out->linesize[plane];
> +outlinesize = -out->linesize[plane];
> +} else {
> +outrow = out->data[plane] + start * out->linesize[plane];
> +outlinesize = out->linesize[plane];
> +}
> +
> +inrow = in->data[plane] + start * in->linesize[plane] +  (width -
> 1) * step;
> +
>  for (i = start; i < end; i++) {
>  s->flip_line[plane](inrow, outrow, width);
>
>  inrow  += in ->linesize[plane];
> -outrow += out->linesize[plane];
> +outrow += outlinesize;
>  }
>  }
>
>  return 0;
>  }
>
> +static int filter_slice(AVFilterContext *ctx, void *arg, int job, int
> nb_jobs)
> +{
> +FlipContext *s = ctx->priv;
> +ThreadData *td = arg;
> +AVFrame *in = td->in;
> +AVFrame *out = td->out;
> +return ff_hflip_filter_slice(s, in, out, job, nb_jobs, 0);
> +}
> +
>  static int filter_frame(AVFilterLink *inlink, AVFrame *in)
>  {
>  AVFilterContext *ctx  = inlink->dst;
> diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c
> index dd54947bd9..8b5c8d3f50 100644
> --- a/libavfilter/vf_transpose.c
> +++ b/libavfilter/vf_transpose.c
> @@ -39,6 +39,7 @@
>  #include "internal.h"
>  #include "video.h"
>  #include "transpose.h"
> +#include "hflip.h"
>
>  typedef struct TransVtable {
>  void (*transpose_8x8)(uint8_t *src, 

Re: [FFmpeg-devel] [PATCH v3] libavfilter: Add derain filter

2019-05-31 Thread Steven Liu


> 在 2019年5月30日,20:35,Xuewei Meng  写道:
> 
> Remove the rain in the input image/video by applying the derain
> methods based on convolutional neural networks. Training scripts
> as well as scripts for model generation are provided in the
> repository at https://github.com/XueweiMeng/derain_filter.git.
> 
> Signed-off-by: Xuewei Meng 
> ---
> doc/filters.texi |  34 +++
> libavfilter/Makefile |   1 +
> libavfilter/allfilters.c |   1 +
> libavfilter/vf_derain.c  | 212 +++
> 4 files changed, 248 insertions(+)
> create mode 100644 libavfilter/vf_derain.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 4fdcfe919e..f1d3841ed3 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -8248,6 +8248,40 @@ delogo=x=0:y=0:w=100:h=77:band=10
> 
> @end itemize
> 
> +@section derain
> +
> +Remove the rain in the input image/video by applying the derain methods 
> based on
> +convolutional neural networks. Supported models:
> +
> +@itemize
> +@item
> +Recurrent Squeeze-and-Excitation Context Aggregation Net (RESCAN).
> +See 
> @url{http://openaccess.thecvf.com/content_ECCV_2018/papers/Xia_Li_Recurrent_Squeeze-and-Excitation_Context_ECCV_2018_paper.pdf}.
> +@end itemize
> +
> +Training scripts as well as scripts for model generation are provided in
> +the repository at @url{https://github.com/XueweiMeng/derain_filter.git}.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +@item dnn_backend
> +Specify which DNN backend to use for model loading and execution. This 
> option accepts
> +the following values:
> +
> +@table @samp
> +@item native
> +Native implementation of DNN loading and execution.
> +@end table
> +Default value is @samp{native}.
> +
> +@item model
> +Set path to model file specifying network architecture and its parameters.
> +Note that different backends use different file formats. TensorFlow backend
> +can load files for both formats, while native backend can load files for only
> +its format.
> +@end table
> +
> @section deshake
> 
> Attempt to fix small changes in horizontal and/or vertical shift. This
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 9a61c25b05..b7191d0081 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -200,6 +200,7 @@ OBJS-$(CONFIG_DCTDNOIZ_FILTER)   += 
> vf_dctdnoiz.o
> OBJS-$(CONFIG_DEBAND_FILTER) += vf_deband.o
> OBJS-$(CONFIG_DEBLOCK_FILTER)+= vf_deblock.o
> OBJS-$(CONFIG_DECIMATE_FILTER)   += vf_decimate.o
> +OBJS-$(CONFIG_DERAIN_FILTER) += vf_derain.o
> OBJS-$(CONFIG_DECONVOLVE_FILTER) += vf_convolve.o framesync.o
> OBJS-$(CONFIG_DEDOT_FILTER)  += vf_dedot.o
> OBJS-$(CONFIG_DEFLATE_FILTER)+= vf_neighbor.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 40534738ee..f3c8883960 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -196,6 +196,7 @@ extern AVFilter ff_vf_deinterlace_vaapi;
> extern AVFilter ff_vf_dejudder;
> extern AVFilter ff_vf_delogo;
> extern AVFilter ff_vf_denoise_vaapi;
> +extern AVFilter ff_vf_derain;
> extern AVFilter ff_vf_deshake;
> extern AVFilter ff_vf_despill;
> extern AVFilter ff_vf_detelecine;
> diff --git a/libavfilter/vf_derain.c b/libavfilter/vf_derain.c
> new file mode 100644
> index 00..c380b40122
> --- /dev/null
> +++ b/libavfilter/vf_derain.c
> @@ -0,0 +1,212 @@
> +/*
> + * Copyright (c) 2019 Xuewei Meng
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +/**
> + * @file
> + * Filter implementing image derain filter using deep convolutional networks.
> + * 
> http://openaccess.thecvf.com/content_ECCV_2018/html/Xia_Li_Recurrent_Squeeze-and-Excitation_Context_ECCV_2018_paper.html
> + */
> +
> +#include "libavformat/avio.h"
> +#include "libavutil/opt.h"
> +#include "avfilter.h"
> +#include "dnn_interface.h"
> +#include "formats.h"
> +#include "internal.h"
> +
> +typedef struct DRContext {
> +const AVClass *class;
> +
> +char  *model_filename;
> +DNNBackendType backend_type;
> +DNNModule *dnn_module;
> +DNNModel  *model;
> +

Re: [FFmpeg-devel] [PATCH] lavu/frame: fix typo for ROI (region of interest) documentation

2019-05-31 Thread Steven Liu


> 在 2019年5月31日,16:02,Guo, Yejun  写道:
> 
> there is already a nice patch set to fix the ROI documentation, but it
> is pending, see 
> https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-May/20.html
> 
> so just fix this obvious typo that the document does not match the code.
> 
> Signed-off-by: Guo, Yejun 
> ---
> libavutil/frame.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 8aa3e88..eebb2c0 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -212,7 +212,7 @@ typedef struct AVFrameSideData {
>  * self_size specifies the size of this data structure. This value
>  * should be set to sizeof(AVRegionOfInterest). EINVAL is returned if 
> self_size is zero.
>  *
> - * Number of pixels to discard from the top/bottom/left/right border of
> + * Number of pixels to discard from the top-left corner of
>  * the frame to obtain the region of interest of the frame.
>  * They are encoder dependent and will be extended internally
>  * if the codec requires an alignment.
> -- 
> 2.7.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".

LGTM

Thanks
Steven





___
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] avformat/hcom: Remove unused variables

2019-05-31 Thread Andreas Rheinhardt
The variables huffcount, rsrc_size and data_size were all set but not
used. Therefore they have been removed. This entailed a chance to
compactify calls to avio_skip; it has been used while retaining the
information about the offsets of the huffcount etc. fields as comments.

This fixes -Wunused-but-set-variable warnings in GCC.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hcom.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/libavformat/hcom.c b/libavformat/hcom.c
index 0d1736b620..9efbc3f434 100644
--- a/libavformat/hcom.c
+++ b/libavformat/hcom.c
@@ -38,17 +38,12 @@ static int hcom_probe(const AVProbeData *p)
 static int hcom_read_header(AVFormatContext *s)
 {
 AVStream *st;
-unsigned data_size, rsrc_size, huffcount;
 unsigned compresstype, divisor;
 unsigned dict_entries;
 int ret;
 
-avio_skip(s->pb, 83);
-data_size = avio_rb32(s->pb);
-rsrc_size = avio_rb32(s->pb);
-avio_skip(s->pb, 128-91+4);
-huffcount = avio_rb32(s->pb);
-avio_skip(s->pb, 4);
+avio_skip(s->pb, 83 + /* data_size */ 4 + /* rsrc_size */ 4
++ 128 - 91 + 4 + /* huffcount */ 4 +  4);
 compresstype = avio_rb32(s->pb);
 if (compresstype > 1)
 return AVERROR_INVALIDDATA;
-- 
2.21.0

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

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

Re: [FFmpeg-devel] [PATCH] avfilter/vf_gblur: add x86 SIMD optimizations

2019-05-31 Thread Carl Eugen Hoyos
Am Do., 30. Mai 2019 um 05:46 Uhr schrieb Ruiling Song :
>
> For details of the implementation, please refer to the comment
> inlined in the assembly code.

This sentence sounds unneeded to me.

> It improves the horizontal pass
> performance about 100% under single thread.

I am not a native speaker but I wonder what a "100% speed
improvement" could mean...

> Tested overall performance using the command(avx2 enabled):
> ./ffmpeg -i 1080p.mp4 -vf gblur -f null /dev/null
> ./ffmpeg -i 1080p.mp4 -vf gblur=threads=1 -f null /dev/null
> For single thread, the fps improves from 43 to 60, about 40%.
> For multi-thread, the fps improves from 110 to 130, about 20%.

Carl Eugen
___
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 librav1e encoder

2019-05-31 Thread Carl Eugen Hoyos
Am Di., 28. Mai 2019 um 19:29 Uhr schrieb Derek Buitenhuis
:

> * The C bindings for rav1e currently live in the crav1e repo. This will
>   be merged into rav1e's repo Soon(TM), when stuff stabalizes.

So is your patch meant to wait until this merge is done?
I would suggest so...

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

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

Re: [FFmpeg-devel] [PATCH] avformat/hcom: Remove unused variables

2019-05-31 Thread Carl Eugen Hoyos
Am Fr., 31. Mai 2019 um 23:43 Uhr schrieb Andreas Rheinhardt
:
>
> The variables huffcount, rsrc_size and data_size were all set but not
> used. Therefore they have been removed. The entailed a chance to
> compactify calls to avio_skip; it has been used.
> This fixes -Wunused-but-set-variable warnings in GCC.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
> My earlier patch [1] forgot to compactify the calls to avio_skip.
> The loss of information regarding the offsets of certain fields
> doesn't seem important to me.

I don't maintain this file but I would prefer a variant where the fields
would be kept in comments to simplify future debugging (which
implies to compacting).

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

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

[FFmpeg-devel] [PATCH] avformat/hcom: Remove unused variables

2019-05-31 Thread Andreas Rheinhardt
The variables huffcount, rsrc_size and data_size were all set but not
used. Therefore they have been removed. The entailed a chance to
compactify calls to avio_skip; it has been used.
This fixes -Wunused-but-set-variable warnings in GCC.

Signed-off-by: Andreas Rheinhardt 
---
My earlier patch [1] forgot to compactify the calls to avio_skip.
The loss of information regarding the offsets of certain fields
doesn't seem important to me. 
[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-May/244001.html

 libavformat/hcom.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/libavformat/hcom.c b/libavformat/hcom.c
index 0d1736b620..8152ee3052 100644
--- a/libavformat/hcom.c
+++ b/libavformat/hcom.c
@@ -38,17 +38,11 @@ static int hcom_probe(const AVProbeData *p)
 static int hcom_read_header(AVFormatContext *s)
 {
 AVStream *st;
-unsigned data_size, rsrc_size, huffcount;
 unsigned compresstype, divisor;
 unsigned dict_entries;
 int ret;
 
-avio_skip(s->pb, 83);
-data_size = avio_rb32(s->pb);
-rsrc_size = avio_rb32(s->pb);
-avio_skip(s->pb, 128-91+4);
-huffcount = avio_rb32(s->pb);
-avio_skip(s->pb, 4);
+avio_skip(s->pb, 128 + 12);
 compresstype = avio_rb32(s->pb);
 if (compresstype > 1)
 return AVERROR_INVALIDDATA;
-- 
2.21.0

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

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

[FFmpeg-devel] [PATCH] doc/filters: move reference to framesync options from lut3d to haldclut

2019-05-31 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 doc/filters.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 4fdcfe919e..e2cbc373d2 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10844,6 +10844,8 @@ Default is @code{1}.
 @code{haldclut} also has the same interpolation options as @ref{lut3d} (both
 filters share the same internals).
 
+This filter also supports the @ref{framesync} options.
+
 More information about the Hald CLUT can be found on Eskil Steenberg's website
 (Hald CLUT author) at @url{http://www.quelsolaar.com/technology/clut.html}.
 
@@ -11929,8 +11931,6 @@ Interpolate values using a tetrahedron.
 @end table
 @end table
 
-This filter also supports the @ref{framesync} options.
-
 @section lumakey
 
 Turn certain luma values into transparency.
-- 
2.16.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] [FFmpeg-cvslog] avcodec/tiff: Recognize DNG/CinemaDNG images

2019-05-31 Thread Carl Eugen Hoyos
Am Do., 30. Mai 2019 um 19:38 Uhr schrieb Nick Renieris :

> diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
> index 4b08650108..81913c6b1a 100644
> --- a/libavcodec/tiff.h
> +++ b/libavcodec/tiff.h
> @@ -20,7 +20,7 @@
>
>  /**
>   * @file
> - * TIFF tables
> + * TIFF constants & data structures

This looks like an unrelated change that should be separate.
(There may be others)

> diff --git a/libavformat/img2.c b/libavformat/img2.c
> index 8432cc0955..16bc9d2abd 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -51,6 +51,7 @@ const IdStrMap ff_img_tags[] = {
>  { AV_CODEC_ID_TARGA,  "tga"  },
>  { AV_CODEC_ID_TIFF,   "tiff" },
>  { AV_CODEC_ID_TIFF,   "tif"  },
> +{ AV_CODEC_ID_TIFF,   "dng"  },

This is ok but imo unrelated to the rest of the patch.

Carl Eugen
___
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/3] lavf/qsv_vpp: add frame format option

2019-05-31 Thread Carl Eugen Hoyos
Am Fr., 31. Mai 2019 um 10:01 Uhr schrieb Zhong Li :

> @@ -104,6 +109,8 @@ static const AVOption options[] = {
>  { "width",  "Output video width",  OFFSET(ow), AV_OPT_TYPE_STRING, { 
> .str="cw" }, 0, 255, .flags = FLAGS },
>  { "h",  "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { 
> .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
>  { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { 
> .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
> +{ "format", "Output pixel format", OFFSET(output_format_str), 
> AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },

AV_OPT_TYPE_PIXEL_FMT?
Or do I miss something?

Carl Eugen
___
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 3/3] lavf/qsv: use av_cold for init/uninit

2019-05-31 Thread Carl Eugen Hoyos
Am Fr., 31. Mai 2019 um 10:01 Uhr schrieb Zhong Li :
>
> Signed-off-by: Zhong Li 
> ---
>  libavfilter/vf_deinterlace_qsv.c | 2 +-
>  libavfilter/vf_overlay_qsv.c | 2 +-
>  libavfilter/vf_scale_qsv.c   | 4 ++--
>  3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_deinterlace_qsv.c 
> b/libavfilter/vf_deinterlace_qsv.c
> index bee10c220f..80217c8419 100644
> --- a/libavfilter/vf_deinterlace_qsv.c
> +++ b/libavfilter/vf_deinterlace_qsv.c
> @@ -83,7 +83,7 @@ typedef struct QSVDeintContext {
>  int mode;
>  } QSVDeintContext;
>
> -static void qsvdeint_uninit(AVFilterContext *ctx)
> +static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
>  {
>  QSVDeintContext *s = ctx->priv;
>  QSVFrame *cur;
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index 9aabb594ba..2a4dc5cb58 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilter/vf_overlay_qsv.c
> @@ -345,7 +345,7 @@ static int overlay_qsv_init(AVFilterContext *ctx)
>  return 0;
>  }
>
> -static void overlay_qsv_uninit(AVFilterContext *ctx)
> +static av_cold void overlay_qsv_uninit(AVFilterContext *ctx)
>  {
>  QSVOverlayContext *vpp = ctx->priv;
>
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 7d593b2b21..db7715fc1b 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -109,7 +109,7 @@ typedef struct QSVScaleContext {
>  char *format_str;
>  } QSVScaleContext;
>
> -static int qsvscale_init(AVFilterContext *ctx)
> +static av_cold int qsvscale_init(AVFilterContext *ctx)
>  {
>  QSVScaleContext *s = ctx->priv;
>
> @@ -126,7 +126,7 @@ static int qsvscale_init(AVFilterContext *ctx)
>  return 0;
>  }
>
> -static void qsvscale_uninit(AVFilterContext *ctx)
> +static av_cold void qsvscale_uninit(AVFilterContext *ctx)

Patch looks fine to me.

Carl Eugen
___
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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Pavel Koshevoy  wrote:
> On Fri, May 31, 2019 at 2:17 PM Paul B Mahol  wrote:
>>
>> On 5/31/19, Pavel Koshevoy  wrote:
>> > On Fri, May 31, 2019 at 2:03 PM Paul B Mahol  wrote:
>> >>
>> >> On 5/31/19, Pavel Koshevoy  wrote:
>> >> > On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy 
>> >> > wrote:
>
> 
>
>
>> >> >> I've had to use zscale to convert 10-bit 4k60p video from HLG HDR to
>> >> >> SDR
>> >> >> (bt709).   It was ~36x times slower than real time.  What I ended up
>> >> >> doing
>> >> >> to speed it up was to generate CLUT image (16-bit yuv444 65x65x65
>> >> >> sampling
>> >> >> of input color space), lay it out as a 2D image (512x537), and run
>> >> >> it
>> >> >> through zscale to generate the HDR->SDR transform CLUT.  Then I used
>> >> >> the
>> >> >> CLUT instead of zscale for every frame...  that got me to about
>> >> >> ~3.5x
>> >> >> times slower than realtime converting 60fps 10-bit 4k HLG to SDR
>> >> >> (and
>> >> >> I
>> >> >> don't know any assembly, so I didn't attempt to optimize the CLUT
>> >> >> trilinear optimization with SIMD, so maybe it could be faster
>> >> >> still).
>> >> >> I
>> >> >> then ported to CUDA and was able to convert 4k60p HLG->SDR faster
>> >> >> than
>> >> >> realtime on a Pascal GPU.
>> >> >>
>> >> >
>> >> > I meant trilinear interpolation
>> >> >
>> >> >
>> >> >> So, I'm not sure that adding slice threading to zscale is the best
>> >> >> optimization for it.  I think capturing the effect of zscale in a
>> >> >> CLUT
>> >> >> would be a more significant optimization.
>> >> >>
>> >> >> Just my 2 cents, hope this helps.
>> >>
>> >> Your logic is completely flawed.
>> >> You can not rescale images with LUT tables.
>> >
>> >
>> > I was not resizing the image from 4K to 1080p ... the output was till
>> > 4K.  I was converting from 10-bit in whatever HDR input colorspace
>> > (HLG, or HDR10), to 8-bit SDR output colorspace.  You most definitely
>> > can approximate that transformation with a CLUT.
>> >
>>
>> Seen lut3d filter?
>
> lut3d works with RGB images, my input and output are all YUV  (P010
> actually)
> also, lut3d requires a file parameter, not great for my use case.  I
> could generate a CLUT with zscale and dump it to disk so I could
> initialize lut3d with it, but I hope you see how inconvenient that is
> from API view point.

lut3d could work with any colorspace, its just current limitation.

>
>
>> > Since zscale is capable of resizing and colorspace conversion --
>> > perhaps this functionality should be split into separate filters so
>> > each can be otpimized differently.
>>
>> You logic is completely flawed yet again.
>> zscale is wrapper around another library.
>
> I know, zimg, C++11.

I think there is option for zimg and available for zscale to speed up
some extremly slow conversions.

Dunno what version of zscale you used, but see agamma option. (This is
pure guessing on my side)
___
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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Carl Eugen Hoyos
Am Fr., 31. Mai 2019 um 16:40 Uhr schrieb Lynne :

> Number of threads should not have any impact at all on quality ever.

Afair, it has for x264...
(not necessarily related to this patch though)

Carl Eugen
___
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/qtrle: return last frame even if unchanged

2019-05-31 Thread Marton Balint



On Thu, 30 May 2019, Michael Niedermayer wrote:


Fixes: Ticket7880

Signed-off-by: Michael Niedermayer 
---
libavcodec/qtrle.c| 42 +++
tests/ref/fate/qtrle-8bit |  1 +
2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index 2c29547e5a..4add1aded6 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -45,6 +45,8 @@ typedef struct QtrleContext {

GetByteContext g;
uint32_t pal[256];
+int need_flush;
+AVPacket flush_pkt;
} QtrleContext;

#define CHECK_PIXEL_PTR(n)  
  \
@@ -444,6 +446,12 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx)
return 0;
}

+static void qtrle_flush(AVCodecContext *avctx){
+QtrleContext *s = avctx->priv_data;
+
+s->need_flush = 0;
+}
+
static int qtrle_decode_frame(AVCodecContext *avctx,
  void *data, int *got_frame,
  AVPacket *avpkt)
@@ -454,11 +462,32 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
int has_palette = 0;
int ret, size;

+if (!avpkt->data) {
+if (s->need_flush) {
+s->need_flush = 0;
+if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+return ret;
+s->frame->pkt_pos  = s->flush_pkt.pos;
+s->frame->pkt_duration = s->flush_pkt.duration;
+s->frame->pkt_dts  = s->flush_pkt.dts;
+s->frame->pkt_pts  =
+s->frame->pts  = s->flush_pkt.pts;


This does not seem to work, because the magic in decode_simple_internal in 
decode.c will overwrite these fields. Alternative approach which seems to 
work is assigning the AVPacket fields instead:


avpkt->pos  = s->flush_pkt.pos;
avpkt->duration = s->flush_pkt.duration;
avpkt->dts  = s->flush_pkt.dts;
avpkt->pts  = s->flush_pkt.pts;

Looks a bit ugly, but as far as I see we are using an internal packet, 
and not the one provided by the user, so it might be OK.


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

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

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Pavel Koshevoy
On Fri, May 31, 2019 at 2:17 PM Paul B Mahol  wrote:
>
> On 5/31/19, Pavel Koshevoy  wrote:
> > On Fri, May 31, 2019 at 2:03 PM Paul B Mahol  wrote:
> >>
> >> On 5/31/19, Pavel Koshevoy  wrote:
> >> > On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy 
> >> > wrote:




> >> >> I've had to use zscale to convert 10-bit 4k60p video from HLG HDR to
> >> >> SDR
> >> >> (bt709).   It was ~36x times slower than real time.  What I ended up
> >> >> doing
> >> >> to speed it up was to generate CLUT image (16-bit yuv444 65x65x65
> >> >> sampling
> >> >> of input color space), lay it out as a 2D image (512x537), and run it
> >> >> through zscale to generate the HDR->SDR transform CLUT.  Then I used
> >> >> the
> >> >> CLUT instead of zscale for every frame...  that got me to about ~3.5x
> >> >> times slower than realtime converting 60fps 10-bit 4k HLG to SDR  (and
> >> >> I
> >> >> don't know any assembly, so I didn't attempt to optimize the CLUT
> >> >> trilinear optimization with SIMD, so maybe it could be faster still).
> >> >> I
> >> >> then ported to CUDA and was able to convert 4k60p HLG->SDR faster than
> >> >> realtime on a Pascal GPU.
> >> >>
> >> >
> >> > I meant trilinear interpolation
> >> >
> >> >
> >> >> So, I'm not sure that adding slice threading to zscale is the best
> >> >> optimization for it.  I think capturing the effect of zscale in a CLUT
> >> >> would be a more significant optimization.
> >> >>
> >> >> Just my 2 cents, hope this helps.
> >>
> >> Your logic is completely flawed.
> >> You can not rescale images with LUT tables.
> >
> >
> > I was not resizing the image from 4K to 1080p ... the output was till
> > 4K.  I was converting from 10-bit in whatever HDR input colorspace
> > (HLG, or HDR10), to 8-bit SDR output colorspace.  You most definitely
> > can approximate that transformation with a CLUT.
> >
>
> Seen lut3d filter?

lut3d works with RGB images, my input and output are all YUV  (P010 actually)
also, lut3d requires a file parameter, not great for my use case.  I
could generate a CLUT with zscale and dump it to disk so I could
initialize lut3d with it, but I hope you see how inconvenient that is
from API view point.


> > Since zscale is capable of resizing and colorspace conversion --
> > perhaps this functionality should be split into separate filters so
> > each can be otpimized differently.
>
> You logic is completely flawed yet again.
> zscale is wrapper around another library.

I know, zimg, C++11.
___
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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Pavel Koshevoy  wrote:
> On Fri, May 31, 2019 at 2:03 PM Paul B Mahol  wrote:
>>
>> On 5/31/19, Pavel Koshevoy  wrote:
>> > On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy 
>> > wrote:
>> >>
>> >>
>> >>
>> >>
>> >> On Fri, May 31, 2019 at 4:46 AM Paul B Mahol  wrote:
>> >> >
>> >> > Signed-off-by: Paul B Mahol 
>> >> > ---
>> >> >  libavfilter/vf_zscale.c | 335
>> >> > +---
>> >> >  1 file changed, 214 insertions(+), 121 deletions(-)
>> >> >
>> >> > diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
>> >> > index f0309272fa..c53bb08ccc 100644
>> >> > --- a/libavfilter/vf_zscale.c
>> >> > +++ b/libavfilter/vf_zscale.c
>> >> > @@ -74,6 +74,16 @@ enum var_name {
>> >> >  VARS_NB
>> >> >  };
>> >> >
>> >> > +typedef struct ZScaleThreadContext {
>> >> > +void *tmp;
>> >> > +size_t tmp_size;
>> >> > +
>> >> > +zimg_image_format src_format, dst_format;
>> >> > +zimg_image_format alpha_src_format, alpha_dst_format;
>> >> > +zimg_graph_builder_params alpha_params, params;
>> >> > +zimg_filter_graph *alpha_graph, *graph;
>> >> > +} ZScaleThreadContext;
>> >> > +
>> >> >  typedef struct ZScaleContext {
>> >> >  const AVClass *class;
>> >> >
>> >> > @@ -100,6 +110,8 @@ typedef struct ZScaleContext {
>> >> >  double nominal_peak_luminance;
>> >> >  int approximate_gamma;
>> >> >
>> >> > +int nb_threads;
>> >> > +
>> >> >  char *w_expr;   ///< width  expression string
>> >> >  char *h_expr;   ///< height expression string
>> >> >
>> >> > @@ -110,13 +122,7 @@ typedef struct ZScaleContext {
>> >> >
>> >> >  int force_original_aspect_ratio;
>> >> >
>> >> > -void *tmp;
>> >> > -size_t tmp_size;
>> >> > -
>> >> > -zimg_image_format src_format, dst_format;
>> >> > -zimg_image_format alpha_src_format, alpha_dst_format;
>> >> > -zimg_graph_builder_params alpha_params, params;
>> >> > -zimg_filter_graph *alpha_graph, *graph;
>> >> > +ZScaleThreadContext *ztd;
>> >> >
>> >> >  enum AVColorSpace in_colorspace, out_colorspace;
>> >> >  enum AVColorTransferCharacteristic in_trc, out_trc;
>> >> > @@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
>> >> >  int ret;
>> >> >  int factor_w, factor_h;
>> >> >
>> >> > +s->nb_threads = ff_filter_get_nb_threads(ctx);
>> >> > +av_freep(>ztd);
>> >> > +s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
>> >> > +if (!s->ztd)
>> >> > +return AVERROR(ENOMEM);
>> >> > +
>> >> >  var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
>> >> >  var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
>> >> >  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
>> >> > @@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange
>> >> > color_range)
>> >> >  }
>> >> >
>> >> >  static void format_init(zimg_image_format *format, AVFrame *frame,
>> >> > const AVPixFmtDescriptor *desc,
>> >> > -int colorspace, int primaries, int transfer,
>> >> > int range, int location)
>> >> > +int colorspace, int primaries, int transfer,
>> >> > int range, int location,
>> >> > +int width, int height,
>> >> > +double active_top, double active_height, int
>> >> > set_active)
>> >> >  {
>> >> > -format->width = frame->width;
>> >> > -format->height = frame->height;
>> >> > +format->width = width;
>> >> > +format->height = height;
>> >> >  format->subsample_w = desc->log2_chroma_w;
>> >> >  format->subsample_h = desc->log2_chroma_h;
>> >> >  format->depth = desc->comp[0].depth;
>> >> > @@ -472,6 +486,10 @@ static void format_init(zimg_image_format
>> >> > *format,
>> >> > AVFrame *frame, const AVPixFm
>> >> >  format->transfer_characteristics = transfer == - 1 ?
>> >> > convert_trc(frame->color_trc) : transfer;
>> >> >  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
>> >> > ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) :
>> >> > range;
>> >> >  format->chroma_location = location == -1 ?
>> >> > convert_chroma_location(frame->chroma_location) : location;
>> >> > +if (!set_active)
>> >> > +return;
>> >> > +format->active_region.top = active_top;
>> >> > +format->active_region.height = active_height;
>> >> >  }
>> >> >
>> >> >  static int graph_build(zimg_filter_graph **graph,
>> >> > zimg_graph_builder_params *params,
>> >> > @@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph
>> >> > **graph,
>> >> > zimg_graph_builder_params *par
>> >> >  return 0;
>> >> >  }
>> >> >
>> >> > +typedef struct ThreadData {
>> >> > +AVFrame *in, *out;
>> >> > +const AVPixFmtDescriptor *desc, *odesc;
>> >> > +} ThreadData;
>> >> > +
>> >> > +static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr,
>> >> > int nb_jobs)
>> >> > +{
>> >> > +ZScaleContext *s = ctx->priv;
>> >> > +

Re: [FFmpeg-devel] [PATCH] tools: Add fuzzer for demuxers

2019-05-31 Thread Michael Niedermayer
On Mon, May 27, 2019 at 11:53:14PM +0200, Michael Niedermayer wrote:
> This is based on target_dec_fuzzer
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  Makefile  |   3 +
>  tools/Makefile|   3 +
>  tools/target_dem_fuzzer.c | 163 ++
>  3 files changed, 169 insertions(+)
>  create mode 100644 tools/target_dem_fuzzer.c

will apply

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

The smallest minority on earth is the individual. Those who deny 
individual rights cannot claim to be defenders of minorities. - Ayn Rand


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] avcodec/gdv: Check remaining output after decode 5/6/8/

2019-05-31 Thread Michael Niedermayer
On Fri, May 31, 2019 at 06:47:47PM +0200, Paul B Mahol wrote:
> On 5/31/19, Michael Niedermayer  wrote:
> > On Fri, May 31, 2019 at 02:12:10PM +0200, Paul B Mahol wrote:
> >> On 5/31/19, Michael Niedermayer  wrote:
> >> > On Thu, May 30, 2019 at 11:28:35AM +0200, Paul B Mahol wrote:
> >> >> On 5/29/19, Michael Niedermayer  wrote:
> >> >> > Improves: Timeout (355sec -> 97sec)
> >> >> > Improves:
> >> >> > 14709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GDV_fuzzer-5704215281795072
> >> >> >
> >> >> > Found-by: continuous fuzzing process
> >> >> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> >> >> > ---
> >> >> >  libavcodec/gdv.c | 7 ++-
> >> >> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >> >> >
> >> >> > diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
> >> >> > index 9cf30c09e4..a5ce6b799e 100644
> >> >> > --- a/libavcodec/gdv.c
> >> >> > +++ b/libavcodec/gdv.c
> >> >> > @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx,
> >> >> > unsigned
> >> >> > skip)
> >> >> >  int len;
> >> >> >  int b = bytestream2_get_byte(gb);
> >> >> >  if (b == 0) {
> >> >> > -break;
> >> >> > +return 0;
> >> >>
> >> >> Why?
> >> >
> >> > i have no testcase for this path, so i did not route it through the new
> >> > check
> >> > but i surely can treat it the same as others if you want ?
> >> >
> >> > thx
> >>
> >> Its fine.
> >
> > as in "the patch is fine"
> 
> This.

ok, will apply

thanks

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

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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Pavel Koshevoy
On Fri, May 31, 2019 at 2:03 PM Paul B Mahol  wrote:
>
> On 5/31/19, Pavel Koshevoy  wrote:
> > On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy  wrote:
> >>
> >>
> >>
> >>
> >> On Fri, May 31, 2019 at 4:46 AM Paul B Mahol  wrote:
> >> >
> >> > Signed-off-by: Paul B Mahol 
> >> > ---
> >> >  libavfilter/vf_zscale.c | 335 +---
> >> >  1 file changed, 214 insertions(+), 121 deletions(-)
> >> >
> >> > diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
> >> > index f0309272fa..c53bb08ccc 100644
> >> > --- a/libavfilter/vf_zscale.c
> >> > +++ b/libavfilter/vf_zscale.c
> >> > @@ -74,6 +74,16 @@ enum var_name {
> >> >  VARS_NB
> >> >  };
> >> >
> >> > +typedef struct ZScaleThreadContext {
> >> > +void *tmp;
> >> > +size_t tmp_size;
> >> > +
> >> > +zimg_image_format src_format, dst_format;
> >> > +zimg_image_format alpha_src_format, alpha_dst_format;
> >> > +zimg_graph_builder_params alpha_params, params;
> >> > +zimg_filter_graph *alpha_graph, *graph;
> >> > +} ZScaleThreadContext;
> >> > +
> >> >  typedef struct ZScaleContext {
> >> >  const AVClass *class;
> >> >
> >> > @@ -100,6 +110,8 @@ typedef struct ZScaleContext {
> >> >  double nominal_peak_luminance;
> >> >  int approximate_gamma;
> >> >
> >> > +int nb_threads;
> >> > +
> >> >  char *w_expr;   ///< width  expression string
> >> >  char *h_expr;   ///< height expression string
> >> >
> >> > @@ -110,13 +122,7 @@ typedef struct ZScaleContext {
> >> >
> >> >  int force_original_aspect_ratio;
> >> >
> >> > -void *tmp;
> >> > -size_t tmp_size;
> >> > -
> >> > -zimg_image_format src_format, dst_format;
> >> > -zimg_image_format alpha_src_format, alpha_dst_format;
> >> > -zimg_graph_builder_params alpha_params, params;
> >> > -zimg_filter_graph *alpha_graph, *graph;
> >> > +ZScaleThreadContext *ztd;
> >> >
> >> >  enum AVColorSpace in_colorspace, out_colorspace;
> >> >  enum AVColorTransferCharacteristic in_trc, out_trc;
> >> > @@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
> >> >  int ret;
> >> >  int factor_w, factor_h;
> >> >
> >> > +s->nb_threads = ff_filter_get_nb_threads(ctx);
> >> > +av_freep(>ztd);
> >> > +s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
> >> > +if (!s->ztd)
> >> > +return AVERROR(ENOMEM);
> >> > +
> >> >  var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
> >> >  var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
> >> >  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
> >> > @@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange
> >> > color_range)
> >> >  }
> >> >
> >> >  static void format_init(zimg_image_format *format, AVFrame *frame,
> >> > const AVPixFmtDescriptor *desc,
> >> > -int colorspace, int primaries, int transfer,
> >> > int range, int location)
> >> > +int colorspace, int primaries, int transfer,
> >> > int range, int location,
> >> > +int width, int height,
> >> > +double active_top, double active_height, int
> >> > set_active)
> >> >  {
> >> > -format->width = frame->width;
> >> > -format->height = frame->height;
> >> > +format->width = width;
> >> > +format->height = height;
> >> >  format->subsample_w = desc->log2_chroma_w;
> >> >  format->subsample_h = desc->log2_chroma_h;
> >> >  format->depth = desc->comp[0].depth;
> >> > @@ -472,6 +486,10 @@ static void format_init(zimg_image_format *format,
> >> > AVFrame *frame, const AVPixFm
> >> >  format->transfer_characteristics = transfer == - 1 ?
> >> > convert_trc(frame->color_trc) : transfer;
> >> >  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
> >> > ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) :
> >> > range;
> >> >  format->chroma_location = location == -1 ?
> >> > convert_chroma_location(frame->chroma_location) : location;
> >> > +if (!set_active)
> >> > +return;
> >> > +format->active_region.top = active_top;
> >> > +format->active_region.height = active_height;
> >> >  }
> >> >
> >> >  static int graph_build(zimg_filter_graph **graph,
> >> > zimg_graph_builder_params *params,
> >> > @@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph **graph,
> >> > zimg_graph_builder_params *par
> >> >  return 0;
> >> >  }
> >> >
> >> > +typedef struct ThreadData {
> >> > +AVFrame *in, *out;
> >> > +const AVPixFmtDescriptor *desc, *odesc;
> >> > +} ThreadData;
> >> > +
> >> > +static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr,
> >> > int nb_jobs)
> >> > +{
> >> > +ZScaleContext *s = ctx->priv;
> >> > +ThreadData *td = arg;
> >> > +AVFrame *in = td->in;
> >> > +AVFrame *out = td->out;
> >> > +const AVPixFmtDescriptor *desc = td->desc;
> >> > +const AVPixFmtDescriptor *odesc = 

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Pavel Koshevoy  wrote:
> On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy  wrote:
>>
>>
>>
>>
>> On Fri, May 31, 2019 at 4:46 AM Paul B Mahol  wrote:
>> >
>> > Signed-off-by: Paul B Mahol 
>> > ---
>> >  libavfilter/vf_zscale.c | 335 +---
>> >  1 file changed, 214 insertions(+), 121 deletions(-)
>> >
>> > diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
>> > index f0309272fa..c53bb08ccc 100644
>> > --- a/libavfilter/vf_zscale.c
>> > +++ b/libavfilter/vf_zscale.c
>> > @@ -74,6 +74,16 @@ enum var_name {
>> >  VARS_NB
>> >  };
>> >
>> > +typedef struct ZScaleThreadContext {
>> > +void *tmp;
>> > +size_t tmp_size;
>> > +
>> > +zimg_image_format src_format, dst_format;
>> > +zimg_image_format alpha_src_format, alpha_dst_format;
>> > +zimg_graph_builder_params alpha_params, params;
>> > +zimg_filter_graph *alpha_graph, *graph;
>> > +} ZScaleThreadContext;
>> > +
>> >  typedef struct ZScaleContext {
>> >  const AVClass *class;
>> >
>> > @@ -100,6 +110,8 @@ typedef struct ZScaleContext {
>> >  double nominal_peak_luminance;
>> >  int approximate_gamma;
>> >
>> > +int nb_threads;
>> > +
>> >  char *w_expr;   ///< width  expression string
>> >  char *h_expr;   ///< height expression string
>> >
>> > @@ -110,13 +122,7 @@ typedef struct ZScaleContext {
>> >
>> >  int force_original_aspect_ratio;
>> >
>> > -void *tmp;
>> > -size_t tmp_size;
>> > -
>> > -zimg_image_format src_format, dst_format;
>> > -zimg_image_format alpha_src_format, alpha_dst_format;
>> > -zimg_graph_builder_params alpha_params, params;
>> > -zimg_filter_graph *alpha_graph, *graph;
>> > +ZScaleThreadContext *ztd;
>> >
>> >  enum AVColorSpace in_colorspace, out_colorspace;
>> >  enum AVColorTransferCharacteristic in_trc, out_trc;
>> > @@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
>> >  int ret;
>> >  int factor_w, factor_h;
>> >
>> > +s->nb_threads = ff_filter_get_nb_threads(ctx);
>> > +av_freep(>ztd);
>> > +s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
>> > +if (!s->ztd)
>> > +return AVERROR(ENOMEM);
>> > +
>> >  var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
>> >  var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
>> >  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
>> > @@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange
>> > color_range)
>> >  }
>> >
>> >  static void format_init(zimg_image_format *format, AVFrame *frame,
>> > const AVPixFmtDescriptor *desc,
>> > -int colorspace, int primaries, int transfer,
>> > int range, int location)
>> > +int colorspace, int primaries, int transfer,
>> > int range, int location,
>> > +int width, int height,
>> > +double active_top, double active_height, int
>> > set_active)
>> >  {
>> > -format->width = frame->width;
>> > -format->height = frame->height;
>> > +format->width = width;
>> > +format->height = height;
>> >  format->subsample_w = desc->log2_chroma_w;
>> >  format->subsample_h = desc->log2_chroma_h;
>> >  format->depth = desc->comp[0].depth;
>> > @@ -472,6 +486,10 @@ static void format_init(zimg_image_format *format,
>> > AVFrame *frame, const AVPixFm
>> >  format->transfer_characteristics = transfer == - 1 ?
>> > convert_trc(frame->color_trc) : transfer;
>> >  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
>> > ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) :
>> > range;
>> >  format->chroma_location = location == -1 ?
>> > convert_chroma_location(frame->chroma_location) : location;
>> > +if (!set_active)
>> > +return;
>> > +format->active_region.top = active_top;
>> > +format->active_region.height = active_height;
>> >  }
>> >
>> >  static int graph_build(zimg_filter_graph **graph,
>> > zimg_graph_builder_params *params,
>> > @@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph **graph,
>> > zimg_graph_builder_params *par
>> >  return 0;
>> >  }
>> >
>> > +typedef struct ThreadData {
>> > +AVFrame *in, *out;
>> > +const AVPixFmtDescriptor *desc, *odesc;
>> > +} ThreadData;
>> > +
>> > +static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr,
>> > int nb_jobs)
>> > +{
>> > +ZScaleContext *s = ctx->priv;
>> > +ThreadData *td = arg;
>> > +AVFrame *in = td->in;
>> > +AVFrame *out = td->out;
>> > +const AVPixFmtDescriptor *desc = td->desc;
>> > +const AVPixFmtDescriptor *odesc = td->odesc;
>> > +const int in_slice_start = (in->height * jobnr) / nb_jobs;
>> > +const int in_slice_end = (in->height * (jobnr+1)) / nb_jobs;
>> > +const int out_slice_start = (out->height * jobnr) / nb_jobs;
>> > +const int out_slice_end = (out->height * (jobnr+1)) / nb_jobs;
>> > +const 

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Pavel Koshevoy
On Fri, May 31, 2019 at 1:44 PM Pavel Koshevoy  wrote:
>
>
>
>
> On Fri, May 31, 2019 at 4:46 AM Paul B Mahol  wrote:
> >
> > Signed-off-by: Paul B Mahol 
> > ---
> >  libavfilter/vf_zscale.c | 335 +---
> >  1 file changed, 214 insertions(+), 121 deletions(-)
> >
> > diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
> > index f0309272fa..c53bb08ccc 100644
> > --- a/libavfilter/vf_zscale.c
> > +++ b/libavfilter/vf_zscale.c
> > @@ -74,6 +74,16 @@ enum var_name {
> >  VARS_NB
> >  };
> >
> > +typedef struct ZScaleThreadContext {
> > +void *tmp;
> > +size_t tmp_size;
> > +
> > +zimg_image_format src_format, dst_format;
> > +zimg_image_format alpha_src_format, alpha_dst_format;
> > +zimg_graph_builder_params alpha_params, params;
> > +zimg_filter_graph *alpha_graph, *graph;
> > +} ZScaleThreadContext;
> > +
> >  typedef struct ZScaleContext {
> >  const AVClass *class;
> >
> > @@ -100,6 +110,8 @@ typedef struct ZScaleContext {
> >  double nominal_peak_luminance;
> >  int approximate_gamma;
> >
> > +int nb_threads;
> > +
> >  char *w_expr;   ///< width  expression string
> >  char *h_expr;   ///< height expression string
> >
> > @@ -110,13 +122,7 @@ typedef struct ZScaleContext {
> >
> >  int force_original_aspect_ratio;
> >
> > -void *tmp;
> > -size_t tmp_size;
> > -
> > -zimg_image_format src_format, dst_format;
> > -zimg_image_format alpha_src_format, alpha_dst_format;
> > -zimg_graph_builder_params alpha_params, params;
> > -zimg_filter_graph *alpha_graph, *graph;
> > +ZScaleThreadContext *ztd;
> >
> >  enum AVColorSpace in_colorspace, out_colorspace;
> >  enum AVColorTransferCharacteristic in_trc, out_trc;
> > @@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
> >  int ret;
> >  int factor_w, factor_h;
> >
> > +s->nb_threads = ff_filter_get_nb_threads(ctx);
> > +av_freep(>ztd);
> > +s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
> > +if (!s->ztd)
> > +return AVERROR(ENOMEM);
> > +
> >  var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
> >  var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
> >  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
> > @@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange 
> > color_range)
> >  }
> >
> >  static void format_init(zimg_image_format *format, AVFrame *frame, const 
> > AVPixFmtDescriptor *desc,
> > -int colorspace, int primaries, int transfer, int 
> > range, int location)
> > +int colorspace, int primaries, int transfer, int 
> > range, int location,
> > +int width, int height,
> > +double active_top, double active_height, int 
> > set_active)
> >  {
> > -format->width = frame->width;
> > -format->height = frame->height;
> > +format->width = width;
> > +format->height = height;
> >  format->subsample_w = desc->log2_chroma_w;
> >  format->subsample_h = desc->log2_chroma_h;
> >  format->depth = desc->comp[0].depth;
> > @@ -472,6 +486,10 @@ static void format_init(zimg_image_format *format, 
> > AVFrame *frame, const AVPixFm
> >  format->transfer_characteristics = transfer == - 1 ? 
> > convert_trc(frame->color_trc) : transfer;
> >  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 
> > ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
> >  format->chroma_location = location == -1 ? 
> > convert_chroma_location(frame->chroma_location) : location;
> > +if (!set_active)
> > +return;
> > +format->active_region.top = active_top;
> > +format->active_region.height = active_height;
> >  }
> >
> >  static int graph_build(zimg_filter_graph **graph, 
> > zimg_graph_builder_params *params,
> > @@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph **graph, 
> > zimg_graph_builder_params *par
> >  return 0;
> >  }
> >
> > +typedef struct ThreadData {
> > +AVFrame *in, *out;
> > +const AVPixFmtDescriptor *desc, *odesc;
> > +} ThreadData;
> > +
> > +static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr, int 
> > nb_jobs)
> > +{
> > +ZScaleContext *s = ctx->priv;
> > +ThreadData *td = arg;
> > +AVFrame *in = td->in;
> > +AVFrame *out = td->out;
> > +const AVPixFmtDescriptor *desc = td->desc;
> > +const AVPixFmtDescriptor *odesc = td->odesc;
> > +const int in_slice_start = (in->height * jobnr) / nb_jobs;
> > +const int in_slice_end = (in->height * (jobnr+1)) / nb_jobs;
> > +const int out_slice_start = (out->height * jobnr) / nb_jobs;
> > +const int out_slice_end = (out->height * (jobnr+1)) / nb_jobs;
> > +const double scale_h = (double)in->height / (double)out->height;
> > +double active_top = out_slice_start * scale_h;
> > +double active_height = (out_slice_end 

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Pavel Koshevoy
On Fri, May 31, 2019 at 4:46 AM Paul B Mahol  wrote:
>
> Signed-off-by: Paul B Mahol 
> ---
>  libavfilter/vf_zscale.c | 335 +---
>  1 file changed, 214 insertions(+), 121 deletions(-)
>
> diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
> index f0309272fa..c53bb08ccc 100644
> --- a/libavfilter/vf_zscale.c
> +++ b/libavfilter/vf_zscale.c
> @@ -74,6 +74,16 @@ enum var_name {
>  VARS_NB
>  };
>
> +typedef struct ZScaleThreadContext {
> +void *tmp;
> +size_t tmp_size;
> +
> +zimg_image_format src_format, dst_format;
> +zimg_image_format alpha_src_format, alpha_dst_format;
> +zimg_graph_builder_params alpha_params, params;
> +zimg_filter_graph *alpha_graph, *graph;
> +} ZScaleThreadContext;
> +
>  typedef struct ZScaleContext {
>  const AVClass *class;
>
> @@ -100,6 +110,8 @@ typedef struct ZScaleContext {
>  double nominal_peak_luminance;
>  int approximate_gamma;
>
> +int nb_threads;
> +
>  char *w_expr;   ///< width  expression string
>  char *h_expr;   ///< height expression string
>
> @@ -110,13 +122,7 @@ typedef struct ZScaleContext {
>
>  int force_original_aspect_ratio;
>
> -void *tmp;
> -size_t tmp_size;
> -
> -zimg_image_format src_format, dst_format;
> -zimg_image_format alpha_src_format, alpha_dst_format;
> -zimg_graph_builder_params alpha_params, params;
> -zimg_filter_graph *alpha_graph, *graph;
> +ZScaleThreadContext *ztd;
>
>  enum AVColorSpace in_colorspace, out_colorspace;
>  enum AVColorTransferCharacteristic in_trc, out_trc;
> @@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
>  int ret;
>  int factor_w, factor_h;
>
> +s->nb_threads = ff_filter_get_nb_threads(ctx);
> +av_freep(>ztd);
> +s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
> +if (!s->ztd)
> +return AVERROR(ENOMEM);
> +
>  var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
>  var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
>  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
> @@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange color_range)
>  }
>
>  static void format_init(zimg_image_format *format, AVFrame *frame, const 
> AVPixFmtDescriptor *desc,
> -int colorspace, int primaries, int transfer, int 
> range, int location)
> +int colorspace, int primaries, int transfer, int 
> range, int location,
> +int width, int height,
> +double active_top, double active_height, int 
> set_active)
>  {
> -format->width = frame->width;
> -format->height = frame->height;
> +format->width = width;
> +format->height = height;
>  format->subsample_w = desc->log2_chroma_w;
>  format->subsample_h = desc->log2_chroma_h;
>  format->depth = desc->comp[0].depth;
> @@ -472,6 +486,10 @@ static void format_init(zimg_image_format *format, 
> AVFrame *frame, const AVPixFm
>  format->transfer_characteristics = transfer == - 1 ? 
> convert_trc(frame->color_trc) : transfer;
>  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 
> ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
>  format->chroma_location = location == -1 ? 
> convert_chroma_location(frame->chroma_location) : location;
> +if (!set_active)
> +return;
> +format->active_region.top = active_top;
> +format->active_region.height = active_height;
>  }
>
>  static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params 
> *params,
> @@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph **graph, 
> zimg_graph_builder_params *par
>  return 0;
>  }
>
> +typedef struct ThreadData {
> +AVFrame *in, *out;
> +const AVPixFmtDescriptor *desc, *odesc;
> +} ThreadData;
> +
> +static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr, int 
> nb_jobs)
> +{
> +ZScaleContext *s = ctx->priv;
> +ThreadData *td = arg;
> +AVFrame *in = td->in;
> +AVFrame *out = td->out;
> +const AVPixFmtDescriptor *desc = td->desc;
> +const AVPixFmtDescriptor *odesc = td->odesc;
> +const int in_slice_start = (in->height * jobnr) / nb_jobs;
> +const int in_slice_end = (in->height * (jobnr+1)) / nb_jobs;
> +const int out_slice_start = (out->height * jobnr) / nb_jobs;
> +const int out_slice_end = (out->height * (jobnr+1)) / nb_jobs;
> +const double scale_h = (double)in->height / (double)out->height;
> +double active_top = out_slice_start * scale_h;
> +double active_height = (out_slice_end - out_slice_start) * scale_h;
> +int ret;
> +
> +zimg_image_format_default(>ztd[jobnr].src_format, ZIMG_API_VERSION);
> +zimg_image_format_default(>ztd[jobnr].dst_format, ZIMG_API_VERSION);
> +zimg_graph_builder_params_default(>ztd[jobnr].params, 
> ZIMG_API_VERSION);
> +
> +

Re: [FFmpeg-devel] [PATCH v1 1/1] vaapi_encode: replace av_new_packet with ff_alloc_packet2

2019-05-31 Thread James Almer
On 5/31/2019 5:26 AM, Jing Sun wrote:
> ff_alloc_packet2 should be used if encode2 API

vaapi_encode seems to be using send/receive API, though, and not encode2.

I see ff_vaapi_encode_receive_packet() -> vaapi_encode_output(), and the
former is the callback function used in all vaapi encoders as
AVCodec.receive_packet, so this patch in not needed.

> 
> Signed-off-by: Jing Sun 
> ---
>  libavcodec/vaapi_encode.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 2dda451..98e3176 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -26,6 +26,7 @@
>  
>  #include "vaapi_encode.h"
>  #include "avcodec.h"
> +#include "internal.h"
>  
>  static const char * const picture_type_name[] = { "IDR", "I", "P", "B" };
>  
> @@ -509,7 +510,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
>  av_log(avctx, AV_LOG_DEBUG, "Output buffer: %u bytes "
> "(status %08x).\n", buf->size, buf->status);
>  
> -err = av_new_packet(pkt, buf->size);
> +err = ff_alloc_packet2(avctx, pkt, buf->size, 0);
>  if (err < 0)
>  goto fail_mapped;
>  
> 

___
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/gdv: Check remaining output after decode 5/6/8/

2019-05-31 Thread Paul B Mahol
On 5/31/19, Michael Niedermayer  wrote:
> On Fri, May 31, 2019 at 02:12:10PM +0200, Paul B Mahol wrote:
>> On 5/31/19, Michael Niedermayer  wrote:
>> > On Thu, May 30, 2019 at 11:28:35AM +0200, Paul B Mahol wrote:
>> >> On 5/29/19, Michael Niedermayer  wrote:
>> >> > Improves: Timeout (355sec -> 97sec)
>> >> > Improves:
>> >> > 14709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GDV_fuzzer-5704215281795072
>> >> >
>> >> > Found-by: continuous fuzzing process
>> >> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> >> > ---
>> >> >  libavcodec/gdv.c | 7 ++-
>> >> >  1 file changed, 6 insertions(+), 1 deletion(-)
>> >> >
>> >> > diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
>> >> > index 9cf30c09e4..a5ce6b799e 100644
>> >> > --- a/libavcodec/gdv.c
>> >> > +++ b/libavcodec/gdv.c
>> >> > @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx,
>> >> > unsigned
>> >> > skip)
>> >> >  int len;
>> >> >  int b = bytestream2_get_byte(gb);
>> >> >  if (b == 0) {
>> >> > -break;
>> >> > +return 0;
>> >>
>> >> Why?
>> >
>> > i have no testcase for this path, so i did not route it through the new
>> > check
>> > but i surely can treat it the same as others if you want ?
>> >
>> > thx
>>
>> Its fine.
>
> as in "the patch is fine"

This.

> or
> "also affecting this path even though its not tested is fine"
> ?
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Opposition brings concord. Out of discord comes the fairest harmony.
> -- Heraclitus
>
___
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/gdv: Check remaining output after decode 5/6/8/

2019-05-31 Thread Michael Niedermayer
On Fri, May 31, 2019 at 02:12:10PM +0200, Paul B Mahol wrote:
> On 5/31/19, Michael Niedermayer  wrote:
> > On Thu, May 30, 2019 at 11:28:35AM +0200, Paul B Mahol wrote:
> >> On 5/29/19, Michael Niedermayer  wrote:
> >> > Improves: Timeout (355sec -> 97sec)
> >> > Improves:
> >> > 14709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GDV_fuzzer-5704215281795072
> >> >
> >> > Found-by: continuous fuzzing process
> >> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> >> > ---
> >> >  libavcodec/gdv.c | 7 ++-
> >> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
> >> > index 9cf30c09e4..a5ce6b799e 100644
> >> > --- a/libavcodec/gdv.c
> >> > +++ b/libavcodec/gdv.c
> >> > @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx,
> >> > unsigned
> >> > skip)
> >> >  int len;
> >> >  int b = bytestream2_get_byte(gb);
> >> >  if (b == 0) {
> >> > -break;
> >> > +return 0;
> >>
> >> Why?
> >
> > i have no testcase for this path, so i did not route it through the new
> > check
> > but i surely can treat it the same as others if you want ?
> >
> > thx
> 
> Its fine.

as in "the patch is fine"
or
"also affecting this path even though its not tested is fine"
?

thx

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus


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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Hendrik Leppkes  wrote:
> On Fri, May 31, 2019 at 5:32 PM Paul B Mahol  wrote:
>>
>> On 5/31/19, Lynne  wrote:
>> >
>> >
>> >
>> > May 31, 2019, 2:33 PM by one...@gmail.com:
>> >
>> >> On 5/31/19, Lynne  wrote:
>> >>
>> >>>
>> >>>
>> >>>
>> >>> May 31, 2019, 2:16 PM by one...@gmail.com:
>> >>>
>>  On 5/31/19, Lynne  wrote:
>> 
>> > May 31, 2019, 11:45 AM by one...@gmail.com
>> > :
>> >
>> >> Signed-off-by: Paul B Mahol <> one...@gmail.com
>> >> >
>> >> >
>> >> ---
>> >> libavfilter/vf_zscale.c | 335
>> >> +---
>> >> 1 file changed, 214 insertions(+), 121 deletions(-)
>> >>
>> >
>> > This will create discontinuities between each slice.
>> >
>> 
>>  Have you actually tried it?
>> 
>>  I had and its just fine.
>> 
>> >>>
>> >>> Bitexact results with non-nearest scaling? Should be even worse with
>> >>> anything better than bilinear.
>> >>>
>> >>
>> >> Results are always bitexact. It just not bitexact with single
>> >> threading and differences are irrelevant.
>> >>
>> >
>> > Number of threads should not have any impact at all on quality ever.
>>
>> Agreed. And it doesn't have any such impact.
>>
>
> If there is a difference between 1 thread (single threaded), and many
> threads, then there is an impact, and thats not good. Don't downplay
> it for your convenience.
>

I'm ignoring this comment.

> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel 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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Hendrik Leppkes
On Fri, May 31, 2019 at 5:32 PM Paul B Mahol  wrote:
>
> On 5/31/19, Lynne  wrote:
> >
> >
> >
> > May 31, 2019, 2:33 PM by one...@gmail.com:
> >
> >> On 5/31/19, Lynne  wrote:
> >>
> >>>
> >>>
> >>>
> >>> May 31, 2019, 2:16 PM by one...@gmail.com:
> >>>
>  On 5/31/19, Lynne  wrote:
> 
> > May 31, 2019, 11:45 AM by one...@gmail.com :
> >
> >> Signed-off-by: Paul B Mahol <> one...@gmail.com
> >> >
> >> >
> >> ---
> >> libavfilter/vf_zscale.c | 335 +---
> >> 1 file changed, 214 insertions(+), 121 deletions(-)
> >>
> >
> > This will create discontinuities between each slice.
> >
> 
>  Have you actually tried it?
> 
>  I had and its just fine.
> 
> >>>
> >>> Bitexact results with non-nearest scaling? Should be even worse with
> >>> anything better than bilinear.
> >>>
> >>
> >> Results are always bitexact. It just not bitexact with single
> >> threading and differences are irrelevant.
> >>
> >
> > Number of threads should not have any impact at all on quality ever.
>
> Agreed. And it doesn't have any such impact.
>

If there is a difference between 1 thread (single threaded), and many
threads, then there is an impact, and thats not good. Don't downplay
it for your convenience.

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

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

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_zscale: update input/output chroma location too

2019-05-31 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_zscale.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 275951e1a3..094f225d24 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -746,10 +746,12 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
 s->in_trc = in->color_trc;
 s->in_primaries   = in->color_primaries;
 s->in_range   = in->color_range;
+s->in_chromal = in->chroma_location;
 s->out_colorspace = out->colorspace;
 s->out_trc= out->color_trc;
 s->out_primaries  = out->color_primaries;
 s->out_range  = out->color_range;
+s->out_chromal= out->chroma_location;
 }
 
 if (s->colorspace != -1)
-- 
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".

[FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_zscale.c | 337 +---
 1 file changed, 216 insertions(+), 121 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index f0309272fa..275951e1a3 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -74,6 +74,16 @@ enum var_name {
 VARS_NB
 };
 
+typedef struct ZScaleThreadContext {
+void *tmp;
+size_t tmp_size;
+
+zimg_image_format src_format, dst_format;
+zimg_image_format alpha_src_format, alpha_dst_format;
+zimg_graph_builder_params alpha_params, params;
+zimg_filter_graph *alpha_graph, *graph;
+} ZScaleThreadContext;
+
 typedef struct ZScaleContext {
 const AVClass *class;
 
@@ -100,6 +110,8 @@ typedef struct ZScaleContext {
 double nominal_peak_luminance;
 int approximate_gamma;
 
+int nb_threads;
+
 char *w_expr;   ///< width  expression string
 char *h_expr;   ///< height expression string
 
@@ -110,13 +122,7 @@ typedef struct ZScaleContext {
 
 int force_original_aspect_ratio;
 
-void *tmp;
-size_t tmp_size;
-
-zimg_image_format src_format, dst_format;
-zimg_image_format alpha_src_format, alpha_dst_format;
-zimg_graph_builder_params alpha_params, params;
-zimg_filter_graph *alpha_graph, *graph;
+ZScaleThreadContext *ztd;
 
 enum AVColorSpace in_colorspace, out_colorspace;
 enum AVColorTransferCharacteristic in_trc, out_trc;
@@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
 int ret;
 int factor_w, factor_h;
 
+s->nb_threads = ff_filter_get_nb_threads(ctx);
+av_freep(>ztd);
+s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
+if (!s->ztd)
+return AVERROR(ENOMEM);
+
 var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
 var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
 var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
@@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange color_range)
 }
 
 static void format_init(zimg_image_format *format, AVFrame *frame, const 
AVPixFmtDescriptor *desc,
-int colorspace, int primaries, int transfer, int 
range, int location)
+int colorspace, int primaries, int transfer, int 
range, int location,
+int width, int height,
+double active_top, double active_width, double 
active_height, int set_active)
 {
-format->width = frame->width;
-format->height = frame->height;
+format->width = width;
+format->height = height;
 format->subsample_w = desc->log2_chroma_w;
 format->subsample_h = desc->log2_chroma_h;
 format->depth = desc->comp[0].depth;
@@ -472,6 +486,12 @@ static void format_init(zimg_image_format *format, AVFrame 
*frame, const AVPixFm
 format->transfer_characteristics = transfer == - 1 ? 
convert_trc(frame->color_trc) : transfer;
 format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 
ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
 format->chroma_location = location == -1 ? 
convert_chroma_location(frame->chroma_location) : location;
+if (!set_active)
+return;
+format->active_region.left = 0;
+format->active_region.top = active_top;
+format->active_region.width = active_width;
+format->active_region.height = active_height;
 }
 
 static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params 
*params,
@@ -502,16 +522,163 @@ static int graph_build(zimg_filter_graph **graph, 
zimg_graph_builder_params *par
 return 0;
 }
 
+typedef struct ThreadData {
+AVFrame *in, *out;
+const AVPixFmtDescriptor *desc, *odesc;
+} ThreadData;
+
+static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ZScaleContext *s = ctx->priv;
+ThreadData *td = arg;
+AVFrame *in = td->in;
+AVFrame *out = td->out;
+const AVPixFmtDescriptor *desc = td->desc;
+const AVPixFmtDescriptor *odesc = td->odesc;
+const int out_slice_start = (out->height * jobnr) / nb_jobs;
+const int out_slice_end = (out->height * (jobnr+1)) / nb_jobs;
+const double scale_h = (double)in->height / (double)out->height;
+const double scale_w = (double)in->width / (double)out->width;
+double active_top = out_slice_start * scale_h;
+double active_height = (out_slice_end - out_slice_start) * scale_h;
+double active_width = out->width * scale_w;
+int ret;
+
+zimg_image_format_default(>ztd[jobnr].src_format, ZIMG_API_VERSION);
+zimg_image_format_default(>ztd[jobnr].dst_format, ZIMG_API_VERSION);
+zimg_graph_builder_params_default(>ztd[jobnr].params, ZIMG_API_VERSION);
+
+s->ztd[jobnr].params.dither_type = s->dither;
+s->ztd[jobnr].params.cpu_type = ZIMG_CPU_AUTO;
+s->ztd[jobnr].params.resample_filter = s->filter;
+s->ztd[jobnr].params.resample_filter_uv = s->filter;
+

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Lynne  wrote:
>
>
>
> May 31, 2019, 2:33 PM by one...@gmail.com:
>
>> On 5/31/19, Lynne  wrote:
>>
>>>
>>>
>>>
>>> May 31, 2019, 2:16 PM by one...@gmail.com:
>>>
 On 5/31/19, Lynne  wrote:

> May 31, 2019, 11:45 AM by one...@gmail.com :
>
>> Signed-off-by: Paul B Mahol <> one...@gmail.com
>> >
>> >
>> ---
>> libavfilter/vf_zscale.c | 335 +---
>> 1 file changed, 214 insertions(+), 121 deletions(-)
>>
>
> This will create discontinuities between each slice.
>

 Have you actually tried it?

 I had and its just fine.

>>>
>>> Bitexact results with non-nearest scaling? Should be even worse with
>>> anything better than bilinear.
>>>
>>
>> Results are always bitexact. It just not bitexact with single
>> threading and differences are irrelevant.
>>
>
> Number of threads should not have any impact at all on quality ever.

Agreed. And it doesn't have any such impact.


> ___
> 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] libavcodec/vaapi_encode_mpeg2: enable constant QP setting

2019-05-31 Thread Phillip Burr
---
 libavcodec/vaapi_encode_mpeg2.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c
index fb1ef71fdc..bd754001d5 100644
--- a/libavcodec/vaapi_encode_mpeg2.c
+++ b/libavcodec/vaapi_encode_mpeg2.c
@@ -31,6 +31,7 @@ typedef struct VAAPIEncodeMPEG2Context {
 VAAPIEncodeContext common;
 
 // User options.
+int qp;
 int profile;
 int level;
 
@@ -624,6 +625,9 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext 
*avctx)
 ctx->surface_width  = FFALIGN(avctx->width,  16);
 ctx->surface_height = FFALIGN(avctx->height, 16);
 
+if (priv->qp > 0)
+ctx->explicit_qp = priv->qp;
+
 return ff_vaapi_encode_init(avctx);
 }
 
@@ -643,6 +647,8 @@ static const AVOption vaapi_encode_mpeg2_options[] = {
 VAAPI_ENCODE_COMMON_OPTIONS,
 VAAPI_ENCODE_RC_OPTIONS,
 
+{ "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
+  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
 { "profile", "Set profile (in profile_and_level_indication)",
   OFFSET(profile), AV_OPT_TYPE_INT,
   { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 7, FLAGS, "profile" },
-- 
2.20.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 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Lynne



May 31, 2019, 2:33 PM by one...@gmail.com:

> On 5/31/19, Lynne  wrote:
>
>>
>>
>>
>> May 31, 2019, 2:16 PM by one...@gmail.com:
>>
>>> On 5/31/19, Lynne  wrote:
>>>
 May 31, 2019, 11:45 AM by one...@gmail.com :

> Signed-off-by: Paul B Mahol <> one...@gmail.com
> >
> >
> ---
> libavfilter/vf_zscale.c | 335 +---
> 1 file changed, 214 insertions(+), 121 deletions(-)
>

 This will create discontinuities between each slice.

>>>
>>> Have you actually tried it?
>>>
>>> I had and its just fine.
>>>
>>
>> Bitexact results with non-nearest scaling? Should be even worse with
>> anything better than bilinear.
>>
>
> Results are always bitexact. It just not bitexact with single
> threading and differences are irrelevant.
>

Number of threads should not have any impact at all on quality ever.
___
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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Lynne  wrote:
>
>
>
> May 31, 2019, 2:16 PM by one...@gmail.com:
>
>> On 5/31/19, Lynne  wrote:
>>
>>> May 31, 2019, 11:45 AM by one...@gmail.com :
>>>
 Signed-off-by: Paul B Mahol <> one...@gmail.com
 >
 >
 ---
 libavfilter/vf_zscale.c | 335 +---
 1 file changed, 214 insertions(+), 121 deletions(-)

>>>
>>> This will create discontinuities between each slice.
>>>
>>
>> Have you actually tried it?
>>
>> I had and its just fine.
>>
>
> Bitexact results with non-nearest scaling? Should be even worse with
> anything better than bilinear.

Results are always bitexact. It just not bitexact with single
threading and differences are irrelevant.

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Lynne



May 31, 2019, 2:16 PM by one...@gmail.com:

> On 5/31/19, Lynne  wrote:
>
>> May 31, 2019, 11:45 AM by one...@gmail.com :
>>
>>> Signed-off-by: Paul B Mahol <> one...@gmail.com >
>>> >
>>> ---
>>> libavfilter/vf_zscale.c | 335 +---
>>> 1 file changed, 214 insertions(+), 121 deletions(-)
>>>
>>
>> This will create discontinuities between each slice.
>>
>
> Have you actually tried it?
>
> I had and its just fine.
>

Bitexact results with non-nearest scaling? Should be even worse with anything 
better than bilinear.
___
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] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
On 5/31/19, Lynne  wrote:
> May 31, 2019, 11:45 AM by one...@gmail.com :
>
>> Signed-off-by: Paul B Mahol <> one...@gmail.com >
>> >
>> ---
>> libavfilter/vf_zscale.c | 335 +---
>> 1 file changed, 214 insertions(+), 121 deletions(-)
>>
>
> This will create discontinuities between each slice.

Have you actually tried it?

I had and its just fine.

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

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

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Lynne
May 31, 2019, 11:45 AM by one...@gmail.com :

> Signed-off-by: Paul B Mahol <> one...@gmail.com > >
> ---
> libavfilter/vf_zscale.c | 335 +---
> 1 file changed, 214 insertions(+), 121 deletions(-)
>

This will create discontinuities between each slice.

___
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/gdv: Check remaining output after decode 5/6/8/

2019-05-31 Thread Paul B Mahol
On 5/31/19, Michael Niedermayer  wrote:
> On Thu, May 30, 2019 at 11:28:35AM +0200, Paul B Mahol wrote:
>> On 5/29/19, Michael Niedermayer  wrote:
>> > Improves: Timeout (355sec -> 97sec)
>> > Improves:
>> > 14709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GDV_fuzzer-5704215281795072
>> >
>> > Found-by: continuous fuzzing process
>> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> > ---
>> >  libavcodec/gdv.c | 7 ++-
>> >  1 file changed, 6 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
>> > index 9cf30c09e4..a5ce6b799e 100644
>> > --- a/libavcodec/gdv.c
>> > +++ b/libavcodec/gdv.c
>> > @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx,
>> > unsigned
>> > skip)
>> >  int len;
>> >  int b = bytestream2_get_byte(gb);
>> >  if (b == 0) {
>> > -break;
>> > +return 0;
>>
>> Why?
>
> i have no testcase for this path, so i did not route it through the new
> check
> but i surely can treat it the same as others if you want ?
>
> thx

Its fine.

>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Those who are too smart to engage in politics are punished by being
> governed by those who are dumber. -- Plato
>
___
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/gdv: Check remaining output after decode 5/6/8/

2019-05-31 Thread Michael Niedermayer
On Thu, May 30, 2019 at 11:28:35AM +0200, Paul B Mahol wrote:
> On 5/29/19, Michael Niedermayer  wrote:
> > Improves: Timeout (355sec -> 97sec)
> > Improves:
> > 14709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GDV_fuzzer-5704215281795072
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > ---
> >  libavcodec/gdv.c | 7 ++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c
> > index 9cf30c09e4..a5ce6b799e 100644
> > --- a/libavcodec/gdv.c
> > +++ b/libavcodec/gdv.c
> > @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx, unsigned
> > skip)
> >  int len;
> >  int b = bytestream2_get_byte(gb);
> >  if (b == 0) {
> > -break;
> > +return 0;
> 
> Why?

i have no testcase for this path, so i did not route it through the new check
but i surely can treat it the same as others if you want ?

thx

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

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

[FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: add slice threading

2019-05-31 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_zscale.c | 335 +---
 1 file changed, 214 insertions(+), 121 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index f0309272fa..c53bb08ccc 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -74,6 +74,16 @@ enum var_name {
 VARS_NB
 };
 
+typedef struct ZScaleThreadContext {
+void *tmp;
+size_t tmp_size;
+
+zimg_image_format src_format, dst_format;
+zimg_image_format alpha_src_format, alpha_dst_format;
+zimg_graph_builder_params alpha_params, params;
+zimg_filter_graph *alpha_graph, *graph;
+} ZScaleThreadContext;
+
 typedef struct ZScaleContext {
 const AVClass *class;
 
@@ -100,6 +110,8 @@ typedef struct ZScaleContext {
 double nominal_peak_luminance;
 int approximate_gamma;
 
+int nb_threads;
+
 char *w_expr;   ///< width  expression string
 char *h_expr;   ///< height expression string
 
@@ -110,13 +122,7 @@ typedef struct ZScaleContext {
 
 int force_original_aspect_ratio;
 
-void *tmp;
-size_t tmp_size;
-
-zimg_image_format src_format, dst_format;
-zimg_image_format alpha_src_format, alpha_dst_format;
-zimg_graph_builder_params alpha_params, params;
-zimg_filter_graph *alpha_graph, *graph;
+ZScaleThreadContext *ztd;
 
 enum AVColorSpace in_colorspace, out_colorspace;
 enum AVColorTransferCharacteristic in_trc, out_trc;
@@ -204,6 +210,12 @@ static int config_props(AVFilterLink *outlink)
 int ret;
 int factor_w, factor_h;
 
+s->nb_threads = ff_filter_get_nb_threads(ctx);
+av_freep(>ztd);
+s->ztd = av_calloc(s->nb_threads, sizeof(*s->ztd));
+if (!s->ztd)
+return AVERROR(ENOMEM);
+
 var_values[VAR_IN_W]  = var_values[VAR_IW] = inlink->w;
 var_values[VAR_IN_H]  = var_values[VAR_IH] = inlink->h;
 var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
@@ -458,10 +470,12 @@ static int convert_range(enum AVColorRange color_range)
 }
 
 static void format_init(zimg_image_format *format, AVFrame *frame, const 
AVPixFmtDescriptor *desc,
-int colorspace, int primaries, int transfer, int 
range, int location)
+int colorspace, int primaries, int transfer, int 
range, int location,
+int width, int height,
+double active_top, double active_height, int 
set_active)
 {
-format->width = frame->width;
-format->height = frame->height;
+format->width = width;
+format->height = height;
 format->subsample_w = desc->log2_chroma_w;
 format->subsample_h = desc->log2_chroma_h;
 format->depth = desc->comp[0].depth;
@@ -472,6 +486,10 @@ static void format_init(zimg_image_format *format, AVFrame 
*frame, const AVPixFm
 format->transfer_characteristics = transfer == - 1 ? 
convert_trc(frame->color_trc) : transfer;
 format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 
ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
 format->chroma_location = location == -1 ? 
convert_chroma_location(frame->chroma_location) : location;
+if (!set_active)
+return;
+format->active_region.top = active_top;
+format->active_region.height = active_height;
 }
 
 static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params 
*params,
@@ -502,16 +520,163 @@ static int graph_build(zimg_filter_graph **graph, 
zimg_graph_builder_params *par
 return 0;
 }
 
+typedef struct ThreadData {
+AVFrame *in, *out;
+const AVPixFmtDescriptor *desc, *odesc;
+} ThreadData;
+
+static int prepare_graph(AVFilterContext *ctx, void *arg, int jobnr, int 
nb_jobs)
+{
+ZScaleContext *s = ctx->priv;
+ThreadData *td = arg;
+AVFrame *in = td->in;
+AVFrame *out = td->out;
+const AVPixFmtDescriptor *desc = td->desc;
+const AVPixFmtDescriptor *odesc = td->odesc;
+const int in_slice_start = (in->height * jobnr) / nb_jobs;
+const int in_slice_end = (in->height * (jobnr+1)) / nb_jobs;
+const int out_slice_start = (out->height * jobnr) / nb_jobs;
+const int out_slice_end = (out->height * (jobnr+1)) / nb_jobs;
+const double scale_h = (double)in->height / (double)out->height;
+double active_top = out_slice_start * scale_h;
+double active_height = (out_slice_end - out_slice_start) * scale_h;
+int ret;
+
+zimg_image_format_default(>ztd[jobnr].src_format, ZIMG_API_VERSION);
+zimg_image_format_default(>ztd[jobnr].dst_format, ZIMG_API_VERSION);
+zimg_graph_builder_params_default(>ztd[jobnr].params, ZIMG_API_VERSION);
+
+s->ztd[jobnr].params.dither_type = s->dither;
+s->ztd[jobnr].params.cpu_type = ZIMG_CPU_AUTO;
+s->ztd[jobnr].params.resample_filter = s->filter;
+s->ztd[jobnr].params.resample_filter_uv = s->filter;
+s->ztd[jobnr].params.nominal_peak_luminance = s->nominal_peak_luminance;
+

[FFmpeg-devel] [PATCH 2/2] avfilter/vf_zscale: update input/output chroma location too

2019-05-31 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/vf_zscale.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index c53bb08ccc..de33579185 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -744,10 +744,12 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
 s->in_trc = in->color_trc;
 s->in_primaries   = in->color_primaries;
 s->in_range   = in->color_range;
+s->in_chromal = in->chroma_location;
 s->out_colorspace = out->colorspace;
 s->out_trc= out->color_trc;
 s->out_primaries  = out->color_primaries;
 s->out_range  = out->color_range;
+s->out_chromal= out->chroma_location;
 }
 
 if (s->colorspace != -1)
-- 
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, v2 1/2] lavf/qsvvpp: allocate continuous memory

2019-05-31 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Linjie Fu
> Sent: Thursday, May 30, 2019 1:01 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Fu, Linjie 
> Subject: [FFmpeg-devel] [PATCH, v2 1/2] lavf/qsvvpp: allocate continuous
> memory
> 
> Mediasdk calls CMRT to copy from video to system memory and requires
> memory to be continuously allocated across Y and UV.
> 
> Add a new path to allocate continuous memory when using system out.
> Use av_image_fill_pointers to arrange data according to pixfmt.
> 
> Signed-off-by: Linjie Fu 
> ---
> [v2]: use av_image_fill_pointers
> 
>  libavfilter/qsvvpp.c | 32 +++-
>  1 file changed, 27 insertions(+), 5 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index
> 06efdf5089..6eeed7e632 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/hwcontext_qsv.h"
>  #include "libavutil/time.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/imgutils.h"
> 
>  #include "internal.h"
>  #include "qsvvpp.h"
> @@ -51,6 +52,7 @@ struct QSVVPPContext {
>  enum AVPixelFormat  out_sw_format;   /* Real output format */
>  mfxVideoParam   vpp_param;
>  mfxFrameInfo   *frame_infos; /* frame info for each
> input */
> +AVBufferPool   *pool;
> 
>  /* members related to the input/output surface */
>  int in_mem_mode;
> @@ -375,10 +377,24 @@ static QSVFrame *query_frame(QSVVPPContext
> *s, AVFilterLink *outlink)
>  out_frame->surface = (mfxFrameSurface1
> *)out_frame->frame->data[3];
>  } else {
>  /* Get a frame with aligned dimensions.
> - * Libmfx need system memory being 128x64 aligned */
> -out_frame->frame = ff_get_video_buffer(outlink,
> -
> FFALIGN(outlink->w, 128),
> -
> FFALIGN(outlink->h, 64));
> + * Libmfx need system memory being 128x64 aligned
> + * and continuously allocated across Y and UV */
> +out_frame->frame = av_frame_alloc();
> +if (!out_frame->frame) {
> +return NULL;

Should be better to return AVERROR(ENOMEM)? 

> +}
> +
> +out_frame->frame->linesize[0] = FFALIGN(outlink->w, 128);
> +out_frame->frame->linesize[1] = out_frame->frame->linesize[0];
> +out_frame->frame->buf[0]  = av_buffer_pool_get(s->pool);
> +out_frame->frame->format  = outlink->format;
> +
> +if (!out_frame->frame->buf[0])
> +return NULL;

Same as frame alloc.

> +
> +av_image_fill_pointers(out_frame->frame->data,
> out_frame->frame->format,
> +FFALIGN(outlink->h, 64),
> out_frame->frame->buf[0]->data,
> +
> + out_frame->frame->linesize);
>  if (!out_frame->frame)
>  return NULL;
> 
> @@ -483,8 +499,13 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
> 
>  av_buffer_unref(>hw_frames_ctx);
>  outlink->hw_frames_ctx = out_frames_ref;
> -} else
> +} else {
>  s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
> +s->pool =
> av_buffer_pool_init(av_image_get_buffer_size(outlink->format,
> +
> FFALIGN(outlink->w, 128),
> +
> FFALIGN(outlink->h, 64), 1),
> +av_buffer_allocz);

1. What is the benefit to use a pool? Comparing with directly alloc a buffer 
use av_buffer_allocz()? 
2. av_buffer_allocz() will memset the whole buffer and make performance drop. 
Is it really necessary here? 
  If no (I believe so), just use av_buffer_alloc()
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v5] avformat/ifv: added support for ifv cctv files

2019-05-31 Thread Swaraj Hota
On Thu, May 30, 2019 at 08:33:35PM +0200, Reimar Döffinger wrote:
> 
> 
> On 29.05.2019, at 19:51, Swaraj Hota  wrote:
> >> 
> >> Entirely depends on the purpose.
> >> If the aim is to have a working demuxer, I think it is acceptable from 
> >> what I looked at.
> >> I guess the only concern might be that not supporting piped input would be 
> >> a bit of a regression from the first patch.
> > 
> > Is there another simpler way to support piped input? Can you explain a
> > bit?
> 
> The mov demuxer code isn't really all that complicated.
> The basic idea is: if the input is not seekable, decided whether to read 
> audio or video based on which one has the lowest file position (a bit like 
> your original patch, but using it only for the "audio or video next" decision.
> If input is seekable, pick the stream with the lowest next timestamp as your 
> patch does now.
> It should be not that complicated in principle, but the details can make it a 
> pain sometimes.

Okay, I think I get the basic idea now. I will surely try to implement
this later in another patch. Thanx a lot!

Swaraj
___
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] lavu/frame: fix typo for ROI (region of interest) documentation

2019-05-31 Thread Guo, Yejun
there is already a nice patch set to fix the ROI documentation, but it
is pending, see 
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-May/20.html

so just fix this obvious typo that the document does not match the code.

Signed-off-by: Guo, Yejun 
---
 libavutil/frame.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8aa3e88..eebb2c0 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -212,7 +212,7 @@ typedef struct AVFrameSideData {
  * self_size specifies the size of this data structure. This value
  * should be set to sizeof(AVRegionOfInterest). EINVAL is returned if 
self_size is zero.
  *
- * Number of pixels to discard from the top/bottom/left/right border of
+ * Number of pixels to discard from the top-left corner of
  * the frame to obtain the region of interest of the frame.
  * They are encoder dependent and will be extended internally
  * if the codec requires an alignment.
-- 
2.7.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".

[FFmpeg-devel] [PATCH 3/3] lavf/qsv: use av_cold for init/uninit

2019-05-31 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavfilter/vf_deinterlace_qsv.c | 2 +-
 libavfilter/vf_overlay_qsv.c | 2 +-
 libavfilter/vf_scale_qsv.c   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index bee10c220f..80217c8419 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -83,7 +83,7 @@ typedef struct QSVDeintContext {
 int mode;
 } QSVDeintContext;
 
-static void qsvdeint_uninit(AVFilterContext *ctx)
+static av_cold void qsvdeint_uninit(AVFilterContext *ctx)
 {
 QSVDeintContext *s = ctx->priv;
 QSVFrame *cur;
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index 9aabb594ba..2a4dc5cb58 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -345,7 +345,7 @@ static int overlay_qsv_init(AVFilterContext *ctx)
 return 0;
 }
 
-static void overlay_qsv_uninit(AVFilterContext *ctx)
+static av_cold void overlay_qsv_uninit(AVFilterContext *ctx)
 {
 QSVOverlayContext *vpp = ctx->priv;
 
diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 7d593b2b21..db7715fc1b 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -109,7 +109,7 @@ typedef struct QSVScaleContext {
 char *format_str;
 } QSVScaleContext;
 
-static int qsvscale_init(AVFilterContext *ctx)
+static av_cold int qsvscale_init(AVFilterContext *ctx)
 {
 QSVScaleContext *s = ctx->priv;
 
@@ -126,7 +126,7 @@ static int qsvscale_init(AVFilterContext *ctx)
 return 0;
 }
 
-static void qsvscale_uninit(AVFilterContext *ctx)
+static av_cold void qsvscale_uninit(AVFilterContext *ctx)
 {
 QSVScaleContext *s = ctx->priv;
 
-- 
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".

[FFmpeg-devel] [PATCH 2/3] lavf/qsvvpp: add P010 output format support

2019-05-31 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavfilter/qsvvpp.c | 1 +
 libavfilter/vf_vpp_qsv.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 5cd1d5d345..fc24426b75 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -153,6 +153,7 @@ static int map_frame_to_surface(AVFrame *frame, 
mfxFrameSurface1 *surface)
 {
 switch (frame->format) {
 case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_P010:
 surface->Data.Y  = frame->data[0];
 surface->Data.UV = frame->data[1];
 break;
diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 39079a410b..915cf748c4 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -401,6 +401,7 @@ static int query_formats(AVFilterContext *ctx)
 };
 static const enum AVPixelFormat out_pix_fmts[] = {
 AV_PIX_FMT_NV12,
+AV_PIX_FMT_P010,
 AV_PIX_FMT_QSV,
 AV_PIX_FMT_NONE
 };
-- 
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".

[FFmpeg-devel] [PATCH 1/3] lavf/qsv_vpp: add frame format option

2019-05-31 Thread Zhong Li
1. Currently output format is hard-coded as NV12, thus means
   CSC is always done for not NV12 input such as P010.
   Follow original input format as default output.
2. Add an option to specify output format.

Signed-off-by: Zhong Li 
---
 libavfilter/vf_vpp_qsv.c | 37 -
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 41a9f38962..39079a410b 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -57,6 +57,10 @@ typedef struct VPPContext{
 
 int out_width;
 int out_height;
+/**
+ * Output sw format. AV_PIX_FMT_NONE for no conversion.
+ */
+enum AVPixelFormat out_format;
 
 AVRational framerate;   /* target framerate */
 int use_frc;/* use framerate conversion */
@@ -79,6 +83,7 @@ typedef struct VPPContext{
 
 char *cx, *cy, *cw, *ch;
 char *ow, *oh;
+char *output_format_str;
 } VPPContext;
 
 static const AVOption options[] = {
@@ -104,6 +109,8 @@ static const AVOption options[] = {
 { "width",  "Output video width",  OFFSET(ow), AV_OPT_TYPE_STRING, { 
.str="cw" }, 0, 255, .flags = FLAGS },
 { "h",  "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { 
.str="w*ch/cw" }, 0, 255, .flags = FLAGS },
 { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { 
.str="w*ch/cw" }, 0, 255, .flags = FLAGS },
+{ "format", "Output pixel format", OFFSET(output_format_str), 
AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
+
 { NULL }
 };
 
@@ -207,6 +214,23 @@ release:
 return ret;
 }
 
+static av_cold int vpp_init(AVFilterContext *ctx)
+{
+VPPContext  *vpp  = ctx->priv;
+
+if (!strcmp(vpp->output_format_str, "same")) {
+vpp->out_format = AV_PIX_FMT_NONE;
+} else {
+vpp->out_format = av_get_pix_fmt(vpp->output_format_str);
+if (vpp->out_format == AV_PIX_FMT_NONE) {
+av_log(ctx, AV_LOG_ERROR, "Unrecognized output pixel format: 
%s\n", vpp->output_format_str);
+return AVERROR(EINVAL);
+}
+}
+
+return 0;
+}
+
 static int config_input(AVFilterLink *inlink)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -251,6 +275,7 @@ static int config_output(AVFilterLink *outlink)
 QSVVPPCrop  crop  = { 0 };
 mfxExtBuffer*ext_buf[ENH_FILTERS_COUNT];
 AVFilterLink*inlink = ctx->inputs[0];
+enum AVPixelFormat in_format;
 
 outlink->w  = vpp->out_width;
 outlink->h  = vpp->out_height;
@@ -258,10 +283,19 @@ static int config_output(AVFilterLink *outlink)
 outlink->time_base  = av_inv_q(vpp->framerate);
 
 param.filter_frame  = NULL;
-param.out_sw_format = AV_PIX_FMT_NV12;
 param.num_ext_buf   = 0;
 param.ext_buf   = ext_buf;
 
+if (inlink->format == AV_PIX_FMT_QSV) {
+ if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)
+ return AVERROR(EINVAL);
+ else
+ in_format = 
((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format;
+} else
+in_format = inlink->format;
+
+param.out_sw_format  = (vpp->out_format == AV_PIX_FMT_NONE) ? in_format : 
vpp->out_format;
+
 if (vpp->use_crop) {
 crop.in_idx = 0;
 crop.x = vpp->crop_x;
@@ -421,6 +455,7 @@ AVFilter ff_vf_vpp_qsv = {
 .description   = NULL_IF_CONFIG_SMALL("Quick Sync Video VPP."),
 .priv_size = sizeof(VPPContext),
 .query_formats = query_formats,
+.init  = vpp_init,
 .uninit= vpp_uninit,
 .inputs= vpp_inputs,
 .outputs   = vpp_outputs,
-- 
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".

[FFmpeg-devel] [PATCH v1 1/1] vaapi_encode: replace av_new_packet with ff_alloc_packet2

2019-05-31 Thread Jing Sun
ff_alloc_packet2 should be used if encode2 API

Signed-off-by: Jing Sun 
---
 libavcodec/vaapi_encode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2dda451..98e3176 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -26,6 +26,7 @@
 
 #include "vaapi_encode.h"
 #include "avcodec.h"
+#include "internal.h"
 
 static const char * const picture_type_name[] = { "IDR", "I", "P", "B" };
 
@@ -509,7 +510,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Output buffer: %u bytes "
"(status %08x).\n", buf->size, buf->status);
 
-err = av_new_packet(pkt, buf->size);
+err = ff_alloc_packet2(avctx, pkt, buf->size, 0);
 if (err < 0)
 goto fail_mapped;
 
-- 
1.8.3.1

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

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

Re: [FFmpeg-devel] [PATCH v2 4/9] vp9_parser: Return stream properties

2019-05-31 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Li, Zhong
> Sent: Sunday, April 28, 2019 6:24 PM
> To: FFmpeg development discussions and patches
> 
> Subject: Re: [FFmpeg-devel] [PATCH v2 4/9] vp9_parser: Return stream
> properties
> 
> > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf
> > Of Mark Thompson
> > Sent: Tuesday, April 2, 2019 7:40 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH v2 4/9] vp9_parser: Return stream
> > properties
> >
> > Rewrites the parser entirely, using CBS for header parsing.
> > ---
> >  libavcodec/vp9_parser.c | 112
> > +---
> >  1 file changed, 82 insertions(+), 30 deletions(-)
> >
> > diff --git a/libavcodec/vp9_parser.c b/libavcodec/vp9_parser.c index
> > c957a75667..6bf4f30e80 100644
> > --- a/libavcodec/vp9_parser.c
> > +++ b/libavcodec/vp9_parser.c
> > @@ -1,8 +1,5 @@
> >  /*
> > - * VP9 compatible video decoder
> > - *
> > - * Copyright (C) 2013 Ronald S. Bultje 
> > - * Copyright (C) 2013 Clément Bœsch 
> > + * VP9 parser
> >   *
> >   * This file is part of FFmpeg.
> >   *
> > @@ -21,50 +18,105 @@
> >   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> > 02110-1301 USA
> >   */
> >
> > -#include "libavutil/intreadwrite.h"
> > -#include "libavcodec/get_bits.h"
> > +#include "libavutil/avassert.h"
> > +#include "cbs.h"
> > +#include "cbs_vp9.h"
> >  #include "parser.h"
> >
> > -static int parse(AVCodecParserContext *ctx,
> > - AVCodecContext *avctx,
> > - const uint8_t **out_data, int *out_size,
> > - const uint8_t *data, int size)
> > +typedef struct VP9ParserContext {
> > +CodedBitstreamContext *cbc;
> > +VP9RawFrameHeader frame_header;
> > +} VP9ParserContext;
> > +
> > +static const enum AVPixelFormat vp9_pix_fmts[3][2][2] = {
> > +{ // 8-bit.
> > +{ AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P },
> > +{ AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P },
> > +},
> > +{ // 10-bit.
> > +{ AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV440P10 },
> > +{ AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10 },
> > +},
> > +{ // 12-bit.
> > +{ AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12 },
> > +{ AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12 },
> > +},
> > +};
> > +
> > +static int vp9_parser_parse(AVCodecParserContext *ctx,
> > +AVCodecContext *avctx,
> > +const uint8_t **out_data, int
> *out_size,
> > +const uint8_t *data, int size)
> >  {
> > -GetBitContext gb;
> > -int res, profile, keyframe;
> > +VP9ParserContext *s = ctx->priv_data;
> > +const CodedBitstreamVP9Context *vp9 = s->cbc->priv_data;
> > +const VP9RawFrameHeader *fh;
> > +int err;
> >
> >  *out_data = data;
> >  *out_size = size;
> >
> > -if (!size || (res = init_get_bits8(, data, size)) < 0)
> > -return size; // parsers can't return errors
> > -get_bits(, 2); // frame marker
> > -profile  = get_bits1();
> > -profile |= get_bits1() << 1;
> > -if (profile == 3) profile += get_bits1();
> > -if (profile > 3)
> > -return size;
> > +ctx->key_frame = -1;
> > +ctx->pict_type = AV_PICTURE_TYPE_NONE;
> > +ctx->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
> >
> > -avctx->profile = profile;
> > +if (!size)
> > +return 0;
> >
> > -if (get_bits1()) {
> > -keyframe = 0;
> > -} else {
> > -keyframe  = !get_bits1();
> > +s->cbc->log_ctx = avctx;
> > +
> > +err = ff_cbs_parse_headers(s->cbc, >frame_header, data, size);
> > +if (err < 0) {
> > +av_log(avctx, AV_LOG_WARNING, "Failed to parse VP9 frame
> > headers.\n");
> > +goto end;
> >  }
> > +fh = >frame_header;
> >
> > -if (!keyframe) {
> > -ctx->pict_type = AV_PICTURE_TYPE_P;
> > -ctx->key_frame = 0;
> > -} else {
> > +avctx->profile = vp9->profile;
> > +avctx->level   = FF_LEVEL_UNKNOWN;
> > +
> > +ctx->width  = ctx->coded_width  = vp9->frame_width;
> > +ctx->height = ctx->coded_height = vp9->frame_height;
> > +
> > +if (fh->frame_type == VP9_KEY_FRAME) {
> >  ctx->pict_type = AV_PICTURE_TYPE_I;
> >  ctx->key_frame = 1;
> > +} else {
> > +ctx->pict_type = fh->intra_only ? AV_PICTURE_TYPE_I :
> > AV_PICTURE_TYPE_P;
> > +ctx->key_frame = 0;
> >  }
> >
> > +ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
> > +
> > +av_assert0(vp9->bit_depth == 8  ||
> > +   vp9->bit_depth == 10 ||
> > +   vp9->bit_depth == 12);
> > +
> > +ctx->format = vp9_pix_fmts[(vp9->bit_depth - 8) / 2]
> > +
> > [vp9->subsampling_x][vp9->subsampling_y];
> > +
> > +end:
> > +s->cbc->log_ctx = NULL;
> > +
> >  return size;
> >  }
> >
> > +static av_cold int vp9_parser_init(AVCodecParserContext