I need some help. Gstreamer. H.264 encoding + decoding + displaying. In c code

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I need some help. Gstreamer. H.264 encoding + decoding + displaying. In c code

peter12
Fist of all, I have to say that I am new in Gstreamer's enviroment.

I would like to encode the source (video/x264), later to decode and finally
to display. But I am doing something wrong. Can someone help me?

You can see here the code I am using:


#include <glib.h>
#include <gst/gst.h>

int main(int argc, char* argv[])
{
  GMainLoop* loop;

  GstElement *pipeline, *source, *encoder, *decoder, *sink;

  gst_init(&argc, &argv);

  loop = g_main_loop_new(NULL, FALSE);

  // initialize elements
  pipeline = gst_pipeline_new("audio-player");
  source = gst_element_factory_make("videotestsrc", "source");
  sink = gst_element_factory_make("autovideosink", "sink");
  encoder = gst_element_factory_make("x264enc", "encoder");
  decoder = gst_element_factory_make("decodebin", "decoder");

  if (!pipeline || !source || !encoder || !decoder || !sink) {
    g_printerr("One element could not be created. Exiting.\n");
    return -1;
  }

  // add elements to pipeline
  gst_bin_add_many(GST_BIN(pipeline), source, encoder, decoder, sink, NULL);

  // link elements
  gst_element_link(source,encoder);
  gst_element_link(encoder,decoder);
  gst_element_link(decoder,sink);
  //gst_element_link_many(source, sink, NULL);

  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  g_main_loop_run(loop);

  // cleanup
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(GST_OBJECT(pipeline));
  g_main_loop_unref(loop);

  return 0;
}



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: I need some help. Gstreamer. H.264 encoding + decoding + displaying. In c code

Marc Leeman

Decodebin does not have src pads by default, you'll need to subscribe to pad-added and link that pad to your video sink.

   944     g_signal_connect (uridecodebin , "pad-added",
   945         G_CALLBACK (uridecodebin_on_pad_added_cb), NULL);

On Thu, 30 Jul 2020 at 12:00, peter12 <[hidden email]> wrote:
Fist of all, I have to say that I am new in Gstreamer's enviroment.

I would like to encode the source (video/x264), later to decode and finally
to display. But I am doing something wrong. Can someone help me?

You can see here the code I am using:


#include <glib.h>
#include <gst/gst.h>

int main(int argc, char* argv[])
{
  GMainLoop* loop;

  GstElement *pipeline, *source, *encoder, *decoder, *sink;

  gst_init(&argc, &argv);

  loop = g_main_loop_new(NULL, FALSE);

  // initialize elements
  pipeline = gst_pipeline_new("audio-player");
  source = gst_element_factory_make("videotestsrc", "source");
  sink = gst_element_factory_make("autovideosink", "sink");
  encoder = gst_element_factory_make("x264enc", "encoder");
  decoder = gst_element_factory_make("decodebin", "decoder");

  if (!pipeline || !source || !encoder || !decoder || !sink) {
    g_printerr("One element could not be created. Exiting.\n");
    return -1;
  }

  // add elements to pipeline
  gst_bin_add_many(GST_BIN(pipeline), source, encoder, decoder, sink, NULL);

  // link elements
  gst_element_link(source,encoder);
  gst_element_link(encoder,decoder);
  gst_element_link(decoder,sink);
  //gst_element_link_many(source, sink, NULL);

  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  g_main_loop_run(loop);

  // cleanup
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(GST_OBJECT(pipeline));
  g_main_loop_unref(loop);

  return 0;
}



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


--
g. Marc

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel