Fixed VFR pts end
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2023-11-06 12:03:14 +01:00
parent 6fbd6290ce
commit 230d505377
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 25 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import (
"io"
"strconv"
"strings"
"time"
)
type Decoder struct {
@ -106,10 +107,16 @@ func (s *Decoder) IsVFR() bool {
// FramePTS Returns -1 if not found
func (s *Decoder) FramePTS(n int) int64 {
if s.IsVFR() {
if n >= len(s.timecodes) {
return -1
pts := s.timecodes.PTS(n)
if pts == -1 {
frameCount := len(s.timecodes) - 1
last := s.timecodes[frameCount]
if frameCount == 0 {
last = 0
}
pts = last + (s.timecodes.FallbackDuration() * time.Duration(n-frameCount+1)).Milliseconds()
}
return s.timecodes[n]
return pts
}
return int64(n)
}

View file

@ -6,11 +6,22 @@ import (
"github.com/nethruster/go-fraction"
"io"
"strings"
"time"
)
// Timecodes Entries in milliseconds
// Timecodes Entries in milliseconds. First entry includes fallback duration, in time.Duration format
type Timecodes []int64
func (tc Timecodes) FallbackDuration() time.Duration {
return time.Duration(tc[0])
}
func (tc Timecodes) PTS(n int) int64 {
if n >= 0 && (n+1) < len(tc) {
return tc[n+1]
}
return -1
}
const timecodesv1Header = "# timecode format v1"
func ParseTimecodesV1(reader io.Reader) (Timecodes, error) {
@ -61,6 +72,9 @@ func ParseTimecodesV1(reader io.Reader) (Timecodes, error) {
var currentFrame int64
//fallback
tc = append(tc, (int64(time.Second)*assumedFraction.Numerator())/assumedFraction.Denominator())
for scanner.Scan() {
line := strings.ReplaceAll(strings.TrimSpace(scanner.Text()), " ", "")
if line == "" || line[0] == '#' {