Skip to content

Replace length fields with NAL start codes [PATCH] #1

Description

@fancycode

Here is a 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) {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions