Allow multiple HLS stream maps

This commit is contained in:
Ingo Oppermann
2025-03-17 10:59:10 +01:00
parent 38b248092d
commit a5831b3b1a
3 changed files with 171 additions and 55 deletions

View File

@@ -569,7 +569,7 @@ func (p *parser) parseHLSStreamMap(line []byte) error {
return err return err
} }
p.process.hlsMapping = &mapping p.process.hlsMapping = append(p.process.hlsMapping, mapping)
return nil return nil
} }

File diff suppressed because one or more lines are too long

View File

@@ -357,7 +357,7 @@ type ffmpegProcess struct {
input []ffmpegProcessIO input []ffmpegProcessIO
output []ffmpegProcessIO output []ffmpegProcessIO
mapping ffmpegStreamMapping mapping ffmpegStreamMapping
hlsMapping *ffmpegHLSStreamMap hlsMapping []ffmpegHLSStreamMap
} }
func (f *ffmpegProcess) ExportMapping() StreamMapping { func (f *ffmpegProcess) ExportMapping() StreamMapping {
@@ -447,16 +447,18 @@ func (p *ffmpegProcess) export() Progress {
progress.Mapping = p.ExportMapping() progress.Mapping = p.ExportMapping()
if p.hlsMapping != nil { for _, hlsmapping := range p.hlsMapping {
progress.Output = applyHLSMapping(progress.Output, p.hlsMapping) progress.Output = applyHLSMapping(progress.Output, hlsmapping)
} }
return progress return progress
} }
func applyHLSMapping(output []ProgressIO, hlsMapping *ffmpegHLSStreamMap) []ProgressIO { func applyHLSMapping(output []ProgressIO, hlsMapping ffmpegHLSStreamMap) []ProgressIO {
minVariantIndex := int64(-1) minVariantIndex := uint64(len(output))
maxVariantIndex := int64(-1) maxVariantIndex := uint64(0)
pivot := -1
// Find all outputs matching the address // Find all outputs matching the address
for i, io := range output { for i, io := range output {
@@ -464,6 +466,8 @@ func applyHLSMapping(output []ProgressIO, hlsMapping *ffmpegHLSStreamMap) []Prog
continue continue
} }
pivot = i
bla: bla:
for _, variant := range hlsMapping.Variants { for _, variant := range hlsMapping.Variants {
for s, stream := range variant.Streams { for s, stream := range variant.Streams {
@@ -471,16 +475,16 @@ func applyHLSMapping(output []ProgressIO, hlsMapping *ffmpegHLSStreamMap) []Prog
continue continue
} }
if minVariantIndex == -1 || int64(io.Index) < minVariantIndex { if io.Index < minVariantIndex {
minVariantIndex = int64(io.Index) minVariantIndex = io.Index
} }
io.Address = variant.Address io.Address = variant.Address
io.Index = io.Index + variant.Variant io.Index = io.Index + variant.Variant
io.Stream = uint64(s) io.Stream = uint64(s)
if int64(io.Index) > maxVariantIndex { if io.Index > maxVariantIndex {
maxVariantIndex = int64(io.Index) maxVariantIndex = io.Index
} }
break bla break bla
@@ -493,17 +497,13 @@ func applyHLSMapping(output []ProgressIO, hlsMapping *ffmpegHLSStreamMap) []Prog
offset := maxVariantIndex - minVariantIndex offset := maxVariantIndex - minVariantIndex
if offset > 0 { if offset > 0 {
// Fix all index values pivot++
for i, io := range output {
if io.Format == "hls" {
continue
}
if int64(io.Index) > minVariantIndex { // Fix all following index values
io.Index += uint64(offset) for i, io := range output[pivot:] {
} io.Index += offset
output[i] = io output[pivot+i] = io
} }
} }