Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deepch committed Apr 30, 2024
1 parent f6346a0 commit b6b1f4a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions format/nvr/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Muxer struct {
pstart, pend time.Duration
started bool
serverID, streamName, channelName, streamID, channelID, hostLong, hostShort string
handleFileChange func(string, string, int64, time.Time, time.Time, time.Duration)
handleFileChange func(bool, string, string, int64, time.Time, time.Time, time.Duration)
}

type Gof struct {
Expand Down Expand Up @@ -75,7 +75,7 @@ func init() {

}

func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpoint []string, patch, format string, limit int, c func(string, string, int64, time.Time, time.Time, time.Duration)) (m *Muxer, err error) {
func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpoint []string, patch, format string, limit int, c func(bool, string, string, int64, time.Time, time.Time, time.Duration)) (m *Muxer, err error) {
hostLong, _ := os.Hostname()
var hostShort string
if p, _, ok := strings.Cut(hostLong, "."); ok {
Expand Down Expand Up @@ -218,9 +218,20 @@ func (m *Muxer) OpenMP4() (err error) {
if err = os.MkdirAll(filepath.Dir(d), 0755); err != nil {
return
}
if m.d, err = os.Create(filepath.Join(filepath.Dir(d), fmt.Sprintf("tmp_%s_%d.mp4", uuid.New(), time.Now().Unix()))); err != nil {
name := filepath.Join(filepath.Dir(d), fmt.Sprintf("tmp_%s_%d.mp4", uuid.New(), time.Now().Unix()))
if m.d, err = os.Create(name); err != nil {
return
}
m.handleFileChange(
true,
m.Codecs(),
name,
0,
m.start,
m.end,
m.dur,
)

m.muxer = mp4.NewMuxer(m.d)
m.muxer.NegativeTsMakeZero = true
if err = m.muxer.WriteHeader(m.gof.Streams); err != nil {
Expand Down Expand Up @@ -329,7 +340,7 @@ func (m *Muxer) filePatch() (string, error) {
func (m *Muxer) Codecs() string {
var codecs []string
for _, stream := range m.gof.Streams {
codecs = append(codecs, stream.Type().String())
codecs = append(codecs, strings.ToLower(stream.Type().String()))
}

return strings.Join(codecs, ",")
Expand All @@ -356,6 +367,7 @@ func (m *Muxer) WriteTrailer() (err error) {
size = fi.Size()
}
m.handleFileChange(
false,
m.Codecs(),
filepath.Join(filepath.Dir(m.d.Name()), filepath.Base(p)),
size,
Expand Down

0 comments on commit b6b1f4a

Please sign in to comment.