Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <iostream>
- using namespace std;
- #include <stdio.h>
- static GMainLoop *loop = NULL;
- static GstElement *pipeline1 = NULL;
- double scale = 4;
- static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
- {
- gchar *userdata = (gchar *) data;
- switch(GST_MESSAGE_TYPE(msg))
- {
- case GST_MESSAGE_EOS:
- {
- g_main_loop_quit(loop);
- break;
- }
- case GST_MESSAGE_ERROR:
- {
- gchar *debug;
- GError *error;
- gst_message_parse_error(msg, &error, &debug);
- g_free(debug);
- g_error_free(error);
- g_main_loop_quit(loop);
- break;
- }
- case GST_MESSAGE_STATE_CHANGED :
- {
- GstState oldstate;
- GstState newstate;
- GstState pending;
- gst_message_parse_state_changed (msg,&oldstate,&newstate,&pending);
- 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));
- break;
- }
- case GST_MESSAGE_WARNING:
- {
- gchar *debug;
- GError *error;
- gst_message_parse_warning (msg,&error,&debug);
- g_warning("pipeline:%s",userdata);
- g_warning("debug: %s", debug);
- g_warning("error: %s", error->message);
- g_free (debug);
- g_error_free (error);
- break;
- }
- default:
- break;
- }
- return TRUE;
- }
- int main(int argc, char **argv)
- {
- GError *error = NULL;
- GstBus *bus = NULL;
- gchar pipeline1_str[556];
- gchar rtmp_location[556];
- gchar filesink_location[556];
- gst_init(&argc, &argv);
- loop = g_main_loop_new(NULL,FALSE);
- int res = 0;
- sprintf(rtmp_location,"'rtmp://127.0.0.1/flvplayback/mynewstream live=1'");
- sprintf(filesink_location,"/home/dev/newoo_1.flv");
- res = sprintf(pipeline1_str, "rtmpsrc location=%s ! decodebin2 ! ffenc_flv ! flvmux streamable=true ! filesink location=%s",rtmp_location , filesink_location);
- if (res < 0)
- return -1;
- pipeline1 = gst_parse_launch(pipeline1_str, &error);
- if (error)
- return -1;
- bus = gst_pipeline_get_bus( GST_PIPELINE(pipeline1) );
- gst_bus_add_watch(bus, bus_call, gst_element_get_name(pipeline1));
- gst_object_unref(bus);
- gst_element_set_state(pipeline1, GST_STATE_PLAYING);
- g_main_loop_run(loop);
- gst_element_set_state(pipeline1, GST_STATE_NULL);
- gst_object_unref( GST_OBJECT(pipeline1) );
- g_main_loop_unref(loop);
- }
Add Comment
Please, Sign In to add comment