JirkaRCK
JirkaRCK

Reputation: 71

Save RTSP into file with GStreamer without re-encoding

I would like to ask for some tips how to save rtsp stream from surveillance IP camera into file by GStreamer. I have found this:

gst-launch -e rtspsrc location="rtsp://(my-camera-stream-address)" ! decodebin ! x264enc ! mp4mux ! filesink location=file.mp4

It works well, but it has a really high CPU consumption. I am sure that it decodes my original stream and encodes it into another one.

Could you please advise me, how to do that without re-encoding - how to just catch live stream and save it into container?

Upvotes: 3

Views: 2474

Answers (1)

nayana
nayana

Reputation: 3932

Well first check whats the type of the stream..

APPROACH 1

Check buffers with identity debugging element:

gst-launch-1.0 rtspsrc location=rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4 name=r ! application/x-rtp,media=video ! identity silent=false ! fakesink -v

And check the info of buffers which should be of form:

 /GstPipeline:pipeline0/GstRTSPSrc:r.GstGhostPad:recv_rtp_src_0_2072847348_96.GstProxyPad:proxypad9: caps = "application/x-rtp\,\ media\=(string)audio\,\ payload\=(int)96\,\ clock-rate\=(int)48000\,\ encoding-name\=(string)MPEG4-GENERIC\,\ encoding-params\=(string)2\,\ profile-level-id\=(string)1\,\ mode\=(string)AAC-hbr\,\ sizelength\=(string)13\,\ indexlength\=(string)3\,\ indexdeltalength\=(string)3\,\ config\=(string)119008c400002000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\,\ a-sdplang\=(string)en\,\ ssrc\=(uint)2072847348\,\ clock-base\=(uint)0\,\ seqnum-base\=(uint)1\,\ npt-start\=(guint64)0\,\ npt-stop\=(guint64)596458000000\,\ play-speed\=(double)1\,\ play-scale\=(double)1

Notice the encoding-name .. this points to aac which is used by default in mp4. The same applies for video - again search for buffers of type application/x-rtp,media=video .. for me its again mp4 generic - h264.


APPROACH 2:

Easier is just use uridecodebin and dump the dot file and view how it constructed the pipeline and copy the respective elements:

GST_DEBUG_DUMP_DOT_DIR=`pwd` gst-launch-1.0 uridecodebin uri=rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4 ! fakesink

This will generate files with .dot extension - get the PAUSE_PLAYING one and make it a picture with dot -T png 0.0blabla.dot -o blabla.png .. check the elements after rtpsometginfdepay.


With all the infos you can construct similar pipeline:

gst-launch-1.0 -e mp4mux name=m ! filesink location=bla.mp4  rtspsrc location=rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4 name=r r. ! "application/x-rtp,media=video" ! rtph264depay ! h264parse ! m.  r. ! "application/x-rtp,media=audio" ! rtpmp4gdepay ! aacparse ! m.

Keep in mind you can create elements at the beginning of gst-launch but use them later (as I did with mp4mux)..

HTH

Upvotes: 2

Related Questions