mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Reorg
This commit is contained in:
47
pkg/manager/task_transcode.go
Normal file
47
pkg/manager/task_transcode.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/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.Debugf("[transcode] <%s> created transcode: %s", t.Scene.Checksum, outputPath)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user