mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-01 06:22:26 +08:00
Added Program
This commit is contained in:
53
program.go
Normal file
53
program.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package astiav
|
||||
|
||||
//#cgo pkg-config: libavformat
|
||||
//#include <libavformat/avformat.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavformat/avformat.h#L1181
|
||||
type Program struct {
|
||||
c *C.struct_AVProgram
|
||||
fc *FormatContext
|
||||
}
|
||||
|
||||
func newProgramFromC(c *C.struct_AVProgram, fc *FormatContext) *Program {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return &Program{
|
||||
c: c,
|
||||
fc: fc,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Program) AddStream(s *Stream) {
|
||||
C.av_program_add_stream_index(p.fc.c, p.c.id, C.uint(s.c.index))
|
||||
}
|
||||
|
||||
func (p *Program) ID() int {
|
||||
return int(p.c.id)
|
||||
}
|
||||
|
||||
func (p *Program) NbStreams() int {
|
||||
return int(p.c.nb_stream_indexes)
|
||||
}
|
||||
|
||||
func (p *Program) SetID(i int) {
|
||||
p.c.id = C.int(i)
|
||||
}
|
||||
|
||||
func (p *Program) Streams() (ss []*Stream) {
|
||||
is := make(map[int]bool)
|
||||
for _, idx := range unsafe.Slice(p.c.stream_index, p.c.nb_stream_indexes) {
|
||||
is[int(idx)] = true
|
||||
}
|
||||
for _, s := range p.fc.Streams() {
|
||||
if _, ok := is[s.Index()]; ok {
|
||||
ss = append(ss, s)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user