Timelapse from the Pi after fitting a Duet

Discussion in 'Guides, Mods, and Upgrades' started by Spoon Unit, Aug 30, 2017.

  1. Spoon Unit

    Spoon Unit Well-Known Member

    Joined:
    Sep 6, 2015
    Messages:
    1,095
    Likes Received:
    322
    So. You moved to the Duet, and you still want a timelapse. Here's how I've connected all the pieces, and I'd be delighted to hear of other, better solutions. For now though, this does work.

    For me, I have a PC on permanently in another part of the house from the printer. I've powered the Pi by connecting the original wire from the RUMBA PWR connection into one of the permanently on fan connections on the Duet (after rewiring into one the the Duet-supplied Molex KK connectors).

    So, now the Pi is on and doing what it always did, and most importantly making a camera feed available. First useful thing we can do is hook that up to the Duet Web Console. For that, open DWC, go to Settings > User Interface and fill in the address of your webcam like this:

    upload_2017-8-30_20-52-32.png

    You'll now see your web cam in the Print Status page.

    To get to a timelapse, I installed VLC (well OK, it was already installed, but I upgraded it as it's not used regularly), and after a bit of Googling, came up with this (https://forum.videolan.org/viewtopic.php?t=130776):

    vlc http://xxx.xxx.xxx.xxx:8080/?action=stream --video-filter=scene --scene-format=jpg --scene-path=./ --scene-ratio 100 --vout=dummy --run-time=7200 vlc://quit

    This assumes you've put the path to the VLC.exe in your path, and will let you run VLC from anywhere when you open a command prompt. So, now you can create a timelapse folder, create a subfolder for the current print, and run that command (changing it for your address of course in place of the xxx.xxx.xxx.xxx). I think the Pi is generating a stream with roughly 10 frames per second, so by using scene-ratio 100, I'm taking every hundredth still, i.e. one shot every 10 seconds. runtime is in seconds, so this was a two hour timelapse. I think it generated around 740 images.

    To convert those images to a video, I used ImageJ (something else I happened to have installed). I probably could have used ffmpeg, but for the fact that the command line for that didn't want to do wildcards or wanted my file numbers in a numerical sequence. I never actually tried that, but it was super simple to do with ImageJ anyway (Option 2 here - http://www.andrewnoske.com/wiki/Con...rtualDub......_.28free.2C_but_Windows_only.29). A couple of clicks later and you have your timelapse.

    Here's a celebratory timelapse of the Volcano printing an EphJar on the PEI plate using a (auto defined) 1.2mm extrusion:



    Interesting to see (around 25 seconds in) the part release from the plate, and then my little priming square follow suit a second or two later.
     
  2. Spoon Unit

    Spoon Unit Well-Known Member

    Joined:
    Sep 6, 2015
    Messages:
    1,095
    Likes Received:
    322
    Have moved from ImageJ to ffmpeg now in order to be able to control. I currently have this boiled down to five batch files in my timelapse folder.

    record.bat - adjust the scene ration of you want to capture more or less than 1 frame for every 100 video video frame

    Code:
    vlc http://xxx.xxx.xxx.xxx:8080/?action=stream --video-filter=scene --scene-format=jpg --scene-path=./ --scene-ratio 100 --vout=dummy --run-time=%1 vlc://quit
    
    example usage: record 1 frame of footage

    Code:
    record 1
    
    rename.bat - this renames the files that came from the recording session into numerical order. Don't accidentally run this twice!

    Code:
    @echo off
    setlocal EnableDelayedExpansion
    set i=0
    for %%a in (*.jpg) do (
        set /a i+=1
        ren "%%a" "IMG!i!.new"
    )
    ren *.new *.jpg
    
    To execute this just run 'rename.bat'.

    process.bat - this expects to find an audio.mp3 file, so go and grab one from somewhere you can get free music from (e.g. http://freemusicarchive.org/). This uses ffmpeg and expects it to be able to encode using h264 - you might need some Googling and fiddling to get that all sorted.

    Code:
    ffmpeg -i IMG%%01d.jpg -i audio.mp3 video.mkv
    
    To execute this, just run 'process'. Once complete (it shouldn't take long), watch the resulting video.mkv. If it goes on far too long, you may want to go and cull some of the images and re-run process. Once you have what you want, note the point in time where you'd like to music to fade out. If that's at say, the 40th second, you want to initiate a 10 second fade from second 30 so ...

    refine.bat - this will fade the audio at at the point you want. You can edit it, but it's set here for a 10 second fade out.

    Code:
    ffmpeg -i IMG%%01d.jpg -i audio.mp3 -filter_complex afade=t=out:st=%1:d=10 video.mkv
    
    To run this type:

    Code:
    refine 30
    
    This will ask you for permission to overwrite the video (you might need to close it first if it's still open). If you're happy with the end result, upload it, or share it however you like; don't forget attributions. And finally

    cleanup.bat - tidy up the mess ready for the next run

    Code:
    del audio.mp3
    del video.mkv
    del *.jpg
    
    I can't upload the files as a zip file due to forum rules. Therefore I've renamed the zip file to .txt. You'll need to rename to zip or 7z if you want to get the content, or just copy and paste from this paste whichever bits you want to use.

    Finally, here's what you can expect:

     

    Attached Files:

Share This Page