From 13bb06083c71921c0f992e2a9f16b7b3668a65d7 Mon Sep 17 00:00:00 2001 From: ma3315865 Date: Wed, 18 Dec 2024 11:23:08 +0800 Subject: [PATCH] SetStreamIndex --- program.go | 7 +++++++ program_test.go | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/program.go b/program.go index 60b3dcc..e8ff9c4 100644 --- a/program.go +++ b/program.go @@ -75,6 +75,13 @@ func (p *Program) StreamIndex() *uint { return &u } +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7967d41af4812ed61a28762e988c7a02 +func (p *Program) SetStreamIndex(n uint) { + if p.c.stream_index != nil { + *p.c.stream_index = C.uint(n) + } +} + // https://ffmpeg.org/doxygen/7.0/structAVProgram.html#ae9dab38d4694e3da9cba0f882f4e43d3 func (p *Program) Metadata() *Dictionary { return newDictionaryFromC(p.c.metadata) diff --git a/program_test.go b/program_test.go index 50a604d..19f7ea4 100644 --- a/program_test.go +++ b/program_test.go @@ -16,7 +16,6 @@ func TestProgram(t *testing.T) { require.Equal(t, 2, p.ID()) p.SetDiscard(DiscardAll) require.Equal(t, DiscardAll, p.Discard()) - require.Nil(t, p.StreamIndex(), nil) d := NewDictionary() require.NoError(t, d.Set("service_name", "test_service_name", 0)) p.SetMetadata(d) @@ -34,8 +33,14 @@ func TestProgram(t *testing.T) { s := fc.NewStream(nil) s.SetID(2) require.Equal(t, 0, p.NbStreams()) + require.Nil(t, p.StreamIndex(), nil) p.AddStream(s) require.Equal(t, 1, p.NbStreams()) + require.Equal(t, uint(0), *p.StreamIndex()) + var streamIndex uint = 1 + p.SetStreamIndex(streamIndex) + require.Equal(t, streamIndex, *p.StreamIndex()) + s.SetIndex(int(streamIndex)) ss := p.Streams() require.Equal(t, 1, len(ss)) require.Equal(t, s.ID(), ss[0].ID())