jneilliii / OctoPrint-RTMPStreamer

22 stars 13 forks source link

Request: Addition Encoders / Use Hardware Encoding (auto) #50

Open EndlessEden opened 11 months ago

EndlessEden commented 11 months ago

Issue: By default, no options are provided to instruct ffmpeg to use hardware encoding/decoding. Solution: add drop-down box and checkbox to enable hardware encoding/decoding to ffmpeg line.

Example:

[x] Enable Hardware Acceleration

(Dropdown box) {Decode} {Encode}

hardware_decode/hardware_encode | -hwaccel_device=auto

Further, the available encoders should include h264_omx, h264_cuvid, h264_amf, h264_vaapi if Hhardware Acceleration is ticked and "Encoding" is selected from the dropdown box.

(Example ffmpeg line with hardware accel enabled: {ffmpeg} -re -f mjpeg -framerate {frame_rate} {hardware_decode} -i {webcam_url} {filter} {hardware_encode} -f lavfi -i anullsrc -acodec aac -ab 128k -s {stream_resolution} -vcodec {videocodec} -threads {threads} -pix_fmt yuv420p -framerate {frame_rate} -g {gop_size} -vb {bitrate} -strict experimental -f flv {stream_url})


This type of solution makes using hardware accel easy, without needing to be a expert in the use of FFMPEG.

A simple description describing the encoders (omx = rpi, cuvid = nvidia, amf = amd, vaapi = intel/quicksync) is all thats needed to get users going. -- any encoding issues due to hardware encoding not being availible on the host os would be the responsibility of the user to resolve.

FFMPEG on Octopi-OS is already built with mmal/h264_omx built in, so not including this when native support exists is a major lost opportunity.

jneilliii commented 11 months ago

You seem knowledgeable about this, happy to accept pull request with these changes, not sure when I'll get to it.

TheSin- commented 11 months ago

The reason HW stuff isn't added is that if docker is selected it has a different build with different modules. I wrote it so that only the common modules are available.

That being said, we should be able to refresh the options if docker is not used. The issue is let's say you do not select docker, then you select a HW module. Then you go back and select docker afterwards. You need to add code to reset the encoder to the defaults at that point.

jneilliii commented 11 months ago

I'd be completely happy removing the docker options entirely.

TheSin- commented 11 months ago

That would simplify it, but then you'd be locking it to RPi only and we'd have to detect that. As technically it can be run on other platforms currently.

jneilliii commented 11 months ago

That would simplify it, but then you'd be locking it to RPi only and we'd have to detect that.

You mean the acceleration options? I tested the ffmpeg option on my windows machine during development and had no issues with the non-docker implementation.

TheSin- commented 11 months ago

yeah I mean if we add HW accel to the lists or options. That or just like docker we only enable them on RPI but have to detect when we aren't on RPI and auto remove them.

That is why I left it to the expert line for those that know what they are doing. As there was no easy way to keep it generic on the fly.

jneilliii commented 11 months ago

Yeah, that makes sense and the reason why I thought you made the command-line editable. I think the idea of detecting RPi and automatically adding the options to the command line is a neat idea, but if that's done why would you make it an option and not just automatically do it?

TheSin- commented 11 months ago

also a valid point, for me if you didn't want that option for whatever reason (bad firmware causing issues) you would have no way to disable it.

I'm not against adding HW Accel as I use it myself. But I just couldn't find a safe way to do it for all situations and not over complicating the startup by adding detection.

I did add a little magic to change the lists, and it could be used to add the options I think.

jneilliii commented 11 months ago

yeah, I was just looking at the pi support plugin and it does have an is_octopi function.

TheSin- commented 11 months ago

which I'm pretty sure is what I use to add the lists of modules. I also detect windows and MacOS IIRC.