Play avi-file
Andreas Büttner
Andreas.Buettner87 at web.de
Mon May 2 07:26:28 PDT 2011
Hi,
I know the topic was already discussed, but I always receive a mistake by
using the following code(its nearly the code from a member here in the
forum):
------------------code------------------
#include <gst/gst.h>
#include <glib.h>
#include <string.h>
static GstElement *source, *demuxer, *vdqueue, *vdsink, *decvd,
*vcolorspace;
void on_pad_added (GstElement *element, GstPad *pad)
{
gchar *name;
name = gst_pad_get_name (pad);
g_debug ("A new pad %s was created\n", name);
GstCaps *caps;
GstStructure *str;
caps = gst_pad_get_caps (pad);
g_assert (caps != NULL);
str = gst_caps_get_structure (caps, 0);
g_assert (str != NULL);
if (g_strrstr (gst_structure_get_name (str), "video")) {
g_debug ("Linking video pad to dec_vd");
// Link it actually
GstPad *targetsink = gst_element_get_pad (decvd, "sink");
g_assert (targetsink != NULL);
gst_pad_link (pad, targetsink);
gst_object_unref (targetsink);
}
gst_caps_unref (caps);
}
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_printerr ("Error: %s (%s) \n", error->message, debug);
g_free (debug);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline;
GstBus *bus;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <AVI filename>\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("media-player");
source = gst_element_factory_make ("filesrc", "file-source");
demuxer = gst_element_factory_make ("avidemux", "avi-demuxer");
decvd = gst_element_factory_make ("decodebin", "video-decoder");
vcolorspace = gst_element_factory_make ("ffmpegcolorspace",
"color-space");
vdsink = gst_element_factory_make ("autovideosink", "video-sink");
vdqueue = gst_element_factory_make ("queue", "video-queue");
if (!pipeline || !source || !demuxer || !decvd || !vdsink
|| !vdqueue) {
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);
gst_bin_add_many (GST_BIN (pipeline), source, demuxer, decvd, vdqueue,
vdsink, NULL);
gst_element_link (source, demuxer);
gst_element_link (demuxer,vdqueue);
gst_element_link (vdqueue, decvd);
gst_element_link (decvd, vcolorspace);
gst_element_link (vcolorspace, vdsink);
g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added),
decvd);
//g_signal_connect (decvd, "pad-added", G_CALLBACK (on_pad_added),
NULL);
/* 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;
}
------------------code-end--------------
I get the following mistake:
(play-avi2:4453): GStreamer-WARNING **: Trying to connect elements that
don't share a common ancestor: color-space and video-sink
(play-avi2:4453): GStreamer-WARNING **: Trying to connect elements that
don't share a common ancestor: color-space and video-sink
Now playing: avi-test2.avi
** (play-avi2:4453): DEBUG: A new pad video_00 was created
** (play-avi2:4453): DEBUG: Linking video pad to dec_vd
Running...
Error: Interner Datenstromfehler. (gstavidemux.c(5134): gst_avi_demux_loop
(): /GstPipeline:media-player/GstAviDemux:avi-demuxer:
streaming stopped, reason not-linked)
Returned, stopping playback
Deleting pipeline
I also tried the command-line tool: gst-launch filesrc
location=avi-test2.avi ! avidemux name=demux demux.video_00 ! queue !
decodebin ! ffmpegcolorspace ! videoscale ! autovideosink
On this way it is working, but with the code it is not possible to play the
avi-file. I think the mistake is at the dynamic src-pad from the avidemuxer,
but I have no idea how to fix it.
Best regards, Andreas
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar
More information about the gstreamer-devel
mailing list