[FFmpeg-devel] [PATCH 3/4] avcodec/librav1e: support AV_CODEC_CAP_ENCODER_RECON_FRAME

James Almer jamrial at gmail.com
Wed Oct 12 16:08:28 EEST 2022


This bumps the minimum required version to 0.5.0

Signed-off-by: James Almer <jamrial at gmail.com>
---
 configure             |  2 +-
 libavcodec/librav1e.c | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 84641fd03e..96479d48d6 100755
--- a/configure
+++ b/configure
@@ -6674,7 +6674,7 @@ enabled libopus           && {
 enabled libplacebo        && require_pkg_config libplacebo "libplacebo >= 4.192.0" libplacebo/vulkan.h pl_vulkan_create
 enabled libpulse          && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new
 enabled librabbitmq       && require_pkg_config librabbitmq "librabbitmq >= 0.7.1" amqp.h amqp_new_connection
-enabled librav1e          && require_pkg_config librav1e "rav1e >= 0.4.0" rav1e.h rav1e_context_new
+enabled librav1e          && require_pkg_config librav1e "rav1e >= 0.5.0" rav1e.h rav1e_context_new
 enabled librist           && require_pkg_config librist "librist >= 0.2.7" librist/librist.h rist_receiver_create
 enabled librsvg           && require_pkg_config librsvg librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
 enabled librtmp           && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index 604115476c..130417622a 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -23,6 +23,7 @@
 #include <rav1e.h>
 
 #include "libavutil/internal.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/avassert.h"
 #include "libavutil/base64.h"
 #include "libavutil/common.h"
@@ -538,6 +539,40 @@ retry:
 
     pkt->pts = pkt->dts = *((int64_t *) rpkt->opaque);
     av_free(rpkt->opaque);
+
+    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
+        AVCodecInternal *avci = avctx->internal;
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+        ptrdiff_t linesizes[4];
+        size_t sizes[4];
+
+        av_frame_unref(avci->recon_frame);
+
+        avci->recon_frame->format = avctx->pix_fmt;
+        avci->recon_frame->width  = avctx->width;
+        avci->recon_frame->height = avctx->height;
+
+        ret = av_frame_get_buffer(avci->recon_frame, 0);
+        if (ret < 0) {
+            rav1e_packet_unref(rpkt);
+            return ret;
+        }
+
+        for (int i = 0; i < 4; i++)
+            linesizes[i] = avci->recon_frame->linesize[i];
+
+        ret = av_image_fill_plane_sizes(sizes, avctx->pix_fmt, avctx->height, linesizes);
+        if (ret < 0) {
+            rav1e_packet_unref(rpkt);
+            return ret;
+        }
+
+        for (int i = 0; i < desc->nb_components; i++) {
+            rav1e_frame_extract_plane(rpkt->rec, i, avci->recon_frame->data[i],
+                                      sizes[i], linesizes[i], desc->comp[i].step);
+        }
+    }
+
     rav1e_packet_unref(rpkt);
 
     return 0;
@@ -601,7 +636,7 @@ const FFCodec ff_librav1e_encoder = {
     .defaults       = librav1e_defaults,
     .p.pix_fmts     = librav1e_pix_fmts,
     .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS |
-                      AV_CODEC_CAP_DR1,
+                      AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
                       FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
     .p.wrapper_name = "librav1e",
-- 
2.37.3



More information about the ffmpeg-devel mailing list