[FFmpeg-cvslog] avformat: Add SMJPEG demuxer.

Paul B Mahol git at videolan.org
Thu Dec 29 02:01:04 CET 2011


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Dec 24 01:57:34 2011 +0000| [b5aecc6bc025461e016baad4486c4e1cacbd6263] | committer: Anton Khirnov

avformat: Add SMJPEG demuxer.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b5aecc6bc025461e016baad4486c4e1cacbd6263
---

 Changelog                |    1 +
 doc/general.texi         |    2 +
 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    1 +
 libavformat/smjpeg.c     |  187 ++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/version.h    |    2 +-
 6 files changed, 193 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index 8176297..19ba73a 100644
--- a/Changelog
+++ b/Changelog
@@ -112,6 +112,7 @@ easier to use. The changes are:
 - OpenMG Audio muxer
 - Simple segmenting muxer
 - Indeo 4 decoder
+- SMJPEG demuxer
 
 
 version 0.7:
diff --git a/doc/general.texi b/doc/general.texi
index 313d73f..8eaa97b 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -296,6 +296,8 @@ library:
     @tab Used in Sierra CD-ROM games.
 @item Smacker                   @tab   @tab X
     @tab Multimedia format used by many games.
+ at item SMJPEG                    @tab   @tab X
+    @tab Used in certain Loki game ports.
 @item Sony OpenMG (OMA)         @tab X @tab X
     @tab Audio format used in Sony Sonic Stage and Sony Vegas.
 @item Sony PlayStation STR      @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index ee623d7..de44050 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -273,6 +273,7 @@ OBJS-$(CONFIG_SEGMENT_MUXER)             += segment.o
 OBJS-$(CONFIG_SHORTEN_DEMUXER)           += rawdec.o
 OBJS-$(CONFIG_SIFF_DEMUXER)              += siff.o
 OBJS-$(CONFIG_SMACKER_DEMUXER)           += smacker.o
+OBJS-$(CONFIG_SMJPEG_DEMUXER)            += smjpeg.o
 OBJS-$(CONFIG_SOL_DEMUXER)               += sol.o pcm.o
 OBJS-$(CONFIG_SOX_DEMUXER)               += soxdec.o pcm.o
 OBJS-$(CONFIG_SOX_MUXER)                 += soxenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 083ee08..1debddb 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -201,6 +201,7 @@ void av_register_all(void)
     REGISTER_DEMUXER  (SHORTEN, shorten);
     REGISTER_DEMUXER  (SIFF, siff);
     REGISTER_DEMUXER  (SMACKER, smacker);
+    REGISTER_DEMUXER  (SMJPEG, smjpeg);
     REGISTER_DEMUXER  (SOL, sol);
     REGISTER_MUXDEMUX (SOX, sox);
     REGISTER_MUXDEMUX (SPDIF, spdif);
diff --git a/libavformat/smjpeg.c b/libavformat/smjpeg.c
new file mode 100644
index 0000000..dc94361
--- /dev/null
+++ b/libavformat/smjpeg.c
@@ -0,0 +1,187 @@
+/*
+ * SMJPEG demuxer
+ * Copyright (c) 2011 Paul B Mahol
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * This is a demuxer for Loki SDL Motion JPEG files
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "riff.h"
+
+static const AVCodecTag codec_smjpeg_video_tags[] = {
+    { CODEC_ID_MJPEG,             MKTAG('J', 'F', 'I', 'F') },
+    { CODEC_ID_NONE, 0 },
+};
+
+static const AVCodecTag codec_smjpeg_audio_tags[] = {
+    { CODEC_ID_ADPCM_IMA_SMJPEG,  MKTAG('A', 'P', 'C', 'M') },
+    { CODEC_ID_PCM_S16LE,         MKTAG('N', 'O', 'N', 'E') },
+    { CODEC_ID_NONE, 0 },
+};
+
+typedef struct SMJPEGContext {
+    int audio_stream_index;
+    int video_stream_index;
+} SMJPEGContext;
+
+static int smjpeg_probe(AVProbeData *p)
+{
+    if (!memcmp(p->buf, "\x0\xaSMJPEG", 8))
+        return AVPROBE_SCORE_MAX;
+    return 0;
+}
+
+static int smjpeg_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+    SMJPEGContext *sc = s->priv_data;
+    AVStream *ast = NULL, *vst = NULL;
+    AVIOContext *pb = s->pb;
+    uint32_t version, htype, hlength, duration;
+    char *comment;
+
+    avio_skip(pb, 8); // magic
+    version = avio_rb32(pb);
+    if (version)
+        av_log_ask_for_sample(s, "unknown version %d\n", version);
+
+    duration = avio_rb32(pb); // in msec
+
+    while (!pb->eof_reached) {
+        htype = avio_rl32(pb);
+        switch (htype) {
+        case MKTAG('_', 'T', 'X', 'T'):
+            hlength = avio_rb32(pb);
+            if (!hlength || hlength > 512)
+                return AVERROR_INVALIDDATA;
+            comment = av_malloc(hlength + 1);
+            if (!comment)
+                return AVERROR(ENOMEM);
+            if (avio_read(pb, comment, hlength) != hlength) {
+                av_freep(&comment);
+                av_log(s, AV_LOG_ERROR, "error when reading comment\n");
+                return AVERROR_INVALIDDATA;
+            }
+            comment[hlength] = 0;
+            av_dict_set(&s->metadata, "comment", comment,
+                        AV_DICT_DONT_STRDUP_VAL);
+            break;
+        case MKTAG('_', 'S', 'N', 'D'):
+            if (ast) {
+                av_log_ask_for_sample(s, "multiple audio streams not supported\n");
+                return AVERROR_INVALIDDATA;
+            }
+            hlength = avio_rb32(pb);
+            if (hlength < 8)
+                return AVERROR_INVALIDDATA;
+            ast = avformat_new_stream(s, 0);
+            if (!ast)
+                return AVERROR(ENOMEM);
+            ast->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
+            ast->codec->sample_rate = avio_rb16(pb);
+            ast->codec->bits_per_coded_sample = avio_r8(pb);
+            ast->codec->channels    = avio_r8(pb);
+            ast->codec->codec_tag   = avio_rl32(pb);
+            ast->codec->codec_id    = ff_codec_get_id(codec_smjpeg_audio_tags,
+                                                      ast->codec->codec_tag);
+            ast->duration           = duration;
+            sc->audio_stream_index  = ast->index;
+            avpriv_set_pts_info(ast, 32, 1, 1000);
+            avio_skip(pb, hlength - 8);
+            break;
+        case MKTAG('_', 'V', 'I', 'D'):
+            if (vst) {
+                av_log_ask_for_sample(s, "multiple video streams not supported\n");
+                return AVERROR_INVALIDDATA;
+            }
+            hlength = avio_rb32(pb);
+            if (hlength < 12)
+                return AVERROR_INVALIDDATA;
+            avio_skip(pb, 4); // number of frames
+            vst = avformat_new_stream(s, 0);
+            if (!vst)
+                return AVERROR(ENOMEM);
+            vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+            vst->codec->width      = avio_rb16(pb);
+            vst->codec->height     = avio_rb16(pb);
+            vst->codec->codec_tag  = avio_rl32(pb);
+            vst->codec->codec_id   = ff_codec_get_id(codec_smjpeg_video_tags,
+                                                     vst->codec->codec_tag);
+            vst->duration          = duration;
+            sc->video_stream_index = vst->index;
+            avpriv_set_pts_info(vst, 32, 1, 1000);
+            avio_skip(pb, hlength - 12);
+            break;
+        case MKTAG('H', 'E', 'N', 'D'):
+            return 0;
+        default:
+            av_log(s, AV_LOG_ERROR, "unknown header %x\n", htype);
+            return AVERROR_INVALIDDATA;
+        }
+    }
+
+    return AVERROR_EOF;
+}
+
+static int smjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    SMJPEGContext *sc = s->priv_data;
+    uint32_t dtype, ret, size, timestamp;
+
+    if (s->pb->eof_reached)
+        return AVERROR_EOF;
+    dtype = avio_rl32(s->pb);
+    switch (dtype) {
+    case MKTAG('s', 'n', 'd', 'D'):
+        timestamp = avio_rb32(s->pb);
+        size = avio_rb32(s->pb);
+        ret = av_get_packet(s->pb, pkt, size);
+        pkt->stream_index = sc->audio_stream_index;
+        pkt->pts = timestamp;
+        break;
+    case MKTAG('v', 'i', 'd', 'D'):
+        timestamp = avio_rb32(s->pb);
+        size = avio_rb32(s->pb);
+        ret = av_get_packet(s->pb, pkt, size);
+        pkt->stream_index = sc->video_stream_index;
+        pkt->pts = timestamp;
+        break;
+    case MKTAG('D', 'O', 'N', 'E'):
+        ret = AVERROR_EOF;
+        break;
+    default:
+        av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype);
+        ret = AVERROR_INVALIDDATA;
+        break;
+    }
+    return ret;
+}
+
+AVInputFormat ff_smjpeg_demuxer = {
+    .name           = "smjpeg",
+    .long_name      = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"),
+    .priv_data_size = sizeof(SMJPEGContext),
+    .read_probe     = smjpeg_probe,
+    .read_header    = smjpeg_read_header,
+    .read_packet    = smjpeg_read_packet,
+    .extensions     = "mjpg",
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index a841701..e113a24 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 18
+#define LIBAVFORMAT_VERSION_MINOR 19
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list