Skip to content

Commit

Permalink
fix: added the possibility to change extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Paxx committed May 3, 2023
1 parent 27ed73e commit 142a78f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sprite/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *service) GenerateFrames() []string {
func (s *service) extract(seek int) string {
seekString := strconv.Itoa(seek)
now := time.Now()
output := random_helper.Generate(5, random_helper.AZAndCaps) + fmt.Sprintf("%d", now.UnixMilli()) + ".jpg"
output := random_helper.Generate(5, random_helper.AZAndCaps) + fmt.Sprintf("%d", now.UnixMilli()) + s.flags.Extension
outputPath := path.Join(path.Dir(s.flags.Vtt), output)
cmd := exec.Command(
"ffmpeg",
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *service) Montage(frames []string) {
cmd.Args = append(cmd.Args, image)
}

spritePath := path.Join(path.Dir(frames[0]), s.flags.Prefix+".jpg")
spritePath := path.Join(path.Dir(frames[0]), s.flags.Prefix+s.flags.Extension)

cmd.Args = append(cmd.Args, spritePath)

Expand All @@ -110,7 +110,7 @@ func (s *service) GenerateVtt(frames []string) {
max := float64(len(frames)) / float64(grid)
nSprites := mathint.Max(1, int(math.Ceil(max)))
for n := 0; n < nSprites; n++ {
output := fmt.Sprintf("%s-%d%s", s.flags.Prefix, n, ".jpg")
output := fmt.Sprintf("%s-%d%s", s.flags.Prefix, n, s.flags.Extension)
for y := 0; y < s.flags.Columns; y++ {
for x := 0; x < s.flags.Rows; x++ {
t2 := time.Duration(s.flags.Frequency) * time.Second
Expand Down
6 changes: 6 additions & 0 deletions types/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Flags struct {
Frequency int
Width int
Height int
Extension string
Help bool
}

Expand All @@ -26,11 +27,13 @@ func (f *Flags) Set() error {
columns := flag.Int("col", 10, "how many columns")
width := flag.Int("w", 160, "frame width")
height := flag.Int("h", 90, "frame height")
extension := flag.String("ext", ".jpg", "output sprite extension")
help := flag.Bool("help", false, "shows help")

flag.Parse()

f.Input = *input
f.Extension = *extension
f.Prefix = *prefix
f.Vtt = *vtt
f.Frequency = *frequency
Expand All @@ -49,6 +52,9 @@ func (f *Flags) Set() error {
if f.Frequency <= 0 {
return fmt.Errorf("need to specify valid target")
}
if f.Extension != ".jpg" && f.Extension != ".jpeg" && f.Extension != ".png" {
return fmt.Errorf("not a valid extension")
}

return nil
}

0 comments on commit 142a78f

Please sign in to comment.