Another tweak to fix sprite generation

This commit is contained in:
Stash Dev
2019-03-29 08:16:39 -07:00
parent 71f8fc9dd5
commit 0ce9e073bd
2 changed files with 11 additions and 3 deletions

View File

@@ -47,12 +47,12 @@ func (g *GeneratorInfo) configure() error {
numberOfFrames, _ := strconv.Atoi(videoStream.NbFrames) 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) 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 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{ args := []string{
"-nostats", "-nostats",
"-i", g.VideoFile.Path, "-i", g.VideoFile.Path,
@@ -82,7 +82,7 @@ func (g *GeneratorInfo) configure() error {
} }
// Something seriously wrong with this file // Something seriously wrong with this file
if numberOfFrames == 0 || framerate == 0 { if numberOfFrames == 0 || !utils.IsValidFloat64(framerate) {
logger.Errorf( logger.Errorf(
"number of frames or framerate is 0. nb_frames <%s> framerate <%s> duration <%s>", "number of frames or framerate is 0. nb_frames <%s> framerate <%s> duration <%s>",
videoStream.NbFrames, videoStream.NbFrames,

8
pkg/utils/float.go Normal file
View File

@@ -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
}