]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mjpeg2jpeg_bsf.c
lavf/mpjpeg: do not include CRLF preceding boundary as part of the returned frame
[ffmpeg] / libavcodec / mjpeg2jpeg_bsf.c
index 68640db9e6212c3a33e2faa65bb49c0233d6da45..92dc3ca230031f92b83e9a0b743f2fb8f839b2d3 100644 (file)
 
 #include "libavutil/error.h"
 #include "libavutil/mem.h"
+#include "libavutil/intreadwrite.h"
 
 #include "avcodec.h"
 #include "jpegtables.h"
+#include "mjpeg.h"
 
 static const uint8_t jpeg_header[] = {
     0xff, 0xd8,                     // SOI
@@ -88,11 +90,15 @@ static int mjpeg2jpeg_filter(AVBitStreamFilterContext *bsfc,
         av_log(avctx, AV_LOG_ERROR, "input is truncated\n");
         return AVERROR_INVALIDDATA;
     }
-    if (memcmp("AVI1", buf + 6, 4)) {
-        av_log(avctx, AV_LOG_ERROR, "input is not MJPEG/AVI1\n");
+    if (AV_RB16(buf) != 0xffd8) {
+        av_log(avctx, AV_LOG_ERROR, "input is not MJPEG\n");
         return AVERROR_INVALIDDATA;
     }
-    input_skip = (buf[4] << 8) + buf[5] + 4;
+    if (buf[2] == 0xff && buf[3] == APP0) {
+        input_skip = (buf[4] << 8) + buf[5] + 4;
+    } else {
+        input_skip = 2;
+    }
     if (buf_size < input_skip) {
         av_log(avctx, AV_LOG_ERROR, "input is truncated\n");
         return AVERROR_INVALIDDATA;