diff --git a/.gitignore b/.gitignore index ee79665..5ac245f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_STORE -coverage.out \ No newline at end of file +coverage.out +.idea \ No newline at end of file diff --git a/discard.go b/discard.go new file mode 100644 index 0000000..de524f7 --- /dev/null +++ b/discard.go @@ -0,0 +1,17 @@ +package astiav + +//#include +import "C" + +// https://ffmpeg.org/doxygen/7.0/group__lavc__decoding.html#ga352363bce7d3ed82c101b3bc001d1c16 +type Discard C.enum_AVDiscard + +const ( + DiscardNone = Discard(C.AVDISCARD_NONE) // discard nothing + DiscardDefault = Discard(C.AVDISCARD_DEFAULT) // discard useless packets like 0 size packets in avi + DiscardNonRef = Discard(C.AVDISCARD_NONREF) // discard all non reference + DiscardBidirectional = Discard(C.AVDISCARD_BIDIR) // discard all bidirectional frames + DiscardNonIntra = Discard(C.AVDISCARD_NONINTRA) // discard all non intra frames + DiscardNonKey = Discard(C.AVDISCARD_NONKEY) // discard all frames except keyframes + DiscardAll = Discard(C.AVDISCARD_ALL) // discard all +) diff --git a/discard_test.go b/discard_test.go new file mode 100644 index 0000000..780f9ea --- /dev/null +++ b/discard_test.go @@ -0,0 +1,17 @@ +package astiav + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDiscard(t *testing.T) { + require.Equal(t, int(DiscardNone), -16) + require.Equal(t, int(DiscardDefault), 0) + require.Equal(t, int(DiscardNonRef), 8) + require.Equal(t, int(DiscardBidirectional), 16) + require.Equal(t, int(DiscardNonIntra), 24) + require.Equal(t, int(DiscardNonKey), 32) + require.Equal(t, int(DiscardAll), 48) +} diff --git a/program.go b/program.go index 76863bf..694a720 100644 --- a/program.go +++ b/program.go @@ -55,3 +55,78 @@ func (p *Program) Streams() (ss []*Stream) { } return } + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a8c87564167b87f54be9171778d51fe49 +func (p *Program) Flags() int { + return int(p.c.flags) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a8c87564167b87f54be9171778d51fe49 +func (p *Program) SetFlags(f int) { + p.c.flags = C.int(f) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a9c7a07c08a1f960aaa49f3f47633af5c +func (p *Program) Discard() Discard { + return Discard(p.c.discard) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a9c7a07c08a1f960aaa49f3f47633af5c +func (p *Program) SetDiscard(d Discard) { + p.c.discard = int32(d) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7967d41af4812ed61a28762e988c7a02 +func (p *Program) StreamIndex() uint { + return uint(C.uint(*p.c.stream_index)) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#ae9dab38d4694e3da9cba0f882f4e43d3 +func (p *Program) Metadata() *Dictionary { + return newDictionaryFromC(p.c.metadata) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#ae9dab38d4694e3da9cba0f882f4e43d3 +func (p *Program) SetMetadata(d *Dictionary) { + p.c.metadata = d.c +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a4c1539ea3c98da979b95a59a3ea163cb +func (p *Program) ProgramNum() int { + return int(p.c.program_num) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a02011963a63c291c6dc6d4eefa56cd69 +func (p *Program) PmtPid() int { + return int(p.c.pmt_pid) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7e026323df87e84a72ec5e5c8ce341a5 +func (p *Program) PcrPid() int { + return int(p.c.pcr_pid) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#acac8164436263b310d867ec650a2ea58 +func (p *Program) PmtVersion() int { + return int(p.c.pmt_version) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a2276db4d51695120664d527f20b7c532 +func (p *Program) StartTime() int64 { + return int64(p.c.start_time) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a5a7795c918153d0f64d68a838e172db4 +func (p *Program) EndTime() int64 { + return int64(p.c.end_time) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7e539e286876577e158039f6e7678452 +func (p *Program) PtsWrapReference() int64 { + return int64(p.c.pts_wrap_reference) +} + +// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#aa3f8af78093a910ff766ac5af381758b +func (p *Program) PtsWrapBehavior() int { + return int(p.c.pts_wrap_behavior) +} diff --git a/program_test.go b/program_test.go index 6c15724..3d54163 100644 --- a/program_test.go +++ b/program_test.go @@ -22,4 +22,13 @@ func TestProgram(t *testing.T) { ss := p.Streams() require.Equal(t, 1, len(ss)) require.Equal(t, s.ID(), ss[0].ID()) + + p.SetFlags(1) + require.Equal(t, 1, p.Flags()) + p.SetDiscard(DiscardAll) + require.Equal(t, DiscardAll, p.Discard()) + d := NewDictionary() + _ = d.Set("service_name", "test_service_name", 0) + p.SetMetadata(d) + require.Equal(t, p.Metadata().Get("service_name", nil, 0).Value(), "test_service_name") }