mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
rename mpegtsencoder into mpegtsmuxer
This commit is contained in:
@@ -46,7 +46,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup H264->MPEGTS encoder
|
// setup H264->MPEGTS encoder
|
||||||
enc, err := newMPEGTSEncoder(h264track.SafeSPS(), h264track.SafePPS())
|
enc, err := newMPEGTSMuxer(h264track.SafeSPS(), h264track.SafePPS())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/asticode/go-astits"
|
"github.com/asticode/go-astits"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mpegtsEncoder allows to save a H264 stream into a MPEG-TS file.
|
// mpegtsMuxer allows to save a H264 stream into a MPEG-TS file.
|
||||||
type mpegtsEncoder struct {
|
type mpegtsMuxer struct {
|
||||||
sps []byte
|
sps []byte
|
||||||
pps []byte
|
pps []byte
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ type mpegtsEncoder struct {
|
|||||||
startDTS time.Duration
|
startDTS time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMPEGTSEncoder allocates a mpegtsEncoder.
|
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
||||||
func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
func newMPEGTSMuxer(sps []byte, pps []byte) (*mpegtsMuxer, error) {
|
||||||
f, err := os.Create("mystream.ts")
|
f, err := os.Create("mystream.ts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -39,7 +39,7 @@ func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
|||||||
})
|
})
|
||||||
mux.SetPCRPID(256)
|
mux.SetPCRPID(256)
|
||||||
|
|
||||||
return &mpegtsEncoder{
|
return &mpegtsMuxer{
|
||||||
sps: sps,
|
sps: sps,
|
||||||
pps: pps,
|
pps: pps,
|
||||||
f: f,
|
f: f,
|
||||||
@@ -48,14 +48,14 @@ func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// close closes all the mpegtsEncoder resources.
|
// close closes all the mpegtsMuxer resources.
|
||||||
func (e *mpegtsEncoder) close() {
|
func (e *mpegtsMuxer) close() {
|
||||||
e.b.Flush()
|
e.b.Flush()
|
||||||
e.f.Close()
|
e.f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode encodes H264 NALUs into MPEG-TS.
|
// encode encodes H264 NALUs into MPEG-TS.
|
||||||
func (e *mpegtsEncoder) encode(nalus [][]byte, pts time.Duration) error {
|
func (e *mpegtsMuxer) encode(nalus [][]byte, pts time.Duration) error {
|
||||||
// prepend an AUD. This is required by some players
|
// prepend an AUD. This is required by some players
|
||||||
filteredNALUs := [][]byte{
|
filteredNALUs := [][]byte{
|
||||||
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
|
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
|
@@ -19,7 +19,7 @@ type serverHandler struct {
|
|||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
h264TrackID int
|
h264TrackID int
|
||||||
h264track *gortsplib.TrackH264
|
h264track *gortsplib.TrackH264
|
||||||
mpegtsMuxer *mpegtsEncoder
|
mpegtsMuxer *mpegtsMuxer
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when a connection is opened.
|
// called when a connection is opened.
|
||||||
@@ -80,7 +80,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup H264->MPEGTS encoder
|
// setup H264->MPEGTS encoder
|
||||||
mpegtsMuxer, err := newMPEGTSEncoder(h264track.SafeSPS(), h264track.SafePPS())
|
mpegtsMuxer, err := newMPEGTSMuxer(h264track.SafeSPS(), h264track.SafePPS())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
|
@@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/asticode/go-astits"
|
"github.com/asticode/go-astits"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mpegtsEncoder allows to save a H264 stream into a MPEG-TS file.
|
// mpegtsMuxer allows to save a H264 stream into a MPEG-TS file.
|
||||||
type mpegtsEncoder struct {
|
type mpegtsMuxer struct {
|
||||||
sps []byte
|
sps []byte
|
||||||
pps []byte
|
pps []byte
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ type mpegtsEncoder struct {
|
|||||||
startDTS time.Duration
|
startDTS time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMPEGTSEncoder allocates a mpegtsEncoder.
|
// newMPEGTSMuxer allocates a mpegtsMuxer.
|
||||||
func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
func newMPEGTSMuxer(sps []byte, pps []byte) (*mpegtsMuxer, error) {
|
||||||
f, err := os.Create("mystream.ts")
|
f, err := os.Create("mystream.ts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -39,7 +39,7 @@ func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
|||||||
})
|
})
|
||||||
mux.SetPCRPID(256)
|
mux.SetPCRPID(256)
|
||||||
|
|
||||||
return &mpegtsEncoder{
|
return &mpegtsMuxer{
|
||||||
sps: sps,
|
sps: sps,
|
||||||
pps: pps,
|
pps: pps,
|
||||||
f: f,
|
f: f,
|
||||||
@@ -48,14 +48,14 @@ func newMPEGTSEncoder(sps []byte, pps []byte) (*mpegtsEncoder, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// close closes all the mpegtsEncoder resources.
|
// close closes all the mpegtsMuxer resources.
|
||||||
func (e *mpegtsEncoder) close() {
|
func (e *mpegtsMuxer) close() {
|
||||||
e.b.Flush()
|
e.b.Flush()
|
||||||
e.f.Close()
|
e.f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode encodes H264 NALUs into MPEG-TS.
|
// encode encodes H264 NALUs into MPEG-TS.
|
||||||
func (e *mpegtsEncoder) encode(nalus [][]byte, pts time.Duration) error {
|
func (e *mpegtsMuxer) encode(nalus [][]byte, pts time.Duration) error {
|
||||||
// prepend an AUD. This is required by some players
|
// prepend an AUD. This is required by some players
|
||||||
filteredNALUs := [][]byte{
|
filteredNALUs := [][]byte{
|
||||||
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
|
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
|
Reference in New Issue
Block a user