mirror of
				https://github.com/aler9/gortsplib
				synced 2025-10-31 18:42:40 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			972 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			972 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"bufio"
 | |
| 	"os"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/bluenviron/mediacommon/pkg/formats/mpegts"
 | |
| )
 | |
| 
 | |
| func durationGoToMPEGTS(v time.Duration) int64 {
 | |
| 	return int64(v.Seconds() * 90000)
 | |
| }
 | |
| 
 | |
| // mpegtsMuxer allows to save a MPEG-4 audio stream into a MPEG-TS file.
 | |
| type mpegtsMuxer struct {
 | |
| 	fileName string
 | |
| 	track    *mpegts.Track
 | |
| 
 | |
| 	f *os.File
 | |
| 	b *bufio.Writer
 | |
| 	w *mpegts.Writer
 | |
| }
 | |
| 
 | |
| // initialize initializes a mpegtsMuxer.
 | |
| func (e *mpegtsMuxer) initialize() error {
 | |
| 	var err error
 | |
| 	e.f, err = os.Create(e.fileName)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 	e.b = bufio.NewWriter(e.f)
 | |
| 
 | |
| 	e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
 | |
| 
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| // close closes all the mpegtsMuxer resources.
 | |
| func (e *mpegtsMuxer) close() {
 | |
| 	e.b.Flush()
 | |
| 	e.f.Close()
 | |
| }
 | |
| 
 | |
| // writeMPEG4Audio writes MPEG-4 audio access units into MPEG-TS.
 | |
| func (e *mpegtsMuxer) writeMPEG4Audio(aus [][]byte, pts time.Duration) error {
 | |
| 	return e.w.WriteMPEG4Audio(e.track, durationGoToMPEGTS(pts), aus)
 | |
| }
 | 
