2019-02-11 20:12:08 +00:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
2019-11-04 21:38:33 +00:00
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
|
2019-02-14 23:42:52 +00:00
|
|
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
2019-11-04 21:38:33 +00:00
|
|
|
"github.com/stashapp/stash/pkg/manager/config"
|
2019-02-14 23:42:52 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-02-11 20:12:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
videoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.Scene.Path)
|
2019-02-11 20:12:08 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Errorf("[transcode] error reading video file: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:53:32 +00:00
|
|
|
outputPath := instance.Paths.Generated.GetTmpPath(t.Scene.Checksum + ".mp4")
|
2019-11-04 21:38:33 +00:00
|
|
|
transcodeSize := config.GetMaxTranscodeSize()
|
2019-02-11 20:12:08 +00:00
|
|
|
options := ffmpeg.TranscodeOptions{
|
2019-11-04 21:38:33 +00:00
|
|
|
OutputPath: outputPath,
|
|
|
|
MaxTranscodeSize: transcodeSize,
|
2019-02-11 20:12:08 +00:00
|
|
|
}
|
2019-03-23 14:56:59 +00:00
|
|
|
encoder := ffmpeg.NewEncoder(instance.FFMPEGPath)
|
2019-02-11 20:12:08 +00:00
|
|
|
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
|
|
|
|
}
|
2019-02-14 22:53:32 +00:00
|
|
|
logger.Debugf("[transcode] <%s> created transcode: %s", t.Scene.Checksum, outputPath)
|
2019-02-11 20:12:08 +00:00
|
|
|
return
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|