Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
@ 2022-08-08  8:57 Martin Storsjö
  2022-08-08  8:59 ` Martin Storsjö
  0 siblings, 1 reply; 13+ messages in thread
From: Martin Storsjö @ 2022-08-08  8:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Bump the version requirement to 122, which introduced b_full_recon.
---
 configure            |  2 +-
 libavcodec/libx264.c | 55 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index eb413a6716..700003aba3 100755
--- a/configure
+++ b/configure
@@ -6675,7 +6675,7 @@ enabled libwebp           && {
     enabled libwebp_encoder      && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
     enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
 enabled libx264           && require_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode &&
-                             require_cpp_condition libx264 x264.h "X264_BUILD >= 118" && {
+                             require_cpp_condition libx264 x264.h "X264_BUILD >= 122" && {
                              [ "$toolchain" != "msvc" ] ||
                              require_cpp_condition libx264 x264.h "X264_BUILD >= 158"; } &&
                              check_cpp_condition libx262 x264.h "X264_MPEG2"
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e8c1fb2106..6afa3cdadb 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -311,6 +311,28 @@ static void free_picture(AVCodecContext *ctx)
     pic->extra_sei.num_payloads = 0;
 }
 
+static enum AVPixelFormat csp_to_pixfmt(int csp)
+{
+    switch (csp) {
+#ifdef X264_CSP_I400
+    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
+    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
+#endif
+    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
+    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
+    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
+    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
+    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
+    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
+    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
+#ifdef X264_CSP_NV21
+    case X264_CSP_NV21:                         return AV_PIX_FMT_NV21;
+#endif
+    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;
+    };
+    return AV_PIX_FMT_NONE;
+}
+
 static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                       int *got_packet)
 {
@@ -496,6 +518,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
         if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
             return AVERROR_EXTERNAL;
 
+        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
+            AVCodecInternal *avci = ctx->internal;
+
+            av_frame_unref(avci->recon_frame);
+
+            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
+            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
+                av_log(ctx, AV_LOG_ERROR,
+                       "Unhandled reconstructed frame colorspace: %d\n",
+                       pic_out.img.i_csp);
+                return AVERROR(ENOSYS);
+            }
+
+            avci->recon_frame->width  = ctx->width;
+            avci->recon_frame->height = ctx->height;
+            for (int i = 0; i < pic_out.img.i_plane; i++) {
+                avci->recon_frame->data[i]     = pic_out.img.plane[i];
+                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
+            }
+
+            ret = av_frame_make_writable(avci->recon_frame);
+            if (ret < 0) {
+                av_frame_unref(avci->recon_frame);
+                return ret;
+            }
+        }
+
         ret = encode_nals(ctx, pkt, nal, nnal);
         if (ret < 0)
             return ret;
@@ -928,6 +977,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
     if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
         x4->params.b_repeat_headers = 0;
 
+    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
+        x4->params.b_full_recon = 1;
+
     if(x4->x264opts){
         const char *p= x4->x264opts;
         while(p){
@@ -1223,7 +1275,8 @@ FFCodec ff_libx264_encoder = {
     .p.id             = AV_CODEC_ID_H264,
     .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
                         AV_CODEC_CAP_OTHER_THREADS |
-                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.priv_class     = &x264_class,
     .p.wrapper_name   = "libx264",
     .priv_data_size   = sizeof(X264Context),
-- 
2.32.0 (Apple Git-132)

_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-08-08  8:57 [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME Martin Storsjö
@ 2022-08-08  8:59 ` Martin Storsjö
  0 siblings, 0 replies; 13+ messages in thread
From: Martin Storsjö @ 2022-08-08  8:59 UTC (permalink / raw)
  To: ffmpeg-devel

On Mon, 8 Aug 2022, Martin Storsjö wrote:

> From: Anton Khirnov <anton@khirnov.net>
>
> Bump the version requirement to 122, which introduced b_full_recon.
> ---
> configure            |  2 +-
> libavcodec/libx264.c | 55 +++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 55 insertions(+), 2 deletions(-)

Sorry, disregard, I accidentally ran send-email on the wrong branch...

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-28 14:24 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
@ 2022-07-28 14:33   ` James Almer
  0 siblings, 0 replies; 13+ messages in thread
From: James Almer @ 2022-07-28 14:33 UTC (permalink / raw)
  To: ffmpeg-devel

On 7/28/2022 11:24 AM, Anton Khirnov wrote:
> Bump the version requirement to 122, which introduced b_full_recon.
> ---
>   configure            |  2 +-
>   libavcodec/libx264.c | 55 +++++++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 55 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 6629d14099..50d73a5325 100755
> --- a/configure
> +++ b/configure
> @@ -6674,7 +6674,7 @@ enabled libwebp           && {
>       enabled libwebp_encoder      && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
>       enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
>   enabled libx264           && require_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode &&
> -                             require_cpp_condition libx264 x264.h "X264_BUILD >= 118" && {
> +                             require_cpp_condition libx264 x264.h "X264_BUILD >= 122" && {
>                                [ "$toolchain" != "msvc" ] ||
>                                require_cpp_condition libx264 x264.h "X264_BUILD >= 158"; } &&
>                                check_cpp_condition libx262 x264.h "X264_MPEG2"
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index e8c1fb2106..6afa3cdadb 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -311,6 +311,28 @@ static void free_picture(AVCodecContext *ctx)
>       pic->extra_sei.num_payloads = 0;
>   }
>   
> +static enum AVPixelFormat csp_to_pixfmt(int csp)
> +{
> +    switch (csp) {
> +#ifdef X264_CSP_I400
> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> +#endif
> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> +    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
> +#ifdef X264_CSP_NV21
> +    case X264_CSP_NV21:                         return AV_PIX_FMT_NV21;
> +#endif
> +    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;
> +    };
> +    return AV_PIX_FMT_NONE;
> +}
> +
>   static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>                         int *got_packet)
>   {
> @@ -496,6 +518,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>           if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
>               return AVERROR_EXTERNAL;
>   
> +        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
> +            AVCodecInternal *avci = ctx->internal;
> +
> +            av_frame_unref(avci->recon_frame);
> +
> +            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
> +            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
> +                av_log(ctx, AV_LOG_ERROR,
> +                       "Unhandled reconstructed frame colorspace: %d\n",
> +                       pic_out.img.i_csp);
> +                return AVERROR(ENOSYS);
> +            }
> +
> +            avci->recon_frame->width  = ctx->width;
> +            avci->recon_frame->height = ctx->height;
> +            for (int i = 0; i < pic_out.img.i_plane; i++) {
> +                avci->recon_frame->data[i]     = pic_out.img.plane[i];
> +                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
> +            }
> +
> +            ret = av_frame_make_writable(avci->recon_frame);
> +            if (ret < 0) {
> +                av_frame_unref(avci->recon_frame);
> +                return ret;
> +            }
> +        }
> +
>           ret = encode_nals(ctx, pkt, nal, nnal);
>           if (ret < 0)
>               return ret;
> @@ -928,6 +977,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
>       if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
>           x4->params.b_repeat_headers = 0;
>   
> +    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
> +        x4->params.b_full_recon = 1;
> +
>       if(x4->x264opts){
>           const char *p= x4->x264opts;
>           while(p){
> @@ -1223,7 +1275,8 @@ FFCodec ff_libx264_encoder = {
>       .p.id             = AV_CODEC_ID_H264,
>       .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>                           AV_CODEC_CAP_OTHER_THREADS |
> -                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> +                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
>       .p.priv_class     = &x264_class, >       .p.wrapper_name   = "libx264",
>       .priv_data_size   = sizeof(X264Context),

LGTM.
_______________________________________________
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-19 18:13 [FFmpeg-devel] [PATCH v2] " James Almer
@ 2022-07-28 14:24 ` Anton Khirnov
  2022-07-28 14:33   ` James Almer
  0 siblings, 1 reply; 13+ messages in thread
From: Anton Khirnov @ 2022-07-28 14:24 UTC (permalink / raw)
  To: ffmpeg-devel

Bump the version requirement to 122, which introduced b_full_recon.
---
 configure            |  2 +-
 libavcodec/libx264.c | 55 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 6629d14099..50d73a5325 100755
--- a/configure
+++ b/configure
@@ -6674,7 +6674,7 @@ enabled libwebp           && {
     enabled libwebp_encoder      && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
     enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
 enabled libx264           && require_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode &&
-                             require_cpp_condition libx264 x264.h "X264_BUILD >= 118" && {
+                             require_cpp_condition libx264 x264.h "X264_BUILD >= 122" && {
                              [ "$toolchain" != "msvc" ] ||
                              require_cpp_condition libx264 x264.h "X264_BUILD >= 158"; } &&
                              check_cpp_condition libx262 x264.h "X264_MPEG2"
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index e8c1fb2106..6afa3cdadb 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -311,6 +311,28 @@ static void free_picture(AVCodecContext *ctx)
     pic->extra_sei.num_payloads = 0;
 }
 
+static enum AVPixelFormat csp_to_pixfmt(int csp)
+{
+    switch (csp) {
+#ifdef X264_CSP_I400
+    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
+    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
+#endif
+    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
+    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
+    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
+    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
+    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
+    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
+    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
+#ifdef X264_CSP_NV21
+    case X264_CSP_NV21:                         return AV_PIX_FMT_NV21;
+#endif
+    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;
+    };
+    return AV_PIX_FMT_NONE;
+}
+
 static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                       int *got_packet)
 {
@@ -496,6 +518,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
         if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
             return AVERROR_EXTERNAL;
 
+        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
+            AVCodecInternal *avci = ctx->internal;
+
+            av_frame_unref(avci->recon_frame);
+
+            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
+            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
+                av_log(ctx, AV_LOG_ERROR,
+                       "Unhandled reconstructed frame colorspace: %d\n",
+                       pic_out.img.i_csp);
+                return AVERROR(ENOSYS);
+            }
+
+            avci->recon_frame->width  = ctx->width;
+            avci->recon_frame->height = ctx->height;
+            for (int i = 0; i < pic_out.img.i_plane; i++) {
+                avci->recon_frame->data[i]     = pic_out.img.plane[i];
+                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
+            }
+
+            ret = av_frame_make_writable(avci->recon_frame);
+            if (ret < 0) {
+                av_frame_unref(avci->recon_frame);
+                return ret;
+            }
+        }
+
         ret = encode_nals(ctx, pkt, nal, nnal);
         if (ret < 0)
             return ret;
@@ -928,6 +977,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
     if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
         x4->params.b_repeat_headers = 0;
 
+    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
+        x4->params.b_full_recon = 1;
+
     if(x4->x264opts){
         const char *p= x4->x264opts;
         while(p){
@@ -1223,7 +1275,8 @@ FFCodec ff_libx264_encoder = {
     .p.id             = AV_CODEC_ID_H264,
     .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
                         AV_CODEC_CAP_OTHER_THREADS |
-                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.priv_class     = &x264_class,
     .p.wrapper_name   = "libx264",
     .priv_data_size   = sizeof(X264Context),
-- 
2.34.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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 12:23   ` James Almer
  2022-07-18 18:15     ` Anton Khirnov
@ 2022-07-19 12:43     ` Anton Khirnov
  1 sibling, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-07-19 12:43 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-07-18 14:23:58)
> On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> > ---
> >   libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
> >   1 file changed, 51 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index 98ec030865..5e360682e6 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
> >       pic->extra_sei.num_payloads = 0;
> >   }
> >   
> > +static enum AVPixelFormat csp_to_pixfmt(int csp)
> > +{
> > +    switch (csp) {
> > +#ifdef X264_CSP_I400
> > +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> > +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> > +#endif
> > +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> > +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> > +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> > +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> > +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> > +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> 
> We're still supporting old x264 versions, so you should add some 
> considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the 
> value of x264_bit_depth.

This will actually build even with pre-153 versions, except subsampled
(420/422) 10-bit reconstructed frames won't actually work with any
version because we lack a pixel format for them (higher-bit nv12
analogue).

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 18:29         ` Anton Khirnov
@ 2022-07-19 11:44           ` Michael Niedermayer
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Niedermayer @ 2022-07-19 11:44 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 2569 bytes --]

On Mon, Jul 18, 2022 at 08:29:56PM +0200, Anton Khirnov wrote:
> Quoting James Almer (2022-07-18 20:18:16)
> > 
> > 
> > On 7/18/2022 3:15 PM, Anton Khirnov wrote:
> > > Quoting James Almer (2022-07-18 14:23:58)
> > >> On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> > >>> ---
> > >>>    libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
> > >>>    1 file changed, 51 insertions(+), 1 deletion(-)
> > >>>
> > >>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > >>> index 98ec030865..5e360682e6 100644
> > >>> --- a/libavcodec/libx264.c
> > >>> +++ b/libavcodec/libx264.c
> > >>> @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
> > >>>        pic->extra_sei.num_payloads = 0;
> > >>>    }
> > >>>    
> > >>> +static enum AVPixelFormat csp_to_pixfmt(int csp)
> > >>> +{
> > >>> +    switch (csp) {
> > >>> +#ifdef X264_CSP_I400
> > >>> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> > >>> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> > >>> +#endif
> > >>> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> > >>> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> > >>> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> > >>> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> > >>> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> > >>> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> > >>
> > >> We're still supporting old x264 versions, so you should add some
> > >> considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the
> > >> value of x264_bit_depth.
> > > 
> > > Is there much point in continuing to support 5.5 year old x264? We could
> > > drop a lot of ugliness, including the abominable X264_init_static().
> > 
> > Afaik we tend to support what's shipped with not yet EOL'd big distros 
> > like Debian and Ubuntu. I assume Michael's Ubuntu setup is one of those, 
> > and it has a libx264 without X264_CSP_I400, for example.
> 
> Debian oldstable has libx264 155 at least.

Ubuntu 18.04LTS has 152
https://packages.ubuntu.com/search?keywords=x264&searchon=names&suite=bionic&section=all

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus

[-- 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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 18:18       ` James Almer
@ 2022-07-18 18:29         ` Anton Khirnov
  2022-07-19 11:44           ` Michael Niedermayer
  0 siblings, 1 reply; 13+ messages in thread
From: Anton Khirnov @ 2022-07-18 18:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-07-18 20:18:16)
> 
> 
> On 7/18/2022 3:15 PM, Anton Khirnov wrote:
> > Quoting James Almer (2022-07-18 14:23:58)
> >> On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> >>> ---
> >>>    libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
> >>>    1 file changed, 51 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> >>> index 98ec030865..5e360682e6 100644
> >>> --- a/libavcodec/libx264.c
> >>> +++ b/libavcodec/libx264.c
> >>> @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
> >>>        pic->extra_sei.num_payloads = 0;
> >>>    }
> >>>    
> >>> +static enum AVPixelFormat csp_to_pixfmt(int csp)
> >>> +{
> >>> +    switch (csp) {
> >>> +#ifdef X264_CSP_I400
> >>> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> >>> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> >>> +#endif
> >>> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> >>> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> >>> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> >>> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> >>> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> >>> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> >>
> >> We're still supporting old x264 versions, so you should add some
> >> considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the
> >> value of x264_bit_depth.
> > 
> > Is there much point in continuing to support 5.5 year old x264? We could
> > drop a lot of ugliness, including the abominable X264_init_static().
> 
> Afaik we tend to support what's shipped with not yet EOL'd big distros 
> like Debian and Ubuntu. I assume Michael's Ubuntu setup is one of those, 
> and it has a libx264 without X264_CSP_I400, for example.

Debian oldstable has libx264 155 at least.

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 18:15     ` Anton Khirnov
@ 2022-07-18 18:18       ` James Almer
  2022-07-18 18:29         ` Anton Khirnov
  0 siblings, 1 reply; 13+ messages in thread
From: James Almer @ 2022-07-18 18:18 UTC (permalink / raw)
  To: ffmpeg-devel



On 7/18/2022 3:15 PM, Anton Khirnov wrote:
> Quoting James Almer (2022-07-18 14:23:58)
>> On 7/18/2022 4:12 AM, Anton Khirnov wrote:
>>> ---
>>>    libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
>>>    1 file changed, 51 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
>>> index 98ec030865..5e360682e6 100644
>>> --- a/libavcodec/libx264.c
>>> +++ b/libavcodec/libx264.c
>>> @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
>>>        pic->extra_sei.num_payloads = 0;
>>>    }
>>>    
>>> +static enum AVPixelFormat csp_to_pixfmt(int csp)
>>> +{
>>> +    switch (csp) {
>>> +#ifdef X264_CSP_I400
>>> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
>>> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
>>> +#endif
>>> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
>>> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
>>> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
>>> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
>>> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
>>> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
>>
>> We're still supporting old x264 versions, so you should add some
>> considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the
>> value of x264_bit_depth.
> 
> Is there much point in continuing to support 5.5 year old x264? We could
> drop a lot of ugliness, including the abominable X264_init_static().

Afaik we tend to support what's shipped with not yet EOL'd big distros 
like Debian and Ubuntu. I assume Michael's Ubuntu setup is one of those, 
and it has a libx264 without X264_CSP_I400, for example.
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 12:23   ` James Almer
@ 2022-07-18 18:15     ` Anton Khirnov
  2022-07-18 18:18       ` James Almer
  2022-07-19 12:43     ` Anton Khirnov
  1 sibling, 1 reply; 13+ messages in thread
From: Anton Khirnov @ 2022-07-18 18:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-07-18 14:23:58)
> On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> > ---
> >   libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
> >   1 file changed, 51 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> > index 98ec030865..5e360682e6 100644
> > --- a/libavcodec/libx264.c
> > +++ b/libavcodec/libx264.c
> > @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
> >       pic->extra_sei.num_payloads = 0;
> >   }
> >   
> > +static enum AVPixelFormat csp_to_pixfmt(int csp)
> > +{
> > +    switch (csp) {
> > +#ifdef X264_CSP_I400
> > +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> > +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> > +#endif
> > +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> > +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> > +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> > +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> > +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> > +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> 
> We're still supporting old x264 versions, so you should add some 
> considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the 
> value of x264_bit_depth.

Is there much point in continuing to support 5.5 year old x264? We could
drop a lot of ugliness, including the abominable X264_init_static().

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18 17:41   ` James Almer
@ 2022-07-18 18:07     ` Anton Khirnov
  0 siblings, 0 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-07-18 18:07 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-07-18 19:41:27)
> Why not ff_encode_alloc_frame() for this? Can 
> csp_to_pixfmt(pic_out.img.i_csp) be different than ctx->pix_fmt?

Yes, the reconstructed frame is in x264's internal format, which will
typically be some flavor of nv12, even if the input format is fully
planar.

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18  7:12 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
  2022-07-18 12:23   ` James Almer
@ 2022-07-18 17:41   ` James Almer
  2022-07-18 18:07     ` Anton Khirnov
  1 sibling, 1 reply; 13+ messages in thread
From: James Almer @ 2022-07-18 17:41 UTC (permalink / raw)
  To: ffmpeg-devel

On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> ---
>   libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 98ec030865..5e360682e6 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
>       pic->extra_sei.num_payloads = 0;
>   }
>   
> +static enum AVPixelFormat csp_to_pixfmt(int csp)
> +{
> +    switch (csp) {
> +#ifdef X264_CSP_I400
> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> +#endif
> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
> +    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
> +    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;
> +    };
> +    return AV_PIX_FMT_NONE;
> +}
> +
>   static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>                         int *got_packet)
>   {
> @@ -496,6 +515,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>           if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
>               return AVERROR_EXTERNAL;
>   
> +        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
> +            AVCodecInternal *avci = ctx->internal;
> +
> +            av_frame_unref(avci->recon_frame);
> +
> +            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
> +            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
> +                av_log(ctx, AV_LOG_ERROR,
> +                       "Unhandled reconstructed frame colorspace: %d\n",
> +                       pic_out.img.i_csp);
> +                return AVERROR(ENOSYS);
> +            }
> +
> +            avci->recon_frame->width  = ctx->width;
> +            avci->recon_frame->height = ctx->height;
> +            for (int i = 0; i < pic_out.img.i_plane; i++) {
> +                avci->recon_frame->data[i]     = pic_out.img.plane[i];
> +                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
> +            }
> +
> +            ret = av_frame_make_writable(avci->recon_frame);

Why not ff_encode_alloc_frame() for this? Can 
csp_to_pixfmt(pic_out.img.i_csp) be different than ctx->pix_fmt?


> +            if (ret < 0) {
> +                av_frame_unref(avci->recon_frame);
> +                return ret;
> +            }
> +        }
> +
>           ret = encode_nals(ctx, pkt, nal, nnal);
>           if (ret < 0)
>               return ret;
> @@ -928,6 +974,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
>       if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
>           x4->params.b_repeat_headers = 0;
>   
> +    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
> +        x4->params.b_full_recon = 1;
> +
>       if(x4->x264opts){
>           const char *p= x4->x264opts;
>           while(p){
> @@ -1223,7 +1272,8 @@ FFCodec ff_libx264_encoder = {
>       .p.id             = AV_CODEC_ID_H264,
>       .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>                           AV_CODEC_CAP_OTHER_THREADS |
> -                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> +                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
>       .p.priv_class     = &x264_class,
>       .p.wrapper_name   = "libx264",
>       .priv_data_size   = sizeof(X264Context),
_______________________________________________
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] 13+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-18  7:12 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
@ 2022-07-18 12:23   ` James Almer
  2022-07-18 18:15     ` Anton Khirnov
  2022-07-19 12:43     ` Anton Khirnov
  2022-07-18 17:41   ` James Almer
  1 sibling, 2 replies; 13+ messages in thread
From: James Almer @ 2022-07-18 12:23 UTC (permalink / raw)
  To: ffmpeg-devel

On 7/18/2022 4:12 AM, Anton Khirnov wrote:
> ---
>   libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 98ec030865..5e360682e6 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
>       pic->extra_sei.num_payloads = 0;
>   }
>   
> +static enum AVPixelFormat csp_to_pixfmt(int csp)
> +{
> +    switch (csp) {
> +#ifdef X264_CSP_I400
> +    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
> +    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
> +#endif
> +    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
> +    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
> +    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
> +    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
> +    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
> +    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;

We're still supporting old x264 versions, so you should add some 
considerations for 9 bit pixfmts. On X264_BUILD < 153, just check the 
value of x264_bit_depth.

> +    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
> +    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;

Missing X264_CSP_NV21 (wrapped like X264_CSP_I400).

That aside, LGTM.

> +    };
> +    return AV_PIX_FMT_NONE;
> +}
> +
>   static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>                         int *got_packet)
>   {
> @@ -496,6 +515,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
>           if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
>               return AVERROR_EXTERNAL;
>   
> +        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
> +            AVCodecInternal *avci = ctx->internal;
> +
> +            av_frame_unref(avci->recon_frame);
> +
> +            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
> +            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
> +                av_log(ctx, AV_LOG_ERROR,
> +                       "Unhandled reconstructed frame colorspace: %d\n",
> +                       pic_out.img.i_csp);
> +                return AVERROR(ENOSYS);
> +            }
> +
> +            avci->recon_frame->width  = ctx->width;
> +            avci->recon_frame->height = ctx->height;
> +            for (int i = 0; i < pic_out.img.i_plane; i++) {
> +                avci->recon_frame->data[i]     = pic_out.img.plane[i];
> +                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
> +            }
> +
> +            ret = av_frame_make_writable(avci->recon_frame);
> +            if (ret < 0) {
> +                av_frame_unref(avci->recon_frame);
> +                return ret;
> +            }
> +        }
> +
>           ret = encode_nals(ctx, pkt, nal, nnal);
>           if (ret < 0)
>               return ret;
> @@ -928,6 +974,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
>       if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
>           x4->params.b_repeat_headers = 0;
>   
> +    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
> +        x4->params.b_full_recon = 1;
> +
>       if(x4->x264opts){
>           const char *p= x4->x264opts;
>           while(p){
> @@ -1223,7 +1272,8 @@ FFCodec ff_libx264_encoder = {
>       .p.id             = AV_CODEC_ID_H264,
>       .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
>                           AV_CODEC_CAP_OTHER_THREADS |
> -                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> +                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
>       .p.priv_class     = &x264_class,
>       .p.wrapper_name   = "libx264",
>       .priv_data_size   = sizeof(X264Context),
_______________________________________________
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] 13+ messages in thread

* [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME
  2022-07-17 22:06 [FFmpeg-devel] [PATCH 4/4] " Michael Niedermayer
@ 2022-07-18  7:12 ` Anton Khirnov
  2022-07-18 12:23   ` James Almer
  2022-07-18 17:41   ` James Almer
  0 siblings, 2 replies; 13+ messages in thread
From: Anton Khirnov @ 2022-07-18  7:12 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavcodec/libx264.c | 52 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 98ec030865..5e360682e6 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -311,6 +311,25 @@ static void free_picture(AVCodecContext *ctx)
     pic->extra_sei.num_payloads = 0;
 }
 
+static enum AVPixelFormat csp_to_pixfmt(int csp)
+{
+    switch (csp) {
+#ifdef X264_CSP_I400
+    case X264_CSP_I400:                         return AV_PIX_FMT_GRAY8;
+    case X264_CSP_I400 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_GRAY10;
+#endif
+    case X264_CSP_I420:                         return AV_PIX_FMT_YUV420P;
+    case X264_CSP_I420 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV420P10;
+    case X264_CSP_I422:                         return AV_PIX_FMT_YUV422P;
+    case X264_CSP_I422 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV422P10;
+    case X264_CSP_I444:                         return AV_PIX_FMT_YUV444P;
+    case X264_CSP_I444 | X264_CSP_HIGH_DEPTH:   return AV_PIX_FMT_YUV444P10;
+    case X264_CSP_NV12:                         return AV_PIX_FMT_NV12;
+    case X264_CSP_NV16:                         return AV_PIX_FMT_NV16;
+    };
+    return AV_PIX_FMT_NONE;
+}
+
 static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                       int *got_packet)
 {
@@ -496,6 +515,33 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
         if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
             return AVERROR_EXTERNAL;
 
+        if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
+            AVCodecInternal *avci = ctx->internal;
+
+            av_frame_unref(avci->recon_frame);
+
+            avci->recon_frame->format = csp_to_pixfmt(pic_out.img.i_csp);
+            if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
+                av_log(ctx, AV_LOG_ERROR,
+                       "Unhandled reconstructed frame colorspace: %d\n",
+                       pic_out.img.i_csp);
+                return AVERROR(ENOSYS);
+            }
+
+            avci->recon_frame->width  = ctx->width;
+            avci->recon_frame->height = ctx->height;
+            for (int i = 0; i < pic_out.img.i_plane; i++) {
+                avci->recon_frame->data[i]     = pic_out.img.plane[i];
+                avci->recon_frame->linesize[i] = pic_out.img.i_stride[i];
+            }
+
+            ret = av_frame_make_writable(avci->recon_frame);
+            if (ret < 0) {
+                av_frame_unref(avci->recon_frame);
+                return ret;
+            }
+        }
+
         ret = encode_nals(ctx, pkt, nal, nnal);
         if (ret < 0)
             return ret;
@@ -928,6 +974,9 @@ static av_cold int X264_init(AVCodecContext *avctx)
     if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
         x4->params.b_repeat_headers = 0;
 
+    if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME)
+        x4->params.b_full_recon = 1;
+
     if(x4->x264opts){
         const char *p= x4->x264opts;
         while(p){
@@ -1223,7 +1272,8 @@ FFCodec ff_libx264_encoder = {
     .p.id             = AV_CODEC_ID_H264,
     .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
                         AV_CODEC_CAP_OTHER_THREADS |
-                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+                        AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                        AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .p.priv_class     = &x264_class,
     .p.wrapper_name   = "libx264",
     .priv_data_size   = sizeof(X264Context),
-- 
2.34.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] 13+ messages in thread

end of thread, other threads:[~2022-08-08  8:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08  8:57 [FFmpeg-devel] [PATCH] lavc/libx264: support AV_CODEC_CAP_ENCODER_RECON_FRAME Martin Storsjö
2022-08-08  8:59 ` Martin Storsjö
  -- strict thread matches above, loose matches on Subject: below --
2022-07-19 18:13 [FFmpeg-devel] [PATCH v2] " James Almer
2022-07-28 14:24 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2022-07-28 14:33   ` James Almer
2022-07-17 22:06 [FFmpeg-devel] [PATCH 4/4] " Michael Niedermayer
2022-07-18  7:12 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2022-07-18 12:23   ` James Almer
2022-07-18 18:15     ` Anton Khirnov
2022-07-18 18:18       ` James Almer
2022-07-18 18:29         ` Anton Khirnov
2022-07-19 11:44           ` Michael Niedermayer
2022-07-19 12:43     ` Anton Khirnov
2022-07-18 17:41   ` James Almer
2022-07-18 18:07     ` Anton Khirnov

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