[FFmpeg-devel] [PATCH 2/2] ffserver JPEG support for snapshots.

Rick van der Zwet info at rickvanderzwet.nl
Sun Mar 4 14:09:03 CET 2012


Snapshots (aka thumbnails) are great to have for displaying an (reset) initial
frame for example. This snapshot support should be used together which commit
bbb4304d3df3efe15fe33f289d10224caf69c2b5 to properly close the stream when an
single frame is sent.

Signed-off-by: Rick van der Zwet <info at rickvanderzwet.nl>
---
 ffserver.c               |    3 ---
 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    1 +
 libavformat/jpeg.c       |   42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100644 libavformat/jpeg.c

diff --git a/ffserver.c b/ffserver.c
index b02d0b4..4b319b4 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -4267,9 +4267,6 @@ static int parse_ffconfig(const char *filename)
                     stream->fmt = NULL;
                 } else {
                     stream->stream_type = STREAM_TYPE_LIVE;
-                    /* jpeg cannot be used here, so use single frame jpeg */
-                    if (!strcmp(arg, "jpeg"))
-                        strcpy(arg, "mjpeg");
                     stream->fmt = ffserver_guess_format(arg, NULL, NULL);
                     if (!stream->fmt) {
                         ERROR("Unknown Format: %s\n", arg);
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5bf2fda..17085ea 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -129,6 +129,7 @@ OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
 OBJS-$(CONFIG_IV8_DEMUXER)               += iv8.o
 OBJS-$(CONFIG_IVF_DEMUXER)               += ivfdec.o
 OBJS-$(CONFIG_IVF_MUXER)                 += ivfenc.o
+OBJS-$(CONFIG_JPEG_MUXER)                += jpeg.o
 OBJS-$(CONFIG_JV_DEMUXER)                += jvdec.o
 OBJS-$(CONFIG_LATM_DEMUXER)              += rawdec.o
 OBJS-$(CONFIG_LATM_MUXER)                += latmenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 614b341..0fbf635 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -125,6 +125,7 @@ void av_register_all(void)
     REGISTER_DEMUXER  (ISS, iss);
     REGISTER_DEMUXER  (IV8, iv8);
     REGISTER_MUXDEMUX (IVF, ivf);
+    REGISTER_MUXER    (JPEG, jpeg);
     REGISTER_DEMUXER  (JV, jv);
     REGISTER_MUXDEMUX (LATM, latm);
     REGISTER_DEMUXER  (LMLM4, lmlm4);
diff --git a/libavformat/jpeg.c b/libavformat/jpeg.c
new file mode 100644
index 0000000..892c5a9
--- /dev/null
+++ b/libavformat/jpeg.c
@@ -0,0 +1,42 @@
+/*
+ * Multipart JPEG format
+ * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "avformat.h"
+
+/* Single Frame JPEG */
+
+#define BOUNDARY_TAG "ffserver"
+
+static int jpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    avio_write(s->pb, pkt->data, pkt->size);
+    avio_flush(s->pb);
+    return 0;
+}
+
+AVOutputFormat ff_jpeg_muxer = {
+    .name              = "jpeg",
+    .long_name         = NULL_IF_CONFIG_SMALL("Single Frame JPEG format"),
+    .mime_type         = "image/jpeg",
+    .extensions        = "jpg",
+    .audio_codec       = CODEC_ID_NONE,
+    .video_codec       = CODEC_ID_MJPEG,
+    .write_packet      = jpeg_write_packet,
+};
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list