From 0ce9e073bd13641b77389a9ebbc50b701b476715 Mon Sep 17 00:00:00 2001 From: Stash Dev Date: Fri, 29 Mar 2019 08:16:39 -0700 Subject: [PATCH] Another tweak to fix sprite generation --- pkg/manager/generator.go | 6 +++--- pkg/utils/float.go | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 pkg/utils/float.go diff --git a/pkg/manager/generator.go b/pkg/manager/generator.go index 4a7a1bf16..e27192fda 100644 --- a/pkg/manager/generator.go +++ b/pkg/manager/generator.go @@ -47,12 +47,12 @@ func (g *GeneratorInfo) configure() error { numberOfFrames, _ := strconv.Atoi(videoStream.NbFrames) - if numberOfFrames == 0 && framerate > 0 && g.VideoFile.Duration > 0 { // TODO: test + if numberOfFrames == 0 && utils.IsValidFloat64(framerate) && g.VideoFile.Duration > 0 { // TODO: test numberOfFrames = int(framerate * g.VideoFile.Duration) } // If we are missing the frame count or frame rate then seek through the file and extract the info with regex - if numberOfFrames == 0 || framerate == 0 { + if numberOfFrames == 0 || !utils.IsValidFloat64(framerate) { args := []string{ "-nostats", "-i", g.VideoFile.Path, @@ -82,7 +82,7 @@ func (g *GeneratorInfo) configure() error { } // Something seriously wrong with this file - if numberOfFrames == 0 || framerate == 0 { + if numberOfFrames == 0 || !utils.IsValidFloat64(framerate) { logger.Errorf( "number of frames or framerate is 0. nb_frames <%s> framerate <%s> duration <%s>", videoStream.NbFrames, diff --git a/pkg/utils/float.go b/pkg/utils/float.go new file mode 100644 index 000000000..b06d8f293 --- /dev/null +++ b/pkg/utils/float.go @@ -0,0 +1,8 @@ +package utils + +import "math" + +// IsValidFloat64 ensures the given value is a valid number (not NaN) which is not equal to 0 +func IsValidFloat64(value float64) bool { + return !math.IsNaN(value) && value != 0 +} \ No newline at end of file