GStreamer - swap color channels of RGB-video

1.6k Views Asked by At

I am new to GStreamer and I try to swap the color channels of a RGB-video. (e.g. red to blue). How can I do this with gst-launch?

I go trough this list but I am unable to find an element to do it: http://gstreamer.freedesktop.org/documentation/plugins.html

2

There are 2 best solutions below

0
On BEST ANSWER

I wrote now my own Element. I used "Colorflip" as my base Element, changed the name to "ChannelFlip" (you must rename all methods from gst_video_flip_bla to gst_channel_flip_bla and rename the structs). Then I was able to register my element with:

gst_element_register(NULL, "channelflip", GST_RANK_NONE, GST_TYPE_CHANNEL_FLIP);

Then I added my enums to GstChannelFlipMethod and my properties to _GstChannelFlip. Changed caps to "RGB" and added my Code to gst_channel_flip_packed_simple and called it in gst_channel_flip_transform_frame instead of videoflip->process (videoflip, out_frame, in_frame); with:

GST_OBJECT_LOCK (videoflip);
    //videoflip->process (videoflip, out_frame, in_frame);
    gst_channel_flip_packed_simple(videoflip, out_frame, in_frame);
GST_OBJECT_UNLOCK (videoflip);
2
On

You can actually trick GStreamer by replacing the caps:

gst-launch-1.0 -v videotestsrc ! video/x-raw, format=RGBx ! capssetter replace=true caps="video/x-raw, format=(string)BGRx, width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive" ! videoconvert ! ximagesink

Please note that:

"width=(int)320, height=(int)240, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive"

are the default settings for videotestsrc. If you, for example, want another resolution, you need to declare it twice:

gst-launch-1.0 -v videotestsrc ! video/x-raw, format=RGBx, width=640, height=480 ! capssetter replace=true caps="video/x-raw, format=(string)BGRx, width=(int)640, height=(int)480, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive" ! videoconvert ! ximagesink

But of course having a dedicated element is the better solution in order to support proper dynamic caps negotiation.