功能完善
UI改进
This commit is contained in:
+43
-12
@@ -19,28 +19,59 @@ type Progress struct {
|
||||
Percent float64 `json:"percent"`
|
||||
}
|
||||
|
||||
var progressRe = regexp.MustCompile(
|
||||
`frame=\s*(\d+)\s+fps=\s*([\d.]+)\s+q=\s*([\d.-]+)\s+(?:size=\s*(\S+)\s+)?time=\s*([\d:.]+)\s+bitrate=\s*(\S+)\s+speed=\s*(\S+)`,
|
||||
)
|
||||
// kvPairRe matches a single key=value token from an ffmpeg progress line.
|
||||
// Keys are alphanumeric (e.g. frame, dup, Lsize). Values are the contiguous
|
||||
// non-whitespace characters after the '=' — this handles N/A, kbits/s, times,
|
||||
// and numeric values equally.
|
||||
var kvPairRe = regexp.MustCompile(`(\w+)=\s*(\S+)`)
|
||||
|
||||
// parseProgressLine parses an ffmpeg stderr progress line into a Progress struct.
|
||||
// Instead of relying on a fixed field order, it extracts every key=value pair
|
||||
// and picks the ones we care about. This tolerates extra fields (dup, drop,
|
||||
// Lsize vs size, etc.) that appear between standard ffmpeg releases.
|
||||
func parseProgressLine(line string) (Progress, bool) {
|
||||
m := progressRe.FindStringSubmatch(line)
|
||||
if m == nil {
|
||||
pairs := kvPairRe.FindAllStringSubmatch(line, -1)
|
||||
if len(pairs) == 0 {
|
||||
return Progress{}, false
|
||||
}
|
||||
|
||||
frame, _ := strconv.ParseInt(m[1], 10, 64)
|
||||
fps, _ := strconv.ParseFloat(m[2], 64)
|
||||
q, _ := strconv.ParseFloat(m[3], 64)
|
||||
kv := make(map[string]string, len(pairs))
|
||||
for _, m := range pairs {
|
||||
kv[m[1]] = m[2]
|
||||
}
|
||||
|
||||
// Frame is required — without it we don't have a real progress line.
|
||||
frameStr, ok := kv["frame"]
|
||||
if !ok {
|
||||
return Progress{}, false
|
||||
}
|
||||
|
||||
frame, _ := strconv.ParseInt(frameStr, 10, 64)
|
||||
fps, _ := strconv.ParseFloat(kv["fps"], 64)
|
||||
q, _ := strconv.ParseFloat(kv["q"], 64)
|
||||
|
||||
// ffmpeg emits either "size" or "Lsize" depending on context.
|
||||
size := kv["size"]
|
||||
if size == "" {
|
||||
size = kv["Lsize"]
|
||||
}
|
||||
if size == "N/A" {
|
||||
size = ""
|
||||
}
|
||||
|
||||
bitrate := kv["bitrate"]
|
||||
if bitrate == "N/A" {
|
||||
bitrate = ""
|
||||
}
|
||||
|
||||
return Progress{
|
||||
Frame: frame,
|
||||
FPS: fps,
|
||||
Q: q,
|
||||
Size: m[4],
|
||||
Time: m[5],
|
||||
Bitrate: m[6],
|
||||
Speed: m[7],
|
||||
Size: size,
|
||||
Time: kv["time"],
|
||||
Bitrate: bitrate,
|
||||
Speed: kv["speed"],
|
||||
}, true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user