diff mbox series

[FFmpeg-devel] Added support to enable VBV-End feature with x265 encode

Message ID CA+kPfyCv5WEVVSRsaS-dyWwVqv3f6MpyzOvFteq8XfQj7y3xpw@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] Added support to enable VBV-End feature with x265 encode | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Yaswanth Sastry Oct. 9, 2024, 8:28 a.m. UTC
From 5cd8272ccf9902a4eb5451fed583909c63941fb7 Mon Sep 17 00:00:00 2001
From: From: yaswanthsastry <yaswanth.sastry@multicorewareinc.com>
Date: Wed, 9 Oct 2024 13:44:54 +0530
Subject: [PATCH] Added support to enable VBV-End feature with x265 encode

---
 fftools/ffmpeg_enc.c | 2 ++
 libavcodec/avcodec.h | 1 +
 libavcodec/libx265.c | 3 +++
 3 files changed, 6 insertions(+)


         x265pic.sliceType = pic->pict_type == AV_PICTURE_TYPE_I ?
@@ -786,6 +787,8 @@ static int libx265_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
         }

 #if X265_BUILD >= 167
+        if(ctx->params->vbvBufferEnd)
+
ctx->api->configure_vbv_end(ctx->encoder,&x265pic,(avctx->duration/1000000));
         sd = av_frame_get_side_data(pic, AV_FRAME_DATA_DOVI_METADATA);
         if (ctx->dovi.cfg.dv_profile && sd) {
             const AVDOVIMetadata *metadata = (const AVDOVIMetadata
*)sd->data;

Comments

Michael Niedermayer Oct. 11, 2024, 5:19 p.m. UTC | #1
On Wed, Oct 09, 2024 at 01:58:13PM +0530, Yaswanth Sastry wrote:
> From 5cd8272ccf9902a4eb5451fed583909c63941fb7 Mon Sep 17 00:00:00 2001
> From: From: yaswanthsastry <yaswanth.sastry@multicorewareinc.com>
> Date: Wed, 9 Oct 2024 13:44:54 +0530
> Subject: [PATCH] Added support to enable VBV-End feature with x265 encode
> 
> ---
>  fftools/ffmpeg_enc.c | 2 ++
>  libavcodec/avcodec.h | 1 +
>  libavcodec/libx265.c | 3 +++
>  3 files changed, 6 insertions(+)

breaks build on ubuntu:

libavcodec/libx265.c: In function ‘libx265_encode_frame’:
libavcodec/libx265.c:791:21: error: ‘x265_api’ {aka ‘const struct x265_api’} has no member named ‘configure_vbv_end’
  791 |             ctx->api->configure_vbv_end(ctx->encoder,&x265pic,(avctx->duration/1000000));
      |                     ^~
make: *** [ffbuild/common.mak:81: libavcodec/libx265.o] Error 1
make: *** Waiting for unfinished jobs....

thx

[...]
Yaswanth Sastry Oct. 17, 2024, 8:59 a.m. UTC | #2
Hi Michael,
Here is the updated patch to support Vbv-end Feature,the API in the patch
is expected to work with X265_BUILD >= 213 only.

From 64ce51509c74d7a4f9d86dd73662e561ab9c8845 Mon Sep 17 00:00:00 2001
From: yaswanthsastry <yaswanth.sastry@multicorewareinc.com>
Date: Thu, 17 Oct 2024 14:24:47 +0530
Subject: [PATCH] Added support to enable VBV-End feature with x265 encode

---
 fftools/ffmpeg_enc.c | 2 ++
 libavcodec/avcodec.h | 1 +
 libavcodec/libx265.c | 5 +++++
 3 files changed, 8 insertions(+)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index a46af4dce1..080e44f2df 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -187,7 +187,9 @@ int enc_open(void *opaque, const AVFrame *frame)
     InputStream *ist = ost->ist;
     Encoder              *e = ost->enc;
     EncoderPriv         *ep = ep_from_enc(e);
+    AVFormatContext* ic = input_files[ost->file->index]->ctx;
     AVCodecContext *enc_ctx = e->enc_ctx;
+    enc_ctx->duration = (double)(ic->duration);
     Decoder            *dec = NULL;
     const AVCodec      *enc = enc_ctx->codec;
     OutputFile          *of = ost->file;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 77ca8dee1f..e6ca5babee 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2086,6 +2086,7 @@ typedef struct AVCodecContext {
      */
     AVFrameSideData  **decoded_side_data;
     int             nb_decoded_side_data;
+    double duration;
 } AVCodecContext;

 /**
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 63cc497f83..44f3de064d 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -693,6 +693,7 @@ static int libx265_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
         }

         x265pic.pts      = pic->pts;
+        x265pic.poc      = pic->pts;
         x265pic.bitDepth =
av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;

         x265pic.sliceType = pic->pict_type == AV_PICTURE_TYPE_I ?
@@ -785,6 +786,10 @@ static int libx265_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
             }
         }

+#if X265_BUILD >= 213
+if(ctx->params->vbvBufferEnd)
+
ctx->api->configure_vbv_end(ctx->encoder,&x265pic,(avctx->duration/1000000));
+#endif
 #if X265_BUILD >= 167
         sd = av_frame_get_side_data(pic, AV_FRAME_DATA_DOVI_METADATA);
         if (ctx->dovi.cfg.dv_profile && sd) {
Anton Khirnov Oct. 17, 2024, 9:16 a.m. UTC | #3
This breaks more development rules than there are lines changed, which
is an impressive achievement.
Yaswanth Sastry Oct. 17, 2024, 12:10 p.m. UTC | #4
Hi Anton,

Thank you for your feedback. Could you please clarify which specific
development rules are being broken in this patch? I'm aiming to ensure that
the implementation is aligned with best practices and any guidelines I may
have missed.

In this patch, I’ve added support for the VBV-End feature, which is
conditional based on X265_BUILD >= 213, to ensure compatibility. The
changes are meant to enable smooth integration with FFmpeg, and the
duration value is being scaled to seconds for the VBV configuration.

If there are any specific issues with coding style, commit structure, or
any other aspect, I'd appreciate your guidance so I can address them
accordingly.

On Thu, Oct 17, 2024 at 2:46 PM Anton Khirnov <anton@khirnov.net> wrote:

> This breaks more development rules than there are lines changed, which
> is an impressive achievement.
>
> --
> 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".
>
Michael Niedermayer Oct. 20, 2024, 5:32 p.m. UTC | #5
On Thu, Oct 17, 2024 at 02:29:36PM +0530, Yaswanth Sastry wrote:
> Hi Michael,
> Here is the updated patch to support Vbv-end Feature,the API in the patch
> is expected to work with X265_BUILD >= 213 only.

[...]

>  fftools/ffmpeg_enc.c |    2 ++
>  libavcodec/avcodec.h |    1 +
>  libavcodec/libx265.c |    5 +++++
>  3 files changed, 8 insertions(+)
> 2cb3d6497999377d776d81684f8b4feee692183a  0001-Added-support-to-enable-VBV-End-feature-with-x265-en.patch
> From 64ce51509c74d7a4f9d86dd73662e561ab9c8845 Mon Sep 17 00:00:00 2001
> From: yaswanthsastry <yaswanth.sastry@multicorewareinc.com>
> Date: Thu, 17 Oct 2024 14:24:47 +0530
> Subject: [PATCH] Added support to enable VBV-End feature with x265 encode
> 
> ---
>  fftools/ffmpeg_enc.c | 2 ++
>  libavcodec/avcodec.h | 1 +
>  libavcodec/libx265.c | 5 +++++
>  3 files changed, 8 insertions(+)
> 
> diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
> index a46af4dce1..080e44f2df 100644
> --- a/fftools/ffmpeg_enc.c
> +++ b/fftools/ffmpeg_enc.c
> @@ -187,7 +187,9 @@ int enc_open(void *opaque, const AVFrame *frame)
>      InputStream *ist = ost->ist;
>      Encoder              *e = ost->enc;
>      EncoderPriv         *ep = ep_from_enc(e);
> +    AVFormatContext* ic = input_files[ost->file->index]->ctx;
>      AVCodecContext *enc_ctx = e->enc_ctx;
> +    enc_ctx->duration = (double)(ic->duration);
>      Decoder            *dec = NULL;
>      const AVCodec      *enc = enc_ctx->codec;
>      OutputFile          *of = ost->file;
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 77ca8dee1f..e6ca5babee 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h

> @@ -2086,6 +2086,7 @@ typedef struct AVCodecContext {
>       */
>      AVFrameSideData  **decoded_side_data;
>      int             nb_decoded_side_data;
> +    double duration;

this is missing doxygen documentation, APIChanges update, minor version bump
and it probably should not be a double but some integer type to be exact

User apps like (FFmpeg) could also access fields from the private context
of libx265.c via AVOption.


[...]
> @@ -785,6 +786,10 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>              }
>          }
>  
> +#if X265_BUILD >= 213
> +if(ctx->params->vbvBufferEnd)

this is not indented correctly

thx

[...]
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index a46af4dce1..080e44f2df 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -187,7 +187,9 @@  int enc_open(void *opaque, const AVFrame *frame)
     InputStream *ist = ost->ist;
     Encoder              *e = ost->enc;
     EncoderPriv         *ep = ep_from_enc(e);
+    AVFormatContext* ic = input_files[ost->file->index]->ctx;
     AVCodecContext *enc_ctx = e->enc_ctx;
+    enc_ctx->duration = (double)(ic->duration);
     Decoder            *dec = NULL;
     const AVCodec      *enc = enc_ctx->codec;
     OutputFile          *of = ost->file;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 77ca8dee1f..e6ca5babee 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2086,6 +2086,7 @@  typedef struct AVCodecContext {
      */
     AVFrameSideData  **decoded_side_data;
     int             nb_decoded_side_data;
+    double duration;
 } AVCodecContext;

 /**
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 63cc497f83..e248eb2edc 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -693,6 +693,7 @@  static int libx265_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
         }

         x265pic.pts      = pic->pts;
+        x265pic.poc      = pic->pts;
         x265pic.bitDepth =
av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth;