From da7d9c8035e8231d3b68c3f702a96ebc96ec8e81 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Sat, 10 May 2025 00:55:16 +0500 Subject: [PATCH] Fix .mts duration parsing by extracting leading digits This update addresses a parsing issue for .mts files by introducing a fallback to extract and parse only the leading digits when converting frame data to a float. A new helper function `getFirstDigits` is added to isolate and handle numeric values correctly. --- kernel/convertor.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/convertor.go b/kernel/convertor.go index 6754874..ac765b5 100644 --- a/kernel/convertor.go +++ b/kernel/convertor.go @@ -11,6 +11,7 @@ import ( "regexp" "strconv" "strings" + "unicode" ) type File struct { @@ -126,7 +127,13 @@ func (s Convertor) GetTotalDuration(file *File) (duration float64, err error) { if len(frames) == 0 { return s.getAlternativeTotalDuration(file) } - return strconv.ParseFloat(frames, 64) + + duration, err = strconv.ParseFloat(frames, 64) + if err != nil { + // fix .mts duration + return strconv.ParseFloat(getFirstDigits(frames), 64) + } + return duration, err } func (s Convertor) getAlternativeTotalDuration(file *File) (duration float64, err error) { @@ -241,3 +248,15 @@ func (s Convertor) GetSupportFormats() (encoder.ConvertorFormatsContract, error) func (s Convertor) GetRunningProcesses() map[int]*exec.Cmd { return s.runningProcesses.items } + +func getFirstDigits(s string) string { + result := "" + for _, r := range s { + if unicode.IsDigit(r) { + result += string(r) + } else { + break + } + } + return result +}