This commit is contained in:
parent
6fbd6290ce
commit
230d505377
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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] == '#' {
|
||||
|
|
Loading…
Reference in a new issue