Reading streaming video frame by frame
Saket Chawla
isak3t at gmail.com
Sun Sep 27 15:29:18 UTC 2020
Hello all,
I am extremely new to gstreamer.
I am trying to read frame data for a live streaming video through gstreamer
in C to create an opengl texture.
Currently going through online repositories and tutorials I could come up
code below, which is still not working. I was hoping if somebody could
point me in the right direction or point out errors in code or errors in
the approach I am using. Any help would be appreciated.
The code below is not creating texture. I am just accessing frame data on
line 21 as a first milestone.
Code lines which I feel are important to approach are marked as bold.
1. #include <gst/gst.h>
2. #include <string.h>
3. #include <stdio.h>
4.
5. typedef struct _CustomData {
6. GstElement *pipeline,*sink,*bin;
7. GstPad *pad,*ghost_pad;
8. GstBus *bus;
9. GstMessage *msg;
10. GMainLoop *loop;
11. gboolean is_live;
12. } CustomData;
13.
14. //signal handling function
15. *void frame_func(GstElement *sink, CustomData *data){*
16. printf("frame signal\n");
17. GstSample *sample;
18. GstBuffer *buf;
19. g_signal_emit_by_name(sink,"pull_sample",&sample);
20. buf=gst_sample_get_buffer(sample);
21. printf("%c\n",buf[0])
22. if(sample){
23. gst_sample_unref(sample);
24. }
25. }
26.
27. int main(int argc, char *argv[]) {
28. GstElement *pipeline,*sink;
29. GstBus *bus;
30. GMainLoop *main_loop;
31. GstStateChangeReturn ret;
32. CustomData data;
33.
34. //initialize
35. gst_init (&argc, &argv);
36. memset (&data, 0, sizeof (data));
37.
38. //setup pipeline
39. * pipeline = gst_parse_launch ("uridecodebin
uri=rtsp://192.168.1.221/stream2.sdp <http://192.168.1.221/stream2.sdp>!
decodebin ! appsink name=video-sink
caps=\"video/x-raw,format=RGB,pixel-aspect-ratio=1/1\"", NULL);*
40.
41. //access sink to create signal
42. * sink=gst_bin_get_by_name(GST_BIN(pipeline),"video-sink");*
43.
44. //setting video to play
45. ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
46. if (ret == GST_STATE_CHANGE_FAILURE) {
47. g_printerr ("Unable to set the pipeline to the playing
state.\n");
48. gst_object_unref (pipeline);
49. return -1;
50. } else{
51. if (ret == GST_STATE_CHANGE_NO_PREROLL)
52. printf("for live sources, state changed but data could not be
produced\n");
53. else if (ret == GST_STATE_CHANGE_ASYNC)
54. printf("state will change async\n");
55. else if (ret == GST_STATE_CHANGE_SUCCESS)
56. printf("successfully played\n");
57. else
58. printf("unknown %d\n",ret);
59. data.is_live=TRUE;
60. }
61. bus = gst_element_get_bus (pipeline);
62.
63. *//setting up signals from sink*
64. * g_object_set(G_OBJECT(sink),"emit-signals",TRUE,NULL);*
65. * g_signal_connect (sink, "new-sample", G_CALLBACK(frame_func),
&data);*
66.
67. //setting up loop
68. main_loop = g_main_loop_new (NULL, FALSE);
69. data.loop = main_loop;
70. data.pipeline = pipeline;
71. data.sink = sink;
72.
73. g_main_loop_run (main_loop);
74.
75. //cleanup
76. if(msg!=NULL)
77. gst_message_unref(msg);
78. g_main_loop_unref (main_loop);
79. gst_object_unref (bus);
80. gst_element_set_state (pipeline, GST_STATE_NULL);
81. gst_object_unref (pipeline);
82. return 0;
83. }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20200927/f66a2f68/attachment.htm>
More information about the gstreamer-devel
mailing list