Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH v2 2/3] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support
Date: Sun, 19 Mar 2023 20:42:39 +0100
Message-ID: <20230319194240.15001-2-michael@niedermayer.cc> (raw)
In-Reply-To: <20230319194240.15001-1-michael@niedermayer.cc>

about 50% faster (based on command line fps)

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavfilter/vf_uspp.c | 53 +++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index f60eb230a2..ffdaa907b2 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -231,16 +231,25 @@ static int filter_1phase(AVFilterContext *ctx, void *arg, int i, int nb_jobs)
         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;
+    if (p->avctx_enc[i]->flags & AV_CODEC_FLAG_RECON_FRAME) {
+        av_packet_unref(pkt);
+        ret = avcodec_receive_frame(p->avctx_enc[i], p->frame_dec[i]);
+        if (ret < 0) {
+            av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from encoding\n");
+            return ret;
+        }
+    } else {
+        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];
@@ -383,23 +392,21 @@ static int config_input(AVFilterLink *inlink)
 
         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;
         avctx_enc->max_b_frames = 0;
         avctx_enc->pix_fmt = inlink->format;
         avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY;
+        if (enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME) {
+            avctx_enc->flags |= AV_CODEC_FLAG_RECON_FRAME;
+            av_dict_set(&opts, "no_bitstream", "1", 0);
+        }
         avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
         avctx_enc->global_quality = 123;
-        avctx_dec->thread_count =
         avctx_enc->thread_count = 1; // We do threading in the filter with muiltiple codecs
         ret = avcodec_open2(avctx_enc, enc, &opts);
         av_dict_free(&opts);
@@ -408,9 +415,17 @@ static int config_input(AVFilterLink *inlink)
         av_assert0(avctx_enc->codec);
 
 
-        ret = avcodec_open2(avctx_dec, dec, NULL);
-        if (ret < 0)
-            return ret;
+        if (!(enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) {
+            if (!(uspp->avctx_dec[i] = avcodec_alloc_context3(NULL)))
+                return AVERROR(ENOMEM);
+            avctx_dec = uspp->avctx_dec[i];
+            avctx_dec->width  = avctx_enc->width;
+            avctx_dec->height = avctx_enc->height;
+            avctx_dec->thread_count = 1;
+            ret = avcodec_open2(avctx_dec, dec, NULL);
+            if (ret < 0)
+                return ret;
+        }
 
         if (!(uspp->frame[i] = av_frame_alloc()))
             return AVERROR(ENOMEM);
-- 
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".

  reply	other threads:[~2023-03-19 19:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19 19:42 [FFmpeg-devel] [PATCH v2 1/3] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support Michael Niedermayer
2023-03-19 19:42 ` Michael Niedermayer [this message]
2023-03-19 19:42 ` [FFmpeg-devel] [PATCH v2 3/3] avfilter/vf_mcdeint: update to new API Michael Niedermayer
2023-03-20 22:07 ` [FFmpeg-devel] [PATCH v2 1/3] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support James Almer
2023-03-23  9:50   ` Michael Niedermayer
2023-03-23 11:32     ` James Almer
2023-03-24  0:08       ` Michael Niedermayer
2023-03-25 20:56         ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230319194240.15001-2-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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