PR #23861 opened by Steven Xiao (younengxiao)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23861
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23861.patch

When the muxer sets AV_CODEC_FLAG_GLOBAL_HEADER (as MKV does), the codec
must populate avctx->extradata with the sequence header so the muxer can
write the av1C codec private entry. Otherwise, the mkv muxer will return
AVERROR_INVALIDDATA on the first packet (Invalid data found when
processing input).

Example usage:
  ffmpeg -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4 -c:v 
av1_d3d12va output.mkv



>From ae8842ff094fae45a86c6c5ecaa08404045ff598 Mon Sep 17 00:00:00 2001
From: younengxiao <[email protected]>
Date: Wed, 24 Jun 2026 13:40:02 -0400
Subject: [PATCH] avcodec/d3d12va_encode: set extradata for global header when
 muxing AV1 to MKV

When the muxer sets AV_CODEC_FLAG_GLOBAL_HEADER (as MKV does), the codec
must populate avctx->extradata with the sequence header so the muxer can
write the av1C codec private entry. Otherwise, the mkv muxer will return
AVERROR_INVALIDDATA on the first packet (Invalid data found when
processing input).

Example usage:
  # use mkv container:
  ffmpeg -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4 -c:v 
av1_d3d12va output.mkv

Signed-off-by: younengxiao <[email protected]>
---
 libavcodec/d3d12va_encode.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index d7125db929..442dbc6a4a 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -1858,6 +1858,27 @@ int ff_d3d12va_encode_init(AVCodecContext *avctx)
     if (!base_ctx->encode_fifo)
         return AVERROR(ENOMEM);
 
+    if (ctx->codec->write_sequence_header &&
+        avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
+        char header_data[MAX_PARAM_BUFFER_SIZE];
+        size_t header_bit_len = 8 * sizeof(header_data);
+
+        err = ctx->codec->write_sequence_header(avctx, header_data, 
&header_bit_len);
+        if (err < 0) {
+            av_log(avctx, AV_LOG_ERROR, "Failed to write sequence header "
+                   "for global header: %d.\n", err);
+            goto fail;
+        }
+        avctx->extradata_size = (int)((header_bit_len + 7) / 8);
+        avctx->extradata = av_mallocz(avctx->extradata_size +
+                                      AV_INPUT_BUFFER_PADDING_SIZE);
+        if (!avctx->extradata) {
+            err = AVERROR(ENOMEM);
+            goto fail;
+        }
+        memcpy(avctx->extradata, header_data, avctx->extradata_size);
+    }
+
     return 0;
 
 fail:
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to