Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Frame Rate #64

Open
AdamWP opened this issue Jan 10, 2021 · 23 comments
Open

Increase Frame Rate #64

AdamWP opened this issue Jan 10, 2021 · 23 comments
Labels
enhancement New feature or request

Comments

@AdamWP
Copy link

AdamWP commented Jan 10, 2021

Is there any way to change the frame rate? The video is smooth in my octoprint control window, but choppy on my youtube live stream.

@jneilliii
Copy link
Owner

If you edit the file entry.sh prior to compiling the docker part you can adjust the framerate. This is the line.

https://github.com/jneilliii/youtubelive/blob/f1f43da4579c9092551fc19da988257e4e9c1329/entry.sh#L7

@jneilliii jneilliii added the support how-to or assistance with operation label Jan 10, 2021
@github-actions
Copy link

github-actions bot commented Feb 1, 2021

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days

@github-actions github-actions bot added the stale label Feb 1, 2021
@AdamWP
Copy link
Author

AdamWP commented Feb 6, 2021

I was able to increase the framerate and it works for a while but then fails. Sometime's it's after 12 hours, sometimes 12 minutes. My internet connection is 500Mb/s and I'm running a raspberry pi 4 with 4GB of ram connected with an ethernet cable rather than wifi. htop reports my memory usage is below 300M and CPU load average is less than 30% Should this setup not be able to handle streaming 720p at 24fps?

It looks great in the octoprint control window, but streaming to youtube is very unreliable. I'd like to keep the resolution at least 720p or go much higher since I'm creating time lapses with octolapse. What kind of resolution, bit rates, and framerates are people streaming reliably?

@jneilliii
Copy link
Owner

I'm not really sure, no one has ever reported any stats and since I've never used it long term don't have the personal details either. I would be curious if you get the same results just running the same ffmpeg command line directly via command line instead of inside the docker container. Might be a little easier to tweak all the various options with ffmpeg. The biggest drawback of the method being used in the plugin is re-encoding the stream rather than using some of the h264 video copy options using direct camera access like described where I got the original idea from here.

@jneilliii jneilliii removed the stale label Feb 6, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had activity in 14 days. It will be closed if no further activity occurs in 7 days

@github-actions github-actions bot added the stale label Feb 21, 2021
@jneilliii
Copy link
Owner

I've made a little progress on decoupling the plugin from using docker. So as long as your device has ffmpeg (recent octopi versions have this be default), then you can try this new version. It gives full control of the ffmpeg commands with default options coming over from the existing docker entry.sh file. I haven't yet dealt with the filters (flip rotate options) but those can be added via command line too. This will allow you to adjust the framerate yourself.

Install by copying/pasting the URL below into Plugin Manager > Get More > ...from URL.

https://github.com/jneilliii/OctoPrint-YouTubeLive/archive/develop/pure_ffmpeg.zip

I haven't tested this plugin fully, but very quick tests confirm that the plugin is able to stream to YouTube. The important part is that you have the ffmpeg command configured in OctoPrint's Timelapse Recording settings section.

image

@jneilliii jneilliii added enhancement New feature or request and removed stale support how-to or assistance with operation labels Feb 24, 2021
@AdamWP
Copy link
Author

AdamWP commented May 11, 2021

This is much easier to configure than the previous version. Just install and it works!

It looks like ffmpeg isn't taking advantage of the pi's hardware acceleration with the default settings. If you change "h264" to "h264_omx" in the ffmpeg command line options it significantly reduces CPU usage and YouTube doesn't complain about low bitrates.

Thanks for the update!

@AdamWP
Copy link
Author

AdamWP commented May 11, 2021

Something's still killing the stream after a few minutes. If I run "ffmpeg -re -f mjpeg -framerate 10 -i http://localhost:8080/?action=stream -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict experimental -vcodec h264_omx -threads 2 -pix_fmt yuv420p -g 10 -vb 1500k -framerate 10 -f flv rtmp://a.rtmp.youtube.com/live2/*****************" from the command line it will play for hours without fail but if I run it from the plugin it quits within 15 minutes. Nothing shows up in the log files to indicate a problem.

@jneilliii
Copy link
Owner

That's interesting, because that is exactly what the plugin is basically doing, running that command. Not sure what would cause it to just stop though.

@AdamWP
Copy link
Author

AdamWP commented May 11, 2021

When the stream is live ffmpeg uses about 60% cpu, when it dies it still shows up as running in htop but shows 0% cpu. Could there be something between octoprint and ffmpeg that puts it to sleep? I tried adding -timeout 60000 but that didn't make a difference.

Btw, I have "stream while printing" unchecked and I'm printing from the SD card while I do this testing. I'll test with a print job running from octoprint once my current print job is completed.

@AdamWP
Copy link
Author

AdamWP commented May 13, 2021

I'm getting the same behaviour even with "stream while printing" checked and printing directly from Octoprint rather than the SD card. It quits just after 4 minutes.

@jneilliii
Copy link
Owner

I've updated the pure_ffmpeg branch with some additional hooks for logging, and a slightly different way of starting the command. I haven't yet figure out the best way to stop the stream once it's started yet, but at least should help with getting some logs. After install go into OctoPrint's logging section and set octoprint.plugins.youtubelive to debug and save the settings prior to starting the stream.

@andyylin
Copy link

I'm also getting the issue of a stream stopping after just a few minutes (4-6 so far in my experience). In the YouTube Live tab, it still shows that it's live. Stopping and restarting with the button causes the live stream to start again just fine.

@jneilliii
Copy link
Owner

Curious if you've tried my RTMPStreamer plugin yet to see if it does it? There was a lot of work that went into it by a contributor that removed docker requirement and uses ffmpeg command lines directly, giving gull control of all the settings. Also incorporated overlays but would try without them first because it adds additional processing time.

@AdamWP
Copy link
Author

AdamWP commented May 30, 2022

Hi. I just installed it directly in Octoprint on a couple machines but I get the following error pop up in the top right corner of Octoprint:

YouTube Live Error
('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

@jneilliii
Copy link
Owner

That error would exist if you were running the docker version of this plugin but don't have the docker bits installed I think?

@AdamWP
Copy link
Author

AdamWP commented May 30, 2022

That was it. I had installed v0.5.2 through the plugin manager rather than running https://github.com/jneilliii/OctoPrint-YouTubeLive/archive/develop/pure_ffmpeg.zip.

Now I have 0.6.0rc2 installed and it's working(It does ask to upgrade to 0.5.0 btw). No more having to ssh into each machine now. I'll try running a few long prints and see how it works.

Great update!

@andyylin
Copy link

Curious if you've tried my RTMPStreamer plugin yet to see if it does it? There was a lot of work that went into it by a contributor that removed docker requirement and uses ffmpeg command lines directly, giving gull control of all the settings. Also incorporated overlays but would try without them first because it adds additional processing time.

Thanks for the suggestion, I just switched to RTMPStreamer and got it working on Twitch. Running the stream gets my Raspberry Pi 3B+ at around 50-60% CPU though. Do you recommend upgrading to a Raspberry 4 for live streaming?

@jneilliii
Copy link
Owner

It would help but would still maintain high CPU load because of transcoding the video from one format (mjpg) to another (h264 flv). You could try tweaking the options for the ffmpeg command, but did find Twitch to be a little more reliable than YouTube Live for some reason. In all cases ethernet connection is ideal for live streaming over WiFi.

A third option might be using restreamer over either plugin and have it supply HLS for OctoPrint, and can stream direct to external source (Twitch). I have notes on setting that up here.

@andyylin
Copy link

andyylin commented Jun 2, 2022

A third option might be using restreamer over either plugin and have it supply HLS for OctoPrint, and can stream direct to external source (Twitch). I have notes on setting that up here.

Thanks, I'm giving it a try, but running into a question that I've posted as a comment on that note.

@jneilliii
Copy link
Owner

jneilliii commented Jun 2, 2022

just in case you don't get replies to gist...

/dev/video0 looks like a raspicam style camera on the CSI connection and in most cases will be the correct device if there is only one camera.

@Puntoboy
Copy link

I'm getting a similar issue. Just installed this with the latest version of OctoPi. Choppy video and errors from Youtube.

image

@jneilliii
Copy link
Owner

Welcome to the club. It's been that way since this plugin's inception. If you have any ideas I'm all ears, although I've considered just dropping this plugin completely in favor of my other more generic rtmpstreamer plugin that doesn't require docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants