GStreamer C Code to play video

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

GStreamer C Code to play video

akaChella
Hi,

I have identified the below pipleine to play the video.

gst-launch-0.10 -v filesrc location=/home/administrator/Desktop/Test.mp4 ! qtdemux ! ffdec_mpeg4 ! autovideosink

With gst-launch i am able to play the video.

I converted the pipeline to a C Code and tried to play the video but it displays the error:GStreamer General Stream Error.

This is code i am using for testing.

Code:

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

static gboolean
bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
  GMainLoop *loop = (GMainLoop *) data;

  switch (GST_MESSAGE_TYPE (msg)) {

    case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      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_printerr ("Error: %s\n", error->message);
      g_error_free (error);

      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }

  return TRUE;
}

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

  GstElement *pipeline, *videosrc, *colorspace, *videoenc,
    *videoq, *audiosrc, *conv, *audioenc, *audioq, *muxer, *sink;

  GstBus *bus;

  /* Initialisation */
  gst_init ((NULL, NULL);

  loop = g_main_loop_new (NULL, FALSE);

  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("audio-player");
  videosrc = gst_element_factory_make ("filesrc", "videosrc");
  muxer = gst_element_factory_make ("qtdemux", "mux");
  videoenc = gst_element_factory_make ("ffdec_mpeg4", "videoenc");
  sink = gst_element_factory_make ("autovideosink", "sink");

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

  /* Set up the pipeline */
  g_print ("Elements are created\n");

  /* set the properties of other elements */
  g_object_set (G_OBJECT (videosrc), "location", "/home/administrator/Desktop/Test.mp4", NULL);

  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* we add all elements into the pipeline */
  gst_bin_add_many (GST_BIN (pipeline),
    videosrc, muxer, videoenc,  
    sink, NULL);

  g_print ("Added all the Elements into the pipeline\n");

  /* we link the elements together */
  gst_element_link_many (videosrc, muxer, videoenc, sink,
      NULL);

  g_print ("Linked all the Elements together\n");
  /* Set the pipeline to "playing" state*/
  g_print ("Playing the video\n");
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Iterate */
  g_print ("Running...\n");
  g_main_loop_run (loop);

  /* Out of the main loop, clean up nicely */
  g_print ("Returned, stopping playback\n");
  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (pipeline));

  return 0;
}

Please let me know if  there is any error in the code.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: GStreamer C Code to play video

ak.ashwini
Hi,
 
You need to check the return status of gst_element_link_many (videosrc, muxer, videoenc, sink,
     NULL); it may be a failure.
 
You may be required to do dynamic linking between mux and decoder.
 
-Ashwini


 
On Wed, Aug 3, 2011 at 4:25 PM, Durga <[hidden email]> wrote:
Hi,

I have identified the below pipleine to play the video.

gst-launch-0.10 -v filesrc location=/home/administrator/Desktop/Test.mp4 !
qtdemux ! ffdec_mpeg4 ! autovideosink

With gst-launch i am able to play the video.

I converted the pipeline to a C Code and tried to play the video but it
displays the error:GStreamer General Stream Error.

This is code i am using for testing.

Code:

#include &lt;gst/gst.h&gt;
#include <glib.h>

static gboolean
bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
 GMainLoop *loop = (GMainLoop *) data;

 switch (GST_MESSAGE_TYPE (msg)) {

   case GST_MESSAGE_EOS:
     g_print ("End of stream\n");
     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_printerr ("Error: %s\n", error->message);
     g_error_free (error);

     g_main_loop_quit (loop);
     break;
   }
   default:
     break;
 }

 return TRUE;
}

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

 GstElement *pipeline, *videosrc, *colorspace, *videoenc,
   *videoq, *audiosrc, *conv, *audioenc, *audioq, *muxer, *sink;

 GstBus *bus;

 /* Initialisation */
 gst_init ((NULL, NULL);

 loop = g_main_loop_new (NULL, FALSE);

 /* Create gstreamer elements */
 pipeline = gst_pipeline_new ("audio-player");
 videosrc = gst_element_factory_make ("filesrc", "videosrc");
 muxer = gst_element_factory_make ("qtdemux", "mux");
 videoenc = gst_element_factory_make ("ffdec_mpeg4", "videoenc");
 sink = gst_element_factory_make ("autovideosink", "sink");

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

 /* Set up the pipeline */
 g_print ("Elements are created\n");

 /* set the properties of other elements */
 g_object_set (G_OBJECT (videosrc), "location",
"/home/administrator/Desktop/Test.mp4", NULL);

 /* we add a message handler */
 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
 gst_bus_add_watch (bus, bus_call, loop);
 gst_object_unref (bus);

 /* we add all elements into the pipeline */
 gst_bin_add_many (GST_BIN (pipeline),
   videosrc, muxer, videoenc,
   sink, NULL);

 g_print ("Added all the Elements into the pipeline\n");

 /* we link the elements together */
 gst_element_link_many (videosrc, muxer, videoenc, sink,
     NULL);

 g_print ("Linked all the Elements together\n");
 /* Set the pipeline to "playing" state*/
 g_print ("Playing the video\n");
 gst_element_set_state (pipeline, GST_STATE_PLAYING);

 /* Iterate */
 g_print ("Running...\n");
 g_main_loop_run (loop);

 /* Out of the main loop, clean up nicely */
 g_print ("Returned, stopping playback\n");
 gst_element_set_state (pipeline, GST_STATE_NULL);

 g_print ("Deleting pipeline\n");
 gst_object_unref (GST_OBJECT (pipeline));

 return 0;
}

Please let me know if  there is any error in the code.

Thanks in advance.

--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-tp3715064p3715064.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


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

Re: GStreamer C Code to play video

akaChella
Ashwini Thank you so much for your reply.

I corrected that and it works fine now!!

I have one other issue :(

When i run the code, it displays the video with the title bar "<unknown>". I do not want the title bar at all.

What should i do for that??

Reply | Threaded
Open this post in threaded view
|

Re: GStreamer C Code to play video

ak.ashwini
For that, may be you can create your own window and then set the x_overlay thru "gst_x_overlay_set_xwindow_id"
 
You can see the gst-player code for help.....
-Ashwini
On Wed, Aug 3, 2011 at 5:18 PM, Durga <[hidden email]> wrote:
Ashwini Thank you so much for your reply.

I corrected that and it works fine now!!

I have one other issue :(

When i run the code, it displays the video with the title bar "<unknown>". I
do not want the title bar at all.

What should i do for that??



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-tp3715064p3715160.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


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

AW: GStreamer C Code to play video

BGraaf

If you only whant to have your program name in title bar, you could use the gst_init(&argc, &argv):

 

int main (int argc, char *argv[])

{

  gst_init (&argc, &argv);

 

 

Bernhard

 


Von: gstreamer-devel-bounces+bernhard.graaf=[hidden email] [mailto:gstreamer-devel-bounces+bernhard.graaf=[hidden email]] Im Auftrag von Ashwini Sharma
Gesendet: Mittwoch, 3. August 2011 14:07
An: Discussion of the development of and with GStreamer
Betreff: Re: GStreamer C Code to play video

 

For that, may be you can create your own window and then set the x_overlay thru "gst_x_overlay_set_xwindow_id"

 

You can see the gst-player code for help.....

-Ashwini

On Wed, Aug 3, 2011 at 5:18 PM, Durga <[hidden email]> wrote:

Ashwini Thank you so much for your reply.

I corrected that and it works fine now!!

I have one other issue :(

When i run the code, it displays the video with the title bar "<unknown>". I
do not want the title bar at all.

What should i do for that??



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-tp3715064p3715160.html

Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

 


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

Re: GStreamer C Code to play video

akaChella
In reply to this post by ak.ashwini
Hi Ashwini,

Thanks for the reply!!

Could you please give more input on this.. because i am completely new to gstreamer..!!

Any kind of help is appreciated..!!

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: AW: GStreamer C Code to play video

akaChella
In reply to this post by BGraaf
BGraaf,

Thanks for the reply..!!

I do not want the title bar at all..! What should i do for that?
Reply | Threaded
Open this post in threaded view
|

AW: AW: GStreamer C Code to play video

BGraaf
Then you should follow Ashwinis tip.
e.g.:
https://github.com/felipec/gst-player/blob/568a67ec342fc20dbc41cade9c4e317f0
c1d00ba/ui.c



-----Ursprüngliche Nachricht-----
Von: gstreamer-devel-bounces+bernhard.graaf=[hidden email]
[mailto:gstreamer-devel-bounces+bernhard.graaf=[hidden email]]
Im Auftrag von Durga
Gesendet: Mittwoch, 3. August 2011 14:31
An: [hidden email]
Betreff: Re: AW: GStreamer C Code to play video

BGraaf,

Thanks for the reply..!!

I do not want the title bar at all..! What should i do for that?

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3715276.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

Re: AW: AW: GStreamer C Code to play video

akaChella
BGraaf,

I saw that code, but i have no clue as how i can create a window / link the sink to that window.

Could you please give more input on this!!

Thanks.
it
Reply | Threaded
Open this post in threaded view
|

RE: AW: GStreamer C Code to play video

it
In reply to this post by akaChella
Hi Durga,

I'm about to start the same thing.

Could you post your working c-code so that I can try it too.

Thanks in advance.

Steve

-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Durga
Sent: 03 August 2011 09:31
To: [hidden email]
Subject: Re: AW: GStreamer C Code to play video

BGraaf,

Thanks for the reply..!!

I do not want the title bar at all..! What should i do for that?

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3715276.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

AW: AW: AW: GStreamer C Code to play video

BGraaf
In reply to this post by akaChella
Hi,

Did you do anythink with gtk+? If you whant to program windowing, you should
use something like this. Gstreamer only use this interface.

-----Ursprüngliche Nachricht-----
Von: gstreamer-devel-bounces+bernhard.graaf=[hidden email]
[mailto:gstreamer-devel-bounces+bernhard.graaf=[hidden email]]
Im Auftrag von Durga
Gesendet: Mittwoch, 3. August 2011 16:25
An: [hidden email]
Betreff: Re: AW: AW: GStreamer C Code to play video

BGraaf,

I saw that code, but i have no clue as how i can create a window / link the
sink to that window.

Could you please give more input on this!!

Thanks.

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3715644.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

Re: AW: AW: AW: GStreamer C Code to play video

akaChella
I have no idea about gtk+...

Actually i completely new to gstreamer :(
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: AW: GStreamer C Code to play video

akaChella
Could you please give some example, as how i can do that?

Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: AW: GStreamer C Code to play video

akaChella
BGraaf and Ashwini,

What are the packages that i need to install in order to create a new window or to run the application ui.c which was shared by BGraaf from the following path:
https://github.com/felipec/gst-player/blob/568a67ec342fc20dbc41cade9c4e317f0
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: AW: GStreamer C Code to play video

ak.ashwini
gtk+, and ofcourse the dependencies of it.... which you can see when configuring compiling gtk+

On Thu, Aug 4, 2011 at 2:55 PM, Durga <[hidden email]> wrote:
BGraaf and Ashwini,

What are the packages that i need to install in order to create a new window
or to run the application ui.c which was shared by BGraaf from the following
path:
https://github.com/felipec/gst-player/blob/568a67ec342fc20dbc41cade9c4e317f0
https://github.com/felipec/gst-player/blob/568a67ec342fc20dbc41cade9c4e317f0

--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-tp3715064p3718094.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


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

RE: AW: GStreamer C Code to play video

akaChella
In reply to this post by it
Steve,

This is the working code!

#include <gst/gst.h>
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)

{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
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_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <Ogg/Vorbis filename>\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("qtdemux", "demuxer");
decoder = gst_element_factory_make ("ffdec_mpeg4", "decoder");
sink = gst_element_factory_make ("autovideosink", "video-output");
if (!pipeline || !source || !demuxer || !decoder || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, demuxer, decoder, sink, NULL);
/* we link the elements together */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}
it
Reply | Threaded
Open this post in threaded view
|

RE: AW: GStreamer C Code to play video

it
Thanks Durga,

Sorry to sound so dim, but do you have a script to compile and link it,
please?

So far I've been only working in Perl, so this is my first excursion into
Perl.

Thanks in advance.

Steve

-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Durga
Sent: 04 August 2011 06:30
To: [hidden email]
Subject: RE: AW: GStreamer C Code to play video

Steve,

This is the working code!

#include &lt;gst/gst.h&gt;
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)

{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
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_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("qtdemux", "demuxer");
decoder = gst_element_factory_make ("ffdec_mpeg4", "decoder");
sink = gst_element_factory_make ("autovideosink", "video-output");
if (!pipeline || !source || !demuxer || !decoder || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, demuxer, decoder, sink, NULL);
/* we link the elements together */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3718109.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
it
Reply | Threaded
Open this post in threaded view
|

RE: AW: GStreamer C Code to play video

it
>So far I've been only working in Perl, so this is my first excursion into
>Perl.

Whoops, typo:

so this is my first excursion into C++.


-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Steve
Sent: 04 August 2011 08:19
To: 'Discussion of the development of and with GStreamer'
Subject: RE: AW: GStreamer C Code to play video

Thanks Durga,

Sorry to sound so dim, but do you have a script to compile and link it,
please?

So far I've been only working in Perl, so this is my first excursion into
Perl.

Thanks in advance.

Steve

-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Durga
Sent: 04 August 2011 06:30
To: [hidden email]
Subject: RE: AW: GStreamer C Code to play video

Steve,

This is the working code!

#include &lt;gst/gst.h&gt;
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)

{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
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_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("qtdemux", "demuxer");
decoder = gst_element_factory_make ("ffdec_mpeg4", "decoder");
sink = gst_element_factory_make ("autovideosink", "video-output");
if (!pipeline || !source || !demuxer || !decoder || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, demuxer, decoder, sink, NULL);
/* we link the elements together */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3718109.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
it
Reply | Threaded
Open this post in threaded view
|

RE: AW: GStreamer C Code to play video

it
In reply to this post by akaChella
Hi Durga,

Well I compiled your code with Code::Blocks and it compiled and ran first
time.

I get a window with a pop-up box saying information or close.

But I don't yet have a video running.

I have two questions:

1 - What format of file name must I use?
2 - I'm not sure what container or codec I should be using. I am using a
'.ogg' video file. By maybe I need a specific codec?

Thanks

Steve.


-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Durga
Sent: 04 August 2011 06:30
To: [hidden email]
Subject: RE: AW: GStreamer C Code to play video

Steve,

This is the working code!

#include &lt;gst/gst.h&gt;
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)

{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
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_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("qtdemux", "demuxer");
decoder = gst_element_factory_make ("ffdec_mpeg4", "decoder");
sink = gst_element_factory_make ("autovideosink", "video-output");
if (!pipeline || !source || !demuxer || !decoder || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, demuxer, decoder, sink, NULL);
/* we link the elements together */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3718109.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
it
Reply | Threaded
Open this post in threaded view
|

RE: AW: GStreamer C Code to play video

it
OK, well, this seems not to be correct.  It seems I have compiled the
default program that comes with Code::Blocks.  

I'll get back to you when I've got the right program compiled.

Sorry.

Steve

-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Steve
Sent: 04 August 2011 14:45
To: 'Discussion of the development of and with GStreamer'
Subject: RE: AW: GStreamer C Code to play video

Hi Durga,

Well I compiled your code with Code::Blocks and it compiled and ran first
time.

I get a window with a pop-up box saying information or close.

But I don't yet have a video running.

I have two questions:

1 - What format of file name must I use?
2 - I'm not sure what container or codec I should be using. I am using a
'.ogg' video file. By maybe I need a specific codec?

Thanks

Steve.


-----Original Message-----
From: gstreamer-devel-bounces+it=[hidden email]
[mailto:gstreamer-devel-bounces+it=[hidden email]] On
Behalf Of Durga
Sent: 04 August 2011 06:30
To: [hidden email]
Subject: RE: AW: GStreamer C Code to play video

Steve,

This is the working code!

#include &lt;gst/gst.h&gt;
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)

{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
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_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s &lt;Ogg/Vorbis filename&gt;\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("qtdemux", "demuxer");
decoder = gst_element_factory_make ("ffdec_mpeg4", "decoder");
sink = gst_element_factory_make ("autovideosink", "video-output");
if (!pipeline || !source || !demuxer || !decoder || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, demuxer, decoder, sink, NULL);
/* we link the elements together */
gst_element_link (source, demuxer);
gst_element_link_many (decoder, sink, NULL);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print ("Now playing: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}

--
View this message in context:
http://gstreamer-devel.966125.n4.nabble.com/GStreamer-C-Code-to-play-video-t
p3715064p3718109.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

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