From 61df210b82ce1067bc54cb6db848087c98162229 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Fri, 24 Jan 2025 15:01:06 +0100 Subject: [PATCH] Added muxer header option --- libav/muxer.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libav/muxer.go b/libav/muxer.go index a83c4b6..d2b71ff 100644 --- a/libav/muxer.go +++ b/libav/muxer.go @@ -20,6 +20,7 @@ type Muxer struct { c *astikit.Chan formatContext *astiav.FormatContext eh *astiencoder.EventHandler + header map[string]string o *sync.Once p *pktPool restamper PktRestamper @@ -32,6 +33,7 @@ type Muxer struct { type MuxerOptions struct { Format *astiav.OutputFormat FormatName string + Header map[string]string Node astiencoder.NodeOptions Restamper PktRestamper URL string @@ -47,6 +49,7 @@ func NewMuxer(o MuxerOptions, eh *astiencoder.EventHandler, c *astikit.Closer, s m = &Muxer{ c: astikit.NewChan(astikit.ChanOptions{ProcessAll: true}), eh: eh, + header: o.Header, o: &sync.Once{}, restamper: o.Restamper, } @@ -150,9 +153,22 @@ func (m *Muxer) FormatContext() *astiav.FormatContext { // Start starts the muxer func (m *Muxer) Start(ctx context.Context, t astiencoder.CreateTaskFunc) { m.BaseNode.Start(ctx, t, func(t *astikit.Task) { + // Create header dictionary + var d *astiav.Dictionary + if len(m.header) > 0 { + d = astiav.NewDictionary() + defer d.Free() + for k, v := range m.header { + if err := d.Set(k, v, astiav.NewDictionaryFlags()); err != nil { + emitError(m, m.eh, err, "setting header dictionary %s=%s", k, v) + return + } + } + } + // Make sure to write header once var err error - m.o.Do(func() { err = m.formatContext.WriteHeader(nil) }) + m.o.Do(func() { err = m.formatContext.WriteHeader(d) }) if err != nil { emitError(m, m.eh, err, "writing header") return