使用的GStreamer与C API显示图像 [英] display image using gstreamer with c API
问题描述
我尝试使用C API来显示此图像我用这个GST-launch命令用来做GStreamer的管道
GST-推出filesrc位置=pluto.jpg! jpegdec! ffmpegcolorspace! videobalance饱和度= 0!不许动! ximagesink
当我尝试它,它做工精细,但是当我尝试将其转换为C code不起作用有人能帮助我吗?
的#include< GST / gst.h>INT主(INT ARGC,CHAR *的argv []){
GstElement *管道* jpdec,* imgf,*鳕鱼,*源,*汇;
GstBus *总线;
GstMessage *味精;
GstStateChangeReturn RET; / *初始化的GStreamer * /
gst_init(安培; ARGC,&安培; argv的); / *创建的元素* /
来源= gst_element_factory_make(filesrc,源);
沉= gst_element_factory_make(ximagesink,汇);
jpdec = gst_element_factory_make(jpegdec,JDEC);
imgf = gst_element_factory_make(imagefreeze,冻结);
鳕= gst_element_factory_make(ffmpegcolorspace,ffmdec); / *创建空的管道* /
管道= gst_pipeline_new(测试管道); 如果(!管线||!来源||!沉||!jpdec ||!imgf ||!COD){
g_printerr(不是可以创造的所有元素\\ n);
返回-1;
} / *建立管道* /
gst_bin_add_many(GST_BIN(管道),来源,jpdec,鳕鱼,imgf,水槽,NULL);
如果(gst_element_link(源,汇)!= TRUE){
g_printerr(元素无法关联\\ n);
gst_object_unref(管道);
返回-1;
} / *修改源的属性* /
g_object_set(G_OBJECT(源),地利,pluto.jpg,NULL); / *开始播放* /
RET = gst_element_set_state(管道,GST_STATE_PLAYING);
如果(RET == GST_STATE_CHANGE_FAILURE){
g_printerr(无法设置管道输送到播放状态\\ n);
gst_object_unref(管道);
返回-1;
} / *等到错误或EOS * /
总线= gst_element_get_bus(管道);
味精= gst_bus_timed_pop_filtered(公共汽车,GST_CLOCK_TIME_NONE,GST_MESSAGE_ERROR | GST_MESSAGE_EOS); / *解析消息* /
如果(MSG!= NULL){
*的GError犯错;
gchar * DEBUG_INFO; 开关(GST_MESSAGE_TYPE(MSG)){
案例GST_MESSAGE_ERROR:
gst_message_parse_error(味精,和放大器;犯错,&安培; DEBUG_INFO);
g_printerr(从元素%s内收到的错误:%s \\ n; SRC),err->消息,GST_OBJECT_NAME(msg-&GT);
g_printerr(调试信息:%S \\ n,DEBUG_INFO DEBUG_INFO:无);
g_clear_error(安培; ERR);
g_free(DEBUG_INFO);
打破;
案例GST_MESSAGE_EOS:
了g_print(尾流达到\\ n);
打破;
默认:
/ *我们不应该到达这里,因为我们只要求对错误和EOS * /
g_printerr(收到意外的消息\\ n);
打破;
}
gst_message_unref(MSG);
} / *免费资源* /
gst_object_unref(巴士);
gst_element_set_state(管道,GST_STATE_NULL);
gst_object_unref(管道);
返回0;
}
有就是我用来播放影像结果的C code
当我编译code我没有错误,但是当我运行它,我有这个ERREUR:
(测试:5355)的GStreamer-CRITICAL **:gst_caps_get_structure:断言`GST_IS_CAPS(上限)'失败(测试:5355)的GStreamer-CRITICAL **:gst_structure_get_int:断言`结构= NULL'失败!
从元素水槽收到错误:无法创建为0x0像素的输出图像缓冲区
调试信息:ximagesink.c(472):gst_ximagesink_ximage_new():/ GstPipeline:测试流水线/ GstXImageSink:水槽:
没能分享0字节内存
您gst_element_link是错误的。是这样的:
如果(gst_element_link_many(来源jpdec,鳕鱼,imgf,水槽,NULL)!= TRUE)
应该工作。
这些错误有可能在xvimagesink一个bug,但你错误地使用它。随时bugzilla.gnome.org有关这些说法的情况下,他们与发生1.0报告的错误。
i try to do a gstreamer pipeline using c API to show image for this i use this gst-launch command
gst-launch filesrc location="pluto.jpg" ! jpegdec ! ffmpegcolorspace ! videobalance saturation=0 ! freeze ! ximagesink
when i try it it work fine but when i try to convert it to c code it doesn't work someone can help me please ?
#include <gst/gst.h>
int main(int argc, char *argv[]) {
GstElement *pipeline, *jpdec, *imgf, *cod, *source, *sink;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
source = gst_element_factory_make ("filesrc", "source");
sink = gst_element_factory_make ("ximagesink", "sink");
jpdec = gst_element_factory_make ("jpegdec", "jdec");
imgf = gst_element_factory_make ("imagefreeze", "freeze");
cod = gst_element_factory_make ("ffmpegcolorspace", "ffmdec");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !source || !sink || !jpdec || !imgf || !cod) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, jpdec, cod, imgf, sink, NULL);
if (gst_element_link (source, sink) != TRUE) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
/* Modify the source's properties */
g_object_set (G_OBJECT (source), "location","pluto.jpg", NULL);
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return -1;
}
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
there is the c code that i use to play image
when i compile the code i don't have errors but when i run it i have this erreur :
(test:5355): GStreamer-CRITICAL **: gst_caps_get_structure: assertion `GST_IS_CAPS (caps)' failed
(test:5355): GStreamer-CRITICAL **: gst_structure_get_int: assertion `structure != NULL' failed
Error received from element sink: Failed to create output image buffer of 0x0 pixels
Debugging information: ximagesink.c(472): gst_ximagesink_ximage_new (): /GstPipeline:test-pipeline/GstXImageSink:sink:
could not get shared memory of 0 bytes
Your gst_element_link is wrong. Something like:
if (gst_element_link_many (source, jpdec, cod, imgf, sink, NULL) != TRUE)
should work.
Those errors are likely a bug in xvimagesink, but you are using it wrongly. Feel free to report a bug at bugzilla.gnome.org about these assertions in case they happen with 1.0.
这篇关于使用的GStreamer与C API显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!