forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_parameters_test.go
105 lines (96 loc) · 3.55 KB
/
codec_parameters_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package astiav
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCodecParameters(t *testing.T) {
fc, err := globalHelper.inputFormatContext("video.mp4", nil)
require.NoError(t, err)
ss := fc.Streams()
require.Len(t, ss, 2)
s1 := ss[0]
s2 := ss[1]
cp1 := s1.CodecParameters()
require.Equal(t, int64(441324), cp1.BitRate())
require.Equal(t, ChromaLocationLeft, cp1.ChromaLocation())
require.Equal(t, CodecIDH264, cp1.CodecID())
require.Equal(t, CodecTag(0x31637661), cp1.CodecTag())
require.Equal(t, ColorPrimariesUnspecified, cp1.ColorPrimaries())
require.Equal(t, ColorRangeUnspecified, cp1.ColorRange())
require.Equal(t, ColorSpaceUnspecified, cp1.ColorSpace())
require.Equal(t, ColorTransferCharacteristicUnspecified, cp1.ColorTransferCharacteristic())
require.Equal(t, 180, cp1.Height())
require.Equal(t, Level(13), cp1.Level())
require.Equal(t, MediaTypeVideo, cp1.MediaType())
require.Equal(t, PixelFormatYuv420P, cp1.PixelFormat())
require.Equal(t, ProfileH264ConstrainedBaseline, cp1.Profile())
require.Equal(t, NewRational(1, 1), cp1.SampleAspectRatio())
require.Equal(t, 320, cp1.Width())
cp2 := s2.CodecParameters()
require.Equal(t, int64(161052), cp2.BitRate())
require.True(t, cp2.ChannelLayout().Equal(ChannelLayoutStereo))
require.Equal(t, CodecIDAac, cp2.CodecID())
require.Equal(t, CodecTag(0x6134706d), cp2.CodecTag())
require.Equal(t, 1024, cp2.FrameSize())
require.Equal(t, MediaTypeAudio, cp2.MediaType())
require.Equal(t, SampleFormatFltp, cp2.SampleFormat())
require.Equal(t, 48000, cp2.SampleRate())
cp3 := AllocCodecParameters()
require.NotNil(t, cp3)
defer cp3.Free()
err = cp2.Copy(cp3)
require.NoError(t, err)
require.Equal(t, cp2.CodecID(), cp3.CodecID())
cc4 := AllocCodecContext(nil)
require.NotNil(t, cc4)
defer cc4.Free()
err = cp2.ToCodecContext(cc4)
require.NoError(t, err)
require.Equal(t, cp2.CodecID(), cc4.CodecID())
cp5 := AllocCodecParameters()
require.NotNil(t, cp5)
defer cp5.Free()
err = cp5.FromCodecContext(cc4)
require.NoError(t, err)
require.Equal(t, cc4.CodecID(), cp5.CodecID())
cp6 := AllocCodecParameters()
require.NotNil(t, cp6)
defer cp6.Free()
cp6.SetChannelLayout(ChannelLayout21)
require.True(t, cp6.ChannelLayout().Equal(ChannelLayout21))
defer cp6.Free()
cp6.SetCodecID(CodecIDRawvideo)
require.Equal(t, CodecIDRawvideo, cp6.CodecID())
cp6.SetCodecTag(CodecTag(2))
require.Equal(t, CodecTag(2), cp6.CodecTag())
cp6.SetColorRange(ColorRangeJpeg)
require.Equal(t, ColorRangeJpeg, cp6.ColorRange())
cp6.SetColorSpace(ColorSpaceBt709)
require.Equal(t, ColorSpaceBt709, cp6.ColorSpace())
cp6.SetFrameSize(1)
require.Equal(t, 1, cp6.FrameSize())
cp6.SetHeight(1)
require.Equal(t, 1, cp6.Height())
cp1.SetLevel(16)
require.Equal(t, Level(16), cp1.Level())
cp6.SetMediaType(MediaTypeAudio)
require.Equal(t, MediaTypeAudio, cp6.MediaType())
cp1.SetProfile(ProfileH264Extended)
require.Equal(t, ProfileH264Extended, cp1.Profile())
cp6.SetPixelFormat(PixelFormat0Bgr)
require.Equal(t, PixelFormat0Bgr, cp6.PixelFormat())
cp6.SetSampleAspectRatio(NewRational(1, 2))
require.Equal(t, NewRational(1, 2), cp6.SampleAspectRatio())
cp6.SetSampleFormat(SampleFormatDbl)
require.Equal(t, SampleFormatDbl, cp6.SampleFormat())
cp6.SetSampleRate(4)
require.Equal(t, 4, cp6.SampleRate())
cp6.SetWidth(2)
require.Equal(t, 2, cp6.Width())
b := []byte("test")
require.NoError(t, cp6.SetExtraData(b))
require.Equal(t, b, cp6.ExtraData())
sd := cp6.SideData()
require.NoError(t, sd.Add(PacketSideDataTypeDisplaymatrix, b))
require.Equal(t, b, sd.Get(PacketSideDataTypeDisplaymatrix))
}