Elgato Camlink & Gstreamer

Hello folks!
First of all I´m new at jetson nano and gstreamer. There is the following situation:
We have a sony alpha 7 R 4 (IV) attached via the mini-HDMI port to an elgato camlink hdmi capture device. We want to acchieve two things: 1. stream the video signal live to another computer 2. save the original input stream on the jetson nano.

Well we got an rtmp stream working with the following commands:

modprobe v4l2loopback devices=1 exclusive_caps=1
ffmpeg -f v4l2 -input_format yuyv422 -video_size 1920x1080 -i /dev/video0 -pix_fmt yuyv422 -codec copy -f v4l2 /dev/video1 > /dev/null &
sleep 5
gst-launch-1.0 -v -e v4l2src device=/dev/video1 ! 'video/x-raw,format=YUY2' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! omxh264enc ! queue ! mux. flvmux name=mux ! rtmpsink location="rtmp://localhost/show/stream live=1"

localhost/show/stream is an nginx server with an rtmp module.

We made it working to perform a live stream and connect a VLC player to the nginx RMTP server. Then we recorded the stream over vlc and the quality wasn´t that good.

How can I tell gstreamer to save the video on the jetson nano?
How can I restart the whole stream when there is an error on the video devices without restarting the jetson nano?

Hi,
For further controls it may not work in running gst-launch-1.0 command. We suggest use C sample so that you can receive events and do saving bitstreams or re-launching the pipeline. Here is a C sample for reference:
Camera liveview cannot show up again after repeated open/close the liveview for several times - #23 by DaneLLL

For saving to a file, you can run like:

v4l2src device=/dev/video1 ! 'video/x-raw,format=YUY2' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! omxh264enc ! queue ! mux. flvmux name=mux ! tee name=t ! queue ! rtmpsink location="rtmp://localhost/show/stream live=1" t. ! queue ! appsink

In appsink, you can decide to save the stream or not.

Can you provide me a sample how I can build this c programm incl. the dependencies?
And where will the appsing save the streamfile and in which format?

Hi,
Please try this build command:

$ g++ -Wall -std=c++11  a.cpp -o test $(pkg-config --cflags --libs gstreamer-app-1.0)

Since appsink is after flvmux, you may save it to test.flv.

For fetching buffers in appsink, may refer to this sample:
Gstreamer decode live video stream with the delay difference between gst-launch-1.0 command and appsink callback - #6 by DaneLLL

Well I ended up with the following code:

nvpmodel -m 0
jetson_clocks

iptables -t nat -F

echo nameserver 8.8.8.8 > /etc/resolv.conf

pkill -f nginx
/usr/local/nginx/sbin/nginx &
sleep 2
gst-launch-1.0 -v -e  v4l2src device=/dev/video0 ! 'video/x-raw,format=YUY2' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! omxh264enc ! queue ! mux. flvmux name=mux ! tee name=t ! queue ! rtmpsink location="rtmp://localhost/show/stream live=1" t. ! queue ! filesink location=test$(date +%s%3N).flv -e

The saved video file is pretty good, but the rtmp stream is very laggy and there are encoding errors and blurred images but sometimes it is near realtime without almost any latency.
I dont know the problem, the CPU usage is about 30%. Is there anything left I can optimize?

Thank you and best regards!

Try boosting if power saving is not a concern:

sudo nvpmodel -m 0
sudo jeston_clocks