Live stream of IP camera

Hello,

I’m looking to find a way to stream from an IP camera connected to the module using LAN and save them as a video file.
I looked on the internet and most of the articles saying about Gstreamer.
In most cases they offered to use RTSPSRC module in Gstreamer.

gst-launch-1.0 rtspsrc location=rtsp://192.168.1.2/stream latency=10 ! decodebin ! autovideosink

But when I run this code it says that there is no module rtspsrc
Should I install it? If so how can I install that? Gstreamer is allready on my module and I have updated it to the latest version.

Is there any suggestion for other software packages that I can install on my Apalis module or even any already installed packages?

Thanks.

If you would like to use the rtspsrc plugin, you can use opkg to install it.

opkg update
opkg install gst-plugins-good-rtsp

You can look for available plugins from feeds here
http://feeds.toradex.com/angstrom/feeds/v2015.06/ipk/glibc/armv7at2hf-vfp-neon/gstreamer/

You can then check the existence of the plugins with

root@apalis-imx6:~# gst-inspect | grep -i "rtsp"
rtsp:  rtspsrc: RTSP packet receiver
rtsp:  rtpdec: RTP Decoder
asf:  rtspwms: WMS RTSP Extension

or gst-inspect rtspsrc

Hi,

I tried to use the Gstreamer to capture video from the IP camera but I couldn’t do it.
This is the command I’m using:

    gst-launch rtspsrc location=rtsp://172.15.1.6/live1.sdp ! autovideosink  

I get this error:

Setting pipeline to PAUSED ...
    [  469.019903] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
    [  469.025830] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
    [  469.031695] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
    MFW_GST_V4LSINK_PLUGIN 4.0.3 build on Dec 15 2015 16:00:19.
    Pipeline is live and does not need PREROLL ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock
    ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0/GstUDPSrc:udpsrc0: Internal data flow error.
    Additional debug info:
    /build/v2015.06/build/tmp-angstrom_v2015_06-glibc/work/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/gstreamer/0.10.36-r2/gstreamer-0.10.36/libs/gst/base/gstbasesrc.c(2625): gst_base_src_loop (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc0/GstUDPSrc:udpsrc0:
    streaming task paused, reason not-linked (-1)
    Execution ended after 2189910000 ns.
    Setting pipeline to PAUSED ...
    Setting pipeline to READY ...
    Setting pipeline to NULL ...
    Total rendered:0
    [--->FINALIZE v4l_sink
    Freeing pipeline ...

Do you have any idea about it?
Is there any other package instead of Gstreamer to capture and save video from IP camera?
I used VLC player on ubuntu and it is working fine. But unfortunately I can not install VLC player on Apalis.

Thanks.

Hi Asad,

There are few possabilities for constructing a gstreamer pipline.

According to the NXP/Freescale Linux User’s Guide, a RTSP pipeline looks like:

Manual Pipeline:

$GSTL rtspsrc location=$RTSP_URI name=source
! queue ! $video_rtp_depacketize_plugin ! $vpu_dec ! $video_sink_plugin source.
! queue ! $audio_rtp_depacketize_plugin ! $audio_parse_plugin ! beepdec !
$audio_sink_plugin

Playbin:

$GSTL $PLAYBIN uri=$RTSP_URI

To simply play the video on the screen, try the following:

gst-launch-0.10 playbin2 uri=rtsp://USERNAME:PASSWORD@CAMADDRESS:PORT

The manual pipeline required to do the same can vary depending on the video encoding. For h264, try (video only):

gst-launch-0.10 rtspsrc location=rtsp://USERNAME:PASSWORD@CAMADDRESS:PORT ! queue ! rtph264depay ! vpudec ! autovideosink

To output the video stream directly to a file, try:

gst-launch-0.10 rtspsrc location=rtsp://USERNAME:PASSWORD@CAMADDRESS:PORT ! rtph264depay ! filesink location=filename.264

Need to transcode?

To transcode to MPEG-4 and output to file (video only), try:

gst-launch-0.10 rtspsrc location=rtsp://USERNAME:PASSWORD@CAMADDRESS:PORT ! rtph264depay ! vpudec ! vpuenc codec=0 ! mp4mux ! filesink location=video.mp4

If you want to implement a framegrabber that outputs frames to JPEG files, try:

gst-launch-0.10 rtspsrc location=rtsp://USERNAME:PASSWORD@CAMADDRESS:PORT ! rtph264depay ! vpudec ! vpuenc codec=12 ! multifilesink location=frame%05d.jpg

Some of these pipeline elements may require additional Gstreamer plugins to be installed. For example, as @sanchayan.maity mentioned, you install the RTSP plugin as follows:

opkg update
opkg install gst-plugins-good-rtsp

You may want to install all of gst-plugins-good and possibly some of those in gst-plugins-bad. If you need to find a plugin to install, you can try searching for one using opkg list. For example:

opkg list | grep gst-plugins | less

Just keep in mind that the most efficient gstreamer elements are generally those included in the BSP which are hardware accelerated (ie. vpudec, vpuenc, etc).

Hello,

I tried to implement your suggestions. First of all I implements the codes on my laptop with ubuntu and I used this command to stream video on local computer (your suggestion code setting gave me error, with using rtph264depay): How ever I should mention that this element can be found on Ubuntu but not in module.

gst-launch -e rtspsrc location=rtsp=/172.15.1.6/stream ! decodebin ! x264enc ! mp4mux ! filesink location=filename1

It works fine and save video stream on my computer.

Now I’m trying to implement it on target module. I installed gstreamer good plugin. I use this command and it is working well:

gst-launch -e rtspsrc location=rtsp=/172.15.1.6/stream ! decodebin ! avimux ! filesink location=filename1

However the mux output in this command is avi format that the output file size is very big (for one minute stream the size is about 100MB) that it is not reasonable since the IP camera is thermal camera that the output file size with VLC player stream is about 5MB).

And also, once I want to change apimux to mp4mux the created output file is always empty.

Do you have any idea about the issue or any way that I can save the smaller size file.

Thanks.

Hi Asad,

If you use the pipeline I suggested above you will get a better result on the iMX6. The reason it is so large is because you decoded it first and didn’t re-encode it. Please see my examples above which cover both use cases - both saving directly to file as well as transcoding.

As previously stated, certain gstreamer elements may have to be additionally installed and keep in mind that the rtph264depay is only used on h264 encoded video - otherwise its not going to work. Use gst-inspect-0.10 | grep depay | grep rtp to see other possible depay elements.

Hi,

Actually I could solve it by sending specifically INT command instead of simple killall command,

I used killall -s SIGINT gst-launch-0.10 to terminate pipeline and then open a new one and now it is working.

Thanks for all you helps.

Asad.

Hi Brandon,

Thanks for all your helps.
I could finally setup the module working with my thermal camera.

gst-launch -e rtspsrc location=rtsp://172.15.1.6/stream ! rtpmp4vdepay ! vpudec ! vpuenc codec=0 ! mp4mux ! filesink location=video.mp4

But I have another issue.
I need to create a new file every predefined intervals, let say 10 minutes. To do so, I kill the gst-launch process every 10 minutes using killall gst-launch-0.10 and run again it in background by adding & to the end of the gst-launch command. I guess this cause the issue that the created MP4 file can not be read after killing the process since when I’m running it in foreground and use ctrl+c to terminate the gst-launch the video is OK can can be played.

Do you know what the issue can be? and how I can run it is background or run it in a way that create an new file every predefined interval?

Thanks.

Did you find a way to view your RTSP stream using gstreamer? I’m facing the same issue 2 years later! (:

Could you ask a new question with all the details about your issue, please? Thanks.