[FFmpeg-devel] [PATCH] Add SUP (raw BluRay PGS subtitle) muxer
Petri Hintukainen
phintuka at gmail.com
Fri Aug 29 12:31:22 CEST 2014
From: Petri Hintukainen <phintuka at users.sourceforge.net>
Fixes ticket #2208
---
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/supenc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+)
create mode 100644 libavformat/supenc.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3d124fb..e3cc653 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -405,6 +405,7 @@ OBJS-$(CONFIG_SRT_MUXER) += srtenc.o
OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o
OBJS-$(CONFIG_SUBVIEWER1_DEMUXER) += subviewer1dec.o subtitles.o
OBJS-$(CONFIG_SUBVIEWER_DEMUXER) += subviewerdec.o subtitles.o
+OBJS-$(CONFIG_SUP_MUXER) += supenc.o
OBJS-$(CONFIG_SWF_DEMUXER) += swfdec.o swf.o
OBJS-$(CONFIG_SWF_MUXER) += swfenc.o swf.o
OBJS-$(CONFIG_TAK_DEMUXER) += takdec.o apetag.o img2.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 8f70c4b..a1a55f7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -280,6 +280,7 @@ void av_register_all(void)
REGISTER_DEMUXER (STR, str);
REGISTER_DEMUXER (SUBVIEWER1, subviewer1);
REGISTER_DEMUXER (SUBVIEWER, subviewer);
+ REGISTER_MUXER (SUP, sup);
REGISTER_MUXDEMUX(SWF, swf);
REGISTER_DEMUXER (TAK, tak);
REGISTER_MUXER (TEE, tee);
diff --git a/libavformat/supenc.c b/libavformat/supenc.c
new file mode 100644
index 0000000..3447f76
--- /dev/null
+++ b/libavformat/supenc.c
@@ -0,0 +1,61 @@
+/*
+ * SUP muxer
+ * Copyright (c) 2014 Petri Hintukainen <phintuka at users.sourceforge.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "internal.h"
+
+
+#define SUP_PGS_MAGIC 0x5047 /* "PG", big endian */
+
+static int sup_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ /* header */
+ avio_wb16(s->pb, SUP_PGS_MAGIC);
+ avio_wb32(s->pb, (uint64_t)pkt->pts);
+ avio_wb32(s->pb, (uint64_t)pkt->dts);
+
+ avio_write(s->pb, pkt->data, pkt->size);
+ return 0;
+}
+
+static int sup_write_header(AVFormatContext *s)
+{
+ if (s->nb_streams != 1) {
+ av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
+ s->oformat->name);
+ return AVERROR(EINVAL);
+ }
+
+ avpriv_set_pts_info(s->streams[0], 32, 1, 90000);
+
+ return 0;
+}
+
+AVOutputFormat ff_sup_muxer = {
+ .name = "sup",
+ .long_name = NULL_IF_CONFIG_SMALL("raw PGS subtitle"),
+ .mime_type = "application/x-pgs",
+ .extensions = "sup",
+ .subtitle_codec = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
+ .write_header = sup_write_header,
+ .write_packet = sup_write_packet,
+ .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
+};
--
1.9.1
More information about the ffmpeg-devel
mailing list