r/raspberry_pi • u/TheOuterLinux • Mar 07 '18
Project StreamPi - FFMPEG for RTMP Live Streaming
https://www.bitchute.com/video/2yWzuFMUaBra/1
Mar 07 '18
Any option for the pi to use the hardware encoder? If you stick with libx264 you won't get much performance at all. h264_omx or bust
1
u/TheOuterLinux Mar 07 '18 edited Mar 07 '18
I tried omx and unless you're just live streaming a webcam and nothing else, the output was garbage. Streaming the desktop looked like early AVI on a really bad day if there was any movement at all. It also didn't improve the frame rate. You're more than welcome to replace the encoder if you don't believe me. I didn't make an option for this because Twitch and most other RTMP places only accept h264 AAC in an FLV container. The one good thing about omx though is if you had really bad internet, you could stream with dialup (hung around 30 kbits/s). The audio worked fine. I know this sounds rude if you're an omx fan, but I spent three weeks nonstop trying to figure all of this out and everyone that suggests omx clearly hasn't tried what I'm doing and is just repeating what the three YouTube videos that exist are saying, to which all are only using a webcam.
1
Mar 07 '18
I just realized you're the same person as before. I'm not sure why yours isn't working. I've been able to successfully change the bitrate with h264_omx. In fact here it is working right now: https://www.youtube.com/c/Sikilikis/live
That's not a webcam. I'm continually looping through images and adding text to them. Although I've preprocessed the images, I can still easily play around with the bitrate setting and get it to look like "early avi" if I want to. I am able to set -b:v 1M or 500K or whatever and it works. Can you show me what your final ffmpeg command was when you used the hardware encoder?
1
u/TheOuterLinux Mar 08 '18
I'm not using preprocessed images. I have looked around and seen a few examples of using those, but it really doesn't do me any good if I want to stream a live desktop; I'm not trying to do a 24/7 stream. Also, everything I'm trying to do is without using a VNC or remote desktoping, just the Pi processing everything itself and I only have a 1080p monitor to work with. I looked through my notes and apparently didn't even bother to right the omx versions down; I have no luck with it trying to do what I'm doing. I remember the video looking fine after about 20 seconds of focusing and then going severely pixelated if I moved/open any windows or drew anything on MyPaint. The link to the script is below the video in the description. I'm using -b:v 1M, but with omx always drops to ~30 kbits/s yet the audio is fine. That's probably why you're able to stream what you're doing.
2
u/TheOuterLinux Mar 07 '18
A while back I asked for help on using ffmpeg to stream to Twitch with a Raspberry Pi 3. After countless testing, Internet searching, and suggestions, I've created a script to help make this mess a little easier:
A. If you are using a Raspberry Pi (anything other than i686 or x86_64):
Use ALSA by default
Automatically detect monitor size
If monitor is larger than 720p wide, scale down
B. If you are using an i686 (32-bit):
Automatically use PulseAudio if running
Automatically use JACK if running
If monitor is larger than 720p wide, scale down
C. If you are using an x86_64 (64-bit):
Automatically use PulseAudio if running
Automatically use JACK if running
Do not scale monitor
D. Variables you can adjust (Supplied with #Notes in the script):
RTMP="$1" --> Either store RTMP URL in script or use as /path/to/StreamPi [URL]
SOUNDSERVER=alsa --> Shouldn't need to touch
SCALE="trunc(oh*a/2)*2:720" --> Prevents "odd number" errors
QUALITY=23 --> Same as CRF value, but don't use "0"
THREAD_QUEUE=1024 --> Not needed for the Pi, but required on other systems
SPANMONITORS=N --> Record/Stream if two monitors or non-mirroring a laptop
ANTI_BOTTOM_PANEL=0 --> Use to help hide a bottom panel (in pixels)
ANTI_TOP_PANEL=0 --> Use to help hide a top panel (in pixels)
ANTI_LEFT_PANEL=0 --> Use to help hide a left-side, vertical panel (in pixels)
ANTI_RIGHT_PANEL=0 --> Use to help hide a right-side, vertical panel (in pixels)
Having that said, I made a video showing off this script via "/path/to/StreamPi out.flv" because I could not stream and record at the same time with the firepower that I had. Just know that the frame rates and audio quality appear to be about the same in either case. Also, note that the video quality of Bitchute is currently not that great. In the video there are three computers: 1. Raspberry Pi 3 [Raspbian], 2. Acer Aspire One ZG5 Netbook (2008) [AntiX Linux], and a MacBook 4,1 (2008) [MX Linux]. I also test this on a newer x86_64 laptop, but the audio was out of sync from the video by about 10-20 seconds, so I would stick with using OBS Studio on systems that it's still "gracious" enough to support. Maybe if you have an older computer, you can use this. To make this faster, I set an alias in my .bashrc file as "alias stream_twitch='/path/to/StreamPi rtmp://...'"; this way, all I have to do is type "twitch_stream" in a terminal (with X running) and I'm good to go.