]> git.sesse.net Git - ffmpeg/blob - libavformat/mpjpeg.c
72d8e82a0dc95690ef1232ff0f96851c0fd9f785
[ffmpeg] / libavformat / mpjpeg.c
1 /*
2  * Multipart JPEG format
3  * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 #include "avformat.h"
20
21 /* Multipart JPEG */
22
23 #define BOUNDARY_TAG "ffserver"
24
25 static int mpjpeg_write_header(AVFormatContext *s)
26 {
27     uint8_t buf1[256];
28
29     snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
30     put_buffer(&s->pb, buf1, strlen(buf1));
31     put_flush_packet(&s->pb);
32     return 0;
33 }
34
35 static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
36 {
37     uint8_t buf1[256];
38
39     snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
40     put_buffer(&s->pb, buf1, strlen(buf1));
41     put_buffer(&s->pb, pkt->data, pkt->size);
42
43     snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
44     put_buffer(&s->pb, buf1, strlen(buf1));
45     put_flush_packet(&s->pb);
46     return 0;
47 }
48
49 static int mpjpeg_write_trailer(AVFormatContext *s)
50 {
51     return 0;
52 }
53
54 AVOutputFormat mpjpeg_muxer = {
55     "mpjpeg",
56     "Mime multipart JPEG format",
57     "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
58     "mjpg",
59     0,
60     CODEC_ID_NONE,
61     CODEC_ID_MJPEG,
62     mpjpeg_write_header,
63     mpjpeg_write_packet,
64     mpjpeg_write_trailer,
65 };