devendradhanal

Untitled

Aug 29th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <gst/gst.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #include <stdio.h>
  6.  
  7. static GMainLoop *loop = NULL;
  8. static GstElement *pipeline1 = NULL;
  9. double scale = 4;
  10.  
  11. static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
  12. {
  13. gchar *userdata = (gchar *) data;
  14. switch(GST_MESSAGE_TYPE(msg))
  15. {
  16. case GST_MESSAGE_EOS:
  17. {
  18. g_main_loop_quit(loop);
  19. break;
  20. }
  21. case GST_MESSAGE_ERROR:
  22. {
  23. gchar *debug;
  24. GError *error;
  25. gst_message_parse_error(msg, &error, &debug);
  26. g_free(debug);
  27. g_error_free(error);
  28. g_main_loop_quit(loop);
  29. break;
  30. }
  31. case GST_MESSAGE_STATE_CHANGED :
  32. {
  33. GstState oldstate;
  34. GstState newstate;
  35. GstState pending;
  36. gst_message_parse_state_changed (msg,&oldstate,&newstate,&pending);
  37. g_debug("pipeline:%s old:%s new:%s pending:%s", userdata,gst_element_state_get_name(oldstate),gst_element_state_get_name(newstate),gst_element_state_get_name(pending));
  38. break;
  39. }
  40. case GST_MESSAGE_WARNING:
  41. {
  42. gchar *debug;
  43. GError *error;
  44. gst_message_parse_warning (msg,&error,&debug);
  45. g_warning("pipeline:%s",userdata);
  46. g_warning("debug: %s", debug);
  47. g_warning("error: %s", error->message);
  48. g_free (debug);
  49. g_error_free (error);
  50. break;
  51. }
  52. default:
  53. break;
  54. }
  55. return TRUE;
  56. }
  57.  
  58. int main(int argc, char **argv)
  59. {
  60.  
  61. GError *error = NULL;
  62. GstBus *bus = NULL;
  63. gchar pipeline1_str[556];
  64. gchar rtmp_location[556];
  65. gchar filesink_location[556];
  66.  
  67. gst_init(&argc, &argv);
  68. loop = g_main_loop_new(NULL,FALSE);
  69. int res = 0;
  70.  
  71.  
  72. sprintf(rtmp_location,"'rtmp://127.0.0.1/flvplayback/mynewstream live=1'");
  73. sprintf(filesink_location,"/home/dev/newoo_1.flv");
  74.  
  75. res = sprintf(pipeline1_str, "rtmpsrc location=%s ! decodebin2 ! ffenc_flv ! flvmux streamable=true ! filesink location=%s",rtmp_location , filesink_location);
  76. if (res < 0)
  77. return -1;
  78.  
  79. pipeline1 = gst_parse_launch(pipeline1_str, &error);
  80. if (error)
  81. return -1;
  82.  
  83. bus = gst_pipeline_get_bus( GST_PIPELINE(pipeline1) );
  84. gst_bus_add_watch(bus, bus_call, gst_element_get_name(pipeline1));
  85. gst_object_unref(bus);
  86. gst_element_set_state(pipeline1, GST_STATE_PLAYING);
  87. g_main_loop_run(loop);
  88. gst_element_set_state(pipeline1, GST_STATE_NULL);
  89. gst_object_unref( GST_OBJECT(pipeline1) );
  90. g_main_loop_unref(loop);
  91.  
  92. }
Add Comment
Please, Sign In to add comment