[FFmpeg-devel] [PATCH] Recognize MJPEG at probing
Andrey Utkin
andrey.krieger.utkin at gmail.com
Mon Jun 9 10:14:12 CEST 2014
Fixes https://trac.ffmpeg.org/ticket/3679
In the ticket, another approach is mentioned: to interpret multipart/x-mixed-replace content-type in HTTP protocol driver. But as long as MJPEG decoder works well even with garbage in the beginning of frame (it uses JPEG markers), this is not critical now.
---8<---
Based on patch from Carl Eugen Hoyos
---
libavformat/rawdec.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index 9b2aa35..cde5f79 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -134,8 +134,22 @@ AVInputFormat ff_latm_demuxer = {
};
#endif
+static int mjpeg_probe(AVProbeData *p)
+{
+ static const char ct_jpeg[] = "\r\nContent-Type: image/jpeg\r\n\r\n";
+
+ /* Detect HTTP-streamed MJPEG in multipart/x-mixed-replace content-type */
+ if (memmem(p->buf, p->buf_size, ct_jpeg, sizeof(ct_jpeg) - 1))
+ return AVPROBE_SCORE_MAX;
+
+ if (AV_RB16(p->buf) == 0xffd8)
+ return AVPROBE_SCORE_EXTENSION / 2;
+
+ return 0;
+}
+
#if CONFIG_MJPEG_DEMUXER
-FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
+FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", mjpeg_probe, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
#endif
#if CONFIG_MLP_DEMUXER
--
1.8.3.2
More information about the ffmpeg-devel
mailing list