From 3fa01c32d29db6a855ecf1c8363400365ce398d2 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Fri, 11 Mar 2022 03:54:07 +0100 Subject: [PATCH] add concurrency flag --- README.md | 5 +++++ main.go | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 591322c..13deacd 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/main.go b/main.go index cd7f0df..0021923 100644 --- a/main.go +++ b/main.go @@ -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") @@ -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) } @@ -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()