Skip to content

Instantly share code, notes, and snippets.

@andrewhodel
Created December 1, 2022 05:07

Revisions

  1. andrewhodel created this gist Dec 1, 2022.
    49 changes: 49 additions & 0 deletions timelapse_tools.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    package main

    import (
    "fmt"
    "io/ioutil"
    "log"
    "os"
    )

    func main() {

    if (len(os.Args) < 3) {
    log.Fatal("set first argument as directory, second argument as ffmpeg")
    }

    var path = os.Args[1]
    var ffmpeg = os.Args[2]

    if (path == "./") {
    log.Fatal("cwd must not be source directory")
    }

    fmt.Println("The speed needs to be fast, .05 is 20 times faster than normal and it is too slow to be impressive.")
    fmt.Println("Timelapses always look best with large zoomed out views, or slowly changing things.")

    files, err := ioutil.ReadDir(os.Args[1])
    if err != nil {
    log.Fatal(err)
    }

    var grid_s = ffmpeg
    var shrink = ""

    for _, file := range files {
    var n = file.Name()

    fmt.Println(ffmpeg + " -y -nostdin -i \"" + path + "/" + n + "\" -filter:v \"setpts=0.02*PTS\" -an \"./" + n + "\"")
    shrink += ffmpeg + " -y -nostdin -i \"./" + n + "\"" + " -s 1280x720 \"./small-" + n + "\"" + "\n"

    grid_s += " -i \"./small-" + n + "\""

    }

    grid_s += " -filter_complex \"[0:v][1:v][2:v]hstack=inputs=3[top];[3:v][4:v][5:v]hstack=inputs=3[mid];[6:v][7:v][8:v]hstack=inputs=3[bottom];[top][mid][bottom]vstack=inputs=3[v]\" -map \"[v]\" grid.mp4"

    fmt.Println(shrink)
    fmt.Println(grid_s)

    }