This commit is contained in:
parent
6fbd6290ce
commit
230d505377
|
@ -10,6 +10,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
|
@ -106,10 +107,16 @@ func (s *Decoder) IsVFR() bool {
|
||||||
// FramePTS Returns -1 if not found
|
// FramePTS Returns -1 if not found
|
||||||
func (s *Decoder) FramePTS(n int) int64 {
|
func (s *Decoder) FramePTS(n int) int64 {
|
||||||
if s.IsVFR() {
|
if s.IsVFR() {
|
||||||
if n >= len(s.timecodes) {
|
pts := s.timecodes.PTS(n)
|
||||||
return -1
|
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)
|
return int64(n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,22 @@ import (
|
||||||
"github.com/nethruster/go-fraction"
|
"github.com/nethruster/go-fraction"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Timecodes Entries in milliseconds
|
// Timecodes Entries in milliseconds. First entry includes fallback duration, in time.Duration format
|
||||||
type Timecodes []int64
|
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"
|
const timecodesv1Header = "# timecode format v1"
|
||||||
|
|
||||||
func ParseTimecodesV1(reader io.Reader) (Timecodes, error) {
|
func ParseTimecodesV1(reader io.Reader) (Timecodes, error) {
|
||||||
|
@ -61,6 +72,9 @@ func ParseTimecodesV1(reader io.Reader) (Timecodes, error) {
|
||||||
|
|
||||||
var currentFrame int64
|
var currentFrame int64
|
||||||
|
|
||||||
|
//fallback
|
||||||
|
tc = append(tc, (int64(time.Second)*assumedFraction.Numerator())/assumedFraction.Denominator())
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.ReplaceAll(strings.TrimSpace(scanner.Text()), " ", "")
|
line := strings.ReplaceAll(strings.TrimSpace(scanner.Text()), " ", "")
|
||||||
if line == "" || line[0] == '#' {
|
if line == "" || line[0] == '#' {
|
||||||
|
|
Loading…
Reference in a new issue