Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
ffmpegtogif
Browse files Browse the repository at this point in the history
  • Loading branch information
bit101 committed Oct 16, 2021
1 parent 388cdfa commit 4c59812
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ import (
"runtime"
)

// ConvertToGIF converts a folder of pngs into an animated gif. Requires imagemagick convert.
func MakeGIF(tool, folder, outFileName string, fps float64) {
if tool == "convert" {
ConvertToGIF(folder, outFileName, fps)
} else if tool == "ffmpeg" {
FfmpegToGIF(folder, outFileName, fps)
}

}

// ConvertToGIF converts a folder of pngs into an animated gif using imagemagick convert.
func ConvertToGIF(folder, outFileName string, fps float64) {
delay := fmt.Sprintf("%f", 1000.0/fps/10.0)
path := folder + "/*.png"
Expand All @@ -20,6 +29,24 @@ func ConvertToGIF(folder, outFileName string, fps float64) {
}
}

// FfmpegToGIF converts a folder of pngs into an animated gif using ffmpeg.
func FfmpegToGIF(folder, outFileName string, fps float64) {
path := folder + "/frame_%04d.png"
fpsArg := fmt.Sprintf("%d", int(fps))

paletteCmd := exec.Command("ffmpeg", "-y", "-i", path, "-vf", "palettegen", "palette.png")
err := paletteCmd.Run()
if err != nil {
log.Fatal(err)
}

outCmd := exec.Command("ffmpeg", "-y", "-framerate", fpsArg, "-i", path, "-i", "palette.png", "-filter_complex", "paletteuse", outFileName)
err = outCmd.Run()
if err != nil {
log.Fatal(err)
}
}

// ConvertToYoutube converts a folder of pngs into a Youtube compatible mp4 video file. Requires ffmpeg.
func ConvertToYoutube(folder, outFileName string, fps int) {
path := folder + "/frame_%04d.png"
Expand Down

0 comments on commit 4c59812

Please sign in to comment.