simplify examples (#389)

This commit is contained in:
Alessandro Ros
2023-08-30 11:23:37 +02:00
committed by GitHub
parent ddec738950
commit fc0c242789
2 changed files with 22 additions and 40 deletions

View File

@@ -23,7 +23,6 @@ type mpegtsMuxer struct {
w *mpegts.Writer w *mpegts.Writer
track *mpegts.Track track *mpegts.Track
dtsExtractor *h264.DTSExtractor dtsExtractor *h264.DTSExtractor
firstIDRReceived bool
} }
// newMPEGTSMuxer allocates a mpegtsMuxer. // newMPEGTSMuxer allocates a mpegtsMuxer.
@@ -103,27 +102,19 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
var dts time.Duration var dts time.Duration
if !e.firstIDRReceived { if e.dtsExtractor == nil {
// skip samples silently until we find one with a IDR // skip samples silently until we find one with a IDR
if !idrPresent { if !idrPresent {
return nil return nil
} }
e.firstIDRReceived = true
e.dtsExtractor = h264.NewDTSExtractor() e.dtsExtractor = h264.NewDTSExtractor()
}
var err error var err error
dts, err = e.dtsExtractor.Extract(au, pts) dts, err = e.dtsExtractor.Extract(au, pts)
if err != nil { if err != nil {
return err return err
} }
} else {
var err error
dts, err = e.dtsExtractor.Extract(au, pts)
if err != nil {
return err
}
}
// encode into MPEG-TS // encode into MPEG-TS
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au) return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)

View File

@@ -23,7 +23,6 @@ type mpegtsMuxer struct {
w *mpegts.Writer w *mpegts.Writer
track *mpegts.Track track *mpegts.Track
dtsExtractor *h264.DTSExtractor dtsExtractor *h264.DTSExtractor
firstIDRReceived bool
} }
// newMPEGTSMuxer allocates a mpegtsMuxer. // newMPEGTSMuxer allocates a mpegtsMuxer.
@@ -103,27 +102,19 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
var dts time.Duration var dts time.Duration
if !e.firstIDRReceived { if e.dtsExtractor == nil {
// skip samples silently until we find one with a IDR // skip samples silently until we find one with a IDR
if !idrPresent { if !idrPresent {
return nil return nil
} }
e.firstIDRReceived = true
e.dtsExtractor = h264.NewDTSExtractor() e.dtsExtractor = h264.NewDTSExtractor()
}
var err error var err error
dts, err = e.dtsExtractor.Extract(au, pts) dts, err = e.dtsExtractor.Extract(au, pts)
if err != nil { if err != nil {
return err return err
} }
} else {
var err error
dts, err = e.dtsExtractor.Extract(au, pts)
if err != nil {
return err
}
}
// encode into MPEG-TS // encode into MPEG-TS
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au) return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)