[FFmpeg-devel] ffserver jpg output

Caligula useraccount caligula at sarijopen.student.utwente.nl
Thu Apr 30 13:35:22 CEST 2015


Ave all

Background:
I'm using ffserver, which feeds of a webcam, to serve .swf and .jpg files.

To serve the .jpg files, I use the patch mentioned in http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2006-June/013107.html
Over the years I "ported" the patch to more current versions of ffmpeg.

Attached is a patch for 2.6.x, older versions are available at 
http://sarijopen.student.utwente.nl/caligula/ffmpeg/

Greetings Martijn
(Who hopes that ffserver is kept alive)





diff -Nrup ffmpeg-2.6.1--orig/ffserver.c ffmpeg-2.6.1/ffserver.c
--- ffmpeg-2.6.1--orig/ffserver.c	2015-03-16 20:25:48.000000000 +0100
+++ ffmpeg-2.6.1/ffserver.c	2015-04-05 02:33:53.000000000 +0200
@@ -967,6 +967,10 @@ static int handle_connection(HTTPContext
          /* close connection if trailer sent */
          if (c->state == HTTPSTATE_SEND_DATA_TRAILER)
              return -1;
+        /* Check if it is a single jpeg frame 123 */
+        if (c->stream->single_frame && c->data_count > c->cur_frame_bytes && c->cur_frame_bytes > 0) {
+            close_connection(c);
+        }
          break;
      case HTTPSTATE_RECEIVE_DATA:
          /* no need to read if no events */
diff -Nrup ffmpeg-2.6.1--orig/ffserver_config.c ffmpeg-2.6.1/ffserver_config.c
--- ffmpeg-2.6.1--orig/ffserver_config.c	2015-03-16 20:25:48.000000000 +0100
+++ ffmpeg-2.6.1/ffserver_config.c	2015-04-05 02:33:53.000000000 +0200
@@ -862,8 +862,10 @@ static int ffserver_parse_config_stream(
          } else {
              stream->stream_type = STREAM_TYPE_LIVE;
              /* JPEG cannot be used here, so use single frame MJPEG */
-            if (!strcmp(arg, "jpeg"))
-                strcpy(arg, "mjpeg");
+            if (!strcmp(arg, "jpeg")) {
+                strcpy(arg, "singlejpeg");
+                stream->single_frame=1; 
+            }
              stream->fmt = ffserver_guess_format(arg, NULL, NULL);
              if (!stream->fmt)
                  ERROR("Unknown Format: '%s'\n", arg);
diff -Nrup ffmpeg-2.6.1--orig/ffserver_config.h ffmpeg-2.6.1/ffserver_config.h
--- ffmpeg-2.6.1--orig/ffserver_config.h	2015-03-16 20:25:48.000000000 +0100
+++ ffmpeg-2.6.1/ffserver_config.h	2015-04-05 02:33:53.000000000 +0200
@@ -79,6 +79,7 @@ typedef struct FFServerStream {
      int multicast_port;           /* first port used for multicast */
      int multicast_ttl;
      int loop;                     /* if true, send the stream in loops (only meaningful if file) */
+    char single_frame;            /* only single frame */

      /* feed specific */
      int feed_opened;              /* true if someone is writing to the feed */
diff -Nrup ffmpeg-2.6.1--orig/libavformat/allformats.c ffmpeg-2.6.1/libavformat/allformats.c
--- ffmpeg-2.6.1--orig/libavformat/allformats.c	2015-03-16 20:25:52.000000000 +0100
+++ ffmpeg-2.6.1/libavformat/allformats.c	2015-04-05 02:33:53.000000000 +0200
@@ -273,6 +273,7 @@ void av_register_all(void)
      REGISTER_MUXER   (SEGMENT,          stream_segment);
      REGISTER_DEMUXER (SHORTEN,          shorten);
      REGISTER_DEMUXER (SIFF,             siff);
+    REGISTER_MUXER   (SINGLEJPEG,       singlejpeg);
      REGISTER_DEMUXER (SLN,              sln);
      REGISTER_DEMUXER (SMACKER,          smacker);
      REGISTER_MUXDEMUX(SMJPEG,           smjpeg);
diff -Nrup ffmpeg-2.6.1--orig/libavformat/rawenc.c ffmpeg-2.6.1/libavformat/rawenc.c
--- ffmpeg-2.6.1--orig/libavformat/rawenc.c	2015-03-16 20:25:54.000000000 +0100
+++ ffmpeg-2.6.1/libavformat/rawenc.c	2015-04-05 02:33:53.000000000 +0200
@@ -250,6 +250,17 @@ AVOutputFormat ff_mjpeg_muxer = {
      .write_packet      = ff_raw_write_packet,
      .flags             = AVFMT_NOTIMESTAMPS,
  };
+
+AVOutputFormat ff_singlejpeg_muxer = {
+    .name              = "singlejpeg",
+    .long_name         = NULL_IF_CONFIG_SMALL("JPEG single image"),
+    .mime_type         = "image/jpeg",
+    .extensions        = "jpg,jpeg",
+    .audio_codec       = AV_CODEC_ID_NONE,
+    .video_codec       = AV_CODEC_ID_MJPEG,
+    .write_packet      = ff_raw_write_packet,
+    .flags             = AVFMT_NOTIMESTAMPS,
+};
  #endif

  #if CONFIG_MLP_MUXER





More information about the ffmpeg-devel mailing list