create the rtsp server with webcam input webcam,udp,rtsp server
Purpose: create the rtsp server with /dev/video0 source method: webcam(/dev/video0) -> udp stream -> rtsp server udpstream command:
This udp stream seems fine and I tested to receive it with udp receiver
sudo gst-launch-1.0 v4l2src device=/dev/video0 \
! videoconvert ! video/x-raw,format=I420 \
! x264enc tune=zerolatency bitrate=1024 speed-preset=ultrafast \
! rtph264pay ! udpsink host=10.10.10.51 port=8554
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Redistribute latency...
Redistribute latency...
2:45:43.9 / 99:99:99.
gst-rtsp-server : https://github.com/steabert/gst-rtsp-launch I used this docker file
I change the docker file
EXPOSE 8554
ENTRYPOINT ["/usr/bin/gst-rtsp-launch"]
#CMD ["videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96"]
CMD ["udpsrc port=8554 ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96 ! rtph264depay ! h264parse ! rtph265pay pt=96 name=pay0"]
This will get the udp stream and send as rtph265 pay then server started fine
---> 848ac9a39dfb
Step 17/20 : COPY --from=build gst-rtsp-launch /usr/bin/gst-rtsp-launch
---> Using cache
---> 63b29c311b78
Step 18/20 : EXPOSE 8554
---> Using cache
---> 2c981b58f366
Step 19/20 : ENTRYPOINT ["/usr/bin/gst-rtsp-launch"]
---> Using cache
---> c19db61bb273
Step 20/20 : CMD ["udpsrc port=8554 ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96 ! rtph264depay ! h264parse ! rtph265pay pt=96 name=pay0"]
---> Running in 45d491872cfb
Removing intermediate container 45d491872cfb
---> 43807e584080
Successfully built 43807e584080
Successfully tagged test_base:latest
Test stream ready at rtsp://0.0.0.0:8554/test
Test receive(try to test the receive the stream):
gst-launch-1.0 -vvv rtspsrc location=rtsp://0.0.0.0:8554/test ! rtph264depay ! h264parse ! decodebin ! videoconvert ! xvimagesink sync=false
Error :
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Progress: (open) Opening Stream
Pipeline is PREROLLED ...
Prerolled, waiting for progress to finish...
Progress: (connect) Connecting to rtsp://0.0.0.0:8554/test
Progress: (open) Retrieving server options
Progress: (open) Retrieving media info
ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0: Unhandled error
Additional debug info:
../gst/rtsp/gstrtspsrc.c(6795): gst_rtspsrc_send (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0:
Service Unavailable (503)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...
Docker file
FROM alpine:edge AS build
RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk add --no-cache gst-rtsp-server-dev
RUN apk add --no-cache libtool
RUN apk add --no-cache gcc
RUN apk add --no-cache musl-dev
COPY src/gst-rtsp-launch.c gst-rtsp-launch.c
RUN libtool --mode=link \
gcc `pkg-config --cflags --libs gstreamer-1.0` \
-L/usr/lib/x86_64-linux-gnu -lgstrtspserver-1.0 \
-o gst-rtsp-launch gst-rtsp-launch.c
FROM alpine:edge
RUN echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk add --no-cache gst-rtsp-server
RUN apk add --no-cache gst-plugins-base
RUN apk add --no-cache gst-plugins-ugly
RUN apk add --no-cache gst-plugins-good
RUN apk add --no-cache gst-plugins-bad
RUN apk add --no-cache gst-libav
RUN apk add --no-cache v4l-utils
COPY --from=build gst-rtsp-launch /usr/bin/gst-rtsp-launch
# Grant necessary privileges to access /dev/video0
RUN addgroup -S mygroup && adduser -S myuser -G mygroup
RUN chown myuser:mygroup -R /dev
USER myuser
EXPOSE 8554
ENTRYPOINT ["/usr/bin/gst-rtsp-launch"]
CMD ["v4l2src device=/dev/video0 ! videoconvert ! queue ! x264enc ! video/x-h264, alignment=au, stream-format=byte-stream, profile=main ! h264parse ! mpegtsmux name=muxer ! tsparse ! rtpmp2tpay name=pay0 pt=96"]
gst-rtsp.launch.c
/* GStreamer
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#define DEFAULT_RTSP_PORT "8554"
static char *port = (char *) DEFAULT_RTSP_PORT;
static GOptionEntry entries[] = {
{"port", 'p', 0, G_OPTION_ARG_STRING, &port,
"Port to listen on (default: " DEFAULT_RTSP_PORT ")", "PORT"},
{NULL}
};
int
main (int argc, char *argv[])
{
GMainLoop *loop;
GstRTSPServer *server;
GstRTSPMountPoints *mounts;
GstRTSPMediaFactory *factory;
GOptionContext *optctx;
GError *error = NULL;
optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n"
"Example: \"( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )\"");
g_option_context_add_main_entries (optctx, entries, NULL);
g_option_context_add_group (optctx, gst_init_get_option_group ());
if (!g_option_context_parse (optctx, &argc, &argv, &error)) {
g_printerr ("Error parsing options: %s\n", error->message);
g_option_context_free (optctx);
g_clear_error (&error);
return -1;
}
g_option_context_free (optctx);
loop = g_main_loop_new (NULL, FALSE);
/* create a server instance */
server = gst_rtsp_server_new ();
g_object_set (server, "address", "0.0.0.0", NULL);
g_object_set (server, "service", port, NULL);
/* get the mount points for this server, every server has a default object
* that be used to map uri mount points to media factories */
mounts = gst_rtsp_server_get_mount_points (server);
/* make a media factory for a test stream. The default media factory can use
* gst-launch syntax to create pipelines.
* any launch line works as long as it contains elements named pay%d. Each
* element with pay%d names will be a stream */
factory = gst_rtsp_media_factory_new ();
gst_rtsp_media_factory_set_launch (factory, argv[1]);
gst_rtsp_media_factory_set_shared (factory, TRUE);
/* attach the test factory to the /test url */
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
/* don't need the ref to the mapper anymore */
g_object_unref (mounts);
/* attach the server to the default maincontext */
gst_rtsp_server_attach (server, NULL);
/* start serving */
g_print ("stream ready at rtsp://0.0.0.0:%s/test\n", port);
g_main_loop_run (loop);
return 0;
}
Error more detail
00:09.947254945 1 0x7f59f2efc4e0 INFO GST_REFCOUNTING gstelement.c:3470:gst_element_finalize:<rtpbin0> 0x7f59f2828ae0 finalize
0:00:09.947263927 1 0x7f59f2efc4e0 INFO GST_REFCOUNTING gstelement.c:3475:gst_element_finalize:<rtpbin0> 0x7f59f2828ae0 finalize parent
0:00:09.947273407 1 0x7f59f2efc4e0 DEBUG rtspmedia rtsp-media.c:2809:gst_rtsp_media_set_status: setting new status to 0
0:00:09.947283034 1 0x7f59f2efc4e0 DEBUG rtspmedia rtsp-media.c:4078:finish_unprepare: removing bus watch
0:00:09.947293657 1 0x7f59f2efc4e0 DEBUG GST_BUS gstelement.c:3543:gst_element_get_bus:<media-pipeline> got bus <bus2>
0:00:09.947301723 1 0x7f59f2efc4e0 DEBUG rtspmedia rtsp-media.c:3421:watch_destroyed:<GstRTSPMedia@0x7f59f3103410> source destroyed
0:00:09.947309835 1 0x7f59f2efc4e0 DEBUG rtspmedia rtsp-media.c:4083:finish_unprepare: destroy source
0:00:09.947316839 1 0x7f59f2efc4e0 DEBUG GST_BUS gstbus.c:846:gst_bus_source_dispose:<bus2> disposing source 0x7f59f29bb990
0:00:09.947325059 1 0x7f59f2efc4e0 DEBUG rtspmedia rtsp-media.c:4089:finish_unprepare: stop thread
0:00:09.947332501 1 0x7f59f2efc4e0 DEBUG default rtsp-thread-pool.c:178:gst_rtsp_thread_stop: stop thread 0x7f59f29b7bd0
0:00:09.947339272 1 0x7f59f2efc4e0 DEBUG default rtsp-thread-pool.c:181:gst_rtsp_thread_stop: add idle source to quit mainloop of thread 0x7f59f29b7bd0
0:00:09.947350667 1 0x7f59f2efc4e0 ERROR rtspclient rtsp-client.c:1115:find_media: client 0x7f59f2efe870: can't prepare media
0:00:09.947359058 1 0x7f59f29b88d0 DEBUG default rtsp-thread-pool.c:159:do_quit: stop mainloop of thread 0x7f59f29b7bd0
0:00:09.947374070 1 0x7f59f29b88d0 INFO rtspthreadpool rtsp-thread-pool.c:331:do_loop: exit mainloop of thread 0x7f59f29b7bd0
0:00:09.947383985 1 0x7f59f29b88d0 DEBUG default rtsp-thread-pool.c:74:_gst_rtsp_thread_free: free thread 0x7f59f29b7bd0
0:00:09.947397351 1 0x7f59f2efc4e0 INFO rtspmedia rtsp-media.c:530:gst_rtsp_media_finalize: finalize media 0x7f59f3103410
0:00:09.947408315 1 0x7f59f2efc4e0 DEBUG rtspstream rtsp-stream.c:390:gst_rtsp_stream_finalize: finalize stream 0x7f59f2f1b980
0:00:09.947418939 1 0x7f59f2efc4e0 DEBUG GST_REFCOUNTING gstpipeline.c:258:gst_pipeline_dispose:<media-pipeline> 0x7f59f31034f0 dispose
0:00:09.947429915 1 0x7f59f2efc4e0 DEBUG GST_REFCOUNTING gstbin.c:517:gst_bin_dispose:<media-pipeline> 0x7f59f31034f0 dispose
0:00:09.947440879 1 0x7f59f2efc4e0 DEBUG GST_PARENTAGE gstbin.c:1864:gst_bin_remove: removing element bin0 from bin media-pipeline
0:00:09.947451496 1 0x7f59f2efc4e0 DEBUG bin gstbin.c:1563:gst_bin_remove_func:<media-pipeline> element :bin0
0:00:09.947460258 1 0x7f59f2efc4e0 DEBUG bin gstbin.c:1650:gst_bin_remove_func:<media-pipeline> we removed the last source
0:00:09.947468917 1 0x7f59f2efc4e0 DEBUG bin gstbin.c:1762:gst_bin_remove_func:<media-pipeline> recalc state preroll: 0, other async: 0, this async 0
0:00:09.947475785 1 0x7f59f2efc4e0 DEBUG GST_PARENTAGE gstelement.c:3488:gst_element_set_bus_func:<bin0> setting bus to 0
0:00:09.947485640 1 0x7f59f2efc4e0 DEBUG GST_CLOCK gstelement.c:443:gst_element_set_clock:<bin0> setting clock 0
0:00:09.947494788 1 0x7f59f2efc4e0 DEBUG GST_CLOCK gstelement.c:443:gst_element_set_clock:<capsfilter0> setting clock 0
0:00:09.947503819 1 0x7f59f2efc4e0 DEBUG GST_CLOCK gstelement.c:443:gst_element_set_clock:<pay0> setting clock 0
0:00:09.947512433 1 0x7f59f2efc4e0 DEBUG GST_CLOCK gstelement.c:443:gst_element_set_clock:<h264parse0> setting clock 0
0:00:09.947522651 1 0x7f59f2efc4e0 DEBUG GST_CLOCK gstelement.c:443:gst_element_set_clock:<x264enc0> setting clock 0
But seems like it does not receive the straming.....
- is this right approach?
- if there is something else to try on?
- if you need more information let me know