Skip to content

Instantly share code, notes, and snippets.

@fancycode
Created October 28, 2013 15:52
Show Gist options
  • Save fancycode/7199355 to your computer and use it in GitHub Desktop.
Save fancycode/7199355 to your computer and use it in GitHub Desktop.
Patch that replaces the 4-byte length fields with NAL start codes, so playing MKV files containing HEVC video works.
diff --git a/libavcodec/libde265.c b/libavcodec/libde265.c
index e3a6d50..d2115c0 100644
--- a/libavcodec/libde265.c
+++ b/libavcodec/libde265.c
@@ -29,6 +29,7 @@
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
+#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "internal.h"
@@ -51,6 +52,14 @@ static int de265_decode(AVCodecContext *avctx,
const uint8_t* src[4];
int stride[4];
+ // replace 4-byte length fields with NAL start codes
+ uint8_t* avpkt_data = avpkt->data;
+ uint8_t* avpkt_end = avpkt->data + avpkt->size;
+ while (avpkt_data + 4 < avpkt_end) {
+ int nal_size = AV_RB32(avpkt_data);
+ AV_WB32(avpkt_data, 0x00000001);
+ avpkt_data += 4 + nal_size;
+ }
err = de265_decode_data(ctx->decoder, avpkt->data, avpkt->size);
if (err != DE265_OK) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment