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.
This commit is contained in:
parent
17c570bf1d
commit
da7d9c8035
@ -11,6 +11,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
@ -126,7 +127,13 @@ func (s Convertor) GetTotalDuration(file *File) (duration float64, err error) {
|
|||||||
if len(frames) == 0 {
|
if len(frames) == 0 {
|
||||||
return s.getAlternativeTotalDuration(file)
|
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) {
|
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 {
|
func (s Convertor) GetRunningProcesses() map[int]*exec.Cmd {
|
||||||
return s.runningProcesses.items
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user