mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Another tweak to fix sprite generation
This commit is contained in:
@@ -4,12 +4,8 @@ import (
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var progressRegex = regexp.MustCompile(`time=(\d+):(\d+):(\d+.\d+)`)
|
||||
|
||||
type Encoder struct {
|
||||
Path string
|
||||
}
|
||||
@@ -42,15 +38,8 @@ func (e *Encoder) run(probeResult VideoFile, args []string) (string, error) {
|
||||
n, err := stderr.Read(buf)
|
||||
if n > 0 {
|
||||
data := string(buf[0:n])
|
||||
regexResult := progressRegex.FindStringSubmatch(data)
|
||||
if len(regexResult) == 4 && probeResult.Duration > 0 {
|
||||
h, _ := strconv.ParseFloat(regexResult[1], 64)
|
||||
m, _ := strconv.ParseFloat(regexResult[2], 64)
|
||||
s, _ := strconv.ParseFloat(regexResult[3], 64)
|
||||
hours := h * 3600
|
||||
mins := m * 60
|
||||
secs := s
|
||||
time := hours + mins + secs
|
||||
time := GetTimeFromRegex(data)
|
||||
if time > 0 && probeResult.Duration > 0 {
|
||||
progress := time / probeResult.Duration
|
||||
logger.Infof("Progress %.2f", progress)
|
||||
}
|
||||
|
||||
34
pkg/ffmpeg/regex.go
Normal file
34
pkg/ffmpeg/regex.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package ffmpeg
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var TimeRegex = regexp.MustCompile(`time=\s*(\d+):(\d+):(\d+.\d+)`)
|
||||
var FrameRegex = regexp.MustCompile(`frame=\s*([0-9]+)`)
|
||||
|
||||
func GetTimeFromRegex(str string) float64 {
|
||||
regexResult := TimeRegex.FindStringSubmatch(str)
|
||||
|
||||
// Bail early if we don't have the results we expect
|
||||
if len(regexResult) != 4 { return 0 }
|
||||
|
||||
h, _ := strconv.ParseFloat(regexResult[1], 64)
|
||||
m, _ := strconv.ParseFloat(regexResult[2], 64)
|
||||
s, _ := strconv.ParseFloat(regexResult[3], 64)
|
||||
hours := h * 3600
|
||||
minutes := m * 60
|
||||
seconds := s
|
||||
return hours + minutes + seconds
|
||||
}
|
||||
|
||||
func GetFrameFromRegex(str string) int {
|
||||
regexResult := FrameRegex.FindStringSubmatch(str)
|
||||
|
||||
// Bail early if we don't have the results we expect
|
||||
if len(regexResult) < 2 { return 0 }
|
||||
|
||||
result, _ := strconv.Atoi(regexResult[1])
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user