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.
8 Answers
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.
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;
videoscalecaps = gst_caps_new_simple ("video/x-raw-rgb",
"width", G_TYPE_INT, 640, //GetWidth(),
"height", G_TYPE_INT, 480,//GetHeight(),
NULL);
...
...
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...");
}
-
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 ... ... Apr 28, 2020 at 21:45
-
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>, ...}
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).
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
-
I am looking for the syntax of the string that specifies the caps. "video/x-raw-yuv,..." Apr 8, 2010 at 17:17
I'm unsure due to your question is about syntax, but "list of defined types" may be helpful.
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()
from x264enc source code: https://github.com/GStreamer/gst-plugins-ugly/blob/master/ext/x264/gstx264enc.c#L693-L704
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-h264, "
"framerate = (fraction) [0/1, MAX], "
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ], "
"stream-format = (string) { avc, byte-stream }, "
"alignment = (string) au, "
"profile = (string) { high-4:4:4, high-4:2:2, high-10, high, main,"
" baseline, constrained-baseline, high-4:4:4-intra, high-4:2:2-intra,"
" high-10-intra }")
);
for this CAPS, when inpstected by gst-inspect, it's like:
Pad Templates:
SRC template: 'src'
Availability: Always
Capabilities:
video/x-h264
framerate: [ 0/1, 2147483647/1 ]
width: [ 1, 2147483647 ]
height: [ 1, 2147483647 ]
stream-format: { (string)avc, (string)byte-stream }
alignment: au
profile: { (string)high-4:4:4, (string)high-4:2:2, (string)high-10, (string)high, (string)main, (string)baseline, (string)constrained-baseline, (string)high-4:4:4-intra, (string)high-4:2:2-intra, (string)high-10-intra }