16

What is the syntax for caps, specifying media capabilities, in gstreamer? Caps are strings that specify the type of media allowed and look like "audio/x-raw-int,..." but I haven't been able to find good documentation on exactly what is allowed in a caps string.

joeforker
  • 36,731
  • 34
  • 138
  • 231

7 Answers7

13

The syntax is:

<type>[,<property>=<value>]...

Note that the type is not a MIME type, however much it may look like one.

You can find out which caps properties elements support by using gst-inspect. It will proviide "pad templates" for the element's pads, which will specify the ranges of caps supported.

The GStreamer plugin writer's guide also contains a list of defined types which describes properties for common audio, video and image formats.

daf
  • 4,547
  • 3
  • 28
  • 34
8

Here is the format as far as I understand it:

caps = <caps_name>, <field_name>=<field_value>[; <caps>]
<caps_name> = image/jpeg etc
<field_name> = width etc
<field_value> = <fixed_field_value>|<ranged_field_value>|<multi_field_value>
<fixed_field_value> = 800 etc
<ranged_field_value> = [<lower_value>, <upper_value>]
<multi_field_value> = {<fixed_field_value>, <fixed_field_value>, <fixed_field_value>, ...}
Meros
  • 1,088
  • 10
  • 10
7

I see you are after audio.

I'll just give you the long version, you can drop or change the parts you don't need. It changes between GStreamer 0.10 and GStreamer 1.0 though. I'll give both:

for GStreamer 0.10:

audio/x-raw-int,rate=44100,channels=2,width=16,depth=16,endianness=1234,signed=true

for GStreamer 1.0:

audio/x-raw,format=S16LE,channels=2,layout=interleaved

As you can see, with 1.0, you will need to combine the audio format. S16LE means signed + int + 16 width + little endian (=1234).

user2032040
  • 101
  • 1
  • 4
6

In Java, for gstreamer-java

final Element videofilter = ElementFactory.make("capsfilter", "flt");
videofilter.setCaps(Caps.fromString("video/x-raw-yuv, width=720, height=576"
+ ", bpp=32, depth=32, framerate=25/1"));

In C, say you want videoscale caps filter

GstElement *videoscale_capsfilter;
GstCaps* videoscalecaps;
...
...
videoscale = gst_element_factory_make ("videoscale", "videoscale");
g_assert (videoscale);
videoscale_capsfilter = gst_element_factory_make ("capsfilter", "videoscale_capsfilter");
g_assert (videoscale_capsfilter);
... 
...

then set properties

g_object_set( G_OBJECT ( videoscale_capsfilter ),  "caps",  videoscalecaps, NULL );

then you could add these to bin and link them the way you have constructed media pipeline using gst-launch

/* Add Elements to the Bin */
gst_bin_add_many (GST_BIN (pipeline),source ,demux ,decoder ,videoscale ,videoscale_capsfilter ,ffmpegcolorspace ,ffmpegcolorspace_capsfilter,autovideosink,NULL);

 /* Link confirmation */
if (!gst_element_link_many (demux, decoder,videoscale, videoscale_capsfilter ,ffmpegcolorspace, ffmpegcolorspace_capsfilter, autovideosink, NULL)){
 g_warning ("Main pipeline link Fail...");
}

/* Dynamic Pad Creation */
if(! g_signal_connect (source, "pad-added", G_CALLBACK (on_pad_added),demux))
{
 g_warning ("Linking Fail...");
}
enthusiasticgeek
  • 2,422
  • 40
  • 49
  • I know this was posted 7 years ago but this was the exact solution I was looking for. However, I needed to figure out that I need to provide my caps into GstCaps* videoscalecaps; which was denoted by ... ... – Marcus Gee Apr 28 '20 at 21:45
5

This is how i use it in python...HTH

caps = gst.Caps("video/x-raw-yuv,format=(fourcc)AYUV,width=704,height=480")
capsFilter = gst.element_factory_make("capsfilter")
capsFilter.props.caps = caps
max taldykin
  • 11,186
  • 5
  • 39
  • 62
Hardy
  • 222
  • 2
  • 9
3

I'm unsure due to your question is about syntax, but "list of defined types" may be helpful.

RaubTieR
  • 59
  • 2
2

a partial answer, which i'm sure you've worked out already:

"MIMETYPE,PROPERTY1=VALUE1,PROPERTY2=VALUE2,..."

formally, caps are not represented by strings but by a GstCaps object containing an array of GstStructures. see the documentation here.

perhaps if we work out a definitive answer here we could submit a documentation patch for the function gst_caps_from_string()

Jeremiah Rose
  • 3,445
  • 4
  • 21
  • 26