Jetson Nano USB stream save while streaming to RTMP server with audio

I have a USB 1080p stream with audio and video. I was able to successfully save the stream as a .ts file with audio without any error. Below is the pipeline

gst-launch-1.0 -e v4l2src device=/dev/video0 ! 'video/x-raw, width=(int)1920, height=(int)1080, framerate=(fraction)30/1' ! queue ! nvvidconv ! nvv4l2h264enc maxperf-enable=1 bitrate=4000000 profile=4 ! h264parse ! mux. pulsesrc device="alsa_input.usb-VXIS_Inc_ezcap_U3_capture-02.analog-stereo" ! audio/x-raw,width=16,depth=16,rate=44100,channel=1 ! queue ! audioconvert ! voaacenc ! aacparse ! mpegtsmux name=mux ! filesink location="av_hdmi_9.ts"

Now I need to save the stream using above while streaming it to an rtmp server.

How can I achieve this?

Hi,
There are topics about RTMP. Please check
https://devtalk.nvidia.com/search/more/sitecommentsearch/rtmp/

Basically it is ‘flvmux ! rtmpsink’. you should utilize tee to run:

... ! nvv4l2h264enc ! tee name=Tee Tee. ! queue ! h264parse ! flvmux ! rtmpsink Tee. ! queue ! h264parse ! mpegtsmux ! filesink

Thank you DaneLLL. I will check the links

As mention I was able to save and stream. Now the issue I have faced is, if the rtmp stream is stopped the whole pipeline closes. I need to continue saving the stream even if the rtmp fails.

Hi,
Your request looks advancing and we don’t have enough experience to give further suggestion. Please go to
http://gstreamer-devel.966125.n4.nabble.com/

You may make a post with software encoder(such as x264nec) and see if gstreamer users can provide working solution. Once you get it working with software encoder, please replace it with nvv4l2h264enc to enable hardware acceleration.

1 Like

I’m a bit confused… why you don’t use 2 pipelines?
One to push stream to RTMP and another to save file…
Jetson Nano has multiple possibilities of encoding. Yes it lacks on audio encoding but maybe resources are enought…

1 Like

I tried to do it in that method, but two separate pipelines could not be used with one single source(After starting one pipeline when the next one is started it gives a message stating the source is already in use). That is the reason to use the tee element. This works fine. But the problem was when the rtmp server fails the whole process stops

Maybe I’ve not explained correctly my suggestion:
You use gone pipeline to read frames from device and push them to RTMP and use a second pipeline to read from RTMP and save to file.

1 Like

I will look into it. Thank you

Hi

According to requirements, you can handle two separated streams (record and RTMP streaming) from a single video sources using GStreamer Interpipes

Regards
Angel

1 Like

Thank you @aphillipso I will try this.