mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Added transcode task
This commit is contained in:
@@ -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) {
|
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) {
|
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 {
|
if transcodes {
|
||||||
go func() {
|
task := GenerateTranscodeTask{Scene: scene}
|
||||||
wg.Done() // TODO
|
go task.Start(&wg)
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
47
manager/task_transcode.go
Normal file
47
manager/task_transcode.go
Normal file
@@ -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
|
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) {
|
func IsStreamable(scene *models.Scene) (bool, error) {
|
||||||
fileType, err := utils.FileType(videoPath)
|
if scene == nil {
|
||||||
|
return false, fmt.Errorf("nil scene")
|
||||||
|
}
|
||||||
|
fileType, err := utils.FileType(scene.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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
|
return true, nil
|
||||||
} else {
|
default:
|
||||||
transcodePath := instance.Paths.Scene.GetTranscodePath(checksum)
|
return HasTranscode(scene)
|
||||||
return utils.FileExists(transcodePath)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user