Skip to content

Commit

Permalink
No need to wait on a useless channel if we just close the video queue…
Browse files Browse the repository at this point in the history
… once we are done with it
  • Loading branch information
HenrySlawniak committed Sep 13, 2018
1 parent f0313fc commit e8ef862
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions main.go
Expand Up @@ -42,10 +42,9 @@ var (
outputInPlace = flag.Bool("in-place", true, "Write images next to videos")
framesPerRow = flag.Int("frames-per-row", 3, "The number of frames per each row in the final contact sheet")
writeAttribution = flag.Bool("write-attribution", true, "Writed \"Generated by thumbnailer.net\" to contact sheet")
workers = flag.Int("workers", 4, "Number of contact sheet workers to run")
workers = flag.Int("workers", runtime.NumCPU()-1, "Number of contact sheet workers to run, dafaults to number of CPUs -1")

videoQueue = make(chan Video)
queueErrors = make(chan error)
videoQueue = make(chan Video)

buildTime string
commit string
Expand All @@ -58,7 +57,7 @@ func init() {
}

func main() {
log.Info("Starting Thumbnailer")
log.Infof("Starting Thumbnailer with %d workers", *workers)
if buildTime != "" {
log.Info("Built: " + buildTime)
}
Expand All @@ -69,11 +68,17 @@ func main() {

createDirectories()

if len(flag.Args()) < 1 {
log.Warn("Please provide a file path to generate a contact sheet from")
log.Info("Use thumbnailer -h for a full list of options")
os.Exit(1)
}

for w := 1; w <= *workers; w++ {
go sheetWorker(w, videoQueue, queueErrors)
go sheetWorker(w, videoQueue)
}

for _, a := range os.Args[1:] {
for _, a := range flag.Args() {
if FileExists(a) {
if !IsDir(a) {
ProcessFile(a)
Expand All @@ -83,15 +88,10 @@ func main() {
}
}

for {
err := <-queueErrors
if err != nil {
log.Error(err)
}
}
close(videoQueue)
}

func sheetWorker(id int, videos chan Video, errors chan error) {
func sheetWorker(id int, videos chan Video) {
for vid := range videos {
log.Infof("Worker %d processing %s", id, vid.Filename)
if *writeInfo {
Expand Down

0 comments on commit e8ef862

Please sign in to comment.