• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer WebM muxer
2  * Copyright (c) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 /**
21  * SECTION:element-webmmux
22  * @title: webmmux
23  *
24  * webmmux muxes VP8 video and Vorbis audio streams into a WebM file.
25  *
26  * ## Example launch line
27  * |[
28  * gst-launch-1.0 webmmux name=mux ! filesink location=newfile.webm         \
29  *   uridecodebin uri=file:///path/to/somefile.ogv name=demux                \
30  *   demux. ! videoconvert ! vp8enc ! queue ! mux.video_0    \
31  *   demux. ! progressreport ! audioconvert ! audiorate ! vorbisenc ! queue ! mux.audio_0
32  * ]| This pipeline re-encodes a video file of any format into a WebM file.
33  * |[
34  * gst-launch-1.0 webmmux name=mux ! filesink location=test.webm            \
35  *   videotestsrc num-buffers=250 ! video/x-raw,framerate=25/1 ! videoconvert ! vp8enc ! queue ! mux.video_0 \
36  *   audiotestsrc samplesperbuffer=44100 num-buffers=10 ! audio/x-raw,rate=44100 ! vorbisenc ! queue ! mux.audio_0
37  * ]| This pipeline muxes a test video and a sine wave into a WebM file.
38  *
39  */
40 
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif
44 
45 #include "gstmatroskaelements.h"
46 #include "webm-mux.h"
47 
48 #define COMMON_VIDEO_CAPS \
49   "width = (int) [ 16, MAX ], " \
50   "height = (int) [ 16, MAX ], " \
51   "framerate = (fraction) [ 0, MAX ]"
52 
53 #define COMMON_AUDIO_CAPS \
54   "channels = (int) [ 1, MAX ], " \
55   "rate = (int) [ 1, MAX ]"
56 
57 G_DEFINE_TYPE (GstWebMMux, gst_webm_mux, GST_TYPE_MATROSKA_MUX);
58 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (webmmux, "webmmux",
59     GST_RANK_PRIMARY, GST_TYPE_WEBM_MUX, matroska_element_init (plugin));
60 
61 static GstStaticPadTemplate webm_src_templ = GST_STATIC_PAD_TEMPLATE ("src",
62     GST_PAD_SRC,
63     GST_PAD_ALWAYS,
64     GST_STATIC_CAPS ("video/webm; audio/webm")
65     );
66 
67 static GstStaticPadTemplate webm_videosink_templ =
68     GST_STATIC_PAD_TEMPLATE ("video_%u",
69     GST_PAD_SINK,
70     GST_PAD_REQUEST,
71     GST_STATIC_CAPS ("video/x-vp8, " COMMON_VIDEO_CAPS ";"
72         "video/x-vp9, " COMMON_VIDEO_CAPS ";" "video/x-av1, " COMMON_VIDEO_CAPS)
73     );
74 
75 static GstStaticPadTemplate webm_audiosink_templ =
76     GST_STATIC_PAD_TEMPLATE ("audio_%u",
77     GST_PAD_SINK,
78     GST_PAD_REQUEST,
79     GST_STATIC_CAPS ("audio/x-vorbis, " COMMON_AUDIO_CAPS ";"
80         "audio/x-opus, " COMMON_AUDIO_CAPS)
81     );
82 
83 static void
gst_webm_mux_class_init(GstWebMMuxClass * klass)84 gst_webm_mux_class_init (GstWebMMuxClass * klass)
85 {
86   GstElementClass *gstelement_class = (GstElementClass *) klass;
87 
88   gst_element_class_add_static_pad_template (gstelement_class,
89       &webm_videosink_templ);
90   gst_element_class_add_static_pad_template (gstelement_class,
91       &webm_audiosink_templ);
92   gst_element_class_add_static_pad_template (gstelement_class, &webm_src_templ);
93   gst_element_class_set_static_metadata (gstelement_class, "WebM muxer",
94       "Codec/Muxer",
95       "Muxes video and audio streams into a WebM stream",
96       "GStreamer maintainers <gstreamer-devel@lists.freedesktop.org>");
97 }
98 
99 static void
gst_webm_mux_init(GstWebMMux * mux)100 gst_webm_mux_init (GstWebMMux * mux)
101 {
102   GST_MATROSKA_MUX (mux)->doctype = GST_MATROSKA_DOCTYPE_WEBM;
103   GST_MATROSKA_MUX (mux)->is_webm = TRUE;
104 }
105