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

Timelapse Compilation - GPU and queue? #184

Open
AcidBurns opened this issue Jan 1, 2016 · 9 comments

Comments

Projects
None yet
5 participants
@AcidBurns
Copy link

commented Jan 1, 2016

Happy new year at first ;)

I got two enhancements for octopi:

  • At first, just a suggestion, there is no queue for the timelapse. So I have to wait for the last timelapse to finish rendering before I can start a new print. There should be a queue or something buffering the print, this could be done by simply adding a hour-minute-stamp to the tmp directory where the jpgs are saved (/home/pi/.octoprint/timelapse/tmp0350 instead of simply tmp)
  • The second thing is: Why is there no use of the Raspberry GPU for those renderings? A preversion which needs manual filename input can be found in the scripts.zip (or in the text here). If there's a need I can code some bash scripts which accept the same parameters as avconv, so the script can be manually exchanged via the "path to avconv"-variable.

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

This comment has been minimized.

Copy link
Author

commented Jan 2, 2016

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

keep in mind that you have to change:

  • the timelapse.py (
    /home/pi/oprint/lib/python2.7/site-packages/OctoPrint-1.2.8-py2.7.egg/octoprint/timelapse.py) to also display .mp4 files (change the *.mpg to *.mp)
  • and adjust the path to ffmpeg to point to this avconv in the octopi settings in the tab "webcam".
  • and set the threads to 1.

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

This comment has been minimized.

Copy link
Owner

commented Jan 2, 2016

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

@AcidBurns

This comment has been minimized.

Copy link
Author

commented Jan 2, 2016

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:

  • just put the script into the octoPI (!!) release
  • modify the octoPRINT (!!) code to also list mp4, avi and/or mkv files in the timelapse section
  • make a tickable box in the webcam section (something like "enable GPU processing (only RPi)").
    the box has to set threads to 1 and call the script instead of the /usr/bin/avconv exec.

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

This comment has been minimized.

Copy link

commented Mar 5, 2016

@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

This comment has been minimized.

Copy link
Author

commented Mar 5, 2016

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

This comment has been minimized.

Copy link

commented Apr 28, 2016

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

This comment has been minimized.

Copy link

commented Sep 17, 2017

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

This comment has been minimized.

Copy link

commented Sep 17, 2017

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

@guysoft

This comment has been minimized.

Copy link
Owner

commented Sep 17, 2017

Please don't spam. There is no guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.