Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.1 KiB

package record
import (
"os"
"path/filepath"
"time"
"github.com/bluenviron/mediamtx/internal/logger"
)
type formatMPEGTSSegment struct {
f *formatMPEGTS
startDTS time.Duration
startNTP time.Time
lastFlush time.Duration
path string
fi *os.File
}
func (s *formatMPEGTSSegment) initialize() {
s.lastFlush = s.startDTS
s.f.dw.setTarget(s)
}
func (s *formatMPEGTSSegment) close() error {
err := s.f.bw.Flush()
if s.fi != nil {
s.f.a.agent.Log(logger.Debug, "closing segment %s", s.path)
err2 := s.fi.Close()
if err == nil {
err = err2
}
if err2 == nil {
s.f.a.agent.OnSegmentComplete(s.path)
}
}
return err
}
func (s *formatMPEGTSSegment) Write(p []byte) (int, error) {
if s.fi == nil {
s.path = Path{Start: s.startNTP}.Encode(s.f.a.pathFormat)
s.f.a.agent.Log(logger.Debug, "creating segment %s", s.path)
err := os.MkdirAll(filepath.Dir(s.path), 0o755)
if err != nil {
return 0, err
}
fi, err := os.Create(s.path)
if err != nil {
return 0, err
}
s.f.a.agent.OnSegmentCreate(s.path)
s.fi = fi
}
return s.fi.Write(p)
}