issue with mp4 player

Daniel Marfil danimarfil0 at gmail.com
Tue Oct 20 11:11:08 PDT 2015


Hi everyone,

I am trying to implement a simple mp4 video player without audio. To do this, first I have done it with gst-launch this way:

gst-launch-1.0 souphttpsrc location="https://download.blender.org/durian/trailer/sintel_trailer-480p.mp4" ! qtdemux name=demux demux. ! queue2 ! h264parse ! avdec_h264 ! autovideosink

And this is working fine, so my next step is to make the equivalent in c:

#include <gst/gst.h>

/* Structure to contain all our information, so we can pass it around */
typedef struct _CustomData {
	GstElement *pipeline; /* Our one and only pipeline */
	GstElement *videosrc;

	GstElement *video_queue; //queue
	GstElement *video_demuxer; //qtdemux
	GstElement *video_decoder; //h264parse
	GstElement *video_convert; //avdec_h264
	GstElement *video_sink;

	GstState state; /* Current state of the pipeline */
	gint64 duration; /* Duration of the clip, in nanoseconds */
} CustomData;

static void pad_added_handler_qtdemux(GstElement *src, GstPad *pad,
		CustomData *data) {

	g_print("Inside the pad_added_handler_qtdemux method \n");
	g_print("Received new pad '%s' from '%s':\n", GST_PAD_NAME(pad),
			GST_ELEMENT_NAME(src));

	if (g_str_has_prefix(gst_pad_get_name(pad), "video/x-h264")) {

		GstPad *sinkpad1 = gst_element_get_static_pad(data->video_queue,
				"sink");
		gst_pad_link(pad, sinkpad1);
		gst_object_unref(sinkpad1);
		g_print("|| I create a  '%s'|| \n", gst_pad_get_name(pad));

	}
}

int main(int argc, char *argv[]) {
	CustomData data;
	GstStateChangeReturn ret;
	GstBus *bus;

	/* Initialize GStreamer */
	gst_init(&argc, &argv);

	/* Initialize our data structure */
	memset(&data, 0, sizeof(data));
	data.duration = GST_CLOCK_TIME_NONE;

	/* Create the elements */
	data.pipeline = gst_pipeline_new("Test");
	data.videosrc = gst_element_factory_make("souphttpsrc", "http-src");

	data.video_demuxer = gst_element_factory_make("qtdemux", "video_demuxer");
	data.video_queue = gst_element_factory_make("queue2", "video_queue2");
	data.video_decoder = gst_element_factory_make("h264parse", "video_decoder");
	data.video_convert = gst_element_factory_make("avdec_h264",
			"video_convert");
	data.video_sink = gst_element_factory_make("autovideosink", "video_sink");

	if (!data.pipeline) {
		g_printerr("Not all elements could be created.\n");
		return -1;
	}

	/* Set the URI to play */
	g_object_set(G_OBJECT(data.videosrc), "location",
			"https://download.blender.org/durian/trailer/sintel_trailer-480p.mp4", NULL);

	/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
	bus = gst_element_get_bus(data.pipeline);
	gst_bus_add_signal_watch(bus);

	g_signal_connect(data.video_demuxer, "pad-added",
			G_CALLBACK (pad_added_handler_qtdemux), NULL);

	gst_object_unref(bus);

	gst_bin_add_many(GST_BIN(data.pipeline), data.videosrc, data.video_queue,
			data.video_demuxer, data.video_decoder, data.video_convert,
			data.video_sink, NULL); //data.audio_queue, data.audio_decoder, data.audio_convert, data.audio_sink, NULL);

	gst_element_link(data.videosrc, data.video_demuxer);

	gst_element_link_many(data.video_queue, data.video_decoder,
			data.video_convert, data.video_sink, NULL);

	/* Start playing */
	ret = gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
	if (ret == GST_STATE_CHANGE_FAILURE) {
		g_printerr("Unable to set the pipeline to the playing state.\n");
		gst_object_unref(data.pipeline);
		return -1;
	}

	/* Free resources */
	gst_element_set_state(data.pipeline, GST_STATE_NULL);
	gst_object_unref(data.pipeline);
	return 0;
}


I can build it fine but when I run it I get the following errors:

(mp4-player-wo-gtk:4563): GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed

(mp4-player-wo-gtk:4563): GStreamer-CRITICAL **: gst_bin_add_many: assertion 'GST_IS_ELEMENT (element_1)' failed

(mp4-player-wo-gtk:4563): GStreamer-CRITICAL **: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (src)’ failed

I think I am doing exactly the same as gst-launch, but it is crashing.

Regards, 

Dani

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20151020/0aec06b7/attachment-0001.html>


More information about the gstreamer-devel mailing list