~ubuntu-branches/ubuntu/natty/gst-entrans/natty

« back to all changes in this revision

Viewing changes to docs/manual/html/howto.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2010-09-13 19:49:29 UTC
  • Revision ID: james.westby@ubuntu.com-20100913194929-qz90a14xyxln9yfz
Tags: upstream-0.10.2
ImportĀ upstreamĀ versionĀ 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
2
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /><title>Chapter&#160;1.&#160;Howto</title><link rel="stylesheet" href="manual.css" type="text/css" /><link rev="made" href="mailto:mnauw@users.sourceforge.net" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><link rel="start" href="index.html" title="GStreamer Transcoding" /><link rel="up" href="index.html" title="GStreamer Transcoding" /><link rel="prev" href="index.html" title="GStreamer Transcoding" /><link rel="next" href="package.html" title="Chapter&#160;2.&#160;Package Documentation" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;1.&#160;Howto</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">&lt;&lt; Previous</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="package.html">Next &gt;&gt;</a></td></tr></table><hr /></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="howto"></a>Chapter&#160;1.&#160;Howto</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="howto.html#sect-introduction">Introduction</a></span></dt><dt><span class="sect1"><a href="howto.html#id522649">GStreamer Pipelines</a></span></dt><dt><span class="sect1"><a href="howto.html#id523110">Media components</a></span></dt><dd><dl><dt><span class="sect2"><a href="howto.html#sect-mpeg-encoding">MPEG encoding</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-ffmpeg-encoders">FFMPEG encoders</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-avi-format">AVI format</a></span></dt><dt><span class="sect2"><a href="howto.html#id523308">OGG/OGM format</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-matroska-format">Matroska format</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-quicktime-format">QuickTime format</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-mpeg-muxing">MPEG PS muxing</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-ffmpeg-muxers">FFMPEG muxers</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-subtitles">
 
3
Subtitles
 
4
</a></span></dt><dt><span class="sect2"><a href="howto.html#sect-recording">Recording</a></span></dt><dt><span class="sect2"><a href="howto.html#id524281">Multiple Images</a></span></dt></dl></dd><dt><span class="sect1"><a href="howto.html#sect-processing">Media processing</a></span></dt><dt><span class="sect1"><a href="howto.html#sect-motivation">Comparison and Motivation</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="sect-introduction"></a>Introduction</h2></div></div></div><p>
 
5
In this context, <em class="firstterm">transcoding</em> can be loosely described
 
6
as decoding, optionally processing and re-encoding of media data (video, audio,
 
7
&#8230;) possibly from one container format to another.
 
8
<em class="firstterm">Recording</em> is very related to this, but only differs in
 
9
that the source material is taken from some live source, rather than an
 
10
existing medium.  In particular, the sequel applies equally to either of these.
 
11
</p><p>
 
12
<a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> is a multimedia (processing) framework that allows the construction of
 
13
graphs of media-handling components ranging from simple playback to
 
14
complex audio (mixing) and video processing, more explanation on
 
15
which can be found on its <a class="ulink" href="http://www.gstreamer.net/" target="_top">homepage</a>.
 
16
It is by no means the only (Un*x) software dealing with
 
17
multimedia; e.g. other players include <a class="ulink" href="http://www.mplayerhq.hu/" target="_top">MPlayer</a>,
 
18
<a class="ulink" href="http://www.xine.org/" target="_top">xine</a>,
 
19
<a class="ulink" href="http://www.videolan.org/" target="_top">VideoLAN</a>,
 
20
&#8230;, and the list of codec processing libraries is equally extensive.
 
21
It is, however, more unique in that it can actually be considered a
 
22
<span class="emphasis"><em>framework</em></span>, and the sequel will (not surprisingly)
 
23
focus on (a particular approach to) transcoding using <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>.
 
24
The primary reason being that there are not so many alternatives
 
25
(including the above) that allow for
 
26
(comfortably) processing and particularly <span class="emphasis"><em>creating</em></span> a
 
27
(fairly wide range of) media files.  Some more considerations can be found in
 
28
<a class="xref" href="howto.html#sect-motivation" title="Comparison and Motivation">&#8220;Comparison and Motivation&#8221;</a>.
 
29
</p><p>
 
30
Of course, there are many more expositions on multimedia (processing); who
 
31
knows (?) what is out there for Google to find, or explanations that can be
 
32
found on Wikipedia &#8230;  Besides all that, there is some
 
33
consolidated information in e.g. the format and codecs sections of <a class="ulink" href="http://www.mplayerhq.hu/design7/info.html#docs" target="_top">MPlayer
 
34
documentation</a>.  All of this need not be recited here, so it
 
35
now &#8220;<span class="quote">only</span>&#8221;remains to consider a <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> approach and point of
 
36
view.
 
37
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="id522649"></a>GStreamer Pipelines</h2></div></div></div><p>
 
38
A <em class="firstterm">pipeline</em> is a central concept in <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>.
 
39
It is a (usually simple) directed graph connecting media handling components,
 
40
typically demuxer, decoder, encoder and muxer or display elements (in this
 
41
order).  For the later purposes here, it should suffice to know and
 
42
understand that:
 
43
</p><div class="itemizedlist"><ul><li><p>
 
44
a "media handling component" is usually referred to as
 
45
<em class="firstterm">element</em>.  There are many kinds of elements, for
 
46
instance (but not exhaustive); demuxer (splits a container file into its
 
47
constituent streams), decoder (decodes compressed data into raw format), and
 
48
symmetrically encoder and muxer &#8230;.  Do note that each type of container
 
49
or compressed data has its own element, e.g. <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-avidemux.html" target="_top"><span class="emphasis"><em>avidemux</em></span></a>,
 
50
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-vorbisenc.html" target="_top"><span class="emphasis"><em>vorbisenc</em></span></a>, &#8230;  Elements are typically made available
 
51
through installed <em class="firstterm">plugins</em>, which are basically
 
52
dynamically loaded libraries.
 
53
</p></li><li><p>
 
54
elements have <em class="firstterm">pads</em>, which are like
 
55
&#8220;<span class="quote">ports</span>&#8221; or &#8220;<span class="quote">plugs</span>&#8221; that connect elements
 
56
and through which data flows.  For example, an encoder/decoder will basically
 
57
have 1 input (sink) and output (source) pad each, whereas typically a demuxer
 
58
has 1 sink pad and several source pads, and a muxer has several sink pads and
 
59
1 source pad.  Evidently, an element's source pad connects to a downstream
 
60
(succeeding) element's sink pad.
 
61
</p></li><li><p>
 
62
data that flows through pads is described by <em class="firstterm">caps</em>
 
63
(short for capabilities),
 
64
which is roughly a mime-type (e.g. <code class="literal">audio/x-raw-int</code>,
 
65
<code class="literal">video/x-raw-yuv</code>) along with a set of descriptive/defining
 
66
properties <span class="emphasis"><em>depending</em></span> on the mime-type (e.g.
 
67
<code class="literal">width</code>, <code class="literal">height</code>,
 
68
<code class="literal">depth</code>).
 
69
Each block/buffer of data typically holds an (un)compressed video frame, or
 
70
some number of (un)compressed audio samples, or even any part of a
 
71
bitstream taken from file or network, &#8230; typically along with some
 
72
metadata (if applicable), e.g. indicating whether or not keyframe, (media)time
 
73
and (media)duration of contained data, &#8230;
 
74
</p></li><li><p>
 
75
there are elements that &#8220;<span class="quote">interface with the world outside a
 
76
pipeline</span>&#8221;.  Such elements have only 1 source pad (source element) or
 
77
only 1 sink pad (sink elements), and are consequently also simply
 
78
collectively called <em class="firstterm">sources</em> or
 
79
<em class="firstterm">sinks</em> respectively.  For example,
 
80
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gstreamer-plugins/html/gstreamer-plugins-filesrc.html" target="_top"><span class="emphasis"><em>filesrc</em></span></a> takes care of reading data from a
 
81
file and feeding this into a pipeline, and <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gstreamer-plugins/html/gstreamer-plugins-filesink.html" target="_top"><span class="emphasis"><em>filesink</em></span></a>
 
82
will happily save data a pipeline has been labouring to produce.  The
 
83
&#8220;<span class="quote">outside</span>&#8221; can be much more live as well;
 
84
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-v4l2src.html" target="_top"><span class="emphasis"><em>v4l2src</em></span></a>
 
85
will capture data from a video4linux compliant device (such as a TV capture
 
86
card), whereas e.g. <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-alsasink.html" target="_top"><span class="emphasis"><em>alsasink</em></span></a> is equally instrumental
 
87
on the downstream side.
 
88
</p></li><li><p>
 
89
<span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-inspect</strong></span></span>(1)</span> can be used to &#8220;<span class="quote">bring the above to life</span>&#8221; by
 
90
providing concrete information on elements.  Specifically, just running
 
91
<code class="literal">gst-inspect</code> yields a listing of (a.o.)
 
92
all elements that are available along with some terse description.  Executing
 
93
<code class="literal">gst-inspect <em class="replaceable"><code>element</code></em></code>
 
94
for some <em class="replaceable"><code>element</code></em> shows (again a.o.):
 
95
</p><div class="itemizedlist"><ul compact="compact"><li><p>
 
96
in the <code class="computeroutput">Pad Templates</code> section; the
 
97
pads the elements has and the type of data to flow through them
 
98
</p></li><li><p>
 
99
in the <code class="computeroutput">Element Properties</code> section;
 
100
various settings determining the operation of the element, e.g. a bitrate for
 
101
encoding, number of (top)lines to crop, volume scale factor to apply, &#8230;
 
102
</p></li></ul></div><p>
 
103
</p></li><li><p>
 
104
many elements provide some additional documentation, which should normally
 
105
be installed along with the plugins themselves (see your distribution system)
 
106
and accessible using Devhelp.  Alternatively, it can also be found on-line in
 
107
<a class="ulink" href="http://www.gstreamer.net/documentation" target="_top">GStreamer's plugin documentation</a>
 
108
</p></li><li><p>
 
109
intermediate conversion between various (raw)
 
110
<a class="ulink" href="http://www.fourcc.org/" target="_top">(YUV or RGB) video</a> and audio formats may be
 
111
necessary in order to connect elements whose caps differ (only in raw format).
 
112
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-ffmpegcolorspace.html" target="_top"><span class="emphasis"><em>ffmpegcolorspace</em></span></a> and 
 
113
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-audioconvert.html" target="_top"><span class="emphasis"><em>audioconvert</em></span></a>
 
114
can take care of this, and may have to be inserted one or more times, depending on
 
115
various formats supported by elements in the pipeline.  As any element, these
 
116
can detect the caps supported by their neighbours and will conduct best effort
 
117
to have linking and subsequent negotiation and dataflow succeed, in this case by
 
118
performing conversion as needed.
 
119
</p></li><li><p>
 
120
having a connected pipeline (graph) is one (static) thing, making it do
 
121
something is another.  This can be loosely called running or activating the
 
122
pipeline, which typically means that sources really get going (reading,
 
123
capturing, &#8230;, and processing/playing takes off.
 
124
In any case, this is a matter for an application to take care of, and similarly
 
125
so for keeping an eye on the pipeline as it runs, providing notifications when
 
126
appropriate, dealing with errors, and finally allowing for clean shutdown when
 
127
the pipeline informs it has had enough.
 
128
</p></li></ul></div><p>
 
129
By now, it should be quite conceivable that all of the above (concepts) can
 
130
nicely cooperate and be linked together to form a pipeline, for instance using a
 
131
syntax as described in <span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-launch</strong></span></span>(1)</span>.  For even more details, one might boldly
 
132
 go into e.g. the introductory part(s) of
 
133
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/manual/html/index.html" target="_top">
 
134
GStreamer Application Development Manual</a>, although this
 
135
actually targets a bit lower technical level.
 
136
</p><p>
 
137
When dealing with <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> applications, one usually need not be aware of or
 
138
concerned with all these things, as it is typically the very goal and merit of an
 
139
application to construct and manage such a pipeline behind the scenes.
 
140
Such is the case for instance with media player <a class="ulink" href="http://www.gnome.org/projects/totem/" target="_top">totem</a>, for which <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> can serve as a backend.
 
141
However, in the goal we are pursuing here, it shall be up to the reader/user to
 
142
conduct transcoding by orchestrating a pipeline, by means of <span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-launch</strong></span></span>(1)</span> or (much)
 
143
more comfortably <a class="xref" href="entrans.html" title="entrans"><span class="command"><strong>entrans</strong></span></a>.  After all, the latter provides (a.o.) a small
 
144
application convenience layer, which alleviates part of the burden, boilerplate,
 
145
minutia and intricacy of pipeline building (hm, what fun is still left
 
146
&#8230;).
 
147
</p><p>
 
148
To emphasize again, the above (possibly daunting) level of detail is not meant
 
149
to add to the rumours that <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> is &#8220;<span class="quote">(way too) complicated</span>&#8221;.
 
150
Rather, on the one hand, it intends to dispel these by unveiling some of the
 
151
mystery by plain and simple overview.  On the other hand, as mentioned above,
 
152
any <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> application can choose to go about its business (including
 
153
transcoding) taking care to (more or less) hide the above details.
 
154
That is, however, simply not the
 
155
approach that has been chosen here (see also e.g. <a class="xref" href="howto.html#sect-motivation" title="Comparison and Motivation">&#8220;Comparison and Motivation&#8221;</a>).
 
156
</p><p>
 
157
The general idea presented here, along with additional explanations and
 
158
specific and concrete examples in <span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-launch</strong></span></span>(1)</span> and <a class="xref" href="entrans.html" title="entrans"><span class="command"><strong>entrans</strong></span></a> should suffice
 
159
to cover quite some transcoding cases.
 
160
Next section(s) will provide some specific information and gotchas to
 
161
consider in pipeline assembling and media handling, depending on the particular
 
162
circumstances.
 
163
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="id523110"></a>Media components</h2></div></div></div><p>
 
164
The purpose here is neither to re-iterate specific <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> related information
 
165
on pads, caps, &#8230; of elements that can be obtained by means of
 
166
<span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-inspect</strong></span></span>(1)</span>, nor to lecture (at least not in great detail) on what is already
 
167
ubiquitously available &#8220;<span class="quote">out there</span>&#8221; (see e.g. references in <a class="xref" href="howto.html#sect-introduction" title="Introduction">&#8220;Introduction&#8221;</a>).
 
168
Similarly, <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> (transcoding) is by no means limited to types
 
169
or formats that are mentioned below (use again <span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-inspect</strong></span></span>(1)</span> to see all that
 
170
is available).
 
171
Rather, it is endeavoured here to provide some minimal (technical) background
 
172
that is pertinent in explaining or avoiding phenomena involving certain
 
173
components turning up as FAQs (on mailinglist, for example).
 
174
</p><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-mpeg-encoding"></a>MPEG encoding</h3></div></div></div><p>
 
175
MPEG-1/2 compressed video can be obtained by means of
 
176
<span class="emphasis"><em>ffenc_mpeg1video</em></span>,
 
177
<span class="emphasis"><em>ffenc_mpeg2video</em></span> or
 
178
<span class="emphasis"><em>mpeg2enc</em></span>, the formers based on <a class="ulink" href="http://ffmpeg.sourceforge.net/" target="_top">ffmpeg</a>'s avcodec library,
 
179
and the latter on <a class="ulink" href="http://mjpeg.sourceforge.net/" target="_top">mjpegtools</a>' mpeg2enc library.
 
180
</p><p>
 
181
Further documentation or usage shall not be discussed here.
 
182
It is noted here, however, that the nature of
 
183
<span class="emphasis"><em>mpeg2enc</em></span>
 
184
leads to it output not having metadata on timestamps
 
185
(at least, for not so recent versions).  As this output is
 
186
typically muxed into <span class="emphasis"><em>mplex</em></span> (see also later in <a class="xref" href="howto.html#sect-mpeg-muxing" title="MPEG PS muxing">&#8220;MPEG PS muxing&#8221;</a>), this is usually not a concern.  If one were to
 
187
put this content into e.g. AVI (which is possible, although why doing so is
 
188
another), then <a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-stamp.html" target="_top"><span class="emphasis"><em>stamp</em></span></a> can easily help one out if needed, as in the fragment
 
189
</p><div class="informalexample"><pre class="programlisting">
 
190
mpeg2enc format=3 ! stamp ! avimux
 
191
</pre></div><p>
 
192
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-ffmpeg-encoders"></a>FFMPEG encoders</h3></div></div></div><p><span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-inspect</strong></span></span>(1)</span> shows quite a list of ffmpeg based encoders
 
193
<code class="literal">ffenc_<em class="replaceable"><code>name</code></em></code>, most of which
 
194
are pretty straightforward to use.  They may have limitations in supported
 
195
video sizes or formats, most common of which are exposed in recent releases
 
196
<sup>[<a id="id523269" href="#ftn.id523269" class="footnote">1</a>]</sup>,
 
197
in which case following pipeline fragment illustrates how to have this
 
198
automatically dealt with:
 
199
</p><div class="informalexample"><pre class="programlisting">
 
200
videoscale ! ffmpegcolorspace ! ffenc_huffyuv
 
201
</pre></div><p>
 
202
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-avi-format"></a>AVI format</h3></div></div></div><p>
 
203
AVI (Audio Video Interleaved) files, designed by Microsoft, have a plain and
 
204
simple format.  Though it has various limitations (for example in streaming),
 
205
it handles many basic purposes well.
 
206
</p><p>
 
207
One of the limitations is that it does not store any timedata, it only
 
208
&#8220;<span class="quote">knows</span>&#8221; of framerate and bitrate.  This is then used to
 
209
deduce what belongs when, which is possible at least with CBR audio and is why
 
210
e.g. VBR is not supported (other than by some esoteric not well-supported
 
211
extensions).
 
212
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id523308"></a>OGG/OGM format</h3></div></div></div><p>
 
213
This is a fileformat from <a class="ulink" href="http://www.xiph.org/" target="_top">Xiphophorus</a>
 
214
typically (but not necessarily) containing <a class="ulink" href="http://www.xiph.org/vorbis/" target="_top">Vorbis</a>
 
215
and/or <a class="ulink" href="http://theora.org/" target="_top">Theora</a> streams.
 
216
It can be handled by means of <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-oggdemux.html" target="_top"><span class="emphasis"><em>oggdemux</em></span></a>
 
217
and <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-oggmux.html" target="_top"><span class="emphasis"><em>oggmux</em></span></a>, and e.g.
 
218
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-vorbisdec.html" target="_top"><span class="emphasis"><em>vorbisdec</em></span></a>,
 
219
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-vorbisenc.html" target="_top"><span class="emphasis"><em>vorbisenc</em></span></a>,
 
220
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-theoradec.html" target="_top"><span class="emphasis"><em>theoradec</em></span></a>
 
221
and <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-theoraenc.html" target="_top"><span class="emphasis"><em>theoraenc</em></span></a>
 
222
will probably come along to play as well.
 
223
</p><p>
 
224
Although it is not quite subject to limitations mentioned above
 
225
(e.g. does handle VBR audio), the format typically expects a
 
226
particular (video) framerate (as much as a specific audio samplerate also
 
227
always applies), and therefore corresponding (time-)regular streams.
 
228
</p><p>
 
229
Some stand-alone tools that may help in manipulating Ogg include the
 
230
<a class="ulink" href="http://www.xiph.org/" target="_top">vorbis-tools</a> and the
 
231
<a class="ulink" href="http://www.bunkus.org/videotools/ogmtools/" target="_top">OGMtools</a>
 
232
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-matroska-format"></a>Matroska format</h3></div></div></div><p>
 
233
Although <a class="ulink" href="http://www.matroska.org/" target="_top">Matroska</a> is not related to
 
234
AVI in either in its origin or its bitstream structure, it is similar
 
235
in that it basically stores chunks/blocks of data, preceded by a header and
 
236
(optionally) followed by index-like data.  A simple
 
237
<span class="emphasis"><em>gst-inspect</em></span>ion
 
238
(of <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-matroskamux.html" target="_top"><span class="emphasis"><em>matroskamux</em></span></a> or
 
239
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-matroskademux.html" target="_top"><span class="emphasis"><em>matroskademux</em></span></a>) easily shows that it can contain quite a range
 
240
of material, forming a superset of AVI capabilities in this regard.
 
241
There are some more differences not evident at this first sight:
 
242
</p><div class="itemizedlist"><ul><li><p>
 
243
it can hold (any number of) video, audio or subtitle streams, although the
 
244
latter are just not yet supported by <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-matroskamux.html" target="_top"><span class="emphasis"><em>matroskamux</em></span></a>
 
245
(however, see also <a class="xref" href="howto.html#sect-subtitles" title="Subtitles">&#8220;
 
246
Subtitles
 
247
&#8221;</a>)
 
248
[whereas an AVI contains at most 1 video stream and a number of audio ones]
 
249
</p></li><li><p>
 
250
each datablock is recorded along with a (media)timestamp and (media)duration;
 
251
in particular this caters for (audio) VBR [whereas AVI does not record such
 
252
information and typically only relies on framerate or constant bitrate]
 
253
</p></li><li><p>
 
254
a table of references (index) is included which could (theoretically) refer to
 
255
every datablock, but usually only does so to a (fairly dense) subset of
 
256
keyframes [whereas an AVI holds an index to all datachunks]
 
257
</p></li><li><p>
 
258
only v2 Matroska files may hold detailed keyframe information
 
259
(as only <code class="literal">SimpleBlock</code> indicates whether or not a block
 
260
holds a keyframe; but this is not used in Matroska v1 files)
 
261
[whereas keyframe info is fully available in any decent non-corrupt AVI]
 
262
</p></li></ul></div><p>
 
263
</p><p>
 
264
Hence, some practical considerations follow
 
265
</p><div class="itemizedlist"><ul><li><p>
 
266
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-matroskamux.html" target="_top"><span class="emphasis"><em>matroskamux</em></span></a> can basically be freely used
 
267
in stead of <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-avimux.html" target="_top"><span class="emphasis"><em>avimux</em></span></a>.
 
268
One need only (additionally) make sure that the
 
269
timestamps going into the former make up a nice consecutive (perfect) stream, as
 
270
they will be recorded for posterity and used in later playback.  This could be
 
271
achieved e.g. by means of <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gstreamer-plugins/html/gstreamer-plugins-identity.html" target="_top"><span class="emphasis"><em>identity</em></span></a> (with
 
272
<span class="property">single-segment</span> <code class="literal">true</code>) or <a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-stamp.html" target="_top"><span class="emphasis"><em>stamp</em></span></a>
 
273
inserted before an encoder element or muxer (some encoders like competing with
 
274
muxer on the notion of time, and also keep an eye on this).
 
275
</p></li><li><p>
 
276
Pass-through transcoding is possible with Matroska input, but may likely need
 
277
an element such as <a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-divxkey.html" target="_top"><span class="emphasis"><em>divxkey</em></span></a> to ensure that the
 
278
meta-information on keyframe-ness is properly marked.  If not, lacking this
 
279
metadata in the input, all data will be assumed a keyframe by default.
 
280
</p></li><li><p>
 
281
If interested in a bit of history and some inter-operability; some (not so
 
282
much) older versions of <a class="ulink" href="http://www.mplayerhq.hu/" target="_top">MPlayer</a> do not recognize the full set of possible
 
283
bytetags in a Matroska file, and may consequently fail to find a valid
 
284
videostream.
 
285
This could be prevented by nudging tags into another direction by means of a
 
286
capsfilter, an example fragment being
 
287
</p><div class="informalexample"><pre class="programlisting">
 
288
  stamp ! ffenc_mpeg4 ! video/x-divx,divxversion=5 ! matroskamux
 
289
</pre></div><p>
 
290
Similarly, older <a class="ulink" href="http://www.mplayerhq.hu/" target="_top">MPlayer</a> versions cannot handle v2 files.
 
291
</p></li></ul></div><p>
 
292
If needed or desired, the stand-alone
 
293
<a class="ulink" href="http://www.bunkus.org/videotools/mkvtoolnix/" target="_top">MKVToolnix</a> tools can aid in managing
 
294
Matroska files.
 
295
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-quicktime-format"></a>QuickTime format</h3></div></div></div><p>
 
296
Likewise, <a class="ulink" href="http://developer.apple.com/quicktime/" target="_top">QuickTime</a>, designed by Apple,
 
297
is quite different in origin and bitstream, but alike in that it also basically
 
298
stores variably sized blocks/atoms of data, along with metadata describing
 
299
the streams/tracks contained in the file and providing index-like data.
 
300
The very same syntactical format is also used as an ISO MPEG-4 container format
 
301
(<code class="literal">.m4a</code>, <code class="literal">.mp4</code>),
 
302
albeit with some variation in types of boxes considered
 
303
(where ISO specs refer to the syntactical entity &#8220;<span class="quote">atom</span>&#8221; as a
 
304
&#8220;<span class="quote">box</span>&#8221;, see e.g. the concise ISO MPEG-4 14496-12 base media specification
 
305
in the <a class="ulink" href="http://standards.iso.org/ittf/PubliclyAvailableStandards/index.html" target="_top">publicly available ISO standards</a>).
 
306
Though hardly a practical concern, it might be noted that the metadata is
 
307
typically stored at the end of a file following the actual media contents,
 
308
unlike other formats considered (and somewhat contrary to colloquially
 
309
referring to metadata as a &#8220;<span class="quote">header</span>&#8221;).
 
310
</p><p>
 
311
The comments and practical considerations of the previous section apply
 
312
just as well in this case, except for the following replacement or additional
 
313
notes:
 
314
</p><div class="itemizedlist"><ul><li><p>
 
315
QuickTime metadata indexes all datablocks (samples) and also holds full keyframe
 
316
info (synchronization sample table).
 
317
</p></li><li><p>
 
318
<span class="emphasis"><em>ffmux_mov</em></span> and
 
319
<span class="emphasis"><em>ffmux_mp4</em></span> provide a working QuickTime
 
320
and MP4 muxer respectively, with only some moderate variation in the resulting
 
321
output and types of accepted input stream (depending on the specification
 
322
involved).  However, the similarly related <span class="emphasis"><em>qtmux</em></span>,
 
323
<span class="emphasis"><em>mp4mux</em></span>, <span class="emphasis"><em>gppmux</em></span>
 
324
and <span class="emphasis"><em>mj2mux</em></span> should be considered more reliable.
 
325
Recall that similar observations with respect to timestamps
 
326
as in the foregoing section apply.
 
327
</p></li></ul></div><p>
 
328
Some stand-alone helper and/or debug management utilities are provided by
 
329
<a class="ulink" href="http://mpeg4ip.sourceforge.net/" target="_top">MPEG4IP</a> or
 
330
<a class="ulink" href="http://libquicktime.sourceforge.net/" target="_top">libquicktime</a>.
 
331
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-mpeg-muxing"></a>MPEG PS muxing</h3></div></div></div><p>
 
332
Either <span class="emphasis"><em>ffmux_mpeg</em></span>
 
333
or <span class="emphasis"><em>mplex</em></span><sup>[<a id="id523746" href="#ftn.id523746" class="footnote">2</a>]</sup>
 
334
produce an MPEG program stream,
 
335
the former based on <a class="ulink" href="http://ffmpeg.sourceforge.net/" target="_top">ffmpeg</a>'s <span class="package">avformat</span> library, and the
 
336
latter on <a class="ulink" href="http://mjpeg.sourceforge.net/" target="_top">mjpegtools</a>' mplex.  Though neither confirmed nor explained, it
 
337
appears that the output of the former element may only (??)
 
338
be handled (well ??) by ffmpeg aware/related (software) players (notably
 
339
<a class="ulink" href="http://www.mplayerhq.hu/" target="_top">MPlayer</a>), a (possible ??) limitation not so affecting the latter's results.
 
340
</p><p>
 
341
Unlike any other (typical) muxer element, <span class="emphasis"><em>mplex</em></span> 
 
342
totally disregards any provided time metadata in input streams.
 
343
This is (implicitly) determined from other information extracted from
 
344
the (compressed) bitstream itself, such as framerate, samplerate, &#8230;
 
345
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-ffmpeg-muxers"></a>FFMPEG muxers</h3></div></div></div><p>
 
346
As already indicated by example in the previous section,
 
347
various muxers of <a class="ulink" href="http://ffmpeg.sourceforge.net/" target="_top">ffmpeg</a>'s avformat library are wrapped and provided
 
348
by the ffmux plugin.  They should<sup>[<a id="id523807" href="#ftn.id523807" class="footnote">3</a>]</sup> produce results similar to those
 
349
of the standalone <span class="command"><strong>ffmpeg</strong></span> binary, possibly with varying
 
350
degrees of success.
 
351
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-subtitles"></a>
 
352
Subtitles
 
353
</h3></div></div></div><p>
 
354
Subtitles can come in a variety of <a class="ulink" href="http://www.matroska.org/technical/specs/subtitles/index.html" target="_top">formats</a>, be it
 
355
containing the actual text to be displayed (optionally with some sort of style
 
356
information) or simply a direct bitmap (encoded) form of what the end-result
 
357
text should be on screen (as for <a class="ulink" href="http://sam.zoy.org/writings/dvd/subtitles/" target="_top">DVD
 
358
subtitles</a>).
 
359
In either case, they can also be supplied in a separate file.
 
360
</p><p>
 
361
Although all of the above are internally basically well supported,
 
362
most <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> (<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-playbin.html" target="_top"><span class="emphasis"><em>playbin</em></span></a> based) players are
 
363
limited to text-based subtitles (whether or not contained in a separate file).
 
364
In particular, that leaves a few gaps when it comes to DVD subtitle playback
 
365
or muxing subtitle streams into a (supporting) container format, e.g. Matroska.
 
366
However, there are some patches in <a class="ulink" href="http://bugzilla.gnome.org/show_bug.cgi?id=415754" target="_top">#415754</a> that
 
367
take care of this.  For instance, having applied these, a DVD
 
368
can be transcoded (including subtitles) into a Matroska container by means of
 
369
following pipeline:
 
370
</p><div class="informalexample"><pre class="programlisting">
 
371
dvdreadsrc title=2 ! dvddemux name=demux \
 
372
matroskamux name=mux ! filesink location=dvd.mkv \
 
373
demux. ! mpeg2dec ! queue  ! ffenc_mpeg4 ! mux. \
 
374
demux.audio_00 ! a52dec ! queue ! audioconvert ! lame ! mux. \
 
375
demux.subpicture_05 ! queue ! dvdsubparse ! mux.subtitle_0
 
376
</pre></div><p>
 
377
Alternatively, <span class="command"><strong>entrans</strong></span> could be used in dynamic mode, with a
 
378
<span class="emphasis"><em>decodebin2</em></span> based pipeline,
 
379
which is much more convenient when it comes to selecting (several) desired streams:
 
380
</p><div class="informalexample"><pre class="programlisting">
 
381
entrans.py --decoder decodebin2 \
 
382
--set-prop 'decodebin2:caps:video/x-raw-yuv;audio/x-raw-int;
 
383
            audio/x-raw-float;video/x-dvd-subpicture' \
 
384
-i dvd://2 -o dvd.mkv --an 1,3 --on 6,16,19,21 -- \
 
385
--video ffenc_mpeg4 \
 
386
--audio audioconvert ! lame \
 
387
--other dvdsubparse
 
388
</pre></div><p>
 
389
Of course, in either case,
 
390
some (source and stream selecting) numbers may be different, and it
 
391
can also be extended to several audio and subtitle streams with the
 
392
corresponding evident modifications.  Similarly, other codecs could
 
393
easily be chosen and configured as desired.
 
394
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="sect-recording"></a>Recording</h3></div></div></div><p>
 
395
In this case, the &#8220;<span class="quote">input</span>&#8221; is some live real-time source, data
 
396
from which is to be recorded and kept for future use by means of (a.o.) one of
 
397
the above muxers. Although this source can be a great many things, e.g.
 
398
network, or nowadays often some type of DVB source, the intention here is to
 
399
focus on a &#8220;<span class="quote">raw</span>&#8221; source, i.e. typically a <a class="ulink" href="url-v4l" target="_top">video4linux</a> device
 
400
(such as an analogue tv capture card or webcam).
 
401
</p><p>
 
402
In many ways, there is nothing special about this, and one can record
 
403
using a pipeline built according to basic principles as
 
404
follows
 
405
</p><div class="informalexample"><pre class="programlisting">
 
406
v4l2src queue-size=15 ! video/x-raw-yuv,framerate=25/1,width=384,height=576 ! \
 
407
  ffenc_mpeg4 name=venc \
 
408
alsasrc ! audio/x-raw-int,rate=48000,channels=1 ! audioconvert ! lame name=aenc \
 
409
avimux name=mux ! filesink location=rec.avi venc. ! mux. aenc. ! mux.
 
410
</pre></div><p>
 
411
Of course, the particular image and audio capture settings may vary,
 
412
albeit within some limitations typically inherent to the device.
 
413
Also, this pipeline may elicit some complaints from the encoder regarding
 
414
timestamps; see also further on.
 
415
</p><p>
 
416
Although the above will (how?) typically work, it is nevertheless reasonable to
 
417
be concerned or have questions about:
 
418
</p><div class="itemizedlist"><ul><li><p><b>Buffering.&#160;</b>
 
419
A lot of things may be going on in a multi-tasking system, which can keep
 
420
(mainly) CPU and other resources temporarily occupied elsewhere, although the
 
421
<span class="emphasis"><em>real-time</em></span> data keeps coming in, and we don't want to miss
 
422
any of this (or as little as possible at least).  Is there some
 
423
buffering going on to (shortly) hold on to data for it to be picked up a bit
 
424
later, as opportunity permits ?
 
425
</p></li><li><p><b>Synchronization.&#160;</b>
 
426
Is there any system in place that (at least) tries to ensure that
 
427
videoframes end up &#8220;<span class="quote">along-side</span>&#8221; the proper audio data
 
428
(or vice versa) ?
 
429
</p></li></ul></div><p>
 
430
</p><p>
 
431
Buffering here occurs on a low (device) level; the driver will arrange
 
432
for a number of buffers and configure the device to capture data into these
 
433
buffers.  As such, the device can always continue capturing in real-time for at
 
434
least a while, even if there are some delays elsewhere.  In case of e.g.
 
435
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-v4l2src.html" target="_top"><span class="emphasis"><em>v4l2src</em></span></a>, the number of framebuffers is
 
436
controlled by the <span class="property">queue-size</span> property, although the
 
437
actual resulting queue still depends on the particular device's capability.
 
438
Similarly, <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-alsasrc.html" target="_top"><span class="emphasis"><em>alsasrc</em></span></a>'
 
439
<span class="property">buffer-time</span> and <span class="property">latency-time</span>
 
440
control the total capacity of the buffer and the size of each individual buffer
 
441
(respectively), again up to best effort approximation by the device(driver).
 
442
</p><p>
 
443
A live audio source such as <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-alsasrc.html" target="_top"><span class="emphasis"><em>alsasrc</em></span></a> will
 
444
provide the pipeline with an (audio) clock, which (basically) advances
 
445
according to the number of captured samples.  All captured data is then
 
446
&#8220;<span class="quote">stamped</span>&#8221; with the time (of capture) as perceived by this
 
447
clock.  Evidently, this already ensures that the captured audio stream makes up
 
448
a very nice, time-perfect stream.  As videoframes are also stamped this way,
 
449
this aligns video data with audio data, for the most part &#8230;
 
450
As indicated in previous sections, most formats (and muxers) expect video data
 
451
to have a particular framerate, and the incoming data to abide by this.
 
452
If not, strange things (notably loss of synchronization) will happen.
 
453
Data may fail to abide due to:
 
454
</p><div class="itemizedlist"><ul><li><p>
 
455
device (mal)performance; a tv capture card usually manages to deliver frames
 
456
in a regular pace at the proper framerate, but this need not be the case for all
 
457
devices, e.g. webcams
 
458
</p></li><li><p>
 
459
delay effects introduced by buffering, that is, when a (video) buffer is taken
 
460
out of a (device) queue and &#8220;<span class="quote">timestamped</span>&#8221;, there is a delay with
 
461
respect to the &#8220;<span class="quote">real</span>&#8221; capture time.  In particular, this can lead
 
462
to irregular clusters of timestamps (even if actual capturing goes by the book).
 
463
In fact, this type of &#8220;<span class="quote">clustering</span>&#8221; prompts the encoder
 
464
to complain about timestamps, as indicated earlier.
 
465
</p></li></ul></div><p>
 
466
So, the video stream needs to be tamed and regularized before encoding and
 
467
muxing it, as a muxer may actually disregard the (nicely accurately computed)
 
468
synchronized timestamp and rely on expected framerate only.
 
469
Such taming could be done by inserting <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videorate.html" target="_top"><span class="emphasis"><em>videorate</em></span></a> (somewhere before the encoder), which would then
 
470
drop and/or duplicate frames as needed to obtain a perfect and (still) synchronized
 
471
stream.
 
472
However, due to <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videorate.html" target="_top"><span class="emphasis"><em>videorate</em></span></a>'s current technique,
 
473
this may lead to more frame drops or duplicates than really needed,
 
474
particularly due to the above timestamp clustering; a concentration of frames
 
475
would call for dropping, a subsequent lack for duplication, &#8230;
 
476
An alternative is to use the following fragment
 
477
</p><div class="informalexample"><pre class="programlisting">
 
478
v4l2src ! stamp sync-margin=2
 
479
</pre></div><p>
 
480
<a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-stamp.html" target="_top"><span class="emphasis"><em>stamp</em></span></a> is aware of desired framerate and also counts incoming frames.  At
 
481
regular intervals (set by <span class="property">sync-interval</span>), it verifies
 
482
whether the incoming videostream timestamp is off by more than
 
483
<span class="property">sync-margin</span> frames with respect to expected timestamp.
 
484
If so, proper dropping or duplication is performed to resync.  Periodic checking
 
485
against &#8220;<span class="quote">real-time</span>&#8221; makes the process less sensitive to
 
486
intermittent variations.
 
487
</p><p>
 
488
In conclusion, the following pipeline should cater for recording in most
 
489
conditions and circumstances:
 
490
</p><div class="informalexample"><pre class="programlisting">
 
491
v4l2src queue-size=16 ! video/x-raw-yuv,framerate=25/1,width=384,height=576 ! \
 
492
  stamp sync-margin=2 sync-interval=5 ! queue ! ffenc_mpeg4 name=venc  \
 
493
alsasrc buffer-time=1000000 ! audio/x-raw-int,rate=48000,channels=1 ! \
 
494
  queue ! audioconvert ! lame name=aenc   \
 
495
avimux name=mux ! filesink location=test.avi aenc. ! mux. venc. ! mux.
 
496
</pre></div><p>
 
497
In particular, it features resync'ing at a higher frequency (in the same thread
 
498
as and immediately following capturing), and provides additional buffering
 
499
(beyond that on driver level).
 
500
</p><p>
 
501
Alternatively, one might turn to a container format and muxer that does
 
502
<span class="emphasis"><em>not</em></span> expect its (video) input to have a particular framerate,
 
503
such as notably the <a class="link" href="howto.html#sect-matroska-format" title="Matroska format">Matroska format</a>.
 
504
Such format caters for faithful snapshot recording and subsequent playback
 
505
(including original timestamps) without needing to regularize input.
 
506
In principle, there is then no need for <a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-stamp.html" target="_top"><span class="emphasis"><em>stamp</em></span></a> or
 
507
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videorate.html" target="_top"><span class="emphasis"><em>videorate</em></span></a>, though an encoder might still complain
 
508
about the quality/regularity of timestamps, as mentioned earlier.
 
509
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
 
510
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-v4l2src.html" target="_top"><span class="emphasis"><em>v4l2src</em></span></a> may produce buffers that contain
 
511
mmap'ed driver buffers (only if <span class="property">always-copy</span>
 
512
is <code class="literal">false</code> in latest version),
 
513
and these may (depending on your mileage) wreac havoc
 
514
with (separate thread) encoding performance.  Presumably, the recycling of
 
515
mmap'ed v4l2src buffers leads to additional (lock or driver)
 
516
contention (particularly when such releasing occurs in a separate thread).
 
517
The above example <span class="emphasis"><em>does not</em></span> suffer from this,
 
518
because <a class="ulink" href="../../gst-entrans-plugins/html/gst-entrans-plugins-stamp.html" target="_top"><span class="emphasis"><em>stamp</em></span></a> copies the data into a
 
519
&#8220;<span class="quote">normal</span>&#8221; buffer.  Alternatively, <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-efence.html" target="_top"><span class="emphasis"><em>efence</em></span></a> or a combination of 2 counter-acting
 
520
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-videobox.html" target="_top"><span class="emphasis"><em>videobox</em></span></a>es could also be (ab)used for this purpose.
 
521
</p></div><p>
 
522
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id524281"></a>Multiple Images</h3></div></div></div><p>
 
523
In this case, the &#8220;<span class="quote">input</span>&#8221; or &#8220;<span class="quote">output</span>&#8221; consists of a
 
524
collection of (image)files.
 
525
</p><p>
 
526
The easiest native <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> way of handling these is for example
 
527
</p><div class="informalexample"><pre class="programlisting">
 
528
multifilesrc location=image-%05d.jpg num-buffers=25 ! image/jpeg,framerate=25/1 ! \
 
529
  jpegdec ! videoflip method=vertical-flip ! jpegenc ! \
 
530
  multifilesink location=image-out-%05d.jpg
 
531
</pre></div><p>
 
532
(assuming that it concerns 25 input files <code class="literal">image-00000.jpg</code>,
 
533
<code class="literal">image-00001.jpg</code>, &#8230;)
 
534
</p><p>
 
535
Another approach is to use external tools to merge/split the set of files
 
536
to/from one file and deal with this file.  One candidate is the multipart
 
537
format used by <a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-multipartmux.html" target="_top"><span class="emphasis"><em>multipartmux</em></span></a> and
 
538
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-multipartdemux.html" target="_top"><span class="emphasis"><em>multipartdemux</em></span></a>.  Each block of data in multipart
 
539
files is preceded by (in <code class="function">printf</code> format)
 
540
</p><pre class="programlisting">
 
541
"\r\n--%s\r\nContent-Type: %s\r\nContent-Length: %u\r\n\r\n",
 
542
  <em class="lineannotation"><span class="lineannotation">boundary, mime-type, size</span></em>
 
543
</pre><p>
 
544
where boundary is configurable (<code class="literal">ThisRandomString</code> by
 
545
default), and the <code class="literal">Content-Length</code> line is optional.
 
546
Clearly, a fairly simple (shell) script or pipeline
 
547
suffices to transform such a file from/to a set a files.  Having such at hand,
 
548
the above example then becomes:
 
549
</p><div class="informalexample"><pre class="programlisting">
 
550
filesrc location=image.multipart ! multipartdemux ! \
 
551
  jpegdec ! videoflip method=vertical-flip ! jpegenc ! \
 
552
  multipartmux ! filesink location=image-out.multipart
 
553
</pre></div><p>
 
554
</p><p>
 
555
A similar approach could use an intermediate single file in <a class="ulink" href="http://mjpeg.sourceforge.net/" target="_top">mjpegtools</a>'
 
556
YUV4MPEG2 format, which is really a sequence of uncompressed images,
 
557
see <a class="ulink" href="../../gst-entrans-plugins/html/ch02.html" target="_top">entrans plugin collection</a>
 
558
documentation for more details on this.
 
559
</p></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="sect-processing"></a>Media processing</h2></div></div></div><p>
 
560
Of course, transcoding is typically not limited to a transformation from one
 
561
(codec or muxer) format to another, but usually also involves applying some
 
562
(filter) operations.  These can range from basic operations such as scaling
 
563
(<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videoscale.html" target="_top"><span class="emphasis"><em>videoscale</em></span></a>) or
 
564
clipping (<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-videobox.html" target="_top"><span class="emphasis"><em>videobox</em></span></a>) to
 
565
various effects (e.g. effectv plugin) or any transformation one can envision. 
 
566
A <span class="citerefentry"><span class="refentrytitle"><span class="command"><strong>gst-inspect</strong></span></span>(1)</span> browse is bound to reveal many more examples.
 
567
</p><p>
 
568
Although the details of the operation performed by such filters is typically
 
569
governed by their properties, some of these elements
 
570
(<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videoscale.html" target="_top"><span class="emphasis"><em>videoscale</em></span></a>,
 
571
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-videorate.html" target="_top"><span class="emphasis"><em>videorate</em></span></a>,
 
572
<a class="ulink" href="http://www.gstreamer.net/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-audiorate.html" target="_top"><span class="emphasis"><em>audiorate</em></span></a>, &#8230;) must necessarily also consider
 
573
the caps of connected elements. Conversely, their operation can be affected by applying
 
574
a specific capsfilter, see e.g. examples in <a class="xref" href="howto.html#sect-ffmpeg-encoders" title="FFMPEG encoders">&#8220;FFMPEG encoders&#8221;</a>.
 
575
</p><p>
 
576
Last but not least, some additional filters are available in the
 
577
<a class="ulink" href="../../gst-entrans-plugins/html/ch02.html" target="_top">entrans plugin collection</a>.
 
578
</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="sect-motivation"></a>Comparison and Motivation</h2></div></div></div><p>
 
579
As mentioned earlier, there is a great many software that handles
 
580
multimedia playback.  <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>, as a framework, makes it (relatively) easy
 
581
to build a player; e.g. GNOME player <a class="ulink" href="http://www.gnome.org/projects/totem/" target="_top">totem</a> has a <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>
 
582
backend, and <a class="ulink" href="http://www.fluendo.com/elisa" target="_top">elisa</a>, to name a
 
583
few among <a class="ulink" href="http://www.gstreamer.net//apps" target="_top">GStreamer
 
584
applications</a>
 
585
</p><p>
 
586
When it comes to <span class="emphasis"><em>creating</em></span> media files, e.g. by transcoding
 
587
existing media, there is not such an abundance of choice.
 
588
The following table compares some media processing and <span class="emphasis"><em>creation</em></span>
 
589
capabilities:
 
590
</p><div class="informaltable"><table border="1"><colgroup><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr><th>&#160;</th><th>Ogg</th><th>Matroska</th><th>AVI</th><th>MPG</th><th>Filters</th><th>Cutting</th></tr></thead><tbody><tr><td><a class="ulink" href="http://www.mplayerhq.hu/" target="_top">mencoder</a></td><td>no</td><td>no</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr><tr><td><a class="ulink" href="http://ffmpeg.sourceforge.net/" target="_top">ffmpeg</a></td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>no</td></tr><tr><td><a class="ulink" href="http://www.transcoding.org/" target="_top">transcode</a></td><td>no</td><td>no</td><td>yes</td><td>no</td><td>yes</td><td>yes</td></tr><tr><td><a class="ulink" href="http://avidemux.sourceforge.net/" target="_top">avidemux</a></td><td>yes</td><td>no</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr><tr><td><a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a></td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr></tbody></table></div><p>
 
591
Quite possibly, other (demuxing, decoding) features that may be of interest have
 
592
been disregarded here, but as it stands above, a (tentative) conclusion follows.
 
593
Fortunately, some applications do actually make use of the above <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>
 
594
capabilities, e.g. <a class="ulink" href="http://www.pitivi.org/" target="_top">PiTiVi</a> (a
 
595
video editor), <a class="ulink" href="http://thoggen.net/" target="_top">Thoggen</a> (a DVD ripper), and of course <span class="command"><strong>entrans</strong></span>.
 
596
So, a non-exhaustive overview of the application spectrum is:
 
597
</p><div class="informaltable"><table border="1"><colgroup><col /><col /><col /><col /></colgroup><thead><tr><th>&#160;</th><th>Non-GStreamer</th><th>GStreamer</th><th>Comments</th></tr></thead><tbody><tr><td>player</td><td>many</td><td>many</td><td class="auto-generated">&#160;</td></tr><tr><td>cmd-line transcoding</td><td><a class="ulink" href="http://www.mplayerhq.hu/" target="_top">mencoder</a>, <a class="ulink" href="http://www.transcoding.org/" target="_top">transcode</a></td><td><span class="command"><strong>entrans</strong></span></td><td class="auto-generated">&#160;</td></tr><tr><td>GUI editing/transcoding</td><td><a class="ulink" href="http://avidemux.sourceforge.net/" target="_top">avidemux</a></td><td><a class="ulink" href="http://www.pitivi.org/" target="_top">PiTiVi</a>, <a class="ulink" href="http://thoggen.net/" target="_top">Thoggen</a></td><td class="auto-generated">&#160;</td></tr></tbody></table></div><p>
 
598
</p><p>
 
599
It should again be noted that all these (<a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a>) applications make use of a
 
600
common API and codebase, and as such can benefit from a &#8220;<span class="quote">single</span>&#8221;
 
601
collective developer build and maintenance effort.  Furthermore, due to its
 
602
plugin system, <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> is not only free software (as many others), but also
 
603
offers the freedom to extend it (comfortably) at will to include more formats,
 
604
filters, &#8230;, which then become available at once to all the above
 
605
applications.
 
606
</p><p>
 
607
Finally, let's demonstrate the &#8220;<span class="quote">many players</span>&#8221; mentioned above,
 
608
although not by lengthy list of examples.
 
609
A <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> player can indeed arise quite easily.  In fact,
 
610
simply running the following pipeline already yields an extremely basic
 
611
&#8220;<span class="quote">player</span>&#8221; with some minimal navigation<sup>[<a id="id524944" href="#ftn.id524944" class="footnote">4</a>]</sup>.
 
612
It requires only trivial
 
613
modification to control which (if any) effects and filters to apply on-the-fly.
 
614
</p><pre class="programlisting">
 
615
filesrc location=example-in.ogm ! decodebin name=bin \
 
616
bin. ! progressreport ! navseek seek-offset=10 ! timeoverlay ! xvimagesink \
 
617
bin. ! audioconvert ! alsasink
 
618
</pre><p>
 
619
</p></div><div class="footnotes"><br /><hr width="100" align="left" /><div class="footnote"><p><sup>[<a id="ftn.id523269" href="#id523269" class="para">1</a>] </sup>As of release 0.10.5 of gst-ffmpeg.</p></div><div class="footnote"><p><sup>[<a id="ftn.id523746" href="#id523746" class="para">2</a>] </sup>As of release 0.10.8
 
620
of gst-plugins-bad, and only operates with latest <a class="ulink" href="http://mjpeg.sourceforge.net/" target="_top">mjpegtools</a> release candidates.
 
621
</p></div><div class="footnote"><p><sup>[<a id="ftn.id523807" href="#id523807" class="para">3</a>] </sup>
 
622
The standalone <span class="command"><strong>ffmpeg</strong></span>'s architecture provides the avformat code
 
623
with full (intimate) access to a corresponding encoder
 
624
<span class="structname">AVCodecContext</span> structure,
 
625
which in ffmux can only be built approximately by means of caps information.
 
626
Results may or may not vary depending on particular format used and the way
 
627
it is coded.
 
628
</p></div><div class="footnote"><p><sup>[<a id="ftn.id524944" href="#id524944" class="para">4</a>] </sup>
 
629
Requires at least <a class="ulink" href="http://www.gstreamer.net/" target="_top"><span class="application">GStreamer</span></a> core 0.10.13.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index.html">&lt;&lt; Previous</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="package.html">Next &gt;&gt;</a></td></tr><tr><td width="40%" align="left" valign="top">GStreamer Transcoding&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Table of Contents</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;2.&#160;Package Documentation</td></tr></table></div><div class="footer-homepage"><table width="100%"><tr><td width="40%" align="left">Last created:
 
630
2010-03-03&#160;22:13:23+01:00</td><td width="20%" align="center"><a href="http://gentrans.sourceforge.net/" title="GEntrans: Home page">GEntrans home page</a></td><td width="40%" align="right"></td></tr></table></div></body></html>