From 82bc3e30107a46dd19e6a5767407f90c54050a89 Mon Sep 17 00:00:00 2001 From: btmxh Date: Sun, 30 Mar 2025 15:17:36 +0700 Subject: [PATCH 1/2] Fix MKV hw encode issue --- example/api2-samples/api2-hw-encode.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/api2-samples/api2-hw-encode.cpp b/example/api2-samples/api2-hw-encode.cpp index cd331e6b..5bc8ec5d 100644 --- a/example/api2-samples/api2-hw-encode.cpp +++ b/example/api2-samples/api2-hw-encode.cpp @@ -3,8 +3,6 @@ * * Thanks to https://github.com/mojie126, for more-less complete sample. * - * Known issues: error on the Matroska header writing. - * */ @@ -155,6 +153,11 @@ int main(int argc, char **argv) { encoder.setTimeBase(Rational{1, 1000}); encoder.setBitRate(vdec.bitRate()); + // MKV format wants global header, so + // this fixes the issue with MKV container + if (ofrmt.raw()->flags & AVFMT_GLOBALHEADER) + encoder.raw()->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + encoder.open(Codec(), ec); if (ec) { cerr << "Can't opent encodec\n"; From 1aa095e4afd01e32d6f6f24a9bd058a43dd53997 Mon Sep 17 00:00:00 2001 From: btmxh Date: Tue, 1 Apr 2025 20:46:16 +0700 Subject: [PATCH 2/2] Set global header using C++ API instead of C --- example/api2-samples/api2-hw-encode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/api2-samples/api2-hw-encode.cpp b/example/api2-samples/api2-hw-encode.cpp index 5bc8ec5d..d049f78a 100644 --- a/example/api2-samples/api2-hw-encode.cpp +++ b/example/api2-samples/api2-hw-encode.cpp @@ -155,8 +155,8 @@ int main(int argc, char **argv) { // MKV format wants global header, so // this fixes the issue with MKV container - if (ofrmt.raw()->flags & AVFMT_GLOBALHEADER) - encoder.raw()->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + if (ofrmt.flags() & AVFMT_GLOBALHEADER) + encoder.addFlags(AV_CODEC_FLAG_GLOBAL_HEADER); encoder.open(Codec(), ec); if (ec) {