* [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs
@ 2023-03-15 23:34 Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_uspp: Support any codec Michael Niedermayer
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-15 23:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
configure | 1 -
libavfilter/vf_uspp.c | 49 ++++++++++++++++++++++++++++++++++++-------
2 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/configure b/configure
index 03d3c429a5..0370e25577 100755
--- a/configure
+++ b/configure
@@ -7359,7 +7359,6 @@ enable frame_thread_encoder
# they are kept disabled for now, but will be removed if
# nobody updates and re-enables them
disable mcdeint_filter
-disable uspp_filter
enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index 051de00771..43114e1b50 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -53,6 +53,7 @@ typedef struct USPPContext {
int outbuf_size;
uint8_t *outbuf;
AVCodecContext *avctx_enc[BLOCK*BLOCK];
+ AVCodecContext *avctx_dec[BLOCK*BLOCK];
AVPacket *pkt;
AVFrame *frame;
AVFrame *frame_dec;
@@ -244,7 +245,6 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
const int BLOCKc = BLOCK >> p->hsub;
int offset;
AVPacket *pkt = p->pkt;
- int got_pkt_ptr;
av_packet_unref(pkt);
pkt->data = p->outbuf;
@@ -255,14 +255,28 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
p->frame->data[2] = p->src[2] + x1c + y1c * p->frame->linesize[2];
p->frame->format = p->avctx_enc[i]->pix_fmt;
- ret = avcodec_encode_video2(p->avctx_enc[i], pkt, p->frame, &got_pkt_ptr);
+ ret = avcodec_send_frame(p->avctx_enc[i], p->frame);
if (ret < 0) {
- av_log(p->avctx_enc[i], AV_LOG_ERROR, "Encoding failed\n");
+ av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error sending a frame for encoding\n");
+ continue;
+ }
+ ret = avcodec_receive_packet(p->avctx_enc[i], pkt);
+ if (ret < 0) {
+ av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error receiving a packet from encoding\n");
continue;
}
- av_packet_unref(pkt);
- p->frame_dec = p->avctx_enc[i]->coded_frame;
+ ret = avcodec_send_packet(p->avctx_dec[i], pkt);
+ av_packet_unref(pkt);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
+ continue;
+ }
+ ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
+ continue;
+ }
offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec->linesize[0];
@@ -315,10 +329,15 @@ static int config_input(AVFilterLink *inlink)
int i;
const AVCodec *enc = avcodec_find_encoder(AV_CODEC_ID_SNOW);
+ const AVCodec *dec = avcodec_find_decoder(AV_CODEC_ID_SNOW);
if (!enc) {
av_log(ctx, AV_LOG_ERROR, "SNOW encoder not found.\n");
return AVERROR(EINVAL);
}
+ if (!dec) {
+ av_log(ctx, AV_LOG_ERROR, "SNOW decoder not found.\n");
+ return AVERROR(EINVAL);
+ }
uspp->hsub = desc->log2_chroma_w;
uspp->vsub = desc->log2_chroma_h;
@@ -341,15 +360,20 @@ static int config_input(AVFilterLink *inlink)
}
for (i = 0; i < (1<<uspp->log2_count); i++) {
- AVCodecContext *avctx_enc;
+ AVCodecContext *avctx_enc, *avctx_dec;
AVDictionary *opts = NULL;
int ret;
if (!(uspp->avctx_enc[i] = avcodec_alloc_context3(NULL)))
return AVERROR(ENOMEM);
+ if (!(uspp->avctx_dec[i] = avcodec_alloc_context3(NULL)))
+ return AVERROR(ENOMEM);
avctx_enc = uspp->avctx_enc[i];
+ avctx_dec = uspp->avctx_dec[i];
+ avctx_dec->width =
avctx_enc->width = width + BLOCK;
+ avctx_dec->height =
avctx_enc->height = height + BLOCK;
avctx_enc->time_base = (AVRational){1,25}; // meaningless
avctx_enc->gop_size = INT_MAX;
@@ -358,17 +382,24 @@ static int config_input(AVFilterLink *inlink)
avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY;
avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
avctx_enc->global_quality = 123;
- av_dict_set(&opts, "no_bitstream", "1", 0);
ret = avcodec_open2(avctx_enc, enc, &opts);
av_dict_free(&opts);
if (ret < 0)
return ret;
av_assert0(avctx_enc->codec);
+
+
+ ret = avcodec_open2(avctx_dec, dec, NULL);
+ if (ret < 0)
+ return ret;
+
}
uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10;
if (!(uspp->frame = av_frame_alloc()))
return AVERROR(ENOMEM);
+ if (!(uspp->frame_dec = av_frame_alloc()))
+ return AVERROR(ENOMEM);
if (!(uspp->pkt = av_packet_alloc()))
return AVERROR(ENOMEM);
if (!(uspp->outbuf = av_malloc(uspp->outbuf_size)))
@@ -460,8 +491,10 @@ static av_cold void uninit(AVFilterContext *ctx)
av_freep(&uspp->src[i]);
}
- for (i = 0; i < (1 << uspp->log2_count); i++)
+ for (i = 0; i < (1 << uspp->log2_count); i++) {
avcodec_free_context(&uspp->avctx_enc[i]);
+ avcodec_free_context(&uspp->avctx_dec[i]);
+ }
av_freep(&uspp->non_b_qp_table);
av_freep(&uspp->outbuf);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] avfilter/vf_uspp: Support any codec
2023-03-15 23:34 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs Michael Niedermayer
@ 2023-03-15 23:34 ` Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads Michael Niedermayer
2023-03-16 16:13 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs James Almer
2 siblings, 0 replies; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-15 23:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
doc/filters.texi | 3 +++
libavfilter/vf_uspp.c | 11 ++++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 77b594f69c..d634924bfb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -23364,6 +23364,9 @@ that value the speed drops by a factor of approximately 2. Default value is
@item qp
Force a constant quantization parameter. If not set, the filter will use the QP
from the video stream (if available).
+
+@item codec
+Use specified codec instead of snow.
@end table
@section v360
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index 43114e1b50..a7bf8e3087 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -46,6 +46,7 @@ typedef struct USPPContext {
int log2_count;
int hsub, vsub;
int qp;
+ char *codec_name;
enum AVVideoEncParamsType qscale_type;
int temp_stride[3];
uint8_t *src[3];
@@ -68,6 +69,7 @@ static const AVOption uspp_options[] = {
{ "quality", "set quality", OFFSET(log2_count), AV_OPT_TYPE_INT, {.i64 = 3}, 0, MAX_LEVEL, FLAGS },
{ "qp", "force a constant quantizer parameter", OFFSET(qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, FLAGS },
{ "use_bframe_qp", "use B-frames' QP", OFFSET(use_bframe_qp), AV_OPT_TYPE_BOOL,{.i64 = 0}, 0, 1, FLAGS },
+ { "codec", "Codec name", OFFSET(codec_name), AV_OPT_TYPE_STRING, {.str = "snow"}, 0, 0, FLAGS },
{ NULL }
};
@@ -327,15 +329,14 @@ static int config_input(AVFilterLink *inlink)
const int width = inlink->w;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
int i;
-
- const AVCodec *enc = avcodec_find_encoder(AV_CODEC_ID_SNOW);
- const AVCodec *dec = avcodec_find_decoder(AV_CODEC_ID_SNOW);
+ const AVCodec *enc = avcodec_find_encoder_by_name(uspp->codec_name);
+ const AVCodec *dec = avcodec_find_decoder_by_name(uspp->codec_name);
if (!enc) {
- av_log(ctx, AV_LOG_ERROR, "SNOW encoder not found.\n");
+ av_log(ctx, AV_LOG_ERROR, "encoder %s not found.\n", uspp->codec_name);
return AVERROR(EINVAL);
}
if (!dec) {
- av_log(ctx, AV_LOG_ERROR, "SNOW decoder not found.\n");
+ av_log(ctx, AV_LOG_ERROR, "decoder %s not found.\n", uspp->codec_name);
return AVERROR(EINVAL);
}
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads
2023-03-15 23:34 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_uspp: Support any codec Michael Niedermayer
@ 2023-03-15 23:34 ` Michael Niedermayer
2023-03-16 7:47 ` Nicolas George
2023-03-16 16:13 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs James Almer
2 siblings, 1 reply; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-15 23:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavfilter/vf_uspp.c | 181 +++++++++++++++++++++++-------------------
1 file changed, 99 insertions(+), 82 deletions(-)
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index a7bf8e3087..0a992df898 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -44,6 +44,7 @@
typedef struct USPPContext {
const AVClass *av_class;
int log2_count;
+ int count;
int hsub, vsub;
int qp;
char *codec_name;
@@ -55,12 +56,13 @@ typedef struct USPPContext {
uint8_t *outbuf;
AVCodecContext *avctx_enc[BLOCK*BLOCK];
AVCodecContext *avctx_dec[BLOCK*BLOCK];
- AVPacket *pkt;
- AVFrame *frame;
- AVFrame *frame_dec;
+ AVPacket *pkt [BLOCK*BLOCK];
+ AVFrame *frame [BLOCK*BLOCK];
+ AVFrame *frame_dec [BLOCK*BLOCK];
int8_t *non_b_qp_table;
int non_b_qp_stride;
int use_bframe_qp;
+ int quality;
} USPPContext;
#define OFFSET(x) offsetof(USPPContext, x)
@@ -188,13 +190,87 @@ static void store_slice_c(uint8_t *dst, const uint16_t *src,
}
}
-static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
+static int filter_1phase(AVFilterContext *ctx, void *arg, int i, int nb_jobs)
+{
+ USPPContext *p = ctx->priv;
+ int ret, x, y;
+ int width = ctx->inputs[0]->w;
+ int height = ctx->inputs[0]->h;
+
+ const int x1 = offset[i+nb_jobs-1][0];
+ const int y1 = offset[i+nb_jobs-1][1];
+ const int x1c = x1 >> p->hsub;
+ const int y1c = y1 >> p->vsub;
+ const int BLOCKc = BLOCK >> p->hsub;
+ int offset;
+ AVPacket *pkt = p->pkt[i];
+
+ av_packet_unref(pkt);
+ pkt->data = p->outbuf;
+ pkt->size = p->outbuf_size;
+
+ p->frame[i]->linesize[0] = p->temp_stride[0];
+ p->frame[i]->linesize[1] = p->temp_stride[1];
+ p->frame[i]->linesize[2] = p->temp_stride[2];
+ p->frame[i]->height = height + BLOCK;
+ p->frame[i]->width = width + BLOCK;
+ p->frame[i]->data[0] = p->src[0] + x1 + y1 * p->frame[i]->linesize[0];
+ p->frame[i]->data[1] = p->src[1] + x1c + y1c * p->frame[i]->linesize[1];
+ p->frame[i]->data[2] = p->src[2] + x1c + y1c * p->frame[i]->linesize[2];
+ p->frame[i]->format = p->avctx_enc[i]->pix_fmt;
+ p->frame[i]->quality = p->quality;
+
+ ret = avcodec_send_frame(p->avctx_enc[i], p->frame[i]);
+ if (ret < 0) {
+ av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error sending a frame for encoding\n");
+ return ret;
+ }
+ ret = avcodec_receive_packet(p->avctx_enc[i], pkt);
+ if (ret < 0) {
+ av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error receiving a packet from encoding\n");
+ return ret;
+ }
+
+ ret = avcodec_send_packet(p->avctx_dec[i], pkt);
+ av_packet_unref(pkt);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
+ return ret;
+ }
+ ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec[i]);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
+ return ret;
+ }
+
+ offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec[i]->linesize[0];
+
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++)
+ p->temp[0][x + y * p->temp_stride[0]] += p->frame_dec[i]->data[0][x + y * p->frame_dec[i]->linesize[0] + offset];
+
+
+ if (!p->frame_dec[i]->data[2] || !p->temp[2])
+ return 0;
+
+ offset = (BLOCKc-x1c) + (BLOCKc-y1c) * p->frame_dec[i]->linesize[1];
+
+ for (y = 0; y < AV_CEIL_RSHIFT(height, p->vsub); y++) {
+ for (x = 0; x < AV_CEIL_RSHIFT(width, p->hsub); x++) {
+ p->temp[1][x + y * p->temp_stride[1]] += p->frame_dec[i]->data[1][x + y * p->frame_dec[i]->linesize[1] + offset];
+ p->temp[2][x + y * p->temp_stride[2]] += p->frame_dec[i]->data[2][x + y * p->frame_dec[i]->linesize[2] + offset];
+ }
+ }
+
+ return 0;
+}
+
+static void filter(AVFilterContext *ctx, uint8_t *dst[3], uint8_t *src[3],
int dst_stride[3], int src_stride[3], int width,
int height, uint8_t *qp_store, int qp_stride)
{
+ USPPContext *p = ctx->priv;
int x, y, i, j;
- const int count = 1<<p->log2_count;
- int ret;
for (i = 0; i < 3; i++) {
int is_chroma = !!i;
@@ -219,12 +295,11 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
memcpy(p->src[i] + (h+block +y) * stride, p->src[i] + (h-y+block-1) * stride, stride);
}
- p->frame->linesize[i] = stride;
memset(p->temp[i], 0, (h + 2 * block) * stride * sizeof(int16_t));
}
if (p->qp)
- p->frame->quality = p->qp * FF_QP2LAMBDA;
+ p->quality = p->qp * FF_QP2LAMBDA;
else {
int qpsum=0;
int qpcount = (height>>4) * (height>>4);
@@ -233,71 +308,11 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
for (x = 0; x < (width>>4); x++)
qpsum += qp_store[x + y * qp_stride];
}
- p->frame->quality = ff_norm_qscale((qpsum + qpcount/2) / qpcount, p->qscale_type) * FF_QP2LAMBDA;
+ p->quality = ff_norm_qscale((qpsum + qpcount/2) / qpcount, p->qscale_type) * FF_QP2LAMBDA;
}
// init per MB qscale stuff FIXME
- p->frame->height = height + BLOCK;
- p->frame->width = width + BLOCK;
-
- for (i = 0; i < count; i++) {
- const int x1 = offset[i+count-1][0];
- const int y1 = offset[i+count-1][1];
- const int x1c = x1 >> p->hsub;
- const int y1c = y1 >> p->vsub;
- const int BLOCKc = BLOCK >> p->hsub;
- int offset;
- AVPacket *pkt = p->pkt;
-
- av_packet_unref(pkt);
- pkt->data = p->outbuf;
- pkt->size = p->outbuf_size;
-
- p->frame->data[0] = p->src[0] + x1 + y1 * p->frame->linesize[0];
- p->frame->data[1] = p->src[1] + x1c + y1c * p->frame->linesize[1];
- p->frame->data[2] = p->src[2] + x1c + y1c * p->frame->linesize[2];
- p->frame->format = p->avctx_enc[i]->pix_fmt;
-
- ret = avcodec_send_frame(p->avctx_enc[i], p->frame);
- if (ret < 0) {
- av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error sending a frame for encoding\n");
- continue;
- }
- ret = avcodec_receive_packet(p->avctx_enc[i], pkt);
- if (ret < 0) {
- av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error receiving a packet from encoding\n");
- continue;
- }
-
- ret = avcodec_send_packet(p->avctx_dec[i], pkt);
- av_packet_unref(pkt);
- if (ret < 0) {
- av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
- continue;
- }
- ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec);
- if (ret < 0) {
- av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
- continue;
- }
-
- offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec->linesize[0];
-
- for (y = 0; y < height; y++)
- for (x = 0; x < width; x++)
- p->temp[0][x + y * p->temp_stride[0]] += p->frame_dec->data[0][x + y * p->frame_dec->linesize[0] + offset];
-
- if (!src[2] || !dst[2])
- continue;
-
- offset = (BLOCKc-x1c) + (BLOCKc-y1c) * p->frame_dec->linesize[1];
- for (y = 0; y < AV_CEIL_RSHIFT(height, p->vsub); y++) {
- for (x = 0; x < AV_CEIL_RSHIFT(width, p->hsub); x++) {
- p->temp[1][x + y * p->temp_stride[1]] += p->frame_dec->data[1][x + y * p->frame_dec->linesize[1] + offset];
- p->temp[2][x + y * p->temp_stride[2]] += p->frame_dec->data[2][x + y * p->frame_dec->linesize[2] + offset];
- }
- }
- }
+ ff_filter_execute(ctx, filter_1phase, NULL, NULL, p->count);
for (j = 0; j < 3; j++) {
int is_chroma = !!j;
@@ -342,6 +357,7 @@ static int config_input(AVFilterLink *inlink)
uspp->hsub = desc->log2_chroma_w;
uspp->vsub = desc->log2_chroma_h;
+ uspp->count = 1<<uspp->log2_count;
for (i = 0; i < 3; i++) {
int is_chroma = !!i;
@@ -360,7 +376,7 @@ static int config_input(AVFilterLink *inlink)
return AVERROR(ENOMEM);
}
- for (i = 0; i < (1<<uspp->log2_count); i++) {
+ for (i = 0; i < uspp->count; i++) {
AVCodecContext *avctx_enc, *avctx_dec;
AVDictionary *opts = NULL;
int ret;
@@ -394,15 +410,15 @@ static int config_input(AVFilterLink *inlink)
if (ret < 0)
return ret;
+ if (!(uspp->frame[i] = av_frame_alloc()))
+ return AVERROR(ENOMEM);
+ if (!(uspp->frame_dec[i] = av_frame_alloc()))
+ return AVERROR(ENOMEM);
+ if (!(uspp->pkt[i] = av_packet_alloc()))
+ return AVERROR(ENOMEM);
}
uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10;
- if (!(uspp->frame = av_frame_alloc()))
- return AVERROR(ENOMEM);
- if (!(uspp->frame_dec = av_frame_alloc()))
- return AVERROR(ENOMEM);
- if (!(uspp->pkt = av_packet_alloc()))
- return AVERROR(ENOMEM);
if (!(uspp->outbuf = av_malloc(uspp->outbuf_size)))
return AVERROR(ENOMEM);
@@ -464,7 +480,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
out->height = in->height;
}
- filter(uspp, out->data, in->data, out->linesize, in->linesize,
+ filter(ctx, out->data, in->data, out->linesize, in->linesize,
inlink->w, inlink->h, qp_table, qp_stride);
}
}
@@ -492,15 +508,16 @@ static av_cold void uninit(AVFilterContext *ctx)
av_freep(&uspp->src[i]);
}
- for (i = 0; i < (1 << uspp->log2_count); i++) {
+ for (i = 0; i < uspp->count; i++) {
avcodec_free_context(&uspp->avctx_enc[i]);
avcodec_free_context(&uspp->avctx_dec[i]);
+ av_frame_free(&uspp->frame[i]);
+ av_frame_free(&uspp->frame_dec[i]);
+ av_packet_free(&uspp->pkt[i]);
}
av_freep(&uspp->non_b_qp_table);
av_freep(&uspp->outbuf);
- av_packet_free(&uspp->pkt);
- av_frame_free(&uspp->frame);
}
static const AVFilterPad uspp_inputs[] = {
@@ -528,5 +545,5 @@ const AVFilter ff_vf_uspp = {
FILTER_OUTPUTS(uspp_outputs),
FILTER_PIXFMTS_ARRAY(pix_fmts),
.priv_class = &uspp_class,
- .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
};
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads Michael Niedermayer
@ 2023-03-16 7:47 ` Nicolas George
2023-03-16 21:26 ` Michael Niedermayer
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas George @ 2023-03-16 7:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Michael Niedermayer (12023-03-16):
> Subject: Re: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with
> threads
Rule of thumb: do not use variation percentages above +100% or below
-50%, use ratios instead:
avfilter/vf_uspp: 11 times faster with threads
(11, really? not 10?)
Regards,
--
Nicolas George
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs
2023-03-15 23:34 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_uspp: Support any codec Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads Michael Niedermayer
@ 2023-03-16 16:13 ` James Almer
2023-03-16 21:15 ` Michael Niedermayer
2 siblings, 1 reply; 8+ messages in thread
From: James Almer @ 2023-03-16 16:13 UTC (permalink / raw)
To: ffmpeg-devel
On 3/15/2023 8:34 PM, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> configure | 1 -
> libavfilter/vf_uspp.c | 49 ++++++++++++++++++++++++++++++++++++-------
> 2 files changed, 41 insertions(+), 9 deletions(-)
>
> diff --git a/configure b/configure
> index 03d3c429a5..0370e25577 100755
> --- a/configure
> +++ b/configure
> @@ -7359,7 +7359,6 @@ enable frame_thread_encoder
> # they are kept disabled for now, but will be removed if
> # nobody updates and re-enables them
> disable mcdeint_filter
> -disable uspp_filter
>
> enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
>
> diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
> index 051de00771..43114e1b50 100644
> --- a/libavfilter/vf_uspp.c
> +++ b/libavfilter/vf_uspp.c
> @@ -53,6 +53,7 @@ typedef struct USPPContext {
> int outbuf_size;
> uint8_t *outbuf;
> AVCodecContext *avctx_enc[BLOCK*BLOCK];
> + AVCodecContext *avctx_dec[BLOCK*BLOCK];
Wouldn't it be more efficient to try to implement recon_frame support on
more encoders, including snow, and limit this filter to those in patch 2/2?
I suggest this mainly seeing how you're creating 256 encoders and now
also 256 decoders, all of which might be threaded since you're not
forcing them to use a single thread, and in patch 3 you'll add slice
threading on top of that.
> AVPacket *pkt;
> AVFrame *frame;
> AVFrame *frame_dec;
> @@ -244,7 +245,6 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
> const int BLOCKc = BLOCK >> p->hsub;
> int offset;
> AVPacket *pkt = p->pkt;
> - int got_pkt_ptr;
>
> av_packet_unref(pkt);
> pkt->data = p->outbuf;
> @@ -255,14 +255,28 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3],
> p->frame->data[2] = p->src[2] + x1c + y1c * p->frame->linesize[2];
> p->frame->format = p->avctx_enc[i]->pix_fmt;
>
> - ret = avcodec_encode_video2(p->avctx_enc[i], pkt, p->frame, &got_pkt_ptr);
> + ret = avcodec_send_frame(p->avctx_enc[i], p->frame);
> if (ret < 0) {
> - av_log(p->avctx_enc[i], AV_LOG_ERROR, "Encoding failed\n");
> + av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error sending a frame for encoding\n");
> + continue;
> + }
> + ret = avcodec_receive_packet(p->avctx_enc[i], pkt);
> + if (ret < 0) {
> + av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error receiving a packet from encoding\n");
> continue;
> }
> - av_packet_unref(pkt);
>
> - p->frame_dec = p->avctx_enc[i]->coded_frame;
> + ret = avcodec_send_packet(p->avctx_dec[i], pkt);
> + av_packet_unref(pkt);
> + if (ret < 0) {
> + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
> + continue;
> + }
> + ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec);
> + if (ret < 0) {
> + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
> + continue;
> + }
>
> offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec->linesize[0];
>
> @@ -315,10 +329,15 @@ static int config_input(AVFilterLink *inlink)
> int i;
>
> const AVCodec *enc = avcodec_find_encoder(AV_CODEC_ID_SNOW);
> + const AVCodec *dec = avcodec_find_decoder(AV_CODEC_ID_SNOW);
> if (!enc) {
> av_log(ctx, AV_LOG_ERROR, "SNOW encoder not found.\n");
> return AVERROR(EINVAL);
> }
> + if (!dec) {
> + av_log(ctx, AV_LOG_ERROR, "SNOW decoder not found.\n");
> + return AVERROR(EINVAL);
> + }
>
> uspp->hsub = desc->log2_chroma_w;
> uspp->vsub = desc->log2_chroma_h;
> @@ -341,15 +360,20 @@ static int config_input(AVFilterLink *inlink)
> }
>
> for (i = 0; i < (1<<uspp->log2_count); i++) {
> - AVCodecContext *avctx_enc;
> + AVCodecContext *avctx_enc, *avctx_dec;
> AVDictionary *opts = NULL;
> int ret;
>
> if (!(uspp->avctx_enc[i] = avcodec_alloc_context3(NULL)))
> return AVERROR(ENOMEM);
> + if (!(uspp->avctx_dec[i] = avcodec_alloc_context3(NULL)))
> + return AVERROR(ENOMEM);
>
> avctx_enc = uspp->avctx_enc[i];
> + avctx_dec = uspp->avctx_dec[i];
> + avctx_dec->width =
> avctx_enc->width = width + BLOCK;
> + avctx_dec->height =
> avctx_enc->height = height + BLOCK;
> avctx_enc->time_base = (AVRational){1,25}; // meaningless
> avctx_enc->gop_size = INT_MAX;
> @@ -358,17 +382,24 @@ static int config_input(AVFilterLink *inlink)
> avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY;
> avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
> avctx_enc->global_quality = 123;
> - av_dict_set(&opts, "no_bitstream", "1", 0);
> ret = avcodec_open2(avctx_enc, enc, &opts);
> av_dict_free(&opts);
> if (ret < 0)
> return ret;
> av_assert0(avctx_enc->codec);
> +
> +
> + ret = avcodec_open2(avctx_dec, dec, NULL);
> + if (ret < 0)
> + return ret;
> +
> }
>
> uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10;
> if (!(uspp->frame = av_frame_alloc()))
> return AVERROR(ENOMEM);
> + if (!(uspp->frame_dec = av_frame_alloc()))
> + return AVERROR(ENOMEM);
> if (!(uspp->pkt = av_packet_alloc()))
> return AVERROR(ENOMEM);
> if (!(uspp->outbuf = av_malloc(uspp->outbuf_size)))
> @@ -460,8 +491,10 @@ static av_cold void uninit(AVFilterContext *ctx)
> av_freep(&uspp->src[i]);
> }
>
> - for (i = 0; i < (1 << uspp->log2_count); i++)
> + for (i = 0; i < (1 << uspp->log2_count); i++) {
> avcodec_free_context(&uspp->avctx_enc[i]);
> + avcodec_free_context(&uspp->avctx_dec[i]);
> + }
>
> av_freep(&uspp->non_b_qp_table);
> av_freep(&uspp->outbuf);
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs
2023-03-16 16:13 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs James Almer
@ 2023-03-16 21:15 ` Michael Niedermayer
2023-03-18 12:31 ` Michael Niedermayer
0 siblings, 1 reply; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-16 21:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2143 bytes --]
On Thu, Mar 16, 2023 at 01:13:54PM -0300, James Almer wrote:
> On 3/15/2023 8:34 PM, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> > configure | 1 -
> > libavfilter/vf_uspp.c | 49 ++++++++++++++++++++++++++++++++++++-------
> > 2 files changed, 41 insertions(+), 9 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 03d3c429a5..0370e25577 100755
> > --- a/configure
> > +++ b/configure
> > @@ -7359,7 +7359,6 @@ enable frame_thread_encoder
> > # they are kept disabled for now, but will be removed if
> > # nobody updates and re-enables them
> > disable mcdeint_filter
> > -disable uspp_filter
> > enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
> > diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
> > index 051de00771..43114e1b50 100644
> > --- a/libavfilter/vf_uspp.c
> > +++ b/libavfilter/vf_uspp.c
> > @@ -53,6 +53,7 @@ typedef struct USPPContext {
> > int outbuf_size;
> > uint8_t *outbuf;
> > AVCodecContext *avctx_enc[BLOCK*BLOCK];
> > + AVCodecContext *avctx_dec[BLOCK*BLOCK];
>
> Wouldn't it be more efficient to try to implement recon_frame support on
> more encoders, including snow, and limit this filter to those in patch 2/2?
recon_frame support makes sense, but i think we should have generic support
first. Then when recon_frame is available use it.
First make it work then make it work fast where an optimization is possible
> I suggest this mainly seeing how you're creating 256 encoders and now also
> 256 decoders, all of which might be threaded since you're not forcing them
> to use a single thread, and in patch 3 you'll add slice threading on top of
> that.
ill add a thread_count = 1 so we dont multiply the threading.
if another variant is faster, of course that should be preferred
[...]
thx
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads
2023-03-16 7:47 ` Nicolas George
@ 2023-03-16 21:26 ` Michael Niedermayer
0 siblings, 0 replies; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-16 21:26 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1171 bytes --]
On Thu, Mar 16, 2023 at 08:47:40AM +0100, Nicolas George wrote:
> Michael Niedermayer (12023-03-16):
> > Subject: Re: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with
> > threads
>
> Rule of thumb: do not use variation percentages above +100% or below
> -50%, use ratios instead:
indeed, i agree
>
> avfilter/vf_uspp: 11 times faster with threads
>
> (11, really? not 10?)
it was a rough number based on the fps on the command line (which fluctuates)
so 10x is better i would not be able to tell 10x from 11x reliably also i had
some NIST PRNG tests running in the background.
If people care i can pause all other stuff and redo this and post precisse
numbers, but iam not sure how interresting the exact factor for 1 thread
vs 32 threads is.
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Any man who breaks a law that conscience tells him is unjust and willingly
accepts the penalty by staying in jail in order to arouse the conscience of
the community on the injustice of the law is at that moment expressing the
very highest respect for law. - Martin Luther King Jr
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs
2023-03-16 21:15 ` Michael Niedermayer
@ 2023-03-18 12:31 ` Michael Niedermayer
0 siblings, 0 replies; 8+ messages in thread
From: Michael Niedermayer @ 2023-03-18 12:31 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2210 bytes --]
On Thu, Mar 16, 2023 at 10:15:44PM +0100, Michael Niedermayer wrote:
> On Thu, Mar 16, 2023 at 01:13:54PM -0300, James Almer wrote:
> > On 3/15/2023 8:34 PM, Michael Niedermayer wrote:
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > > configure | 1 -
> > > libavfilter/vf_uspp.c | 49 ++++++++++++++++++++++++++++++++++++-------
> > > 2 files changed, 41 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/configure b/configure
> > > index 03d3c429a5..0370e25577 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -7359,7 +7359,6 @@ enable frame_thread_encoder
> > > # they are kept disabled for now, but will be removed if
> > > # nobody updates and re-enables them
> > > disable mcdeint_filter
> > > -disable uspp_filter
> > > enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
> > > diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
> > > index 051de00771..43114e1b50 100644
> > > --- a/libavfilter/vf_uspp.c
> > > +++ b/libavfilter/vf_uspp.c
> > > @@ -53,6 +53,7 @@ typedef struct USPPContext {
> > > int outbuf_size;
> > > uint8_t *outbuf;
> > > AVCodecContext *avctx_enc[BLOCK*BLOCK];
> > > + AVCodecContext *avctx_dec[BLOCK*BLOCK];
> >
> > Wouldn't it be more efficient to try to implement recon_frame support on
> > more encoders, including snow, and limit this filter to those in patch 2/2?
>
> recon_frame support makes sense, but i think we should have generic support
> first. Then when recon_frame is available use it.
> First make it work then make it work fast where an optimization is possible
will apply the patchset later today and then look into recon_frame in snow and uspp
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-03-18 12:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 23:34 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 2/3] avfilter/vf_uspp: Support any codec Michael Niedermayer
2023-03-15 23:34 ` [FFmpeg-devel] [PATCH 3/3] avfilter/vf_uspp: 1000% faster with threads Michael Niedermayer
2023-03-16 7:47 ` Nicolas George
2023-03-16 21:26 ` Michael Niedermayer
2023-03-16 16:13 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs James Almer
2023-03-16 21:15 ` Michael Niedermayer
2023-03-18 12:31 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git