• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

asticode / go-astiav / 20960391307

13 Jan 2026 02:10PM UTC coverage: 86.203% (-0.2%) from 86.374%
20960391307

push

github

web-flow
Now compatible with n8.0 (#178)

* n7.1: Migrate deprecated methods, fields, and definitions

* n7.1: Add new definitions

* n7.1: Add new field

* n7.1: Update doxygen url

* n8.0: Clean up remaining n7.x deprecations

* n8.0: Add new CodecIDs and fields

* n8.0: Migration to n8.0

* n8.0: Refactor swscale with Publicly expose struct SwsContext, enum SwsDither, and enum SwsAlphaBlend

n8.0: Stash commit

* n8.0: Update doxygen url

* n8.0: Fix windows.patch to apply new library.mak in n8.0

* n8.0: Clean up and organize the APIs, remove redundant implementations, and reorder the enum fields

* n8.0: Refactor SoftwareScaleContext to simplify and optimize update logic and remove redundant code

* Add tests for supported sample rates and frame rates in codec encoders

* Revert changes in `Free` and `Class`, other minor improvements

* Adapt the examples to the current library

* Update breaking changes

109 of 112 new or added lines in 5 files covered. (97.32%)

1 existing line in 1 file now uncovered.

3049 of 3537 relevant lines covered (86.2%)

53.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.78
/codec.go
1
package astiav
2

3
//#include <libavcodec/avcodec.h>
4
//#include <libavutil/channel_layout.h>
5
import "C"
6
import (
7
        "unsafe"
8
)
9

10
// https://ffmpeg.org/doxygen/8.0/structAVCodec.html
11
type Codec struct {
12
        c *C.AVCodec
13
}
14

15
func newCodecFromC(c *C.AVCodec) *Codec {
2,135✔
16
        if c == nil {
2,138✔
17
                return nil
3✔
18
        }
3✔
19
        return &Codec{c: c}
2,132✔
20
}
21

22
// https://ffmpeg.org/doxygen/8.0/structAVCodec.html#ad3daa3e729850b573c139a83be8938ca
23
func (c *Codec) Name() string {
24✔
24
        return C.GoString(c.c.name)
24✔
25
}
24✔
26

27
func (c *Codec) String() string {
12✔
28
        return c.Name()
12✔
29
}
12✔
30

31
// https://ffmpeg.org/doxygen/8.0/structAVCodec.html#a01a53d07936f4c7ee280444793b6967b
32
func (c *Codec) ID() CodecID {
2,084✔
33
        return CodecID(c.c.id)
2,084✔
34
}
2,084✔
35

36
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga6dc18eef1afca3610644a52565cf8a31
37
func (c *Codec) IsDecoder() bool {
12✔
38
        return int(C.av_codec_is_decoder(c.c)) != 0
12✔
39
}
12✔
40

41
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga2b665824e4d9144f8d4f6c01e3e85aa3
42
func (c *Codec) IsEncoder() bool {
12✔
43
        return int(C.av_codec_is_encoder(c.c)) != 0
12✔
44
}
12✔
45

46
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#gadd58e6b0bbca99fdbc547efbaa6b0ef1
47
func (c *Codec) supportedConfig(config C.enum_AVCodecConfig, fn func(ptr unsafe.Pointer), size C.size_t) {
36✔
48
        var outConfigs unsafe.Pointer
36✔
49
        var outNumConfigs C.int
36✔
50
        ret := C.avcodec_get_supported_config(nil, c.c, config, 0, &outConfigs, &outNumConfigs)
36✔
51
        if ret >= 0 && outConfigs != nil {
60✔
52
                numConfigs := uintptr(outNumConfigs)
24✔
53
                for i := uintptr(0); i < numConfigs; i++ {
183✔
54
                        fn(unsafe.Pointer(uintptr(outConfigs) + i*uintptr(size)))
159✔
55
                }
159✔
56
        }
57
}
58

59
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
60
func (c *Codec) SupportedChannelLayouts() (o []ChannelLayout) {
6✔
61
        c.supportedConfig(C.AV_CODEC_CONFIG_CHANNEL_LAYOUT, func(ptr unsafe.Pointer) {
39✔
62
                v, _ := newChannelLayoutFromC((*C.AVChannelLayout)(ptr)).clone()
33✔
63
                o = append(o, v)
33✔
64
        }, C.sizeof_AVChannelLayout)
33✔
65
        return
6✔
66
}
67

68
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
69
func (c *Codec) SupportedColorRanges() (o []ColorRange) {
3✔
70
        c.supportedConfig(C.AV_CODEC_CONFIG_COLOR_RANGE, func(ptr unsafe.Pointer) {
6✔
71
                o = append(o, ColorRange(*(*C.enum_AVColorRange)(ptr)))
3✔
72
        }, C.sizeof_enum_AVColorRange)
3✔
73
        return
3✔
74
}
75

76
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
77
func (c *Codec) SupportedColorSpaces() (o []ColorSpace) {
3✔
78
        c.supportedConfig(C.AV_CODEC_CONFIG_COLOR_SPACE, func(ptr unsafe.Pointer) {
3✔
NEW
79
                o = append(o, ColorSpace(*(*C.enum_AVColorSpace)(ptr)))
×
NEW
80
        }, C.sizeof_enum_AVColorSpace)
×
81
        return
3✔
82
}
83

84
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
85
func (c *Codec) SupportedPixelFormats() (o []PixelFormat) {
9✔
86
        c.supportedConfig(C.AV_CODEC_CONFIG_PIX_FORMAT, func(ptr unsafe.Pointer) {
45✔
87
                o = append(o, PixelFormat(*(*C.enum_AVPixelFormat)(ptr)))
36✔
88
        }, C.sizeof_enum_AVPixelFormat)
36✔
89
        return
9✔
90
}
91

92
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
93
func (c *Codec) SupportedSampleFormats() (o []SampleFormat) {
9✔
94
        c.supportedConfig(C.AV_CODEC_CONFIG_SAMPLE_FORMAT, func(ptr unsafe.Pointer) {
18✔
95
                o = append(o, SampleFormat(*(*C.enum_AVSampleFormat)(ptr)))
9✔
96
        }, C.sizeof_enum_AVSampleFormat)
9✔
97
        return
9✔
98
}
99

100
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
101
func (c *Codec) SupportedFrameRates() (o []Rational) {
3✔
102
        c.supportedConfig(C.AV_CODEC_CONFIG_FRAME_RATE, func(ptr unsafe.Pointer) {
42✔
103
                o = append(o, newRationalFromC(*(*C.AVRational)(ptr)))
39✔
104
        }, C.sizeof_AVRational)
39✔
105
        return
3✔
106
}
107

108
// https://ffmpeg.org/doxygen/8.0/group__lavc__decoding.html#ga9abe043ed40f3c270dff77235fcfcd0b
109
func (c *Codec) SupportedSampleRates() (o []int) {
3✔
110
        c.supportedConfig(C.AV_CODEC_CONFIG_SAMPLE_RATE, func(ptr unsafe.Pointer) {
42✔
111
                o = append(o, int(*(*C.int)(ptr)))
39✔
112
        }, C.sizeof_int)
39✔
113
        return
3✔
114
}
115

116
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga51e35d01da2b3833b3afa839212c58fa
117
func FindDecoder(id CodecID) *Codec {
30✔
118
        return newCodecFromC(C.avcodec_find_decoder((C.enum_AVCodecID)(id)))
30✔
119
}
30✔
120

121
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#gad4e08a758f3560006145db074d16cb47
122
func FindDecoderByName(n string) *Codec {
6✔
123
        cn := C.CString(n)
6✔
124
        defer C.free(unsafe.Pointer(cn))
6✔
125
        return newCodecFromC(C.avcodec_find_decoder_by_name(cn))
6✔
126
}
6✔
127

128
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga68e4b5f31de5e5fc25d5781a1be22331
129
func FindEncoder(id CodecID) *Codec {
6✔
130
        return newCodecFromC(C.avcodec_find_encoder((C.enum_AVCodecID)(id)))
6✔
131
}
6✔
132

133
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga9fa02c1eae54a2ec67beb789c2688d6e
134
func FindEncoderByName(n string) *Codec {
9✔
135
        cn := C.CString(n)
9✔
136
        defer C.free(unsafe.Pointer(cn))
9✔
137
        return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
9✔
138
}
9✔
139

140
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga4f80582a2ea9c0e141de5d6f6152008f
141
func (c *Codec) HardwareConfigs() (configs []CodecHardwareConfig) {
×
142
        var i int
×
143
        for {
×
144
                config := C.avcodec_get_hw_config(c.c, C.int(i))
×
145
                if config == nil {
×
146
                        break
×
147
                }
148
                configs = append(configs, newCodecHardwareConfigFromC(config))
×
149
                i++
×
150
        }
151
        return
×
152
}
153

154
// https://ffmpeg.org/doxygen/8.0/group__lavc__core.html#ga7cd040fcc147340186deb0c54dc996b0
155
func Codecs() (cs []*Codec) {
3✔
156
        var opq *C.void = nil
3✔
157
        for {
2,084✔
158
                c := C.av_codec_iterate((*unsafe.Pointer)(unsafe.Pointer(&opq)))
2,081✔
159
                if c == nil {
2,084✔
160
                        break
3✔
161
                }
162
                cs = append(cs, newCodecFromC(c))
2,078✔
163
        }
164
        return
3✔
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc