Compare commits
No commits in common. "bb6177811b5aceb1a372733b8fe89c207476dce5" and "c6ffd29fe9bcb140602748227990cc2539dc6569" have entirely different histories.
bb6177811b
...
c6ffd29fe9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
*.gif
|
*.gif
|
||||||
*.jpeg
|
*.jpeg
|
||||||
*.png
|
*.png
|
||||||
*.mp4
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@ -24,7 +24,7 @@ Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations>
|
|||||||
### Example
|
### Example
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./glitch_img img.jpeg 100 30 2
|
./glitch*img img.jpeg 100 30 2
|
||||||
```
|
```
|
||||||
|
|
||||||
Outputs 100 images into a destination folder _output_ with 30 random bytes of data, running through the file twice
|
Outputs 100 images into a destination folder _output_ with 30 random bytes of data, running through the file twice
|
||||||
|
43
glitch.go
43
glitch.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -55,47 +54,7 @@ func glitchImage(inputFile string, outputFile string, shitSize int64, iterations
|
|||||||
_, err = destination.Write(shit)
|
_, err = destination.Write(shit)
|
||||||
check(err, "failed to write shit data: %w")
|
check(err, "failed to write shit data: %w")
|
||||||
|
|
||||||
|
// fmt.Printf("Successfully wrote %d bytes of shit at offset %d in file %s\n", shitSize, offset, outputFilePath)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyImage(inputFile string, outputFile string) error {
|
|
||||||
// Ensure the output directory exists
|
|
||||||
makeOutputDir()
|
|
||||||
|
|
||||||
// Prepend the "output" directory to the output file
|
|
||||||
outputFilePath := filepath.Join("output", outputFile)
|
|
||||||
|
|
||||||
// Open the source file for reading
|
|
||||||
source, err := os.Open(inputFile)
|
|
||||||
check(err, "failed to open source file: %w")
|
|
||||||
defer source.Close()
|
|
||||||
|
|
||||||
// Create a new file for writing the copy
|
|
||||||
destination, err := os.Create(outputFilePath)
|
|
||||||
check(err, "failed to create output file: %w")
|
|
||||||
defer destination.Close()
|
|
||||||
|
|
||||||
// Copy the contents of the source file to the destination
|
|
||||||
_, err = destination.ReadFrom(source)
|
|
||||||
check(err, "failed to copy file contents: %w")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateGlitchedSequence(inputFile string, totalImages int, shitSize int64, iterations int64) {
|
|
||||||
for i := 1; i <= totalImages; i++ {
|
|
||||||
outputFileName := fmt.Sprintf("img_glitched_%d.jpeg", i) // Generate unique filenames
|
|
||||||
|
|
||||||
// Randomly decide whether to glitch or copy the image
|
|
||||||
if rand.Int32N(2) == 0 {
|
|
||||||
// Glitched image
|
|
||||||
err := glitchImage(inputFile, outputFileName, shitSize, iterations)
|
|
||||||
check(err, "failed to glitch image: %w")
|
|
||||||
} else {
|
|
||||||
// Normal image
|
|
||||||
err := copyImage(inputFile, outputFileName)
|
|
||||||
check(err, "failed to copy normal image: %w")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
BIN
glitch_img
BIN
glitch_img
Binary file not shown.
51
main.go
51
main.go
@ -2,16 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
if len(os.Args) < 5 {
|
if len(os.Args) < 5 {
|
||||||
fmt.Println("Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations>")
|
fmt.Println("Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations>")
|
||||||
return
|
return
|
||||||
@ -32,7 +29,6 @@ func main() {
|
|||||||
|
|
||||||
iterations, err := strconv.ParseInt(os.Args[4], 10, 8)
|
iterations, err := strconv.ParseInt(os.Args[4], 10, 8)
|
||||||
|
|
||||||
/*
|
|
||||||
for i := 1; i <= numCopies; i++ {
|
for i := 1; i <= numCopies; i++ {
|
||||||
outputFile := fmt.Sprintf("%s_glitched_%d%s",
|
outputFile := fmt.Sprintf("%s_glitched_%d%s",
|
||||||
stripExtension(sourceFile),
|
stripExtension(sourceFile),
|
||||||
@ -45,48 +41,11 @@ func main() {
|
|||||||
fmt.Printf("Error glitching file %d: %v\n", i, err)
|
fmt.Printf("Error glitching file %d: %v\n", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
generateGlitchedSequence(sourceFile, numCopies, shitSize, iterations)
|
|
||||||
|
|
||||||
inputPattern := "./output/img_glitched_%d.jpeg"
|
fmt.Println("GENREATING GIF YEAHH ")
|
||||||
outputVideo := "output.mp4"
|
// now run ffmpeg to make a gif!
|
||||||
|
cmd := exec.Command("ffmpeg", "-y", "-framerate 60", "-i", "./output/img_glitched_%d.jpeg output.gif")
|
||||||
cmd := exec.Command(
|
err = cmd.Run()
|
||||||
"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!")
|
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!")
|
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
8
util.go
8
util.go
@ -11,14 +11,6 @@ func check(e error, s string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dots(count int) string {
|
|
||||||
dotStr := ""
|
|
||||||
for i := 0; i < count; i++ {
|
|
||||||
dotStr += "."
|
|
||||||
}
|
|
||||||
return dotStr
|
|
||||||
}
|
|
||||||
|
|
||||||
func stripExtension(filename string) string {
|
func stripExtension(filename string) string {
|
||||||
ext := filepath.Ext(filename)
|
ext := filepath.Ext(filename)
|
||||||
return filename[:len(filename)-len(ext)]
|
return filename[:len(filename)-len(ext)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user