Internal data stream error. Display PNG using nvoverlaysink with c API

I want to play rtsp and PNG using nvoverlaysink and nvcompositor with c API.
(PNG or GIF, either one is OK.)
I have successfully decoded rtsp stream.
But,fails to display PNG.

I have successfully displayed a PNG file from the command line.
Compare command line and program debug output,
Execution from command line has pause and prerolling
It happens, but it does not occur when run from a program.

Here is the command.
gst-launch-1.0 -v nvcompositor name=comp
sink_0::xpos=0 sink_0::ypos=0 sink_0::width=720 sink_0::height=480
! nvoverlaysink overlay=1 overlay-x=0 overlay-y=0 overlay-w=1920 overlay-h=1080
uridecodebin uri=‘file:///home/admin/work/sample.png’ ! imagefreeze ! nvvidconv ! comp. -e

Here is the source.

int main(int argc, char *argv){

GMainLoop *loop;
GstBus *bus;
guint bus_watch_id;

gst_init(&argc, &argv);

GstElement *pipeline = gst_pipeline_new(“pipeline”);

GstElement *comp = gst_element_factory_make(“nvcompositor”,“comp”);

GstElement *videoSink = gst_element_factory_make(“nvoverlaysink”, “sink_nv”);
g_object_set(G_OBJECT (videoSink),
“overlay_x”, 0,“overlay_y”, 0,
“overlay_w”, 1920,“overlay_h”,1080,
“sync”,FALSE,NULL);

if (!pipeline || !comp || !videoSink){
g_printerr(“Error linking fields …1 \n”);
return 0;
}
gst_bin_add_many (GST_BIN(pipeline),comp,videoSink,NULL);
if(!gst_element_link_many(comp,videoSink,NULL)){printf("\nFailed to link parse to sink 1\n");}

loop = g_main_loop_new (NULL, FALSE);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));

bus_watch_id = gst_bus_add_watch (bus, bus_callback, loop);

GstElement *decode = gst_element_factory_make (“uridecodebin”,NULL);
g_object_set (G_OBJECT(decode), “uri”,“file:///home/admin/work/sample.png”, NULL);

GstElement *freeze =gst_element_factory_make (“imagefreeze”,NULL);
GstElement *conv=gst_element_factory_make(“nvvidconv”,NULL);

gst_bin_add_many (GST_BIN(pipeline),decode,freeze,conv, NULL);
gst_element_link_many(decode,freeze,conv,NULL);

GstPad *srcpad = gst_element_get_static_pad (conv,“src”);
GstPadTemplate *sink_pad_template = gst_element_class_get_pad_template(GST_ELEMENT_GET_CLASS(comp),“sink_%u”);
GstPad *sinkpad=gst_element_request_pad (comp,sink_pad_template,NULL, NULL);

if(gst_pad_link(srcpad,sinkpad)!= GST_PAD_LINK_OK) {
g_printerr (“source and sink pads could not be linked.\n”);
return;
}
g_object_set(sinkpad, “xpos”,0, NULL);
g_object_set(sinkpad, “ypos”,0, NULL);
g_object_set(sinkpad, “width”,720, NULL);
g_object_set(sinkpad, “height”,480, NULL);

gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_main_loop_run (loop);

g_print(“Close\n”);

gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);
gst_deinit ();
return 0;

Hi,
You may try pngdec plugin. Please check
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good/html/gst-plugins-good-plugins-pngdec.html

Thank you.It worked very well.
I re-wrote code.

GstElement *source = gst_element_factory_make (“filesrc”,NULL);
g_object_set (G_OBJECT(source),“location”,"/home/admin/work/sample.png",NULL);
GstElement *dec=gst_element_factory_make(“pngdec”,NULL);
GstElement *freeze = gst_element_factory_make(“imagefreeze”,NULL);
GstElement *conv = gst_element_factory_make(“nvvidconv”,NULL);

gst_bin_add_many (GST_BIN(pipeline),source,dec,freeze,conv,NULL);
gst_element_link_many(source,dec,freeze,conv,NULL);

GstPad *srcpad = gst_element_get_static_pad (conv,“src”);
GstPadTemplate *sink_pad_template = gst_element_class_get_pad_template(GST_ELEMENT_GET_CLASS(comp),“sink_%u”);
GstPad *sinkpad=gst_element_request_pad (comp,sink_pad_template,NULL, NULL);
if(gst_pad_link(srcpad,sinkpad)!= GST_PAD_LINK_OK) {
g_printerr (“source and sink pads could not be linked.\n”);
return;
}
g_object_set(sinkpad, “xpos”,0,“ypos”,0,“width”,720,“height”,480, NULL);

1 Like