simplify examples (#493)

This commit is contained in:
Alessandro Ros
2024-01-01 19:56:40 +01:00
committed by GitHub
parent 013a8d8463
commit bcd17a992c
8 changed files with 28 additions and 20 deletions

View File

@@ -52,8 +52,9 @@ func main() {
// setup H264 -> MPEG-TS muxer // setup H264 -> MPEG-TS muxer
mpegtsMuxer := &mpegtsMuxer{ mpegtsMuxer := &mpegtsMuxer{
sps: forma.SPS, fileName: "mystream.ts",
pps: forma.PPS, sps: forma.SPS,
pps: forma.PPS,
} }
mpegtsMuxer.initialize() mpegtsMuxer.initialize()
if err != nil { if err != nil {

View File

@@ -15,8 +15,9 @@ func durationGoToMPEGTS(v time.Duration) int64 {
// mpegtsMuxer allows to save a H264 stream into a MPEG-TS file. // mpegtsMuxer allows to save a H264 stream into a MPEG-TS file.
type mpegtsMuxer struct { type mpegtsMuxer struct {
sps []byte fileName string
pps []byte sps []byte
pps []byte
f *os.File f *os.File
b *bufio.Writer b *bufio.Writer
@@ -28,7 +29,7 @@ type mpegtsMuxer struct {
// initialize initializes a mpegtsMuxer. // initialize initializes a mpegtsMuxer.
func (e *mpegtsMuxer) initialize() error { func (e *mpegtsMuxer) initialize() error {
var err error var err error
e.f, err = os.Create("mystream.ts") e.f, err = os.Create(e.fileName)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -52,9 +52,10 @@ func main() {
// setup H265 -> MPEG-TS muxer // setup H265 -> MPEG-TS muxer
mpegtsMuxer := &mpegtsMuxer{ mpegtsMuxer := &mpegtsMuxer{
vps: forma.VPS, fileName: "mystream.ts",
sps: forma.SPS, vps: forma.VPS,
pps: forma.PPS, sps: forma.SPS,
pps: forma.PPS,
} }
mpegtsMuxer.initialize() mpegtsMuxer.initialize()
if err != nil { if err != nil {

View File

@@ -15,9 +15,10 @@ func durationGoToMPEGTS(v time.Duration) int64 {
// mpegtsMuxer allows to save a H265 stream into a MPEG-TS file. // mpegtsMuxer allows to save a H265 stream into a MPEG-TS file.
type mpegtsMuxer struct { type mpegtsMuxer struct {
vps []byte fileName string
sps []byte vps []byte
pps []byte sps []byte
pps []byte
f *os.File f *os.File
b *bufio.Writer b *bufio.Writer
@@ -29,7 +30,7 @@ type mpegtsMuxer struct {
// initialize initializes a mpegtsMuxer. // initialize initializes a mpegtsMuxer.
func (e *mpegtsMuxer) initialize() error { func (e *mpegtsMuxer) initialize() error {
var err error var err error
e.f, err = os.Create("mystream.ts") e.f, err = os.Create(e.fileName)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -51,7 +51,8 @@ func main() {
// setup MPEG-4 audio -> MPEG-TS muxer // setup MPEG-4 audio -> MPEG-TS muxer
mpegtsMuxer := &mpegtsMuxer{ mpegtsMuxer := &mpegtsMuxer{
config: forma.Config, fileName: "mystream.ts",
config: forma.Config,
} }
mpegtsMuxer.initialize() mpegtsMuxer.initialize()
if err != nil { if err != nil {

View File

@@ -15,7 +15,8 @@ func durationGoToMPEGTS(v time.Duration) int64 {
// mpegtsMuxer allows to save a MPEG4-audio stream into a MPEG-TS file. // mpegtsMuxer allows to save a MPEG4-audio stream into a MPEG-TS file.
type mpegtsMuxer struct { type mpegtsMuxer struct {
config *mpeg4audio.Config fileName string
config *mpeg4audio.Config
f *os.File f *os.File
b *bufio.Writer b *bufio.Writer
@@ -26,7 +27,7 @@ type mpegtsMuxer struct {
// initialize initializes a mpegtsMuxer. // initialize initializes a mpegtsMuxer.
func (e *mpegtsMuxer) initialize() error { func (e *mpegtsMuxer) initialize() error {
var err error var err error
e.f, err = os.Create("mystream.ts") e.f, err = os.Create(e.fileName)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -84,8 +84,9 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
// setup H264 -> MPEGTS muxer // setup H264 -> MPEGTS muxer
mpegtsMuxer := &mpegtsMuxer{ mpegtsMuxer := &mpegtsMuxer{
sps: forma.SPS, fileName: "mystream.ts",
pps: forma.PPS, sps: forma.SPS,
pps: forma.PPS,
} }
mpegtsMuxer.initialize() mpegtsMuxer.initialize()
if err != nil { if err != nil {

View File

@@ -15,8 +15,9 @@ func durationGoToMPEGTS(v time.Duration) int64 {
// mpegtsMuxer allows to save a H264 stream into a MPEG-TS file. // mpegtsMuxer allows to save a H264 stream into a MPEG-TS file.
type mpegtsMuxer struct { type mpegtsMuxer struct {
sps []byte fileName string
pps []byte sps []byte
pps []byte
f *os.File f *os.File
b *bufio.Writer b *bufio.Writer
@@ -28,7 +29,7 @@ type mpegtsMuxer struct {
// initialize initializes a mpegtsMuxer. // initialize initializes a mpegtsMuxer.
func (e *mpegtsMuxer) initialize() error { func (e *mpegtsMuxer) initialize() error {
var err error var err error
e.f, err = os.Create("mystream.ts") e.f, err = os.Create(e.fileName)
if err != nil { if err != nil {
return err return err
} }