ffmpeg icon indicating copy to clipboard operation
ffmpeg copied to clipboard

Replace length fields with NAL start codes [PATCH]

Open fancycode opened this issue 11 years ago • 0 comments

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) {

fancycode avatar Oct 28 '13 15:10 fancycode