guysoft / OctoPi

Scripts to build OctoPi, a Raspberry PI distro for controlling 3D printers over the web
GNU General Public License v3.0
2.47k stars 367 forks source link

Timelapse Compilation - GPU and queue? #184

Open AcidBurns opened 8 years ago

AcidBurns commented 8 years ago

Happy new year at first ;)

I got two enhancements for octopi:

The comparison for a ~2h print between the ocotpi standard cpu mpg encoding and the gpu enabled h264/mp4 encoding on a raspberry 2 with 4 threads: CPU: real 43m42.090s, user 71m38.760s, sys 0m43.810s GPU: real 02m12.324s, user 01m50.230s, sys 0m5.230s

To render the movies, everything is already installed on octopi, just run this command: gst-launch-1.0 multifilesrc location=/home/pi/.octoprint/timelapse/tmp/tmp_%05d.jpg index=0 caps="image/jpeg,framerate=(fraction)24/1" ! jpegdec ! queue ! omxh264enc target-bitrate=15000000 control-rate=variable ! video/x-h264,width=1280,height=720,framerate=24/1,profile=high ! h264parse ! mp4mux faststart=true ! filesink location=/home/pi/.octoprint/timelapse/NAME.mp4

The zip also has different containers (avi, mp4, mkv), where mp4 is recommended. avi doesn't display a thumbnail in windows and mkv has 3 seconds blank at the beginng: scripts.zip

AcidBurns commented 8 years ago

Here's the parameterline compatible script which uses the raspberry pi gpu to render videos.

keep in mind that you have to change:

Known Problems with this setup: deleting and downloading of the mp4 files is not possible via the octopi website, however the files are displayed. I just don't know what else to modify to enable correct downloading and deleting. (I'm not a cutting edge programmer as you may already have encountered)

avconv.txt

guysoft commented 8 years ago

That could be a cool plugin/improvement if we can detect GPU. @foosel ?

AcidBurns commented 8 years ago

a note up front: the script will only work on systems where gstreamer with the omx package is installed. I'm not sure if this is possible for other linux systems, especially the embedded ones.. so detecting the gpu doesn't really help if you can't get hold on gstreamer and omxh264enc.

Due to the fact that the avconv.txt script is now parameter compatible to the avconv call from octoprint:

To circumvent errors one can simply check for the System by running: sudo lshw -short | grep system | awk '{ print $2 }' If it puts out "Raspberry" it's running on a raspberry pi and supports the method above. No need to say that this command is present on all debian distros. Attention: the lshw command needs about 2-3 seconds to process. rpis can also be indentified by cat /proc/cpuinfo, but that's more complicated.

2bitoperations commented 8 years ago

@AcidBurns thanks for putting together the avconv.txt wrapper script. I've tested it on my pi2 and it works a treat - much faster encodes and video that looks waaaaaaay better.

I opened a tiny pull request that lets octoprint see and manage the mp4 files that get created by the wrapper script. Hope we can get it merged to a release eventually. Would you mind if I included your wrapper script too in the pull request?

AcidBurns commented 8 years ago

sure you can include it. To my mind the stuff here is GPL V3 CC-by-sa if I read it correctly, so my script would also be; that's why I included my name and email in it. HOWEVER besides the "legal issues": the newest octoPI version (0.13; beta status for now i think) was build on jessie, it no longer has the gstreamer installed. give me til monday and I'll rewrite the script to check/install gstreamer and all necessary plugins and stuff to run.

Oh and there's also some changes made to the timelapse stuff after I wrote the wrapper. I think octoprint introduced some kind of "queue processing" which enables to print another print while still rendering the old timelapse without overwriting the "old", still in render process, jpgs. I will have to take a look at this also.

ntoff commented 8 years ago

This seems to choke if the images aren't the same size as set in the video/x-h264 parameters. Removing the width and height constraints seems to fix it and render out at the input image size, at least for me anyway. Trying it out on a raspberry pi 3.

ManuGithubSteam commented 6 years ago

Hi What must be done to get this to work ? I would prefer a step to step guide :-) EDIT: Ok i figured it out:

  1. Download the avconv.txt and rename it. (remove .txt)
  2. Point the Octoprint path to the new file.
  3. I did change one line in the timelapse.py to make mp4 output file standard. Its quite on top of the file. Its self explanatory. New path is this one: OctoPrint/venv/local/lib/python2.7/site-packages/OctoPrint-1.3.4-py2.7.egg/octoprint/
  4. I bought the mpeg decoder license. Don't know if this is needed.
  5. installed a bunch of stuff just google what you need if some commands are not found
  6. The files are now manageable in octoprint ui.

PS: I did not use the scripts folder. PSPS: i looked at the code in timelapse.py it should be possible to modify it to make a que possible but i fear im not skilled enough to do it properly and not in a hackish manner...

Thanks!

ManuGithubSteam commented 6 years ago

Thanks for this! How can i check if the GPU is really used ? Thanks!

guysoft commented 6 years ago

Please don't spam. There is no guide.