mirror of https://github.com/stashapp/stash.git
Added transcode task
This commit is contained in:
parent
505ea8ea9a
commit
4f80decce4
|
@ -87,7 +87,7 @@ func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (models.Sc
|
|||
}
|
||||
|
||||
func (r *sceneResolver) IsStreamable(ctx context.Context, obj *models.Scene) (bool, error) {
|
||||
return manager.IsStreamable(obj.Path, obj.Checksum)
|
||||
return manager.IsStreamable(obj)
|
||||
}
|
||||
|
||||
func (r *sceneResolver) SceneMarkers(ctx context.Context, obj *models.Scene) ([]models.SceneMarker, error) {
|
||||
|
|
|
@ -98,9 +98,8 @@ func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcod
|
|||
}
|
||||
|
||||
if transcodes {
|
||||
go func() {
|
||||
wg.Done() // TODO
|
||||
}()
|
||||
task := GenerateTranscodeTask{Scene: scene}
|
||||
go task.Start(&wg)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package manager
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/ffmpeg"
|
||||
"github.com/stashapp/stash/logger"
|
||||
"github.com/stashapp/stash/models"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type GenerateTranscodeTask struct {
|
||||
Scene models.Scene
|
||||
}
|
||||
|
||||
func (t *GenerateTranscodeTask) Start(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
videoCodec := t.Scene.VideoCodec.String
|
||||
if ffmpeg.IsValidCodec(videoCodec) {
|
||||
return
|
||||
}
|
||||
|
||||
hasTranscode, _ := HasTranscode(&t.Scene)
|
||||
if hasTranscode {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof("[transcode] <%s> scene has codec %s", t.Scene.Checksum, t.Scene.VideoCodec.String)
|
||||
|
||||
videoFile, err := ffmpeg.NewVideoFile(instance.StaticPaths.FFProbe, t.Scene.Path)
|
||||
if err != nil {
|
||||
logger.Errorf("[transcode] error reading video file: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
outputPath := instance.Paths.Generated.GetTmpPath(t.Scene.Checksum+".mp4")
|
||||
options := ffmpeg.TranscodeOptions{
|
||||
OutputPath: outputPath,
|
||||
}
|
||||
encoder := ffmpeg.NewEncoder(instance.StaticPaths.FFMPEG)
|
||||
encoder.Transcode(*videoFile, options)
|
||||
if err := os.Rename(outputPath, instance.Paths.Scene.GetTranscodePath(t.Scene.Checksum)); err != nil {
|
||||
logger.Errorf("[transcode] error generating transcode: %s", err.Error())
|
||||
return
|
||||
}
|
||||
logger.Debug("[transcode] <%s> created transcode: ", t.Scene.Checksum)
|
||||
return
|
||||
}
|
|
@ -1,17 +1,32 @@
|
|||
package manager
|
||||
|
||||
import "github.com/stashapp/stash/utils"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stashapp/stash/models"
|
||||
"github.com/stashapp/stash/utils"
|
||||
)
|
||||
|
||||
func IsStreamable(videoPath string, checksum string) (bool, error) {
|
||||
fileType, err := utils.FileType(videoPath)
|
||||
func IsStreamable(scene *models.Scene) (bool, error) {
|
||||
if scene == nil {
|
||||
return false, fmt.Errorf("nil scene")
|
||||
}
|
||||
fileType, err := utils.FileType(scene.Path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if fileType.MIME.Value == "video/quicktime" || fileType.MIME.Value == "video/mp4" || fileType.MIME.Value == "video/webm" || fileType.MIME.Value == "video/x-m4v" {
|
||||
switch fileType.MIME.Value {
|
||||
case "video/quicktime", "video/mp4", "video/webm", "video/x-m4v":
|
||||
return true, nil
|
||||
} else {
|
||||
transcodePath := instance.Paths.Scene.GetTranscodePath(checksum)
|
||||
return utils.FileExists(transcodePath)
|
||||
default:
|
||||
return HasTranscode(scene)
|
||||
}
|
||||
}
|
||||
|
||||
func HasTranscode(scene *models.Scene) (bool, error) {
|
||||
if scene == nil {
|
||||
return false, fmt.Errorf("nil scene")
|
||||
}
|
||||
transcodePath := instance.Paths.Scene.GetTranscodePath(scene.Checksum)
|
||||
return utils.FileExists(transcodePath)
|
||||
}
|
Loading…
Reference in New Issue