Timelapse video quality and retaining snapshots

What is the problem?
I have a wide-angle Raspberry Pi camera I have set up to take snapshots at the max resolution of 2592x1944 and that appears to be working properly as the snapshot URL shows a nice crisp photo at that resolution (or at least as crisp as the Pi Cam can produce).

When the timelapse is rendered, it looks like crap, blocky, artifacts no detail, etc.

And the video produced, mpg, is not playable on my Windows 10 PC (but is at the 2592x1944 res)

The tmp folder does not contain any of the snapshots after the render is complete. I would like to have those files retained so I can download them and render myself if there is no solution to improving render quality on the Pi:
/home/pi/.octoprint/timelapse/tmp

What did you already try to solve it?
I've changed the bitrate to 20000kbs in the UI but that didn't help much. The bitrate did increase to 18159kbps, but it still looks pretty bad.

So I found a thread about changing the timelapse.py script for x264 and mp4 output:
[Request] H.264 timelapse output #2373

I made those changes to the script in:
/home/pi/oprint/lib/python2.7/site-packages/octoprint/timelapse.py

 command = [
                        ffmpeg, '-framerate', str(fps), '-loglevel', 'error', '-i', '"{}"'.format(input), '-vcodec', 'libx264',
                        '-threads', str(threads), '-r', "25", '-y',
                        # '-b', str(bitrate),
                        '-f', 'mp4']

And tried again - same result: mpg filename/format, unplayable on Windows PC, and poor quality.
So now, I have rebooted the Pi and am trying another timelapse right now.

So, what I am asking for help with is:

  1. Improve video quality from the render.
  2. output a format that Windows 10 understands
  3. Retain snapshots after render has completed.

Apologies if I have missed a thread, or two, that covers these questions - I did search here on the forum and Googled for answers and found very little, very old, posts that didn't seem to help.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)
OctoPrint: Version 1.3.10
OctoPi: Version 0.15.1, running on Raspberry Pi 3 Model B Rev 1.2
Hypercube Evolution Printer
SmoothieWare firmware: Aug 2018

Thank you, and please let me know if you need additional information.

DaHai

So, I rebooted the Pi and tried another timelapse. The rendering failed with the following error:

Rendering timelapse failed

Rendering of timelapse shroomhead_-_White_210_Hevo_20190605093140 failed with return code 1

More:

x264 [error]: malloc of size 26916160 failed
Video encoding failed

Its a 16GB SD Card in the Pi and a RPi 3B+

What am I doing wrong?

Thanks

P.S. So, at least with this failure, I have the *.jpg snapshots to build a good mp4 file from on my PC :slight_smile:

A malloc is a request for physical memory of which there is only 1GB on an RPi 3. At the resolution you are trying to render, I'm not surprised that the RPi can't handle it. You could increase the size of the swap partition, but I'm not sure that is a workable solution.

The first thing I would suggest is to (greatly) reduce the resolution of the snapshots so you can get the rest of the process perfected. Once that is done, you can increase the resolution in steps until it fails and then you know the limits of what your RPi can do.

If the resolution is the most important factor, then I believe you will need to render the movie on a more powerful system. You could use Samba or NFS to get the snapshots located on storage convenient to the rendering system and some communication mechanism to tell the rendering system when to start.

Thank you.
I've been downloading the snapshots to my Windows PC and rendering them there. But that's only possible because the render on the Pi fails and so leaves the .jpg files intact. Otherwise they get automatically deleted at the completion of the rendering on the Pi.
Any idea how to turn OFF auto-deletion of the snapshots?
Thanks again!

This seems too simple... In OctoPrint Settings, Webcam & Timelapse, Path to FFMPEG, change the path to /home/pi/fail and create fail in /home/pi:

#!/bin/bash
# Do nothing, exit with a failure
exit 1

Of course, the script could be expanded to copy the snapshots to your Windows PC and then return success (exit 0). I assume the success path deletes the snapshots.

That's an interesting idea. I will give that a try.
I was thinking there was a json/yaml/config setting somewhere to change that would retain images, but I guess not.
Thanks again.

I believe the Pi3+ can not do 4K, the Pi4 will be able too