Raw to jpeg image conversion using gstreamer in C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Raw to jpeg image conversion using gstreamer in C

5,571 Views
nikitbiraj
Contributor I

Hi,

I am working on encoding a raw file image to jpeg image in C

Below is working structure in comand line to encode image :

gst-launch filesrc location=/home/root/one.raw blocksize=608256 ! \

'video/x-raw-yuv, format=(fourcc)I420,width=(int)704,height=(int)576,framerate=(fraction)0/1'

! ffmpegcolorspace ! 'video/x-raw-yuv,format=(fourcc)I420,width=(int)704,height=(int)576,,framerate=(fraction)0/1' ! vpuenc codec = 12 ! \

filesink location=/home/root/image.jpg

Below are pipeline structure :

app->src = gst_element_factory_make("filesrc", "mysrc");

app->encoder = gst_element_factory_make("vpuenc", "enc");

app->video_convert  = gst_element_factory_make ("ffmpegcolorspace",  "converter");

app->imagesink = gst_element_factory_make("filesink", "myvsink");

have created all elements, objects.

g_object_set (app->src, "blocksize", BUFF_SIZE, NULL);

where BUFF_SIZE is 608256

g_object_set (app->encoder, "codec", 12, NULL);

gst_bin_add_many(GST_BIN(app->pipeline), (GstElement*)app->src,app->video_convert,app->encoder,

                         app->imagesink, NULL);

filesrc location using : g_object_set(G_OBJECT(app->src),

                                "location", "/home/root/one.raw",NULL);

and,

filesink location using  : g_object_set(G_OBJECT(app->imagesink),

                                   "location", "/home/root/tr2.jpg",NULL);

I am getting link failed when I try to link app->src and app->video_convert, and

app->video_convert and app->encoder

Below is C code for linking :

link_ok = gst_element_link_filtered (app->src, app->video_convert,

                                                    gst_caps_new_simple ("video/x-raw-yuv",

                                                        "format", G_TYPE_STRING, "I420",

                                                        "width",G_TYPE_INT, 704,

                                                        "height",G_TYPE_INT, 576,

                                                        //"framerate",GST_TYPE_FRACTION, 0,1,

                                                        NULL));

and

link_ok = gst_element_link_filtered (app->video_convert, app->encoder,

                                                          gst_caps_new_simple ("video/x-raw-yuv",

                                                              "format", G_TYPE_STRING, "I420",

                                                              "width",G_TYPE_INT, 704,

                                                              "height",G_TYPE_INT, 576,

                                                              "framerate",GST_TYPE_FRACTION, 1,1,

                                                          //  "pixel-aspect-ratio",GST_TYPE_FRACTION,1,1,

                                                              NULL));

Surprisingly the same caps works in command line but if I link through C its giving error.

What am I doing wrong?

Please do help.

Labels (1)
0 Kudos
5 Replies

2,197 Views
LeonardoSandova
Specialist I

What is the error's log? vpuenc is not able to do JPEG encoding, so try the ffmpeg one. Freescale has a color-space converter, called mfw_ipucsc, try it. It would be nice if you post the whole code (perhaps attached).

Leo

0 Kudos

2,197 Views
nikitbiraj
Contributor I

Please find attached code.

Preferably I want to use gstreamer hardware accelerator.

As you said I used mfw_ipucsc in converter, but I get linked failed. You can see in code as I am handling error.

0 Kudos

2,197 Views
LeonardoSandova
Specialist I

This is wrong

gst_bin_add_many(GST_BIN(app->pipeline), (GstElement*)app->src,app->video_convert,app->encoder,

                         app->imagesink, NULL);

You should build something like this

filesrc ! mfw_ipu_csc ! capsfilter ! jpegenc ! filesink

Leo

0 Kudos

2,197 Views
nikitbiraj
Contributor I

As you said I used mfw_ipu_csc and capfilter. Below is working structure in command line using gst-launch

gst-launch filesrc location=/home/root/one.raw blocksize=608256 ! \

capsfilter caps="video/x-raw-yuv,format=(fourcc)I420,width=704,height=576,framerate=(fraction)0/1" ! \

mfw_ipucsc ! capsfilter caps="video/x-raw-yuv,format=(fourcc)I420,width=704,height=576,framerate=(fraction)0/1" ! \

vpuenc codec=12 ! filesink location=/home/root/j1.jpg

Attached is my c code file which I created same like what I did in gst-launch command above. !

I get link failed at app->postcapsfilter, app->video_convert.

If I check error message I am getting Segmentation Fault.

What am I missing or is it correct way of linking? !

Is setting of capsfilter correct in code?

Gst-launch command works perfectly but if I convert same thing in C code I am getting error

0 Kudos

2,197 Views
LeonardoSandova
Specialist I

The first capsfilter element is redundant, so remove it. Enable debug log on you C code and share log; you need to figure out which element is the offending one.

0 Kudos