Skip to content

Commit

Permalink
add concurrency flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gadelkareem committed Mar 11, 2022
1 parent f65e58d commit 3fa01c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The command line application generates thumbnails for videos and run the builtin
- Check the [releases](https://github.com/gadelkareem/video-gallery-generator/releases) page for executable versions.
- By default, the application will only run the server on http://0.0.0.0:8282/. To generate thumbnails for all videos in a directory, use the `-g` option.

# Prerequisites
- FFmpeg installed on your system. Download [here](https://ffmpeg.org/download.html).

# Usage
```bash
# Run the server using current directory as the root directory
Expand All @@ -13,6 +16,8 @@ The command line application generates thumbnails for videos and run the builtin
./vgg-darwin-arm64 -g
# Run the server using a specific path as the root directory and different port
./vgg-darwin-arm64 -d /path/to/videos -p 8080
# Control the maximum number of generators to run concurrently
./vgg-darwin-arm64 -g -c 10
```

# Build for all platforms
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
//go:embed gallery.html
var html string

var maxConcurrency = flag.Int64("c", 2, "Maximum number of generators to run concurrently")

func main() {
port := flag.String("p", "8282", "port to serve on")
d := flag.String("d", ".", "static file folder")
Expand Down Expand Up @@ -65,7 +67,7 @@ func generateThumbs(d string, fs []string) {
log.Fatal(err)
}

wg := h.NewWgExec(3)
wg := h.NewWgExec(*maxConcurrency)
for _, f := range fs {
wg.Run(createThumb, thumbsDir, f)
}
Expand All @@ -90,7 +92,7 @@ func createThumb(ps ...interface{}) {
s := strings.TrimSuffix(string(b), "\n")
//log.Printf("Video has %s seconds\n", s)
numSec, _ := strconv.ParseFloat(s, 64)
log.Printf("%f seconds in '%s'\n", numSec, f)
//log.Printf("%f seconds in '%s'\n", numSec, f)
cmd = fmt.Sprintf("ffmpeg -y -i '%s' -vf scale=220:-1 -vframes 1 -ss %f '%s'", f, numSec/2, thumb)
//log.Printf("%s\n", cmd)
err = exec.Command("/bin/bash", "-c", cmd).Run()
Expand Down

0 comments on commit 3fa01c3

Please sign in to comment.