[Ffmpeg-devel] single jpeg stream

Otávio Ribeiro otavio
Sun Jun 18 12:55:21 CEST 2006


Hi for all,

i started using ffmpeg to broadcast an image from a webcam. It's
perfect, but, when a try to get a single jpeg image (thumbnail) the
browser keep downloading it forever.

So i've made a patch to correct this. In my solution a new flag has been
created at FFStream structure to indicate that this is a single frame
stream. With this is possible to close the connection after a frame
transmission. I've also corrected the mime-type at libavformat.

I don't known if this is a good way to solve this but decide to share
it. Maybe can be used by someone.

tanks and waiting for suggestions,
Ot?vio Ribeiro


Follow the patch:

*** ./ffmpeg/ffserver.c 2006-06-18 10:44:19.297702512 -0300
--- ./ffmpeg_novo/ffserver.c    2006-06-18 10:48:30.583501264 -0300
*************** typedef struct FFStream {
*** 211,216 ****
--- 211,218 ----
      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 */
*************** static int handle_connection(HTTPContext
*** 863,868 ****
--- 865,875 ----
          }
          if (http_send_data(c) < 0)
              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 */
*************** static int parse_ffconfig(const char *fi
*** 3979,3985 ****
--- 3986,3992 ----
                  stream->stream_type = STREAM_TYPE_LIVE;
                  /* jpeg cannot be used here, so use single frame jpeg
*/
                  if (!strcmp(arg, "jpeg"))
-                     strcpy(arg, "mjpeg");
+                     stream->single_frame=1;
                  stream->fmt = guess_stream_format(arg, NULL, NULL);
                  if (!stream->fmt) {
                      fprintf(stderr, "%s:%d: Unknown Format: %s\n",


*** ./ffmpeg/libavformat/raw.c  2006-06-18 10:44:19.241711024 -0300
--- ./ffmpeg_novo/libavformat/raw.c     2006-06-17 19:30:57.000000000
-0300
*************** AVInputFormat ingenient_iformat = {
*** 648,653 ****
--- 648,666 ----
  };

  #ifdef CONFIG_MUXERS
+ AVOutputFormat jpeg_oformat = {
+     "jpeg",
+     "JPEG single image",
+     "image/jpeg",
+     "jpg,jpeg",
+     0,
+     0,
+     CODEC_ID_MJPEG,
+     raw_write_header,
+     raw_write_packet,
+     raw_write_trailer,
+ };
+
  AVOutputFormat mjpeg_oformat = {
      "mjpeg",
      "MJPEG video",
*************** int raw_init(void)
*** 854,859 ****
--- 867,873 ----

      av_register_input_format(&mjpeg_iformat);
      av_register_output_format(&mjpeg_oformat);
+     av_register_output_format(&jpeg_oformat);

      av_register_input_format(&ingenient_iformat);






More information about the ffmpeg-devel mailing list