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

Yaswanth Sastry yaswanth.sastry at multicorewareinc.com
Thu Oct 17 11:59:36 EEST 2024


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 at 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) {
-- 
2.17.1



On Fri, Oct 11, 2024 at 10:50 PM Michael Niedermayer <michael at niedermayer.cc>
wrote:

> 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 at 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
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> What is money laundering? Its paying someone and not telling the
> government.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Added-support-to-enable-VBV-End-feature-with-x265-en.patch
Type: application/octet-stream
Size: 2236 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241017/04757680/attachment.obj>


More information about the ffmpeg-devel mailing list