Add support FLAC codec to MP4/MSE
This commit is contained in:
+15
-6
@@ -32,6 +32,16 @@ const (
|
||||
Mdat = "mdat"
|
||||
)
|
||||
|
||||
const (
|
||||
sampleIsNonSync = 0x10000
|
||||
sampleDependsOn1 = 0x1000000
|
||||
sampleDependsOn2 = 0x2000000
|
||||
|
||||
SampleVideoIFrame = sampleDependsOn2
|
||||
SampleVideoNonIFrame = sampleDependsOn1 | sampleIsNonSync
|
||||
SampleAudio = sampleIsNonSync
|
||||
)
|
||||
|
||||
func (m *Movie) WriteFileType() {
|
||||
m.StartAtom(Ftyp)
|
||||
m.WriteString("iso5")
|
||||
@@ -250,7 +260,7 @@ func (m *Movie) WriteAudioTrack(id uint32, codec string, timescale uint32, chann
|
||||
m.EndAtom() // TRAK
|
||||
}
|
||||
|
||||
func (m *Movie) WriteMovieFragment(seq, tid, duration, size uint32, time uint64) {
|
||||
func (m *Movie) WriteMovieFragment(seq, tid, duration, size, flags uint32, time uint64) {
|
||||
m.StartAtom(Moof)
|
||||
|
||||
m.StartAtom(MoofMfhd)
|
||||
@@ -276,10 +286,10 @@ func (m *Movie) WriteMovieFragment(seq, tid, duration, size uint32, time uint64)
|
||||
TfhdDefaultSampleFlags |
|
||||
TfhdDefaultBaseIsMoof,
|
||||
)
|
||||
m.WriteUint32(tid) // track id
|
||||
m.WriteUint32(duration) // default sample duration
|
||||
m.WriteUint32(size) // default sample size
|
||||
m.WriteUint32(0x2000000) // default sample flags
|
||||
m.WriteUint32(tid) // track id
|
||||
m.WriteUint32(duration) // default sample duration
|
||||
m.WriteUint32(size) // default sample size
|
||||
m.WriteUint32(flags) // default sample flags
|
||||
m.EndAtom()
|
||||
|
||||
m.StartAtom(MoofTrafTfdt)
|
||||
@@ -314,5 +324,4 @@ func (m *Movie) WriteData(b []byte) {
|
||||
m.StartAtom(Mdat)
|
||||
m.Write(b)
|
||||
m.EndAtom()
|
||||
|
||||
}
|
||||
|
||||
+14
-2
@@ -2,6 +2,7 @@ package iso
|
||||
|
||||
import (
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/AlexxIT/go2rtc/pkg/pcm"
|
||||
)
|
||||
|
||||
func (m *Movie) WriteVideo(codec string, width, height uint16, conf []byte) {
|
||||
@@ -46,9 +47,11 @@ func (m *Movie) WriteVideo(codec string, width, height uint16, conf []byte) {
|
||||
func (m *Movie) WriteAudio(codec string, channels uint16, sampleRate uint32, conf []byte) {
|
||||
switch codec {
|
||||
case core.CodecAAC, core.CodecMP3:
|
||||
m.StartAtom("mp4a")
|
||||
m.StartAtom("mp4a") // supported in all players and browsers
|
||||
case core.CodecFLAC:
|
||||
m.StartAtom("fLaC") // supported in all players and browsers
|
||||
case core.CodecOpus:
|
||||
m.StartAtom("Opus")
|
||||
m.StartAtom("Opus") // supported in Chrome and Firefox
|
||||
case core.CodecPCMU:
|
||||
m.StartAtom("ulaw")
|
||||
case core.CodecPCMA:
|
||||
@@ -56,6 +59,11 @@ func (m *Movie) WriteAudio(codec string, channels uint16, sampleRate uint32, con
|
||||
default:
|
||||
panic("unsupported iso audio: " + codec)
|
||||
}
|
||||
|
||||
if channels == 0 {
|
||||
channels = 1
|
||||
}
|
||||
|
||||
m.Skip(6)
|
||||
m.WriteUint16(1) // data_reference_index
|
||||
m.Skip(2) // version
|
||||
@@ -72,6 +80,10 @@ func (m *Movie) WriteAudio(codec string, channels uint16, sampleRate uint32, con
|
||||
m.WriteEsdsAAC(conf)
|
||||
case core.CodecMP3:
|
||||
m.WriteEsdsMP3()
|
||||
case core.CodecFLAC:
|
||||
m.StartAtom("dfLa")
|
||||
m.Write(pcm.FLACHeader(false, sampleRate))
|
||||
m.EndAtom()
|
||||
case core.CodecOpus:
|
||||
// don't know what means this magic
|
||||
m.StartAtom("dOps")
|
||||
|
||||
Reference in New Issue
Block a user