2003-02-02 19:18:09 +00:00
|
|
|
/*
|
|
|
|
* Multipart JPEG format
|
2009-01-19 15:46:40 +00:00
|
|
|
* Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard
|
2003-02-02 19:18:09 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2003-02-02 19:18:09 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-02-02 19:18:09 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2003-02-02 19:18:09 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-02-02 19:18:09 +00:00
|
|
|
*/
|
2014-10-29 16:57:18 +00:00
|
|
|
#include "libavutil/opt.h"
|
2003-02-02 19:18:09 +00:00
|
|
|
#include "avformat.h"
|
2023-01-27 14:06:00 +00:00
|
|
|
#include "mux.h"
|
2003-02-02 19:18:09 +00:00
|
|
|
|
|
|
|
/* Multipart JPEG */
|
|
|
|
|
2017-10-21 18:52:04 +00:00
|
|
|
#define BOUNDARY_TAG "ffmpeg"
|
2003-02-02 19:18:09 +00:00
|
|
|
|
2014-10-29 16:57:18 +00:00
|
|
|
typedef struct MPJPEGContext {
|
|
|
|
AVClass *class;
|
|
|
|
char *boundary_tag;
|
|
|
|
} MPJPEGContext;
|
|
|
|
|
2003-02-02 19:18:09 +00:00
|
|
|
static int mpjpeg_write_header(AVFormatContext *s)
|
|
|
|
{
|
2014-10-29 16:57:18 +00:00
|
|
|
MPJPEGContext *mpj = s->priv_data;
|
2015-07-08 21:53:08 +00:00
|
|
|
avio_printf(s->pb, "--%s\r\n", mpj->boundary_tag);
|
2003-02-02 19:18:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-29 02:06:32 +00:00
|
|
|
static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
|
2003-02-02 19:18:09 +00:00
|
|
|
{
|
2014-10-29 16:57:18 +00:00
|
|
|
MPJPEGContext *mpj = s->priv_data;
|
2015-07-08 21:53:08 +00:00
|
|
|
avio_printf(s->pb, "Content-type: image/jpeg\r\n");
|
2015-07-08 22:10:20 +00:00
|
|
|
avio_printf(s->pb, "Content-length: %d\r\n\r\n",
|
2015-07-03 22:48:47 +00:00
|
|
|
pkt->size);
|
2011-02-21 18:28:17 +00:00
|
|
|
avio_write(s->pb, pkt->data, pkt->size);
|
2003-02-02 19:18:09 +00:00
|
|
|
|
2015-07-08 21:53:08 +00:00
|
|
|
avio_printf(s->pb, "\r\n--%s\r\n", mpj->boundary_tag);
|
2003-02-02 19:18:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-29 16:57:18 +00:00
|
|
|
static const AVOption options[] = {
|
|
|
|
{ "boundary_tag", "Boundary tag", offsetof(MPJPEGContext, boundary_tag), AV_OPT_TYPE_STRING, {.str = BOUNDARY_TAG}, .flags = AV_OPT_FLAG_ENCODING_PARAM },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass mpjpeg_muxer_class = {
|
|
|
|
.class_name = "mpjpeg_muxer",
|
2024-01-19 12:33:28 +00:00
|
|
|
.item_name = av_default_item_name,
|
2014-10-29 16:57:18 +00:00
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2023-01-27 14:06:00 +00:00
|
|
|
const FFOutputFormat ff_mpjpeg_muxer = {
|
|
|
|
.p.name = "mpjpeg",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("MIME multipart JPEG"),
|
|
|
|
.p.mime_type = "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
|
|
|
|
.p.extensions = "mjpg",
|
2014-10-29 16:57:18 +00:00
|
|
|
.priv_data_size = sizeof(MPJPEGContext),
|
2023-01-27 14:06:00 +00:00
|
|
|
.p.audio_codec = AV_CODEC_ID_NONE,
|
|
|
|
.p.video_codec = AV_CODEC_ID_MJPEG,
|
2011-07-16 20:18:12 +00:00
|
|
|
.write_header = mpjpeg_write_header,
|
|
|
|
.write_packet = mpjpeg_write_packet,
|
2023-01-27 14:06:00 +00:00
|
|
|
.p.flags = AVFMT_NOTIMESTAMPS,
|
|
|
|
.p.priv_class = &mpjpeg_muxer_class,
|
2003-02-02 19:18:09 +00:00
|
|
|
};
|