Use gstreamer to take rtsp input and output rtmp - gstreamer

I'm trying to use gstreamer to go from h264 rtsp input to rtmp output to youtube without re-encoding. in ffmpeg I can simply do a codec copy, but in gstreamer, I can't my pipeline to work:
gst-launch-1.0 -e -v rtspsrc location="rtsp://rtsp/input" protocols=tcp latency=0 ! rtph264depay ! h264parse ! flvmux streamable=true ! rtmpsink sync=true async=true location='rtmp://a.rtmp.youtube.com/live2/key live=true'
I have a feeling it has to do with the audio. I'm receiving aac audio from the rtsp feed but can't figure out how to parse it into the rtmp output.

Related

How to publish RTSP stream from ip camera with gstreamer?

I have a rtsp-simple-server running on Debian and
I try to publish RTSP from my ip camera (h264 + pcm ulaw) to RTSP server with gstreamer.
I tried this command:
gst-launch-1.0 rtspsrc location=rtsp://192.168.1.1:554/11 !
rtph264depay ! rtspclientsink location=rtsp://server.com:8554/camstream1 protocols=tcp
It works, but it streams video only. The following command streams audio only:
gst-launch-1.0 rtspsrc location=rtsp://192.168.1.1:554/11 !
rtppcmudepay ! rtspclientsink location=rtsp://server.com:8554/camstream1 protocols=tcp
How can I stream video + audio?
Try this (or something like this) :
gst-launch-1.0 rtspsrc location=rtsp://192.168.1.1:554/11 name=mysrc !
rtph264depay ! rtspclientsink location=rtsp://server.com:8554/camstream1 protocols=tcp mysrc. ! rtppcmudepay ! rtspclientsink location=rtsp://server.com:8554/camstream1 protocols=tcp
OR you might have to MUX the audio and video first, before sending to rtspclientsink (this part is beyond me)
Try this first on a PC to see if the first part works
gst-launch-1.0 rtspsrc location=rtsp://192.168.1.1:554/11 name=mysrc !
rtph264depay ! autovideosink mysrc. ! rtppcmudepay ! autoaudiosink

GStreamer - RTSP to HLS / mp4

I try to save RTSP h.264 stream to HLS mp4 files:
gst-launch-1.0 rtspsrc location="rtsp://....." ! rtph264depay ! h264parse ! matroskamux ! hlssink max-files=0 playlist-length=0 location="/home/user/ch%05d.mp4" playlist-location="/home/user/list.m3u8" target-duration=15
As a result - there is only one file ch00000.mp4, which includes the whole videostream (3min instead of 15sec in "target-duration").
If I save to mpegtsmux / ts files - all is ok for the same command.
What is wrong? Thanks in advance.
HLS consists of MPEG transport stream segments. So first: matroskamux does not make sense here. You will need mpegtsmux instead. To indicate what it really is you normally would name the files with a .ts extension. It may still work for GStreamer as it is just a file name - players may reject playing it because the expect another sort of file format.
E.g.
gst-launch-1.0 rtspsrc location="rtsp://....." ! rtph264depay ! h264parse ! \
mpegtsmux ! hlssink max-files=0 playlist-length=0 location="/home/user/ch%05d.ts" \
playlist-location="/home/user/list.m3u8" target-duration=15
Do you have to use gstreamer? Otherwise I believe this ffmpeg command does what you want.
ffmpeg -i rtsp://... -c copy -hls_list_size 10 -hls_segment_type fmp4 output.m3u8

How to add audio to a h264 video stream using gstreamer

I can successfully stream HD video using following pipelines:
streame server:
gst-launch-1.0 filesrc location="Gravity.2013.720p.BluRay.x264.YIFY.mp4" ! decodebin ! x264enc ! rtph264pay pt=96 ssrc=0 timestamp-offset=0 seqnum-offset=0 pt=96 ! gdppay ! tcpclientsink host=192.168.1.93 port=5000
client:
gst-launch-1.0 tcpserversrc host=192.168.1.93 port=5000 ! gdpdepay ! rtph264depay ! decodebin ! autovideosink
I want to add the audio stream too.
I guess it is possible to use a different port and tcpserver/tcpclient combination to stream audio parallel to video. But I am not certain, how gstreamer would synchronize two streams properly to play the movie in the client end. Apart from this method, are there any other methods? such as muxing two streams before and demuxing it in client end?

Compress H264 Stream Using Gstreamer

I am trying to create a GStreamer pipeline (v 1.0) in order to record and play special file format.
For recording purpose I use the following pipeline:
gst-launch-1.0 videotestsrc ! video/x-raw-yuv, format=\(fourcc\)I420, width=640, height=480 ! videoconvert ! x264enc byte-stream=1 ! queue ! appsink
In appsink (using new_sample() callback) I use a compression method to compress H264 stream and finally store in a output file.
I use the following pipeline to play the recorded file:
gst-launch-1.0 appsrc ! video/x-h264 ! avdec_h264 ! autovideosink
In appsrc I decompress H264 stream and send it to appsrc buffer (using push-buffer). The size of each buffer is 4095.
Unfortunately GStreamer after push 2 buffers print the following debug message:
Error: Internal data flow error.
Is there any way to fix the problem?
Add legacyh264parse or h264parse (depending on your version of gst components) before your decoder. You need to be able to send full frames to the decoder.
Post avdec_h264 it would be nice to have a ffmpegcolorspace to be able to convert the video format to your display requirements.

Using gst-launch to streaming video?

I want to stream a media file (video or audio). I used command:
gst-launch-0.10 filesrc location="/home/ms/GStreamerTest/test.ogg" ! vorbisenc \
! rtpvorbispay pt=96 ! udpsink host=127.0.0.1 port=5000
to stream the file test.ogg, but, I got an error:
"ERROR: from element /GstPipeline:pipeline0/GstVorbisEnc:vorbisenc0: Internal GStreamer error: negotiation problem. Please file a bug at http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer.
Additional debug info:
gstvorbisenc.c(1227): gst_vorbis_enc_chain (): /GstPipeline:pipeline0/GstVorbisEnc:vorbisenc0:
encoder not initialized (input is not audio?)
ERROR: pipeline doesn't want to preroll.
Please help me solve this problem, thanks.
You plugged an encoded and muxed bitstream into an audio encoder. That cannot possibly work.
In your case filesrc ! udpsink would send your file across the network and on the other side you have to receive it udpsrc, demux it oggdemux, decode it theoradec or vorbisdec, and pipe it into a sink autovideosink or autoaudiosink