-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream.go
71 lines (59 loc) · 2.71 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package ffmpeg
//#include <libavformat/avformat.h>
import "C"
import (
"errors"
"unsafe"
)
type Stream C.struct_AVStream
// NewStream creates new stream and add them to formatContext.streams
func NewStream(formatContext *FormatContext) (*Stream, error) {
stream := (*Stream)(unsafe.Pointer(C.avformat_new_stream(formatContext.ctype(), nil)))
if stream == nil {
return nil, errors.New("create stream error")
}
stream.id = C.int(formatContext.nb_streams - 1)
return stream, nil
}
func (s *Stream) SetCodecParameters(parms *CodecParameters) {
*(s.ctype().codecpar) = *(parms.ctype())
}
func (s *Stream) CodecParameters() *CodecParameters {
p := CodecParameters{
ExtraData: C.GoBytes(unsafe.Pointer(s.ctype().codecpar.extradata), s.ctype().codecpar.extradata_size),
CodecType: MediaType(s.ctype().codecpar.codec_type),
CodecID: CodecID(s.ctype().codecpar.codec_id),
CodecTag: uint32(s.ctype().codecpar.codec_tag),
Format: int(s.ctype().codecpar.format),
Bitrate: int(s.ctype().codecpar.bit_rate),
BitsPerCodedSample: int(s.ctype().codecpar.bits_per_coded_sample),
BitsPerRawSample: int(s.ctype().codecpar.bits_per_raw_sample),
Profile: int(s.ctype().codecpar.profile),
Level: int(s.ctype().codecpar.level),
Width: int(s.ctype().codecpar.width),
Height: int(s.ctype().codecpar.height),
SampleAspectRatio: Rational{int(s.ctype().codecpar.sample_aspect_ratio.num), int(s.ctype().codecpar.sample_aspect_ratio.den)},
FieldOrder: FieldOrder(s.ctype().codecpar.field_order),
ColorRange: ColorRange(s.ctype().codecpar.color_range),
ColorPrimaries: ColorPrimaries(s.ctype().codecpar.color_primaries),
ColorTrc: ColorTransferCharacteristic(s.ctype().codecpar.color_trc),
ColorSpace: ColorSpace(s.ctype().codecpar.color_space),
ChromaLocation: ChromaLocation(s.ctype().codecpar.chroma_location),
VideoDelay: int(s.ctype().codecpar.video_delay),
ChannelLayout: ChannelLayout(s.ctype().codecpar.channel_layout),
Channels: int(s.ctype().codecpar.channels),
SampleRate: int(s.ctype().codecpar.sample_rate),
BlockAlign: int(s.ctype().codecpar.block_align),
FrameSize: int(s.ctype().codecpar.frame_size),
InitialPadding: int(s.ctype().codecpar.initial_padding),
TrailingPadding: int(s.ctype().codecpar.trailing_padding),
SeekPreroll: int(s.ctype().codecpar.seek_preroll),
}
return &p
}
func (s *Stream) TimeBase() Rational {
return Rational{int(s.ctype().time_base.num), int(s.ctype().time_base.den)}
}
func (s *Stream) ctype() *C.struct_AVStream {
return (*C.struct_AVStream)(unsafe.Pointer(s))
}