summaryrefslogtreecommitdiff
path: root/subprojects/gst-plugins-good/gst/matroska/webm-mux.c
blob: 1c616bd1207457d8f68a5c0a0b9f95633e1b2884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* GStreamer WebM muxer
 * Copyright (c) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

/**
 * SECTION:element-webmmux
 * @title: webmmux
 *
 * webmmux muxes VP8 video and Vorbis audio streams into a WebM file.
 *
 * ## Example launch line
 * |[
 * gst-launch-1.0 webmmux name=mux ! filesink location=newfile.webm         \
 *   uridecodebin uri=file:///path/to/somefile.ogv name=demux                \
 *   demux. ! videoconvert ! vp8enc ! queue ! mux.video_0    \
 *   demux. ! progressreport ! audioconvert ! audiorate ! vorbisenc ! queue ! mux.audio_0
 * ]| This pipeline re-encodes a video file of any format into a WebM file.
 * |[
 * gst-launch-1.0 webmmux name=mux ! filesink location=test.webm            \
 *   videotestsrc num-buffers=250 ! video/x-raw,framerate=25/1 ! videoconvert ! vp8enc ! queue ! mux.video_0 \
 *   audiotestsrc samplesperbuffer=44100 num-buffers=10 ! audio/x-raw,rate=44100 ! vorbisenc ! queue ! mux.audio_0
 * ]| This pipeline muxes a test video and a sine wave into a WebM file.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gstmatroskaelements.h"
#include "webm-mux.h"

#define COMMON_VIDEO_CAPS \
  "width = (int) [ 16, MAX ], " \
  "height = (int) [ 16, MAX ], " \
  "framerate = (fraction) [ 0, MAX ]"

#define COMMON_AUDIO_CAPS \
  "channels = (int) [ 1, MAX ], " \
  "rate = (int) [ 1, MAX ]"

G_DEFINE_TYPE (GstWebMMux, gst_webm_mux, GST_TYPE_MATROSKA_MUX);
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (webmmux, "webmmux",
    GST_RANK_PRIMARY, GST_TYPE_WEBM_MUX, matroska_element_init (plugin));

static GstStaticPadTemplate webm_src_templ = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/webm; audio/webm")
    );

static GstStaticPadTemplate webm_videosink_templ =
    GST_STATIC_PAD_TEMPLATE ("video_%u",
    GST_PAD_SINK,
    GST_PAD_REQUEST,
    GST_STATIC_CAPS ("video/x-vp8, " COMMON_VIDEO_CAPS ";"
        "video/x-vp9, " COMMON_VIDEO_CAPS ";" "video/x-av1, "
        "stream-format = (string) \"obu-stream\", "
        "alignment = (string) \"tu\", " COMMON_VIDEO_CAPS)
    );

static GstStaticPadTemplate webm_audiosink_templ =
    GST_STATIC_PAD_TEMPLATE ("audio_%u",
    GST_PAD_SINK,
    GST_PAD_REQUEST,
    GST_STATIC_CAPS ("audio/x-vorbis, " COMMON_AUDIO_CAPS ";"
        "audio/x-opus, " COMMON_AUDIO_CAPS)
    );

static void
gst_webm_mux_class_init (GstWebMMuxClass * klass)
{
  GstElementClass *gstelement_class = (GstElementClass *) klass;

  gst_element_class_add_static_pad_template_with_gtype (gstelement_class,
      &webm_videosink_templ, GST_TYPE_MATROSKA_MUX_PAD);
  gst_element_class_add_static_pad_template_with_gtype (gstelement_class,
      &webm_audiosink_templ, GST_TYPE_MATROSKA_MUX_PAD);
  gst_element_class_add_static_pad_template (gstelement_class, &webm_src_templ);
  gst_element_class_set_static_metadata (gstelement_class, "WebM muxer",
      "Codec/Muxer",
      "Muxes video and audio streams into a WebM stream",
      "GStreamer maintainers <gstreamer-devel@lists.freedesktop.org>");
}

static void
gst_webm_mux_init (GstWebMMux * mux)
{
  GST_MATROSKA_MUX (mux)->doctype = GST_MATROSKA_DOCTYPE_WEBM;
  GST_MATROSKA_MUX (mux)->is_webm = TRUE;
}