2019-02-10 05:30:54 +00:00
|
|
|
package ffmpeg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2019-11-04 21:34:57 +00:00
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/utils"
|
2019-02-10 05:30:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ScenePreviewChunkOptions struct {
|
2020-07-23 02:51:35 +00:00
|
|
|
StartTime float64
|
|
|
|
Duration float64
|
2019-02-10 05:30:54 +00:00
|
|
|
Width int
|
|
|
|
OutputPath string
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:33:49 +00:00
|
|
|
func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePreviewChunkOptions, preset string) {
|
2019-02-10 05:30:54 +00:00
|
|
|
args := []string{
|
2019-11-04 21:34:57 +00:00
|
|
|
"-v", "error",
|
2020-05-26 23:33:49 +00:00
|
|
|
"-xerror",
|
2020-07-23 02:51:35 +00:00
|
|
|
"-ss", strconv.FormatFloat(options.StartTime, 'f', 2, 64),
|
2020-05-13 07:23:23 +00:00
|
|
|
"-i", probeResult.Path,
|
2020-07-23 02:51:35 +00:00
|
|
|
"-t", strconv.FormatFloat(options.Duration, 'f', 2, 64),
|
2019-06-21 21:03:00 +00:00
|
|
|
"-max_muxing_queue_size", "1024", // https://trac.ffmpeg.org/ticket/6375
|
2019-02-10 05:30:54 +00:00
|
|
|
"-y",
|
|
|
|
"-c:v", "libx264",
|
2019-03-29 15:23:21 +00:00
|
|
|
"-pix_fmt", "yuv420p",
|
2019-02-10 05:30:54 +00:00
|
|
|
"-profile:v", "high",
|
|
|
|
"-level", "4.2",
|
2020-05-26 23:33:49 +00:00
|
|
|
"-preset", preset,
|
2019-02-10 05:30:54 +00:00
|
|
|
"-crf", "21",
|
|
|
|
"-threads", "4",
|
|
|
|
"-vf", fmt.Sprintf("scale=%v:-2", options.Width),
|
|
|
|
"-c:a", "aac",
|
|
|
|
"-b:a", "128k",
|
2019-03-27 15:34:04 +00:00
|
|
|
"-strict", "-2",
|
2019-02-10 05:30:54 +00:00
|
|
|
options.OutputPath,
|
|
|
|
}
|
|
|
|
_, _ = e.run(probeResult, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Encoder) ScenePreviewVideoChunkCombine(probeResult VideoFile, concatFilePath string, outputPath string) {
|
|
|
|
args := []string{
|
2019-11-04 21:34:57 +00:00
|
|
|
"-v", "error",
|
2019-02-10 05:30:54 +00:00
|
|
|
"-f", "concat",
|
2019-02-10 18:13:23 +00:00
|
|
|
"-i", utils.FixWindowsPath(concatFilePath),
|
2019-02-10 05:30:54 +00:00
|
|
|
"-y",
|
|
|
|
"-c", "copy",
|
|
|
|
outputPath,
|
|
|
|
}
|
|
|
|
_, _ = e.run(probeResult, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Encoder) ScenePreviewVideoToImage(probeResult VideoFile, width int, videoPreviewPath string, outputPath string) error {
|
|
|
|
args := []string{
|
2019-11-04 21:34:57 +00:00
|
|
|
"-v", "error",
|
2019-02-10 05:30:54 +00:00
|
|
|
"-i", videoPreviewPath,
|
|
|
|
"-y",
|
|
|
|
"-c:v", "libwebp",
|
|
|
|
"-lossless", "1",
|
|
|
|
"-q:v", "70",
|
|
|
|
"-compression_level", "6",
|
|
|
|
"-preset", "default",
|
|
|
|
"-loop", "0",
|
|
|
|
"-threads", "4",
|
|
|
|
"-vf", fmt.Sprintf("scale=%v:-2,fps=12", width),
|
|
|
|
"-an",
|
|
|
|
outputPath,
|
|
|
|
}
|
|
|
|
_, err := e.run(probeResult, args)
|
|
|
|
return err
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|