Yellowsink
Yellowsink

Reputation: 189

How do I get a folder of frames from a video using golang and FFmpeg?

I am using the https://github.com/floostack/transcoder library to interact with FFmpeg, and everything seems to work fine, except extracting images from a video.

I have tried passing it both the directory name and a %6d.png out pattern but both these just do nothing and exit.

My code is the following:

func ExtractImages(inPath string, outDir string) error {
    imgFormat := "png"
    opts := ffmpeg.Options{
        OutputFormat: &imgFormat,
    }

    err := os.Mkdir(outDir, os.ModeDir|fs.ModePerm)
    if err != nil {
        return err
    }

    _, err = GetTranscoder(inPath).
        WithOptions(opts).
        Output(path.Join(outDir, "%6d.png")).
        Start(opts)
    if err != nil {
        return err
    }

    return nil
}

Upvotes: 0

Views: 1274

Answers (1)

Zombo
Zombo

Reputation: 1

I just do it like this:

package main

import (
   "os"
   "os/exec"
)

func main() {
   c := exec.Command(
      "ffmpeg", "-i", "file.webm",
      "-vf", "select='eq(pict_type, I)'", "-vsync", "vfr", "%d.jpg",
   )
   c.Stderr = os.Stderr
   c.Run()
}

https://github.com/89z/sienna/tree/f7084c20/cmd/video-to-image

Upvotes: 1

Related Questions