From: Michael Niedermayer <[email protected]>

This allows muxing properly into Matroska and MP4.

Signed-off-by: Michael Niedermayer <[email protected]>
Signed-off-by: Derek Buitenhuis <[email protected]>
---
 libavcodec/libx265.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index a6e4193..1cc1d71 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -190,10 +190,11 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
     for (i = 0; i < nnal; i++)
         ctx->header_size += nal[i].sizeBytes;
 
-    ctx->header = av_malloc(ctx->header_size);
+    ctx->header = av_malloc(ctx->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!ctx->header) {
         av_log(avctx, AV_LOG_ERROR,
-               "Cannot allocate HEVC header of size %d.\n", ctx->header_size);
+               "Cannot allocate HEVC header of size %d (%d with padding).\n",
+               ctx->header_size, ctx->header_size + 
FF_INPUT_BUFFER_PADDING_SIZE);
         libx265_encode_close(avctx);
         return AVERROR(ENOMEM);
     }
@@ -204,6 +205,14 @@ static av_cold int libx265_encode_init(AVCodecContext 
*avctx)
         buf += nal[i].sizeBytes;
     }
 
+    if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+        avctx->extradata_size = ctx->header_size;
+        avctx->extradata      = ctx->header;
+
+        ctx->header_size = 0;
+        ctx->header      = NULL;
+    }
+
     return 0;
 }
 
-- 
1.9.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to