Gstreamer-1.0 Mp4 video RTSP streaming - appsrc

Shabeer shaf.nttf at gmail.com
Mon Feb 18 00:50:10 UTC 2019


My requirement is to stream mp4 video [audio is optional] via RTSP. I have
used a code shared in the forum to check the rtsp video
streaming.reference:http://gstreamer-devel.966125.n4.nabble.com/Continuously-streaming-a-video-file-code-review-td4671364.html1.
The pipeline seems to be proper and the bus callback and need data function
is invoked.2. The caps string is retrieved from the video file using the
"gst-discoverer-1.0  xx.mp4 -v" command     [Is this the proper way to fetch
the caps ? ]3.  Using this command [client]gst-launch-1.0 playbin
uri="rtsp://19x.16x.12x.xx:554/test" tried to play the video stream.4. The
command line shows the server is active and the video is streaming. But no
video output is displayed in the console. need_data and bus_callback
functions are called when needed and I could see the buffer is pushed to
appsrc.5. The .mp4 file has both audio and video. But the pipeline
constructed has only video src. I was able to use the same pipeline and
stream the video without appsrc. I am sure that the issue may be in caps
filters, but not sure how t build the cap filters manually.The problem
occurs only when trying to use appsrc to stream the video. Can you please
suggest the issue in the below code ? I tried to search in forum but with no
help on this particular issue.I am using appsrc to continuously stream the
video by adding a bus watch for the EOS. Also tried using VLC to stream the
video, no video is displayed but I could see the seekbar is moving with time
lapsed [which means the video is streamed but not displayed due to wrong
caps ?? ]Thank you in advance for your help. [I tried to attach the source
file but the "upload file"  menu is not showing up]#include
"stdafx.h"#include <gst/gst.h>#include <gst/app/gstappsink.h>#include
<gst/app/gstappsrc.h>#include <gst/rtsp-server/rtsp-server.h>#include
#include #include #define DEFAULT_RTSP_PORT "554"static char *port = (char
*)DEFAULT_RTSP_PORT;static char *server_addr = "19x.16x.12x.xx";typedef
struct _App App;struct _App{	GstElement *videosink;};App s_app;typedef
struct {	App *glblapp;	GstClockTime timestamp;} Context;const gchar
*pipe_line_string = "appsrc name=mysrc is-live=true max-bytes=0
do-timestamp=true min-latency=0 ! queue ! h264parse name=parse ! queue !
rtph264pay name=pay0 pt=96 timestamp-offset=0";const gchar *videocaps = 
"video/x-h264, stream-format=(string)avc, alignment=(string)au,
level=(string)2.1, profile=(string)high,
codec_data=(buffer)01640015ffe1001967640015acd941e08fea1000000300100000030320f162d96001000668ebe3cb22c0,
width=(int)480, height=(int)270, framerate=(fraction)25/1,
pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive,
chroma-format=(string)4:2:0, bit-depth-luma=(uint)8,
bit-depth-chroma=(uint)8, parsed=(boolean)true";// RTSP server signal and
event handlerstatic void need_data(GstElement *appsrc, guint unused, Context
*ctx){	GstFlowReturn ret;	GstSample *sample =
gst_app_sink_pull_sample(GST_APP_SINK(ctx->glblapp->videosink));	if (sample
!= NULL) {		GstBuffer *buffer = gst_sample_get_buffer(sample);	
gst_sample_unref(sample);		GST_BUFFER_PTS(buffer) = ctx->timestamp;	
GST_BUFFER_DURATION(buffer) = gst_util_uint64_scale_int(1, GST_SECOND, 25);  	
ctx->timestamp += GST_BUFFER_DURATION(buffer);	
g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret);			}}static void
media_configure(GstRTSPMediaFactory *factory, GstRTSPMedia *media, App
*app){	Context *ctx;	GstElement *pipeline;	GstElement *appsrc;	pipeline =
gst_rtsp_media_get_element(media);	appsrc =
gst_bin_get_by_name_recurse_up(GST_BIN(pipeline), "mysrc");
gst_rtsp_media_set_reusable(media, TRUE);
gst_util_set_object_arg(G_OBJECT(appsrc), "format", "time");
g_object_set(G_OBJECT(appsrc), "caps", gst_caps_from_string(videocaps),
NULL);	g_object_set(G_OBJECT(appsrc), "max-bytes",	
gst_app_src_get_max_bytes(GST_APP_SRC(appsrc)), NULL);	ctx = g_new0(Context,
1);	ctx->glblapp = app;	ctx->timestamp = 0;	g_signal_connect(appsrc,
"need-data", (GCallback)need_data, ctx);}gboolean bus_callback(GstBus *bus,
GstMessage *msg, gpointer data){	GstElement *pipeline = GST_ELEMENT(data);
switch (GST_MESSAGE_TYPE(msg)) {	case GST_MESSAGE_EOS:		if
(!gst_element_seek(pipeline,			1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,		
GST_SEEK_TYPE_SET, 1000000000,			GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {		
g_message("Seek failed!");		}else{			g_print(" Added data after seek");		}	
break;	default:		break;	}	return TRUE;}gint main(gint argc, gchar *argv[]){
App *app = &s_app;	GstBus *bus;	GstRTSPServer *server;	GstRTSPMediaFactory
*factory;	GstRTSPMountPoints *mountpoints;	gst_init(&argc, &argv);	GMainLoop
*loop = g_main_loop_new(NULL, FALSE);	GstElement *playbin =
gst_element_factory_make("playbin", "play");	app->videosink =
gst_element_factory_make("appsink", "video_sink");
g_object_set(G_OBJECT(app->videosink), "emit-signals", FALSE, "sync", TRUE,
NULL);	g_object_set(G_OBJECT(playbin), "video-sink", app->videosink, NULL);
gst_app_sink_set_drop(GST_APP_SINK(app->videosink), TRUE);
gst_app_sink_set_max_buffers(GST_APP_SINK(app->videosink), 1);	bus =
gst_pipeline_get_bus(GST_PIPELINE(playbin));	gst_bus_add_watch(bus,
bus_callback, playbin);	g_object_set(G_OBJECT(playbin), "uri",
"file:///C:/test.mp4", NULL);	gst_element_set_state(playbin,
GST_STATE_PLAYING);	// RTSP server, setup and configuration	server =
gst_rtsp_server_new();	mountpoints =
gst_rtsp_server_get_mount_points(server);	factory =
gst_rtsp_media_factory_new();	/* create a server instance */
gst_rtsp_server_set_address(server, server_addr);	g_object_set(server,
"service", port, NULL);	// multi-stream 
gst_rtsp_media_factory_set_shared(factory, TRUE);
gst_rtsp_media_factory_set_launch(factory, pipe_line_string);
g_signal_connect(factory, "media-configure", (GCallback)media_configure,
app);	gst_rtsp_mount_points_add_factory(mountpoints, "/test", factory);
g_object_unref(mountpoints);	gst_rtsp_server_attach(server, NULL);
g_print("RTSP Server started...");	g_main_loop_run(loop);	// Clean up
gst_element_set_state(playbin, GST_STATE_NULL);	gst_object_unref(bus);
return 0;}



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20190217/26c24a3b/attachment.html>


More information about the gstreamer-devel mailing list