diff mbox

[FFmpeg-devel] lavf/supenc: Add a raw PGS muxer

Message ID CAB0OVGo9bTXLz0k22kQJ0=SWJr6mQ1AEoSZAsSgfADRXa2NN2w@mail.gmail.com
State Superseded
Headers show

Commit Message

Carl Eugen Hoyos Sept. 7, 2017, 1:32 p.m. UTC
Hi!

Attached patch implements ticket #2208.

Please comment, Carl Eugen

Comments

wm4 Sept. 7, 2017, 2:14 p.m. UTC | #1
On Thu, 7 Sep 2017 15:32:58 +0200
Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Hi!
> 
> Attached patch implements ticket #2208.
> 
> Please comment, Carl Eugen

Probably worse than:

 From: phintuka@gmail.com
 To: ffmpeg-devel@ffmpeg.org
 Cc: Petri Hintukainen <phintuka@users.sourceforge.net>
 Subject: [FFmpeg-devel] [PATCH v2] Add SUP/PGS subtitle muxer
 Date: Tue, 30 Sep 2014 11:01:17 +0300
Carl Eugen Hoyos Sept. 7, 2017, 2:21 p.m. UTC | #2
2017-09-07 16:14 GMT+02:00 wm4 <nfxjfg@googlemail.com>:
> On Thu, 7 Sep 2017 15:32:58 +0200
> Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
>> Hi!
>>
>> Attached patch implements ticket #2208.
>>
>> Please comment, Carl Eugen
>
> Probably worse than:

Looks similar except for working with mkv input and a useless cast.

>  From: phintuka@gmail.com
>  To: ffmpeg-devel@ffmpeg.org
>  Cc: Petri Hintukainen <phintuka@users.sourceforge.net>
>  Subject: [FFmpeg-devel] [PATCH v2] Add SUP/PGS subtitle muxer
>  Date: Tue, 30 Sep 2014 11:01:17 +0300

You reviewed it but sadly, you forgot to push.

Please mention ticket #2208 in the commit message.

Carl Eugen
diff mbox

Patch

From 919cd9728e73a9570a11f0d575b23c0212ca52e4 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Thu, 7 Sep 2017 15:28:55 +0200
Subject: [PATCH] lavf/supenc: Add a raw PGS muxer.

Fixes ticket #2208.
---
 Changelog                |    1 +
 libavformat/Makefile     |    1 +
 libavformat/allformats.c |    2 +-
 libavformat/supenc.c     |   54 ++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/version.h    |    2 +-
 5 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/supenc.c

diff --git a/Changelog b/Changelog
index cae5254..b62291a 100644
--- a/Changelog
+++ b/Changelog
@@ -43,6 +43,7 @@  version <next>:
 - add --disable-autodetect build switch
 - drop deprecated qtkit input device (use avfoundation instead)
 - despill video filter
+- raw PGS subtitle muxer
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/libavformat/Makefile b/libavformat/Makefile
index de954af..ef44f14 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -473,6 +473,7 @@  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_DEMUXER)               += supdec.o
+OBJS-$(CONFIG_SUP_MUXER)                 += supenc.o
 OBJS-$(CONFIG_SVAG_DEMUXER)              += svag.o
 OBJS-$(CONFIG_SWF_DEMUXER)               += swfdec.o swf.o
 OBJS-$(CONFIG_SWF_MUXER)                 += swfenc.o swf.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index cb09a60..62b0cf8 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -303,7 +303,7 @@  static void register_all(void)
     REGISTER_DEMUXER (STL,              stl);
     REGISTER_DEMUXER (SUBVIEWER1,       subviewer1);
     REGISTER_DEMUXER (SUBVIEWER,        subviewer);
-    REGISTER_DEMUXER (SUP,              sup);
+    REGISTER_MUXDEMUX(SUP,              sup);
     REGISTER_DEMUXER (SVAG,             svag);
     REGISTER_MUXDEMUX(SWF,              swf);
     REGISTER_DEMUXER (TAK,              tak);
diff --git a/libavformat/supenc.c b/libavformat/supenc.c
new file mode 100644
index 0000000..bc8cd0b
--- /dev/null
+++ b/libavformat/supenc.c
@@ -0,0 +1,54 @@ 
+/*
+ * raw PGS muxer
+ * Copyright (c) 2017 Carl Eugen Hoyos
+ *
+ * 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"
+
+static int sup_write_header(AVFormatContext *s)
+{
+    if (s->nb_streams != 1) {
+        av_log(s, AV_LOG_ERROR, "only exactly one PGS stream is supported\n");
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
+static int sup_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    AVIOContext *pb = s->pb;
+
+    avio_wb16(pb, 0x5047); /* PG */
+    avio_wb32(pb, pkt->pts == AV_NOPTS_VALUE ? 0 : pkt->pts);
+    avio_wb32(pb, pkt->dts == AV_NOPTS_VALUE ? 0 : pkt->dts);
+    avio_write(pb, pkt->data, pkt->size);
+
+    return 0;
+}
+
+AVOutputFormat ff_sup_muxer = {
+    .name              = "sup",
+    .long_name         = NULL_IF_CONFIG_SMALL("raw HDMV Presentation Graphic Stream subtitles"),
+    .extensions        = "sup",
+    .subtitle_codec    = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
+    .write_header      = sup_write_header,
+    .write_packet      = sup_write_packet,
+};
diff --git a/libavformat/version.h b/libavformat/version.h
index 9cca76e..aeb5940 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@ 
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
-#define LIBAVFORMAT_VERSION_MINOR  81
+#define LIBAVFORMAT_VERSION_MINOR  82
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
1.7.10.4