You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
glitch_img/main.go

92 lines
1.9 KiB

package main
import (
"fmt"
"math/rand"
"os"
"os/exec"
"strconv"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
if len(os.Args) < 5 {
fmt.Println("Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations>")
return
}
sourceFile := os.Args[1]
numCopies, err := strconv.Atoi(os.Args[2])
if err != nil || numCopies <= 0 {
fmt.Println("Invalid number of copies. Must be a positive integer.")
return
}
shitSize, err := strconv.ParseInt(os.Args[3], 10, 64) // Parse shitSize as int64
if err != nil || shitSize <= 0 {
fmt.Println("Invalid shit size. Must be a positive integer.")
return
}
iterations, err := strconv.ParseInt(os.Args[4], 10, 8)
/*
for i := 1; i <= numCopies; i++ {
outputFile := fmt.Sprintf("%s_glitched_%d%s",
stripExtension(sourceFile),
i,
filepath.Ext(sourceFile),
)
err := glitchImage(sourceFile, outputFile, shitSize, iterations)
if err != nil {
fmt.Printf("Error glitching file %d: %v\n", i, err)
}
}
*/
generateGlitchedSequence(sourceFile, numCopies, shitSize, iterations)
inputPattern := "./output/img_glitched_%d.jpeg"
outputVideo := "output.mp4"
cmd := exec.Command(
"ffmpeg",
"-y",
"-framerate", "30",
"-i", inputPattern,
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2,setpts=PTS*2.0", // Scale and slow down playback
"-vcodec", "libx264", // Use H.264 codec
"-pix_fmt", "yuv420p",
"-crf", "23", // Compression level: lower is higher quality (range: 18-28)
"-preset", "fast",
outputVideo,
)
done := make(chan bool)
go func() {
err := cmd.Run()
check(err, "cannot run ffmpeg command!")
done <- true
}()
go func() {
msg := "Generating MP4"
c := 0
for {
select {
case <-done:
return
default:
fmt.Printf("\r%s%s", msg, dots(c))
c = (c + 1)
time.Sleep(500 * time.Millisecond)
}
}
}()
<-done
fmt.Println("\nGIF successfully created in ./output.mp4!")
//
}