Question / Help Could Raspberry Pi 4 do live streaming?

Flyrain

New Member
This didn't work:
[h264_omx @ 0x148b150] OMX error 80001000
[h264_omx @ 0x148b150] err 80001018 (-2147479528) on line 561
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
 

Flyrain

New Member
With software encoder it works, but...

"frame= 123 fps=1.7 q=17.0 size= 6450kB time=00:00:18.35 bitrate=2878.8kbits/s speed=0.257x"

maybe the problem is the standard output from the camlink?

"The V4L2 driver changed the video from 1280x720 to 3840x2160"

Command: ffmpeg -f video4linux2 -input_format yuyv422 -s 1280x720 -i /dev/video0 -vcodec h264 -b:v 3M -maxrate:v 4M -f flv rtmp://live.twitch.tv/app/live_XXXXXXXXXXXXXXXXXXXXXX
 
Last edited:

Filip S

Member
I‘m trying almost the same. I want to use the pi4 and camlink with a GoPro for my mobile setup to stream directly to Twitch. Something like the expensive LiveU Solo. It works but only with 10 fps. The Pi is only at 50% percent usage of 1 core. Maybe someone knew some ffmpeg tweaks? No Desktop, only command line. I tried your ffmpeg command you posted earlier.

What gopro ? the hero7 black can do custom rtmp
I don't use "-filter:v scale"
I think: ffmpeg -f video4linux2 -input_format yuyv422 -s 1280x720 -i /dev/video0 -vcodec h264_omx -b:v 3M -maxrate:v 4M -f mpegts 'udp://192.168.10.100:9250'


This is almost working - the speed was 50 fps and I did get a signal only 192.168.10.100 the video was dark and red and no audio
so its possible - I tried to leavout -s 1280x720 because it also did see the streams as a 1280x720 resolution.

Is it possible to do the same but i vlc ?
 

Flyrain

New Member
What gopro ? the hero7 black can do custom rtmp
I try to give the possibility to use every HDMI Source you want.

Do you have a different Cam link? Not the 4k one?

I see... i dont have other options and the pi4 cant handle the cam link 4k :D

[video4linux2,v4l2 @ 0xd8a1c0] Raw : nv12 : Y/CbCr 4:2:0 : 3840x2160
[video4linux2,v4l2 @ 0xd8a1c0] Raw : nv12 : Y/CbCr 4:2:0 : 3840x2160
[video4linux2,v4l2 @ 0xd8a1c0] Raw : yuv420p : Planar YUV 4:2:0 : 3840x2160

These are the only options i can use. Maybe i try to get an older one.
 
Last edited:

Filip S

Member
I try to give the possibility to use every HDMI Source you want.

Do you have a different Cam link? Not the 4k one?

I see... i dont have other options and the pi4 cant handle the cam link 4k :D

[video4linux2,v4l2 @ 0xd8a1c0] Raw : nv12 : Y/CbCr 4:2:0 : 3840x2160
[video4linux2,v4l2 @ 0xd8a1c0] Raw : nv12 : Y/CbCr 4:2:0 : 3840x2160
[video4linux2,v4l2 @ 0xd8a1c0] Raw : yuv420p : Planar YUV 4:2:0 : 3840x2160

These are the only options i can use. Maybe i try to get an older one.

No my camlink does only 1280x720 and possible not nv12 maybe only lanar YUV 4:2:0 and I dont know if it can be upgraded
the firmware but It works nice on my ubunto with OBS givning also 1920x1080 but no need to steam out in full hd.

Maybe rpi4 ffmpeg does not give the right output - the strange thing is I can do a read from the USB3 camlink with
the VLC so maybe I can restream the output but surely ffmpeg with h264_omx gives best fps but maybe my
vlc on the recieving end does not handle the h264_omx I am not really sure about this.

I also have a HD60 but this does not work with my Linux as this does not work as webcam device
 

Tomasz Góral

Active Member
No my camlink does only 1280x720 and possible not nv12 maybe only lanar YUV 4:2:0 and I dont know if it can be upgraded
the firmware but It works nice on my ubunto with OBS givning also 1920x1080 but no need to steam out in full hd.

Maybe rpi4 ffmpeg does not give the right output - the strange thing is I can do a read from the USB3 camlink with
the VLC so maybe I can restream the output but surely ffmpeg with h264_omx gives best fps but maybe my
vlc on the recieving end does not handle the h264_omx I am not really sure about this.

I also have a HD60 but this does not work with my Linux as this does not work as webcam device

is normal vlc get RAW data, use yuv420p, yuyv422 is too rich for omx encoder.
 

Filip S

Member
is normal vlc get RAW data, use yuv420p, yuyv422 is too rich for omx encoder.

Now I tried this and it works - but dont get any audio transfers in my vlc but it looks like its more easy to keep up with the 25 frames in
mpeg1/mpeg2 for transmission so If I can get the audio to work also I will get a cooling fan for the rpi4 maybe another rpi4 can do
the encoding to h264 and rtmps :)


ffmpeg -i /dev/video0 \
-r 25 -b:v 3M -maxrate:v 4M \
-crf 0 -tune zerolatency -preset ultrafast \
-f mpegts 'udp://192.168.10.100:9250'
 

Filip S

Member
Now I tried this and it works - but dont get any audio transfers in my vlc but it looks like its more easy to keep up with the 25 frames in
mpeg1/mpeg2 for transmission so If I can get the audio to work also I will get a cooling fan for the rpi4 maybe another rpi4 can do
the encoding to h264 and rtmps :)


ffmpeg -i /dev/video0 \
-r 25 -b:v 3M -maxrate:v 4M \
-crf 0 -tune zerolatency -preset ultrafast \
-f mpegts 'udp://192.168.10.100:9250'

By the way if I select /dev/video0 and hw:1,0 for the audio it gets pcm S16 LE (s16|) with stereo 4800hz bit pr sample 16
and this gives the audio from the camera fine.
 

Filip S

Member
By the way if I select /dev/video0 and hw:1,0 for the audio it gets pcm S16 LE (s16|) with stereo 4800hz bit pr sample 16
and this gives the audio from the camera fine.

Now this is working for me with audio also - but I will do some more testing

ffmpeg -f alsa -ac 2 -i hw:1,0 -i /dev/video0 -acodec aac -ab 128k \
-r 25 \
-b:v 8M -maxrate:v 8M \
-crf 0 -tune zerolatency -preset ultrafast \
-f mpegts 'udp://192.168.10.100:9250'


vcgencmd measure_temp
temp=85.0'C

So does get very hot with heat sink on but it works so I am happy I dont know about the load using other than the udp but load avarage is 3.05

This is my test - some recording done via vlc and obs this my test https://www.youtube.com/watch?v=0p-43YPZHzs
 
Last edited:

Filip S

Member
I am happy Raspberry PI4 with camlink is working very nice.

Important to say its only 1280x720 on my camlink also if the camera is on and connected
You have to turn off the camera and on again like it needs to initialize hdmi - I would like
to avoid this step or possible force it by software. (a small problem and also you
have to remember to use the same usb3 connection)

Anyway I have done nice streaming both rtmp,udp,tcp to both youtube,facebook and
nginx or my big computer with vlc it have been running for more than 9 hours with just
a heat sink but I think a small cooler fan would be important in a hot room.

- All this would be nice to have some fance webgui configuration to switch
setups and its even more usefull than the Terradek VidiU because it can
include openvpn maybe even a local storage of the stream and some old
videocamera with tapes can be used even if they are old ;)


#!/bin/bash
# SSL Stunnel at port 19350 with destination to facebook to get rtmpS
OBS_DEST="-f flv rtmp://127.0.0.1:19350/rtmp/{Yourkey}"

# Destination to youtube no stunnel needed here
#OBS_DEST="-f flv rtmp://a.rtmp.youtube.com/live2/{yourkey}"

#Videocodec="h264"
Videocodec="h264_omx"
#Videocodec="libx265"
#Videocodec="mpeg2video"

# -pix_fmts
#Pixelformat="yuv420p"
#Pixelformat="yuv422p"

printf "\n--- Start $Videocodec Transmission\n"

# ffmpeg -hide_banner -f alsa -ac 2 -map 0:0 -map 1:0 -i hw:1,0 -f video4linux2 -i /dev/video0 -vcodec $Videocodec\
ffmpeg -hide_banner -f alsa -ac 2 -i hw:1,0 -re -f video4linux2 -i /dev/video0 -vcodec $Videocodec\
-acodec aac -b:a 128k -ar 48000\
-r 25 \
-qmin 2 -qmax 51 -b:v 2M -maxrate:v 8M -bufsize 10M -g 50\
-crf 18\
-tune zerolatency \
-preset fast \
$OBS_DEST
 

Filip S

Member
I have found a may to reset til camlink using

sudo usbreset 0fd9:0061

But not really sure it solve my problem - I looks like a delay is needed after because it says

ioctl(VIDIOC_STREAMON): No such file or directory
/dev/video0: No such file or directory

So the /dev/video0 need to be back again but I think its maybe a way to avoid turn off and on the camera maybe ;)
 

Filip S

Member
Today I did try to setup the gopro hero7 black to do a 720p rmtp via the wifi to my rpi4 running with ngnix with hls streaming.
Also the rpi4 was reading/capture via the usb3 also 720p from the elgato camlink output to - f flv rtmp://127.0.0.1/hls/webcam"

I was able to open to vlcs showing both hls streams ;)

the vcgencmd measure_temp temp=78.0'C with heat sink

Anyway the streams was not started at the same time - but is it possible to maybe sync the two rtmp streams ?
Any fancy way to do this ? the data via the camlink usb is with a delay other than the data from the gropro
rtmp stream its not a big surprise.
 

Filip S

Member
General use case would be for the ever so common twitch streaming using NDI to send the footage from my main computer to the Raspberry Pi for encoding and sending to twich or any kind of streaming service

I don't use NDI just UDP unicast or if I do make a multicast i do it on the loopback interface 127.0.0.1 and use the udpxy demon
to listen for multicasting like this (mpegts udp://224.0.0.0:9250) - I did find some parts of my network was not happy with
the global multicast and unicast was maybe not a problem on my wifi but using udpxy from http://www.udpxy.com/download/udpxy/udpxy-src.tar.gz is very usefull also.

# On Rasberry route because of possible multicast trafic network noice ;)
# You can also just use loopback 127.0.0.1 else
ip address add 1.2.3.4/32 dev lo label lo:1
ip route add 224.0.0.0/4 dev lo:1
# with udpxy I can do this
sudo udpxy -m lo -p 4040

Any http connection to port 4040 gives me acces to the multicast don on the lo interface - the main reason was to avoid problems with unicast
I am not really sure what gain it would have to use a NDI solution but the raspberry can listen for any multicast and make the trafic tcp/http available.
 

peardox

New Member
I attempted to do this tonight, and while I do think I made a lot of progress, I eventually hit an error I couldn’t troubleshoot further. I came here hoping for some suggestions, but I’m guessing I won’t get any.

I got CMake to build all of the necessary configurations. There were a lot of dependencies I needed to get installed. I went through the missing items one by one in the output from CMake, and eventually got it to recognize all of the requirements. When I attempt to run sudo make -j4 it errors out. I’ve spent some time troubleshooting the error I’m seeing, but I can’t find the culprit. The errors appear to be related to ffmpeg-mux, although it seems like all of the ffmpeg dependencies are in place. It’s generating errors in a library that I do have installed, so I’m sort of at a loss.

I am assuming this isn’t an issue I’ll be able to fix since it wasn’t designed to run on ARM. I checked a bunch of the specs before I started this, and I thought the RPi4 met the necessary requirements, but I guess not.

Does anyone have a recommendation for a similar low end computer that OBS will actually run on? I’m doing a couple things that require software like OBS, but this is the only thing I need this computer to do, so I don’t want to spend too much.

I've got a full build on a Pi4 in 32/64 bit and another on a Jetson Nano 64 bit - they all crash as soon as they hit OpenGL

The SSE stuff can be replaced with NEON versions - I'm waiting for a macro to be converted (_MM_TRANSPOSE4_PS is hard coded in the middle of a C source file, someone's on the case)

I'm worried about the OpenGL requirements - OpenGL 3.2 is stated but the Pi only has OpenGL ES 3.2, wondering if this will be an issue.

The Nano has OpenGL 4.6 but don't work either...

When I get the translation of _MM_TRANSPOSE4_PS thru I'll give it another go - this could possibly be causing the current core dump

My version's somewhat of a hack but if/when I get it working I'll do a proper fix
 
Top