aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-01-17 01:40:45 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-01-17 02:37:30 +0100
commit67f5650a78de2567c58dbd7545434cc6d3ef9b7e (patch)
tree34b08ed769cd7a1f071bf9ff4eca1348481c0bf1 /libavformat
parent905c4dc2b0d564e1b9b6bc6eeca0b8915b81cd8c (diff)
parent9e12002f114d7e0b0ef69519518cdc0391e5e198 (diff)
downloadffmpeg-67f5650a78de2567c58dbd7545434cc6d3ef9b7e.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: rv34: add NEON rv34_idct_add rv34: 1-pass inter MB reconstruction add SMJPEG muxer avformat: split out common SMJPEG code pictordec: Use bytestream2 functions avconv: use avcodec_encode_audio2() pcmenc: use AVCodec.encode2() avcodec: bump minor version and add APIChanges for the new audio encoding API avcodec: Add avcodec_encode_audio2() as replacement for avcodec_encode_audio() avcodec: add a public function, avcodec_fill_audio_frame(). rv34: Intra 16x16 handling rv34: Inter/intra MB code split Conflicts: Changelog libavcodec/avcodec.h libavcodec/pictordec.c libavcodec/utils.c libavcodec/version.h libavcodec/x86/rv34dsp.asm libavformat/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile3
-rw-r--r--libavformat/allformats.c2
-rw-r--r--libavformat/smjpeg.c159
-rw-r--r--libavformat/smjpeg.h45
-rw-r--r--libavformat/smjpegdec.c177
-rw-r--r--libavformat/smjpegenc.c149
-rw-r--r--libavformat/version.h2
7 files changed, 381 insertions, 156 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 86518f6a58..c135eb8675 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -291,7 +291,8 @@ OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o
OBJS-$(CONFIG_SHORTEN_DEMUXER) += rawdec.o
OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o
OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o
-OBJS-$(CONFIG_SMJPEG_DEMUXER) += smjpeg.o
+OBJS-$(CONFIG_SMJPEG_DEMUXER) += smjpegdec.o smjpeg.o
+OBJS-$(CONFIG_SMJPEG_MUXER) += smjpegenc.o smjpeg.o
OBJS-$(CONFIG_SOL_DEMUXER) += sol.o pcm.o
OBJS-$(CONFIG_SOX_DEMUXER) += soxdec.o pcm.o
OBJS-$(CONFIG_SOX_MUXER) += soxenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d8ca0d50ea..ab766c0911 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -212,7 +212,7 @@ void av_register_all(void)
REGISTER_DEMUXER (SHORTEN, shorten);
REGISTER_DEMUXER (SIFF, siff);
REGISTER_DEMUXER (SMACKER, smacker);
- REGISTER_DEMUXER (SMJPEG, smjpeg);
+ REGISTER_MUXDEMUX (SMJPEG, smjpeg);
REGISTER_DEMUXER (SOL, sol);
REGISTER_MUXDEMUX (SOX, sox);
REGISTER_MUXDEMUX (SPDIF, spdif);
diff --git a/libavformat/smjpeg.c b/libavformat/smjpeg.c
index e23e0cb7a2..82316ed448 100644
--- a/libavformat/smjpeg.c
+++ b/libavformat/smjpeg.c
@@ -1,6 +1,6 @@
/*
- * SMJPEG demuxer
- * Copyright (c) 2011 Paul B Mahol
+ * SMJPEG common code
+ * Copyright (c) 2011-2012 Paul B Mahol
*
* This file is part of FFmpeg.
*
@@ -21,167 +21,20 @@
/**
* @file
- * This is a demuxer for Loki SDL Motion JPEG files
+ * SMJPEG common code
*/
#include "avformat.h"
#include "internal.h"
-#include "riff.h"
+#include "smjpeg.h"
-static const AVCodecTag codec_smjpeg_video_tags[] = {
+const AVCodecTag ff_codec_smjpeg_video_tags[] = {
{ CODEC_ID_MJPEG, MKTAG('J', 'F', 'I', 'F') },
{ CODEC_ID_NONE, 0 },
};
-static const AVCodecTag codec_smjpeg_audio_tags[] = {
+const AVCodecTag ff_codec_smjpeg_audio_tags[] = {
{ CODEC_ID_ADPCM_IMA_SMJPEG, MKTAG('A', 'P', 'C', 'M') },
{ CODEC_ID_PCM_S16LE, MKTAG('N', 'O', 'N', 'E') },
{ CODEC_ID_NONE, 0 },
};
-
-typedef struct SMJPEGContext {
- int audio_stream_index;
- int video_stream_index;
-} SMJPEGContext;
-
-static int smjpeg_probe(AVProbeData *p)
-{
- if (!memcmp(p->buf, "\x0\xaSMJPEG", 8))
- return AVPROBE_SCORE_MAX;
- return 0;
-}
-
-static int smjpeg_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- SMJPEGContext *sc = s->priv_data;
- AVStream *ast = NULL, *vst = NULL;
- AVIOContext *pb = s->pb;
- uint32_t version, htype, hlength, duration;
- char *comment;
-
- avio_skip(pb, 8); // magic
- version = avio_rb32(pb);
- if (version)
- av_log_ask_for_sample(s, "unknown version %d\n", version);
-
- duration = avio_rb32(pb); // in msec
-
- while (!pb->eof_reached) {
- htype = avio_rl32(pb);
- switch (htype) {
- case MKTAG('_', 'T', 'X', 'T'):
- hlength = avio_rb32(pb);
- if (!hlength || hlength > 512)
- return AVERROR_INVALIDDATA;
- comment = av_malloc(hlength + 1);
- if (!comment)
- return AVERROR(ENOMEM);
- if (avio_read(pb, comment, hlength) != hlength) {
- av_freep(&comment);
- av_log(s, AV_LOG_ERROR, "error when reading comment\n");
- return AVERROR_INVALIDDATA;
- }
- comment[hlength] = 0;
- av_dict_set(&s->metadata, "comment", comment,
- AV_DICT_DONT_STRDUP_VAL);
- break;
- case MKTAG('_', 'S', 'N', 'D'):
- if (ast) {
- av_log_ask_for_sample(s, "multiple audio streams not supported\n");
- return AVERROR_INVALIDDATA;
- }
- hlength = avio_rb32(pb);
- if (hlength < 8)
- return AVERROR_INVALIDDATA;
- ast = avformat_new_stream(s, 0);
- if (!ast)
- return AVERROR(ENOMEM);
- ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
- ast->codec->sample_rate = avio_rb16(pb);
- ast->codec->bits_per_coded_sample = avio_r8(pb);
- ast->codec->channels = avio_r8(pb);
- ast->codec->codec_tag = avio_rl32(pb);
- ast->codec->codec_id = ff_codec_get_id(codec_smjpeg_audio_tags,
- ast->codec->codec_tag);
- ast->duration = duration;
- sc->audio_stream_index = ast->index;
- avpriv_set_pts_info(ast, 32, 1, 1000);
- avio_skip(pb, hlength - 8);
- break;
- case MKTAG('_', 'V', 'I', 'D'):
- if (vst) {
- av_log_ask_for_sample(s, "multiple video streams not supported\n");
- return AVERROR_INVALIDDATA;
- }
- hlength = avio_rb32(pb);
- if (hlength < 12)
- return AVERROR_INVALIDDATA;
- avio_skip(pb, 4); // number of frames
- vst = avformat_new_stream(s, 0);
- if (!vst)
- return AVERROR(ENOMEM);
- vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- vst->codec->width = avio_rb16(pb);
- vst->codec->height = avio_rb16(pb);
- vst->codec->codec_tag = avio_rl32(pb);
- vst->codec->codec_id = ff_codec_get_id(codec_smjpeg_video_tags,
- vst->codec->codec_tag);
- vst->duration = duration;
- sc->video_stream_index = vst->index;
- avpriv_set_pts_info(vst, 32, 1, 1000);
- avio_skip(pb, hlength - 12);
- break;
- case MKTAG('H', 'E', 'N', 'D'):
- return 0;
- default:
- av_log(s, AV_LOG_ERROR, "unknown header %x\n", htype);
- return AVERROR_INVALIDDATA;
- }
- }
-
- return AVERROR_EOF;
-}
-
-static int smjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- SMJPEGContext *sc = s->priv_data;
- uint32_t dtype, ret, size, timestamp;
-
- if (s->pb->eof_reached)
- return AVERROR_EOF;
- dtype = avio_rl32(s->pb);
- switch (dtype) {
- case MKTAG('s', 'n', 'd', 'D'):
- timestamp = avio_rb32(s->pb);
- size = avio_rb32(s->pb);
- ret = av_get_packet(s->pb, pkt, size);
- pkt->stream_index = sc->audio_stream_index;
- pkt->pts = timestamp;
- break;
- case MKTAG('v', 'i', 'd', 'D'):
- timestamp = avio_rb32(s->pb);
- size = avio_rb32(s->pb);
- ret = av_get_packet(s->pb, pkt, size);
- pkt->stream_index = sc->video_stream_index;
- pkt->pts = timestamp;
- break;
- case MKTAG('D', 'O', 'N', 'E'):
- ret = AVERROR_EOF;
- break;
- default:
- av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype);
- ret = AVERROR_INVALIDDATA;
- break;
- }
- return ret;
-}
-
-AVInputFormat ff_smjpeg_demuxer = {
- .name = "smjpeg",
- .long_name = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"),
- .priv_data_size = sizeof(SMJPEGContext),
- .read_probe = smjpeg_probe,
- .read_header = smjpeg_read_header,
- .read_packet = smjpeg_read_packet,
- .extensions = "mjpg",
-};
diff --git a/libavformat/smjpeg.h b/libavformat/smjpeg.h
new file mode 100644
index 0000000000..c56fe46939
--- /dev/null
+++ b/libavformat/smjpeg.h
@@ -0,0 +1,45 @@
+/*
+ * SMJPEG common code
+ * Copyright (c) 2011-2012 Paul B Mahol
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * 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
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * SMJPEG common code
+ */
+
+#ifndef AVFORMAT_SMJPEG_H
+#define AVFORMAT_SMJPEG_H
+
+#include "internal.h"
+
+#define SMJPEG_MAGIC "\x0\xaSMJPEG"
+
+#define SMJPEG_DONE MKTAG('D', 'O', 'N', 'E')
+#define SMJPEG_HEND MKTAG('H', 'E', 'N', 'D')
+#define SMJPEG_SND MKTAG('_', 'S', 'N', 'D')
+#define SMJPEG_SNDD MKTAG('s', 'n', 'd', 'D')
+#define SMJPEG_TXT MKTAG('_', 'T', 'X', 'T')
+#define SMJPEG_VID MKTAG('_', 'V', 'I', 'D')
+#define SMJPEG_VIDD MKTAG('v', 'i', 'd', 'D')
+
+extern const AVCodecTag ff_codec_smjpeg_video_tags[];
+extern const AVCodecTag ff_codec_smjpeg_audio_tags[];
+
+#endif /* AVFORMAT_SMJPEG_H */
diff --git a/libavformat/smjpegdec.c b/libavformat/smjpegdec.c
new file mode 100644
index 0000000000..d7ff9799ef
--- /dev/null
+++ b/libavformat/smjpegdec.c
@@ -0,0 +1,177 @@
+/*
+ * SMJPEG demuxer
+ * Copyright (c) 2011 Paul B Mahol
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * 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
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * This is a demuxer for Loki SDL Motion JPEG files
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "riff.h"
+#include "smjpeg.h"
+
+typedef struct SMJPEGContext {
+ int audio_stream_index;
+ int video_stream_index;
+} SMJPEGContext;
+
+static int smjpeg_probe(AVProbeData *p)
+{
+ if (!memcmp(p->buf, SMJPEG_MAGIC, 8))
+ return AVPROBE_SCORE_MAX;
+ return 0;
+}
+
+static int smjpeg_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+ SMJPEGContext *sc = s->priv_data;
+ AVStream *ast = NULL, *vst = NULL;
+ AVIOContext *pb = s->pb;
+ uint32_t version, htype, hlength, duration;
+ char *comment;
+
+ avio_skip(pb, 8); // magic
+ version = avio_rb32(pb);
+ if (version)
+ av_log_ask_for_sample(s, "unknown version %d\n", version);
+
+ duration = avio_rb32(pb); // in msec
+
+ while (!pb->eof_reached) {
+ htype = avio_rl32(pb);
+ switch (htype) {
+ case SMJPEG_TXT:
+ hlength = avio_rb32(pb);
+ if (!hlength || hlength > 512)
+ return AVERROR_INVALIDDATA;
+ comment = av_malloc(hlength + 1);
+ if (!comment)
+ return AVERROR(ENOMEM);
+ if (avio_read(pb, comment, hlength) != hlength) {
+ av_freep(&comment);
+ av_log(s, AV_LOG_ERROR, "error when reading comment\n");
+ return AVERROR_INVALIDDATA;
+ }
+ comment[hlength] = 0;
+ av_dict_set(&s->metadata, "comment", comment,
+ AV_DICT_DONT_STRDUP_VAL);
+ break;
+ case SMJPEG_SND:
+ if (ast) {
+ av_log_ask_for_sample(s, "multiple audio streams not supported\n");
+ return AVERROR_INVALIDDATA;
+ }
+ hlength = avio_rb32(pb);
+ if (hlength < 8)
+ return AVERROR_INVALIDDATA;
+ ast = avformat_new_stream(s, 0);
+ if (!ast)
+ return AVERROR(ENOMEM);
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codec->sample_rate = avio_rb16(pb);
+ ast->codec->bits_per_coded_sample = avio_r8(pb);
+ ast->codec->channels = avio_r8(pb);
+ ast->codec->codec_tag = avio_rl32(pb);
+ ast->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_audio_tags,
+ ast->codec->codec_tag);
+ ast->duration = duration;
+ sc->audio_stream_index = ast->index;
+ avpriv_set_pts_info(ast, 32, 1, 1000);
+ avio_skip(pb, hlength - 8);
+ break;
+ case SMJPEG_VID:
+ if (vst) {
+ av_log_ask_for_sample(s, "multiple video streams not supported\n");
+ return AVERROR_INVALIDDATA;
+ }
+ hlength = avio_rb32(pb);
+ if (hlength < 12)
+ return AVERROR_INVALIDDATA;
+ avio_skip(pb, 4); // number of frames
+ vst = avformat_new_stream(s, 0);
+ if (!vst)
+ return AVERROR(ENOMEM);
+ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ vst->codec->width = avio_rb16(pb);
+ vst->codec->height = avio_rb16(pb);
+ vst->codec->codec_tag = avio_rl32(pb);
+ vst->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_video_tags,
+ vst->codec->codec_tag);
+ vst->duration = duration;
+ sc->video_stream_index = vst->index;
+ avpriv_set_pts_info(vst, 32, 1, 1000);
+ avio_skip(pb, hlength - 12);
+ break;
+ case SMJPEG_HEND:
+ return 0;
+ default:
+ av_log(s, AV_LOG_ERROR, "unknown header %x\n", htype);
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ return AVERROR_EOF;
+}
+
+static int smjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SMJPEGContext *sc = s->priv_data;
+ uint32_t dtype, ret, size, timestamp;
+
+ if (s->pb->eof_reached)
+ return AVERROR_EOF;
+ dtype = avio_rl32(s->pb);
+ switch (dtype) {
+ case SMJPEG_SNDD:
+ timestamp = avio_rb32(s->pb);
+ size = avio_rb32(s->pb);
+ ret = av_get_packet(s->pb, pkt, size);
+ pkt->stream_index = sc->audio_stream_index;
+ pkt->pts = timestamp;
+ break;
+ case SMJPEG_VIDD:
+ timestamp = avio_rb32(s->pb);
+ size = avio_rb32(s->pb);
+ ret = av_get_packet(s->pb, pkt, size);
+ pkt->stream_index = sc->video_stream_index;
+ pkt->pts = timestamp;
+ break;
+ case SMJPEG_DONE:
+ ret = AVERROR_EOF;
+ break;
+ default:
+ av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype);
+ ret = AVERROR_INVALIDDATA;
+ break;
+ }
+ return ret;
+}
+
+AVInputFormat ff_smjpeg_demuxer = {
+ .name = "smjpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"),
+ .priv_data_size = sizeof(SMJPEGContext),
+ .read_probe = smjpeg_probe,
+ .read_header = smjpeg_read_header,
+ .read_packet = smjpeg_read_packet,
+ .extensions = "mjpg",
+};
diff --git a/libavformat/smjpegenc.c b/libavformat/smjpegenc.c
new file mode 100644
index 0000000000..45ba20b643
--- /dev/null
+++ b/libavformat/smjpegenc.c
@@ -0,0 +1,149 @@
+/*
+ * SMJPEG muxer
+ * Copyright (c) 2012 Paul B Mahol
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * 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
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * This is a muxer for Loki SDL Motion JPEG files
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "riff.h"
+#include "smjpeg.h"
+
+typedef struct SMJPEGMuxContext {
+ uint32_t duration;
+} SMJPEGMuxContext;
+
+static int smjpeg_write_header(AVFormatContext *s)
+{
+ AVDictionaryEntry *t = NULL;
+ AVIOContext *pb = s->pb;
+ int n, tag;
+
+ if (s->nb_streams > 2) {
+ av_log(s, AV_LOG_ERROR, "more than >2 streams are not supported\n");
+ return AVERROR(EINVAL);
+ }
+ avio_write(pb, SMJPEG_MAGIC, 8);
+ avio_wb32(pb, 0);
+ avio_wb32(pb, 0);
+
+ while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ avio_wl32(pb, SMJPEG_TXT);
+ avio_wb32(pb, strlen(t->key) + strlen(t->value) + 3);
+ avio_write(pb, t->key, strlen(t->key));
+ avio_write(pb, " = ", 3);
+ avio_write(pb, t->value, strlen(t->value));
+ }
+
+ for (n = 0; n < s->nb_streams; n++) {
+ AVStream *st = s->streams[n];
+ AVCodecContext *codec = st->codec;
+ if (codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ tag = ff_codec_get_tag(ff_codec_smjpeg_audio_tags, codec->codec_id);
+ if (!tag) {
+ av_log(s, AV_LOG_ERROR, "unsupported audio codec\n");
+ return AVERROR(EINVAL);
+ }
+ avio_wl32(pb, SMJPEG_SND);
+ avio_wb32(pb, 8);
+ avio_wb16(pb, codec->sample_rate);
+ avio_w8(pb, av_get_bits_per_sample(codec->codec_id));
+ avio_w8(pb, codec->channels);
+ avio_wl32(pb, tag);
+ avpriv_set_pts_info(st, 32, 1, 1000);
+ } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ tag = ff_codec_get_tag(ff_codec_smjpeg_video_tags, codec->codec_id);
+ if (!tag) {
+ av_log(s, AV_LOG_ERROR, "unsupported video codec\n");
+ return AVERROR(EINVAL);
+ }
+ avio_wl32(pb, SMJPEG_VID);
+ avio_wb32(pb, 12);
+ avio_wb32(pb, 0);
+ avio_wb16(pb, codec->width);
+ avio_wb16(pb, codec->height);
+ avio_wl32(pb, tag);
+ avpriv_set_pts_info(st, 32, 1, 1000);
+ }
+ }
+
+ avio_wl32(pb, SMJPEG_HEND);
+ avio_flush(pb);
+
+ return 0;
+}
+
+static int smjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ SMJPEGMuxContext *smc = s->priv_data;
+ AVIOContext *pb = s->pb;
+ AVStream *st = s->streams[pkt->stream_index];
+ AVCodecContext *codec = st->codec;
+
+ if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ avio_wl32(pb, SMJPEG_SNDD);
+ else if (codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ avio_wl32(pb, SMJPEG_VIDD);
+ else
+ return 0;
+
+ avio_wb32(pb, pkt->pts);
+ avio_wb32(pb, pkt->size);
+ avio_write(pb, pkt->data, pkt->size);
+ avio_flush(pb);
+
+ smc->duration = FFMAX(smc->duration, pkt->pts + pkt->duration);
+ return 0;
+}
+
+static int smjpeg_write_trailer(AVFormatContext *s)
+{
+ SMJPEGMuxContext *smc = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int64_t currentpos;
+
+ if (pb->seekable) {
+ currentpos = avio_tell(pb);
+ avio_seek(pb, 12, SEEK_SET);
+ avio_wb32(pb, smc->duration);
+ avio_seek(pb, currentpos, SEEK_SET);
+ }
+
+ avio_wl32(pb, SMJPEG_DONE);
+ avio_flush(pb);
+
+ return 0;
+}
+
+AVOutputFormat ff_smjpeg_muxer = {
+ .name = "smjpeg",
+ .long_name = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"),
+ .priv_data_size = sizeof(SMJPEGMuxContext),
+ .audio_codec = CODEC_ID_PCM_S16LE,
+ .video_codec = CODEC_ID_MJPEG,
+ .write_header = smjpeg_write_header,
+ .write_packet = smjpeg_write_packet,
+ .write_trailer = smjpeg_write_trailer,
+ .flags = AVFMT_GLOBALHEADER,
+ .codec_tag = (const AVCodecTag *const []){ ff_codec_smjpeg_video_tags, ff_codec_smjpeg_audio_tags, 0 },
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index e2cc0fb26b..aaa5212ff9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 53
-#define LIBAVFORMAT_VERSION_MINOR 29
+#define LIBAVFORMAT_VERSION_MINOR 30
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \