How to set audio format in code

Tim-Philipp Müller t.i.m at zen.co.uk
Thu Feb 28 08:57:00 PST 2013


On Thu, 2013-02-28 at 09:46 -0700, Jim wrote:
> In the following gst-launch command line, right before the alsasink
> element, the audio format is being specified:
>
> gst-launch filesrc location=video.ts typefind=true ! flutsdemux
> name=demux demux. ! queue max-size-buffers=0 max-size-time=0 !
> vpudec ! mfw_v4lsink demux. ! queue max-size-buffers=0
> max-size-time=0 ! beepdec ! audioconvert ! 'audio/x-raw-int,
> channels=2' ! alsasink
> 
> 
> How would I specify the audio format in my C code? Since this is
> separated with an exclamation point (!) in the command line, it seems
> like a separate element so I tried:
> 
> gst_element_factory_make("audio/x-raw-int, channels=2",
> "myAudioFormat"); 
> 
> but that didn’t work.

That .. ! caps ! .. notation is a shortcut for a capsfilter element with
the given caps.

GstElement *capsfilter = gst_element_factory_make("capsfilter", NULL);
GstCaps *caps = gst_caps_from_string("audio/x-raw-int,channels=2");
g_object_set (capsfilter, "caps", caps, NULL);
gst_caps_unref (caps);

Cheers
 -Tim

PS: there's also gst_parse_launch() to create a complete pipeline from a
string like in gst-launch.







More information about the gstreamer-devel mailing list