From e8bc1bcac81aafb25ea09235dccc965d57826b64 Mon Sep 17 00:00:00 2001 From: Henry Slawniak Date: Wed, 5 Sep 2018 20:39:38 -0500 Subject: [PATCH] Add output directoy option --- contactsheet.go | 2 +- main.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/contactsheet.go b/contactsheet.go index c8b75c6..6711ed0 100644 --- a/contactsheet.go +++ b/contactsheet.go @@ -168,7 +168,7 @@ func generateContactSheet(vid *Video, numFrames int) { } - outFile, err := os.Create(vid.Filename + ".png") + outFile, err := os.Create(filepath.Join(*outputDir, vid.Filename+".png")) if err != nil { log.Error(err) return diff --git a/main.go b/main.go index 1bf3555..4e367b4 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ var ( numFrames = flag.Int("frames", 12, "The number of frames to generate") writeInfo = flag.Bool("write-info", true, "Write info JSON to file") frameWidth = flag.Int("frame-width", 854, "The width to generate thumbnails at") + outputDir = flag.String("o", ".", "The directory to output to") buildTime string commit string @@ -85,6 +86,14 @@ func createDirectories() { log.Panic(err) } + if !FileExists(*outputDir) { + err = os.MkdirAll(*outputDir, 0755) + if err != nil { + log.Error("Cannot create output directory") + log.Panic(err) + } + } + err = ioutil.WriteFile(filepath.Join("bin", "readme.txt"), []byte(binHelp), 0644) if err != nil { log.Error("Error writing readme") @@ -154,7 +163,7 @@ func ProcessFile(path string) { if *writeInfo { j, _ := json.MarshalIndent(video, "", " ") - ioutil.WriteFile(video.Filename+".json", j, 0644) + ioutil.WriteFile(filepath.Join(*outputDir, video.Filename+".json"), j, 0644) } generateThumbnails(&video, *numFrames)