00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022
00023
00024
00025 #define BOUNDARY_TAG "ffserver"
00026
00027 static int mpjpeg_write_header(AVFormatContext *s)
00028 {
00029 uint8_t buf1[256];
00030
00031 snprintf(buf1, sizeof(buf1), "--%s\r\n", BOUNDARY_TAG);
00032 avio_write(s->pb, buf1, strlen(buf1));
00033 avio_flush(s->pb);
00034 return 0;
00035 }
00036
00037 static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
00038 {
00039 uint8_t buf1[256];
00040
00041 snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\r\n");
00042 avio_write(s->pb, buf1, strlen(buf1));
00043
00044 snprintf(buf1, sizeof(buf1), "Content-length: %d\r\n\r\n", pkt->size);
00045 avio_write(s->pb, buf1, strlen(buf1));
00046 avio_write(s->pb, pkt->data, pkt->size);
00047
00048 snprintf(buf1, sizeof(buf1), "\r\n--%s\r\n", BOUNDARY_TAG);
00049 avio_write(s->pb, buf1, strlen(buf1));
00050 avio_flush(s->pb);
00051 return 0;
00052 }
00053
00054 static int mpjpeg_write_trailer(AVFormatContext *s)
00055 {
00056 return 0;
00057 }
00058
00059 AVOutputFormat ff_mpjpeg_muxer = {
00060 .name = "mpjpeg",
00061 .long_name = NULL_IF_CONFIG_SMALL("MIME multipart JPEG"),
00062 .mime_type = "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
00063 .extensions = "mjpg",
00064 .audio_codec = AV_CODEC_ID_NONE,
00065 .video_codec = AV_CODEC_ID_MJPEG,
00066 .write_header = mpjpeg_write_header,
00067 .write_packet = mpjpeg_write_packet,
00068 .write_trailer = mpjpeg_write_trailer,
00069 };