stash/pkg/manager/utils.go

51 lines
1.6 KiB
Go
Raw Normal View History

2019-02-09 12:30:49 +00:00
package manager
2019-02-11 20:12:08 +00:00
import (
"fmt"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/logger"
2019-02-14 23:42:52 +00:00
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
2019-02-11 20:12:08 +00:00
)
2019-02-09 12:30:49 +00:00
2019-02-11 20:12:08 +00:00
func IsStreamable(scene *models.Scene) (bool, error) {
if scene == nil {
return false, fmt.Errorf("nil scene")
}
var container ffmpeg.Container
if scene.Format.Valid {
container = ffmpeg.Container(scene.Format.String)
} else { // container isn't in the DB
// shouldn't happen, fallback to ffprobe reading from file
tmpVideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, scene.Path)
if err != nil {
return false, fmt.Errorf("error reading video file: %s", err.Error())
}
container = ffmpeg.MatchContainer(tmpVideoFile.Container, scene.Path)
}
2019-02-09 12:30:49 +00:00
videoCodec := scene.VideoCodec.String
audioCodec := ffmpeg.MissingUnsupported
if scene.AudioCodec.Valid {
audioCodec = ffmpeg.AudioCodec(scene.AudioCodec.String)
}
if ffmpeg.IsValidCodec(videoCodec) && ffmpeg.IsValidCombo(videoCodec, container) && ffmpeg.IsValidAudioForContainer(audioCodec, container) {
logger.Debugf("File is streamable %s, %s, %s\n", videoCodec, audioCodec, container)
2019-02-09 12:30:49 +00:00
return true, nil
} else {
hasTranscode, _ := HasTranscode(scene)
logger.Debugf("File is not streamable , transcode is needed %s, %s, %s\n", videoCodec, audioCodec, container)
return hasTranscode, nil
2019-02-11 20:12:08 +00:00
}
}
func HasTranscode(scene *models.Scene) (bool, error) {
if scene == nil {
return false, fmt.Errorf("nil scene")
2019-02-09 12:30:49 +00:00
}
2019-02-11 20:12:08 +00:00
transcodePath := instance.Paths.Scene.GetTranscodePath(scene.Checksum)
return utils.FileExists(transcodePath)
}