Statistics
| Branch: | Revision:

ffmpeg / libavformat / mpjpeg.c @ a7eb3c8d

History | View | Annotate | Download (2.87 KB)

1 0250738f Fabrice Bellard
/*
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
#include "avformat.h"
20
21
/* Multipart JPEG */
22
23
#define BOUNDARY_TAG "ffserver"
24
25 764ef400 Mike Melanson
#ifdef CONFIG_ENCODERS
26 0250738f Fabrice Bellard
static int mpjpeg_write_header(AVFormatContext *s)
27
{
28 0c1a9eda Zdenek Kabelac
    uint8_t buf1[256];
29 0250738f Fabrice Bellard
30
    snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
31
    put_buffer(&s->pb, buf1, strlen(buf1));
32
    put_flush_packet(&s->pb);
33
    return 0;
34
}
35
36
static int mpjpeg_write_packet(AVFormatContext *s, int stream_index, 
37 49057904 Fabrice Bellard
                               const uint8_t *buf, int size, int64_t pts)
38 0250738f Fabrice Bellard
{
39 0c1a9eda Zdenek Kabelac
    uint8_t buf1[256];
40 0250738f Fabrice Bellard
41
    snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
42
    put_buffer(&s->pb, buf1, strlen(buf1));
43
    put_buffer(&s->pb, buf, size);
44
45
    snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
46
    put_buffer(&s->pb, buf1, strlen(buf1));
47
    put_flush_packet(&s->pb);
48
    return 0;
49
}
50
51
static int mpjpeg_write_trailer(AVFormatContext *s)
52
{
53
    return 0;
54
}
55
56
static AVOutputFormat mpjpeg_format = {
57
    "mpjpeg",
58
    "Mime multipart JPEG format",
59
    "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
60
    "mjpg",
61
    0,
62
    CODEC_ID_NONE,
63
    CODEC_ID_MJPEG,
64
    mpjpeg_write_header,
65
    mpjpeg_write_packet,
66
    mpjpeg_write_trailer,
67
};
68
69
70
/*************************************/
71
/* single frame JPEG */
72
73
static int single_jpeg_write_header(AVFormatContext *s)
74
{
75
    return 0;
76
}
77
78
static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
79 49057904 Fabrice Bellard
                                    const uint8_t *buf, int size, int64_t pts)
80 0250738f Fabrice Bellard
{
81
    put_buffer(&s->pb, buf, size);
82
    put_flush_packet(&s->pb);
83
    return 1; /* no more data can be sent */
84
}
85
86
static int single_jpeg_write_trailer(AVFormatContext *s)
87
{
88
    return 0;
89
}
90
91
static AVOutputFormat single_jpeg_format = {
92
    "singlejpeg",
93
    "single JPEG image",
94
    "image/jpeg",
95
    NULL, /* note: no extension to favorize jpeg multiple images match */
96
    0,
97
    CODEC_ID_NONE,
98
    CODEC_ID_MJPEG,
99
    single_jpeg_write_header,
100
    single_jpeg_write_packet,
101
    single_jpeg_write_trailer,
102
};
103
104
int jpeg_init(void)
105
{
106
    av_register_output_format(&mpjpeg_format);
107
    av_register_output_format(&single_jpeg_format);
108
    return 0;
109
}
110 764ef400 Mike Melanson
#endif //CONFIG_ENCODERS