├── .gitignore ├── LICENSE ├── README.md ├── avcodec ├── avcodec.go ├── codecparameters.go ├── codecparameters_struct.go ├── codecs.go ├── context.go ├── context_struct.go ├── packet.go ├── packet_struct.go └── pixelformat.go ├── avdevice ├── avdevice.go └── format.go ├── avfilter ├── avfilter.go ├── filter.go └── graph.go ├── avformat ├── avformat.go ├── context.go ├── context_struct.go ├── stream.go └── stream_struct.go ├── avutil ├── avutil.go ├── dictionary.go ├── frame.go ├── frame_struct.go ├── intreadwrite.go ├── log.go ├── mathematics.go ├── memory.go ├── picture.go ├── pixel_format.go ├── rational_struct.go ├── samplefmt.go └── time.go ├── go.mod ├── goav.go ├── swresample ├── context.go └── swresample.go ├── swscale ├── context.go ├── swscale.go └── vector.go ├── versions └── versions.go └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | /tmp 2 | /vendor 3 | /example 4 | .idea 5 | 6 | # Wercker temp directory 7 | .wercker/ 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 H.G. Giorgis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Warning 2 | 3 | This project is not maintained anymore. 4 | 5 | I've created my [own bindings](https://github.com/asticode/go-astiav) that I maintain actively. Feel free to check them out. -------------------------------------------------------------------------------- /avcodec/avcodec.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | //Package avcodec contains the codecs (decoders and encoders) provided by the libavcodec library 5 | //Provides some generic global options, which can be set on all the encoders and decoders. 6 | package avcodec 7 | 8 | //#cgo pkg-config: libavformat libavcodec libavutil libswresample 9 | //#include 10 | //#include 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | import "C" 19 | import ( 20 | "unsafe" 21 | 22 | "github.com/asticode/goav/avutil" 23 | ) 24 | 25 | type ( 26 | Codec C.struct_AVCodec 27 | Context C.struct_AVCodecContext 28 | CodecParameters C.struct_AVCodecParameters 29 | Descriptor C.struct_AVCodecDescriptor 30 | Parser C.struct_AVCodecParser 31 | ParserContext C.struct_AVCodecParserContext 32 | Frame C.struct_AVFrame 33 | MediaType C.enum_AVMediaType 34 | Packet C.struct_AVPacket 35 | BitStreamFilter C.struct_AVBitStreamFilter 36 | BitStreamFilterContext C.struct_AVBitStreamFilterContext 37 | Rational C.struct_AVRational 38 | Class C.struct_AVClass 39 | AvHWAccel C.struct_AVHWAccel 40 | AvPacketSideData C.struct_AVPacketSideData 41 | AvPanScan C.struct_AVPanScan 42 | Picture C.struct_AVPicture 43 | AvProfile C.struct_AVProfile 44 | AvSubtitle C.struct_AVSubtitle 45 | AvSubtitleRect C.struct_AVSubtitleRect 46 | RcOverride C.struct_RcOverride 47 | AvBufferRef C.struct_AVBufferRef 48 | AvAudioServiceType C.enum_AVAudioServiceType 49 | AvChromaLocation C.enum_AVChromaLocation 50 | CodecId C.enum_AVCodecID 51 | AvColorPrimaries C.enum_AVColorPrimaries 52 | AvColorRange C.enum_AVColorRange 53 | AvColorSpace C.enum_AVColorSpace 54 | AvColorTransferCharacteristic C.enum_AVColorTransferCharacteristic 55 | AvDiscard C.enum_AVDiscard 56 | AvFieldOrder C.enum_AVFieldOrder 57 | AvPacketSideDataType C.enum_AVPacketSideDataType 58 | AvSampleFormat C.enum_AVSampleFormat 59 | ) 60 | 61 | const ( 62 | AV_PKT_FLAG_KEY = C.AV_PKT_FLAG_KEY 63 | AV_PKT_FLAG_CORRUPT = C.AV_PKT_FLAG_CORRUPT 64 | AV_PKT_FLAG_DISCARD = C.AV_PKT_FLAG_DISCARD 65 | ) 66 | 67 | const ( 68 | AVDISCARD_NONE = C.AVDISCARD_NONE // discard nothing 69 | AVDISCARD_DEFAULT = C.AVDISCARD_DEFAULT // discard useless packets like 0 size packets in avi 70 | AVDISCARD_NONREF = C.AVDISCARD_NONREF // discard all non reference 71 | AVDISCARD_BIDIR = C.AVDISCARD_BIDIR // discard all bidirectional frames 72 | AVDISCARD_NONINTRA = C.AVDISCARD_NONINTRA // discard all non intra frames 73 | AVDISCARD_NONKEY = C.AVDISCARD_NONKEY // discard all frames except keyframes 74 | AVDISCARD_ALL = C.AVDISCARD_ALL // discard all 75 | ) 76 | 77 | const ( 78 | AVMEDIA_TYPE_ATTACHMENT = C.AVMEDIA_TYPE_ATTACHMENT 79 | AVMEDIA_TYPE_AUDIO = C.AVMEDIA_TYPE_AUDIO 80 | AVMEDIA_TYPE_DATA = C.AVMEDIA_TYPE_DATA 81 | AVMEDIA_TYPE_NB = C.AVMEDIA_TYPE_NB 82 | AVMEDIA_TYPE_SUBTITLE = C.AVMEDIA_TYPE_SUBTITLE 83 | AVMEDIA_TYPE_UNKNOWN = C.AVMEDIA_TYPE_UNKNOWN 84 | AVMEDIA_TYPE_VIDEO = C.AVMEDIA_TYPE_VIDEO 85 | ) 86 | 87 | const ( 88 | AV_PKT_DATA_PALETTE = C.AV_PKT_DATA_PALETTE 89 | AV_PKT_DATA_NEW_EXTRADATA = C.AV_PKT_DATA_NEW_EXTRADATA 90 | AV_PKT_DATA_PARAM_CHANGE = C.AV_PKT_DATA_PARAM_CHANGE 91 | AV_PKT_DATA_H263_MB_INFO = C.AV_PKT_DATA_H263_MB_INFO 92 | AV_PKT_DATA_REPLAYGAIN = C.AV_PKT_DATA_REPLAYGAIN 93 | AV_PKT_DATA_DISPLAYMATRIX = C.AV_PKT_DATA_DISPLAYMATRIX 94 | AV_PKT_DATA_STEREO3D = C.AV_PKT_DATA_STEREO3D 95 | AV_PKT_DATA_AUDIO_SERVICE_TYPE = C.AV_PKT_DATA_AUDIO_SERVICE_TYPE 96 | AV_PKT_DATA_SKIP_SAMPLES = C.AV_PKT_DATA_SKIP_SAMPLES 97 | AV_PKT_DATA_JP_DUALMONO = C.AV_PKT_DATA_JP_DUALMONO 98 | AV_PKT_DATA_STRINGS_METADATA = C.AV_PKT_DATA_STRINGS_METADATA 99 | AV_PKT_DATA_SUBTITLE_POSITION = C.AV_PKT_DATA_SUBTITLE_POSITION 100 | AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL = C.AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL 101 | AV_PKT_DATA_WEBVTT_IDENTIFIER = C.AV_PKT_DATA_WEBVTT_IDENTIFIER 102 | AV_PKT_DATA_WEBVTT_SETTINGS = C.AV_PKT_DATA_WEBVTT_SETTINGS 103 | AV_PKT_DATA_METADATA_UPDATE = C.AV_PKT_DATA_METADATA_UPDATE 104 | AV_PKT_DATA_MPEGTS_STREAM_ID = C.AV_PKT_DATA_MPEGTS_STREAM_ID 105 | AV_PKT_DATA_MASTERING_DISPLAY_METADATA = C.AV_PKT_DATA_MASTERING_DISPLAY_METADATA 106 | AV_PKT_DATA_CONTENT_LIGHT_LEVEL = C.AV_PKT_DATA_CONTENT_LIGHT_LEVEL 107 | AV_PKT_DATA_SPHERICAL = C.AV_PKT_DATA_SPHERICAL 108 | AV_PKT_DATA_A53_CC = C.AV_PKT_DATA_A53_CC 109 | ) 110 | 111 | const ( 112 | FF_THREAD_FRAME = C.FF_THREAD_FRAME 113 | FF_THREAD_SLICE = C.FF_THREAD_SLICE 114 | ) 115 | 116 | const ( 117 | FF_COMPLIANCE_EXPERIMENTAL = C.FF_COMPLIANCE_EXPERIMENTAL 118 | ) 119 | 120 | func (c *Codec) AvCodecGetMaxLowres() int { 121 | panic("deprecated") 122 | return 0 123 | //return int(C.av_codec_get_max_lowres((*C.struct_AVCodec)(c))) 124 | } 125 | 126 | //If c is NULL, returns the first registered codec, if c is non-NULL, 127 | func (c *Codec) AvCodecNext() *Codec { 128 | panic("deprecated") 129 | return nil 130 | //return (*Codec)(C.av_codec_next((*C.struct_AVCodec)(c))) 131 | } 132 | 133 | //Register the codec codec and initialize libavcodec. 134 | func (c *Codec) AvcodecRegister() { 135 | panic("deprecated") 136 | //C.avcodec_register((*C.struct_AVCodec)(c)) 137 | } 138 | 139 | //Return a name for the specified profile, if available. 140 | func (c *Codec) AvGetProfileName(p int) string { 141 | return C.GoString(C.av_get_profile_name((*C.struct_AVCodec)(c), C.int(p))) 142 | } 143 | 144 | //Allocate an Context and set its fields to default values. 145 | func (c *Codec) AvcodecAllocContext3() *Context { 146 | return (*Context)(unsafe.Pointer(C.avcodec_alloc_context3((*C.struct_AVCodec)(c)))) 147 | } 148 | 149 | func (c *Codec) AvCodecIsEncoder() int { 150 | return int(C.av_codec_is_encoder((*C.struct_AVCodec)(c))) 151 | } 152 | 153 | func (c *Codec) AvCodecIsDecoder() int { 154 | return int(C.av_codec_is_decoder((*C.struct_AVCodec)(c))) 155 | } 156 | 157 | func (c *Codec) SupportedSamplerates() []int { 158 | r := make([]int, 0) 159 | if c.supported_samplerates == nil { 160 | return r 161 | } 162 | size := unsafe.Sizeof(*c.supported_samplerates) 163 | for i := 0; ; i++ { 164 | p := *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(c.supported_samplerates)) + uintptr(i)*size)) 165 | if p == 0 { 166 | break 167 | } 168 | r = append(r, int(p)) 169 | } 170 | return r 171 | } 172 | 173 | func (c *Codec) SampleFmts() []AvSampleFormat { 174 | r := make([]AvSampleFormat, 0) 175 | if c.sample_fmts == nil { 176 | return r 177 | } 178 | size := unsafe.Sizeof(*c.sample_fmts) 179 | for i := 0; ; i++ { 180 | p := *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(c.sample_fmts)) + uintptr(i)*size)) 181 | if p == C.AV_SAMPLE_FMT_NONE { 182 | break 183 | } 184 | r = append(r, AvSampleFormat(p)) 185 | } 186 | return r 187 | } 188 | 189 | func (c *Codec) ChannelLayouts() []uint64 { 190 | r := make([]uint64, 0) 191 | if c.channel_layouts == nil { 192 | return r 193 | } 194 | size := unsafe.Sizeof(*c.channel_layouts) 195 | for i := 0; ; i++ { 196 | p := *(*C.uint64_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.channel_layouts)) + uintptr(i)*size)) 197 | if p == 0 { 198 | break 199 | } 200 | r = append(r, uint64(p)) 201 | } 202 | return r 203 | } 204 | 205 | //Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0. 206 | func AvFastPaddedMalloc(p unsafe.Pointer, s *uint, t uintptr) { 207 | C.av_fast_padded_malloc(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(t)) 208 | } 209 | 210 | //Return the LIBAvCODEC_VERSION_INT constant. 211 | func AvcodecVersion() uint { 212 | return uint(C.avcodec_version()) 213 | } 214 | 215 | //Return the libavcodec build-time configuration. 216 | func AvcodecConfiguration() string { 217 | return C.GoString(C.avcodec_configuration()) 218 | 219 | } 220 | 221 | //Return the libavcodec license. 222 | func AvcodecLicense() string { 223 | return C.GoString(C.avcodec_license()) 224 | } 225 | 226 | //Get the Class for Context. 227 | func AvcodecGetClass() *Class { 228 | return (*Class)(C.avcodec_get_class()) 229 | } 230 | 231 | //Get the Class for Frame. 232 | func AvcodecGetFrameClass() *Class { 233 | return (*Class)(C.avcodec_get_frame_class()) 234 | } 235 | 236 | //Get the Class for AvSubtitleRect. 237 | func AvcodecGetSubtitleRectClass() *Class { 238 | return (*Class)(C.avcodec_get_subtitle_rect_class()) 239 | } 240 | 241 | //Free all allocated data in the given subtitle struct. 242 | func AvsubtitleFree(s *AvSubtitle) { 243 | C.avsubtitle_free((*C.struct_AVSubtitle)(s)) 244 | } 245 | 246 | //Pack a dictionary for use in side_data. 247 | func AvPacketPackDictionary(d *avutil.Dictionary, s *int) *uint8 { 248 | return (*uint8)(C.av_packet_pack_dictionary((*C.struct_AVDictionary)(d), (*C.int)(unsafe.Pointer(s)))) 249 | } 250 | 251 | //Unpack a dictionary from side_data. 252 | func AvPacketUnpackDictionary(d *uint8, s int, dt **avutil.Dictionary) int { 253 | return int(C.av_packet_unpack_dictionary((*C.uint8_t)(d), C.int(s), (**C.struct_AVDictionary)(unsafe.Pointer(dt)))) 254 | } 255 | 256 | //Find a registered decoder with a matching codec ID. 257 | func AvcodecFindDecoder(id CodecId) *Codec { 258 | return (*Codec)(C.avcodec_find_decoder((C.enum_AVCodecID)(id))) 259 | } 260 | 261 | //Find a registered decoder with the specified name. 262 | func AvcodecFindDecoderByName(n string) *Codec { 263 | cn := C.CString(n) 264 | defer C.free(unsafe.Pointer(cn)) 265 | return (*Codec)(C.avcodec_find_decoder_by_name(cn)) 266 | } 267 | 268 | //Converts AvChromaLocation to swscale x/y chroma position. 269 | func AvcodecEnumToChromaPos(x, y *int, l AvChromaLocation) int { 270 | return int(C.avcodec_enum_to_chroma_pos((*C.int)(unsafe.Pointer(x)), (*C.int)(unsafe.Pointer(y)), (C.enum_AVChromaLocation)(l))) 271 | } 272 | 273 | //Converts swscale x/y chroma position to AvChromaLocation. 274 | func AvcodecChromaPosToEnum(x, y int) AvChromaLocation { 275 | return (AvChromaLocation)(C.avcodec_chroma_pos_to_enum(C.int(x), C.int(y))) 276 | } 277 | 278 | //Find a registered encoder with a matching codec ID. 279 | func AvcodecFindEncoder(id CodecId) *Codec { 280 | return (*Codec)(C.avcodec_find_encoder((C.enum_AVCodecID)(id))) 281 | } 282 | 283 | //Find a registered encoder with the specified name. 284 | func AvcodecFindEncoderByName(c string) *Codec { 285 | cc := C.CString(c) 286 | defer C.free(unsafe.Pointer(cc)) 287 | return (*Codec)(C.avcodec_find_encoder_by_name(cc)) 288 | } 289 | 290 | //Put a string representing the codec tag codec_tag in buf. 291 | // Deprecated 292 | // func AvGetCodecTagString(b string, bf uintptr, c uint) uintptr { 293 | // return uintptr(C.av_get_codec_tag_string(C.CString(b), C.size_t(bf), C.uint(c))) 294 | // } 295 | 296 | func AvcodecString(b string, bs int, ctxt *Context, e int) { 297 | cb := C.CString(b) 298 | defer C.free(unsafe.Pointer(cb)) 299 | C.avcodec_string(cb, C.int(bs), (*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), C.int(e)) 300 | } 301 | 302 | //Fill Frame audio data and linesize pointers. 303 | func AvcodecFillAudioFrame(f *Frame, c int, s AvSampleFormat, b *uint8, bs, a int) int { 304 | return int(C.avcodec_fill_audio_frame((*C.struct_AVFrame)(f), C.int(c), (C.enum_AVSampleFormat)(s), (*C.uint8_t)(b), C.int(bs), C.int(a))) 305 | } 306 | 307 | //Return codec bits per sample. 308 | func AvGetBitsPerSample(c CodecId) int { 309 | return int(C.av_get_bits_per_sample((C.enum_AVCodecID)(c))) 310 | } 311 | 312 | //Return the PCM codec associated with a sample format. 313 | func AvGetPcmCodec(f AvSampleFormat, b int) CodecId { 314 | return (CodecId)(C.av_get_pcm_codec((C.enum_AVSampleFormat)(f), C.int(b))) 315 | } 316 | 317 | //Return codec bits per sample. 318 | func AvGetExactBitsPerSample(c CodecId) int { 319 | return int(C.av_get_exact_bits_per_sample((C.enum_AVCodecID)(c))) 320 | } 321 | 322 | //Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call. 323 | func AvFastPaddedMallocz(p unsafe.Pointer, s *uint, t uintptr) { 324 | C.av_fast_padded_mallocz(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(t)) 325 | } 326 | 327 | //Encode extradata length to a buffer. 328 | func AvXiphlacing(s *string, v uint) uint { 329 | return uint(C.av_xiphlacing((*C.uchar)(unsafe.Pointer(s)), (C.uint)(v))) 330 | } 331 | 332 | //If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL, 333 | //returns the next registered hardware accelerator after hwaccel, or NULL if hwaccel is the last one. 334 | func (a *AvHWAccel) AvHwaccelNext() *AvHWAccel { 335 | panic("deprecated") 336 | return nil 337 | //return (*AvHWAccel)(C.av_hwaccel_next((*C.struct_AVHWAccel)(a))) 338 | } 339 | 340 | //Get the type of the given codec. 341 | func AvcodecGetType(c CodecId) MediaType { 342 | return (MediaType)(C.avcodec_get_type((C.enum_AVCodecID)(c))) 343 | } 344 | 345 | //Get the name of a codec. 346 | func AvcodecGetName(d CodecId) string { 347 | return C.GoString(C.avcodec_get_name((C.enum_AVCodecID)(d))) 348 | } 349 | 350 | //const Descriptor *avcodec_descriptor_get (enum CodecId id) 351 | func AvcodecDescriptorGet(id CodecId) *Descriptor { 352 | return (*Descriptor)(C.avcodec_descriptor_get((C.enum_AVCodecID)(id))) 353 | } 354 | 355 | func (d *Descriptor) Name() string { 356 | return C.GoString(d.name) 357 | } 358 | 359 | //Iterate over all codec descriptors known to libavcodec. 360 | func (d *Descriptor) AvcodecDescriptorNext() *Descriptor { 361 | return (*Descriptor)(C.avcodec_descriptor_next((*C.struct_AVCodecDescriptor)(d))) 362 | } 363 | 364 | func AvcodecDescriptorGetByName(n string) *Descriptor { 365 | cn := C.CString(n) 366 | defer C.free(unsafe.Pointer(cn)) 367 | return (*Descriptor)(C.avcodec_descriptor_get_by_name(cn)) 368 | } 369 | 370 | func AvcodecReceivePacket(avctx *Context, avpkt *Packet) int { 371 | return int(C.avcodec_receive_packet((*C.struct_AVCodecContext)(avctx), (*C.struct_AVPacket)(avpkt))) 372 | } 373 | 374 | // AvcodecSendPacket send packet data as input to a decoder. 375 | // See the ffmpeg documentation: https://www.ffmpeg.org/doxygen/trunk/group__lavc__encdec.html 376 | func AvcodecSendPacket(avctx *Context, avpkt *Packet) int { 377 | return int(C.avcodec_send_packet((*C.struct_AVCodecContext)(avctx), (*C.struct_AVPacket)(avpkt))) 378 | } 379 | 380 | // AvcodecReceiveFrame receives a frame from the codec 381 | // See the ffmpeg documentation: https://www.ffmpeg.org/doxygen/trunk/group__lavc__encdec.html 382 | func AvcodecReceiveFrame(avctx *Context, frame *avutil.Frame) int { 383 | return int(C.avcodec_receive_frame((*C.struct_AVCodecContext)(avctx), (*C.struct_AVFrame)(unsafe.Pointer(frame)))) 384 | } 385 | 386 | func AvcodecSendFrame(avctx *Context, frame *avutil.Frame) int { 387 | return int(C.avcodec_send_frame((*C.struct_AVCodecContext)(avctx), (*C.struct_AVFrame)(unsafe.Pointer(frame)))) 388 | } 389 | -------------------------------------------------------------------------------- /avcodec/codecparameters.go: -------------------------------------------------------------------------------- 1 | package avcodec 2 | 3 | //#include 4 | import "C" 5 | 6 | func AvcodecParametersToContext(codecContext *Context, codecParameters *CodecParameters) int { 7 | return int(C.avcodec_parameters_to_context((*C.struct_AVCodecContext)(codecContext), (*C.struct_AVCodecParameters)(codecParameters))) 8 | } 9 | 10 | func AvcodecParametersFromContext(codecParameters *CodecParameters, codecContext *Context) int { 11 | return int(C.avcodec_parameters_from_context((*C.struct_AVCodecParameters)(codecParameters), (*C.struct_AVCodecContext)(codecContext))) 12 | } 13 | 14 | func AvcodecParametersCopy(out, in *CodecParameters) int { 15 | return int(C.avcodec_parameters_copy((*C.struct_AVCodecParameters)(out), (*C.struct_AVCodecParameters)(in))) 16 | } 17 | -------------------------------------------------------------------------------- /avcodec/codecparameters_struct.go: -------------------------------------------------------------------------------- 1 | package avcodec 2 | import "C" 3 | 4 | func (cp *CodecParameters) CodecType() MediaType { 5 | return MediaType(cp.codec_type) 6 | } 7 | 8 | func (cp *CodecParameters) CodecId() CodecId { 9 | return CodecId(cp.codec_id) 10 | } 11 | 12 | func (cp *CodecParameters) SetCodecTag(tag uint) { 13 | cp.codec_tag = C.uint(tag) 14 | } 15 | -------------------------------------------------------------------------------- /avcodec/codecs.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avcodec 5 | 6 | //#cgo pkg-config: libavformat 7 | //#include 8 | import "C" 9 | 10 | // Multiple encoders have the same ID and are able to encode compatible streams. 11 | const ( 12 | AV_CODEC_ID_012V = int(C.AV_CODEC_ID_012V) 13 | AV_CODEC_ID_4XM = int(C.AV_CODEC_ID_4XM) 14 | AV_CODEC_ID_8BPS = int(C.AV_CODEC_ID_8BPS) 15 | AV_CODEC_ID_8SVX_EXP = int(C.AV_CODEC_ID_8SVX_EXP) 16 | AV_CODEC_ID_8SVX_FIB = int(C.AV_CODEC_ID_8SVX_FIB) 17 | AV_CODEC_ID_A64_MULTI = int(C.AV_CODEC_ID_A64_MULTI) 18 | AV_CODEC_ID_A64_MULTI5 = int(C.AV_CODEC_ID_A64_MULTI5) 19 | AV_CODEC_ID_AAC = int(C.AV_CODEC_ID_AAC) 20 | AV_CODEC_ID_AAC_LATM = int(C.AV_CODEC_ID_AAC_LATM) 21 | AV_CODEC_ID_AASC = int(C.AV_CODEC_ID_AASC) 22 | AV_CODEC_ID_AC3 = int(C.AV_CODEC_ID_AC3) 23 | AV_CODEC_ID_ADPCM_4XM = int(C.AV_CODEC_ID_ADPCM_4XM) 24 | AV_CODEC_ID_ADPCM_ADX = int(C.AV_CODEC_ID_ADPCM_ADX) 25 | AV_CODEC_ID_ADPCM_AFC = int(C.AV_CODEC_ID_ADPCM_AFC) 26 | AV_CODEC_ID_ADPCM_CT = int(C.AV_CODEC_ID_ADPCM_CT) 27 | AV_CODEC_ID_ADPCM_DTK = int(C.AV_CODEC_ID_ADPCM_DTK) 28 | AV_CODEC_ID_ADPCM_EA = int(C.AV_CODEC_ID_ADPCM_EA) 29 | AV_CODEC_ID_ADPCM_EA_MAXIS_XA = int(C.AV_CODEC_ID_ADPCM_EA_MAXIS_XA) 30 | AV_CODEC_ID_ADPCM_EA_R1 = int(C.AV_CODEC_ID_ADPCM_EA_R1) 31 | AV_CODEC_ID_ADPCM_EA_R2 = int(C.AV_CODEC_ID_ADPCM_EA_R2) 32 | AV_CODEC_ID_ADPCM_EA_R3 = int(C.AV_CODEC_ID_ADPCM_EA_R3) 33 | AV_CODEC_ID_ADPCM_EA_XAS = int(C.AV_CODEC_ID_ADPCM_EA_XAS) 34 | AV_CODEC_ID_ADPCM_G722 = int(C.AV_CODEC_ID_ADPCM_G722) 35 | AV_CODEC_ID_ADPCM_G726 = int(C.AV_CODEC_ID_ADPCM_G726) 36 | AV_CODEC_ID_ADPCM_G726LE = int(C.AV_CODEC_ID_ADPCM_G726LE) 37 | AV_CODEC_ID_ADPCM_IMA_AMV = int(C.AV_CODEC_ID_ADPCM_IMA_AMV) 38 | AV_CODEC_ID_ADPCM_IMA_APC = int(C.AV_CODEC_ID_ADPCM_IMA_APC) 39 | AV_CODEC_ID_ADPCM_IMA_DK3 = int(C.AV_CODEC_ID_ADPCM_IMA_DK3) 40 | AV_CODEC_ID_ADPCM_IMA_DK4 = int(C.AV_CODEC_ID_ADPCM_IMA_DK4) 41 | AV_CODEC_ID_ADPCM_IMA_EA_EACS = int(C.AV_CODEC_ID_ADPCM_IMA_EA_EACS) 42 | AV_CODEC_ID_ADPCM_IMA_EA_SEAD = int(C.AV_CODEC_ID_ADPCM_IMA_EA_SEAD) 43 | AV_CODEC_ID_ADPCM_IMA_ISS = int(C.AV_CODEC_ID_ADPCM_IMA_ISS) 44 | AV_CODEC_ID_ADPCM_IMA_OKI = int(C.AV_CODEC_ID_ADPCM_IMA_OKI) 45 | AV_CODEC_ID_ADPCM_IMA_QT = int(C.AV_CODEC_ID_ADPCM_IMA_QT) 46 | AV_CODEC_ID_ADPCM_IMA_RAD = int(C.AV_CODEC_ID_ADPCM_IMA_RAD) 47 | AV_CODEC_ID_ADPCM_IMA_SMJPEG = int(C.AV_CODEC_ID_ADPCM_IMA_SMJPEG) 48 | AV_CODEC_ID_ADPCM_IMA_WAV = int(C.AV_CODEC_ID_ADPCM_IMA_WAV) 49 | AV_CODEC_ID_ADPCM_IMA_WS = int(C.AV_CODEC_ID_ADPCM_IMA_WS) 50 | AV_CODEC_ID_ADPCM_MS = int(C.AV_CODEC_ID_ADPCM_MS) 51 | AV_CODEC_ID_ADPCM_SBPRO_2 = int(C.AV_CODEC_ID_ADPCM_SBPRO_2) 52 | AV_CODEC_ID_ADPCM_SBPRO_3 = int(C.AV_CODEC_ID_ADPCM_SBPRO_3) 53 | AV_CODEC_ID_ADPCM_SBPRO_4 = int(C.AV_CODEC_ID_ADPCM_SBPRO_4) 54 | AV_CODEC_ID_ADPCM_SWF = int(C.AV_CODEC_ID_ADPCM_SWF) 55 | AV_CODEC_ID_ADPCM_THP = int(C.AV_CODEC_ID_ADPCM_THP) 56 | AV_CODEC_ID_ADPCM_VIMA = int(C.AV_CODEC_ID_ADPCM_VIMA) 57 | AV_CODEC_ID_ADPCM_VIMA_DEPRECATED = int(C.AV_CODEC_ID_ADPCM_VIMA) 58 | AV_CODEC_ID_ADPCM_XA = int(C.AV_CODEC_ID_ADPCM_XA) 59 | AV_CODEC_ID_ADPCM_YAMAHA = int(C.AV_CODEC_ID_ADPCM_YAMAHA) 60 | AV_CODEC_ID_AIC = int(C.AV_CODEC_ID_AIC) 61 | AV_CODEC_ID_ALAC = int(C.AV_CODEC_ID_ALAC) 62 | AV_CODEC_ID_ALIAS_PIX = int(C.AV_CODEC_ID_ALIAS_PIX) 63 | AV_CODEC_ID_AMR_NB = int(C.AV_CODEC_ID_AMR_NB) 64 | AV_CODEC_ID_AMR_WB = int(C.AV_CODEC_ID_AMR_WB) 65 | AV_CODEC_ID_AMV = int(C.AV_CODEC_ID_AMV) 66 | AV_CODEC_ID_ANM = int(C.AV_CODEC_ID_ANM) 67 | AV_CODEC_ID_ANSI = int(C.AV_CODEC_ID_ANSI) 68 | AV_CODEC_ID_APE = int(C.AV_CODEC_ID_APE) 69 | AV_CODEC_ID_ASS = int(C.AV_CODEC_ID_ASS) 70 | AV_CODEC_ID_ASV1 = int(C.AV_CODEC_ID_ASV1) 71 | AV_CODEC_ID_ASV2 = int(C.AV_CODEC_ID_ASV2) 72 | AV_CODEC_ID_ATRAC1 = int(C.AV_CODEC_ID_ATRAC1) 73 | AV_CODEC_ID_ATRAC3 = int(C.AV_CODEC_ID_ATRAC3) 74 | AV_CODEC_ID_ATRAC3P = int(C.AV_CODEC_ID_ATRAC3P) 75 | AV_CODEC_ID_AURA = int(C.AV_CODEC_ID_AURA) 76 | AV_CODEC_ID_AURA2 = int(C.AV_CODEC_ID_AURA2) 77 | AV_CODEC_ID_AVRN = int(C.AV_CODEC_ID_AVRN) 78 | AV_CODEC_ID_AVRP = int(C.AV_CODEC_ID_AVRP) 79 | AV_CODEC_ID_AVS = int(C.AV_CODEC_ID_AVS) 80 | AV_CODEC_ID_AVUI = int(C.AV_CODEC_ID_AVUI) 81 | AV_CODEC_ID_AYUV = int(C.AV_CODEC_ID_AYUV) 82 | AV_CODEC_ID_BETHSOFTVID = int(C.AV_CODEC_ID_BETHSOFTVID) 83 | AV_CODEC_ID_BFI = int(C.AV_CODEC_ID_BFI) 84 | AV_CODEC_ID_BINKAUDIO_DCT = int(C.AV_CODEC_ID_BINKAUDIO_DCT) 85 | AV_CODEC_ID_BINKAUDIO_RDFT = int(C.AV_CODEC_ID_BINKAUDIO_RDFT) 86 | AV_CODEC_ID_BINKVIDEO = int(C.AV_CODEC_ID_BINKVIDEO) 87 | AV_CODEC_ID_BINTEXT = int(C.AV_CODEC_ID_BINTEXT) 88 | AV_CODEC_ID_BIN_DATA = int(C.AV_CODEC_ID_BIN_DATA) 89 | AV_CODEC_ID_BMP = int(C.AV_CODEC_ID_BMP) 90 | AV_CODEC_ID_BMV_AUDIO = int(C.AV_CODEC_ID_BMV_AUDIO) 91 | AV_CODEC_ID_BMV_VIDEO = int(C.AV_CODEC_ID_BMV_VIDEO) 92 | AV_CODEC_ID_BRENDER_PIX = int(C.AV_CODEC_ID_BRENDER_PIX) 93 | AV_CODEC_ID_BRENDER_PIX_DEPRECATED = int(C.AV_CODEC_ID_BRENDER_PIX) 94 | AV_CODEC_ID_C93 = int(C.AV_CODEC_ID_C93) 95 | AV_CODEC_ID_CAVS = int(C.AV_CODEC_ID_CAVS) 96 | AV_CODEC_ID_CDGRAPHICS = int(C.AV_CODEC_ID_CDGRAPHICS) 97 | AV_CODEC_ID_CDXL = int(C.AV_CODEC_ID_CDXL) 98 | AV_CODEC_ID_CELT = int(C.AV_CODEC_ID_CELT) 99 | AV_CODEC_ID_CINEPAK = int(C.AV_CODEC_ID_CINEPAK) 100 | AV_CODEC_ID_CLJR = int(C.AV_CODEC_ID_CLJR) 101 | AV_CODEC_ID_CLLC = int(C.AV_CODEC_ID_CLLC) 102 | AV_CODEC_ID_CMV = int(C.AV_CODEC_ID_CMV) 103 | AV_CODEC_ID_COMFORT_NOISE = int(C.AV_CODEC_ID_COMFORT_NOISE) 104 | AV_CODEC_ID_COOK = int(C.AV_CODEC_ID_COOK) 105 | AV_CODEC_ID_CPIA = int(C.AV_CODEC_ID_CPIA) 106 | AV_CODEC_ID_CSCD = int(C.AV_CODEC_ID_CSCD) 107 | AV_CODEC_ID_CYUV = int(C.AV_CODEC_ID_CYUV) 108 | AV_CODEC_ID_DFA = int(C.AV_CODEC_ID_DFA) 109 | AV_CODEC_ID_DIRAC = int(C.AV_CODEC_ID_DIRAC) 110 | AV_CODEC_ID_DNXHD = int(C.AV_CODEC_ID_DNXHD) 111 | AV_CODEC_ID_DPX = int(C.AV_CODEC_ID_DPX) 112 | AV_CODEC_ID_DSD_LSBF = int(C.AV_CODEC_ID_DSD_LSBF) 113 | AV_CODEC_ID_DSD_LSBF_PLANAR = int(C.AV_CODEC_ID_DSD_LSBF_PLANAR) 114 | AV_CODEC_ID_DSD_MSBF = int(C.AV_CODEC_ID_DSD_MSBF) 115 | AV_CODEC_ID_DSD_MSBF_PLANAR = int(C.AV_CODEC_ID_DSD_MSBF_PLANAR) 116 | AV_CODEC_ID_DSICINAUDIO = int(C.AV_CODEC_ID_DSICINAUDIO) 117 | AV_CODEC_ID_DSICINVIDEO = int(C.AV_CODEC_ID_DSICINVIDEO) 118 | AV_CODEC_ID_DTS = int(C.AV_CODEC_ID_DTS) 119 | AV_CODEC_ID_DVAUDIO = int(C.AV_CODEC_ID_DVAUDIO) 120 | AV_CODEC_ID_DVB_SUBTITLE = int(C.AV_CODEC_ID_DVB_SUBTITLE) 121 | AV_CODEC_ID_DVB_TELETEXT = int(C.AV_CODEC_ID_DVB_TELETEXT) 122 | AV_CODEC_ID_DVD_NAV = int(C.AV_CODEC_ID_DVD_NAV) 123 | AV_CODEC_ID_DVD_SUBTITLE = int(C.AV_CODEC_ID_DVD_SUBTITLE) 124 | AV_CODEC_ID_DVVIDEO = int(C.AV_CODEC_ID_DVVIDEO) 125 | AV_CODEC_ID_DXA = int(C.AV_CODEC_ID_DXA) 126 | AV_CODEC_ID_DXTORY = int(C.AV_CODEC_ID_DXTORY) 127 | AV_CODEC_ID_EAC3 = int(C.AV_CODEC_ID_EAC3) 128 | AV_CODEC_ID_EIA_608 = int(C.AV_CODEC_ID_EIA_608) 129 | AV_CODEC_ID_ESCAPE124 = int(C.AV_CODEC_ID_ESCAPE124) 130 | AV_CODEC_ID_ESCAPE130 = int(C.AV_CODEC_ID_ESCAPE130) 131 | AV_CODEC_ID_ESCAPE130_DEPRECATED = int(C.AV_CODEC_ID_ESCAPE130) 132 | AV_CODEC_ID_EVRC = int(C.AV_CODEC_ID_EVRC) 133 | AV_CODEC_ID_EXR = int(C.AV_CODEC_ID_EXR) 134 | AV_CODEC_ID_EXR_DEPRECATED = int(C.AV_CODEC_ID_EXR) 135 | AV_CODEC_ID_FFMETADATA = int(C.AV_CODEC_ID_FFMETADATA) 136 | AV_CODEC_ID_FFV1 = int(C.AV_CODEC_ID_FFV1) 137 | AV_CODEC_ID_FFVHUFF = int(C.AV_CODEC_ID_FFVHUFF) 138 | AV_CODEC_ID_FFWAVESYNTH = int(C.AV_CODEC_ID_FFWAVESYNTH) 139 | AV_CODEC_ID_FIC = int(C.AV_CODEC_ID_FIC) 140 | AV_CODEC_ID_FIRST_AUDIO = int(C.AV_CODEC_ID_FIRST_AUDIO) 141 | AV_CODEC_ID_FIRST_SUBTITLE = int(C.AV_CODEC_ID_FIRST_SUBTITLE) 142 | AV_CODEC_ID_FIRST_UNKNOWN = int(C.AV_CODEC_ID_FIRST_UNKNOWN) 143 | AV_CODEC_ID_FLAC = int(C.AV_CODEC_ID_FLAC) 144 | AV_CODEC_ID_FLASHSV = int(C.AV_CODEC_ID_FLASHSV) 145 | AV_CODEC_ID_FLASHSV2 = int(C.AV_CODEC_ID_FLASHSV2) 146 | AV_CODEC_ID_FLIC = int(C.AV_CODEC_ID_FLIC) 147 | AV_CODEC_ID_FLV1 = int(C.AV_CODEC_ID_FLV1) 148 | AV_CODEC_ID_FRAPS = int(C.AV_CODEC_ID_FRAPS) 149 | AV_CODEC_ID_FRWU = int(C.AV_CODEC_ID_FRWU) 150 | AV_CODEC_ID_G2M = int(C.AV_CODEC_ID_G2M) 151 | AV_CODEC_ID_G2M_DEPRECATED = int(C.AV_CODEC_ID_G2M) 152 | AV_CODEC_ID_G723_1 = int(C.AV_CODEC_ID_G723_1) 153 | AV_CODEC_ID_G729 = int(C.AV_CODEC_ID_G729) 154 | AV_CODEC_ID_GIF = int(C.AV_CODEC_ID_GIF) 155 | AV_CODEC_ID_GSM = int(C.AV_CODEC_ID_GSM) 156 | AV_CODEC_ID_GSM_MS = int(C.AV_CODEC_ID_GSM_MS) 157 | AV_CODEC_ID_H261 = int(C.AV_CODEC_ID_H261) 158 | AV_CODEC_ID_H263 = int(C.AV_CODEC_ID_H263) 159 | AV_CODEC_ID_H263I = int(C.AV_CODEC_ID_H263I) 160 | AV_CODEC_ID_H263P = int(C.AV_CODEC_ID_H263P) 161 | AV_CODEC_ID_H264 = int(C.AV_CODEC_ID_H264) 162 | AV_CODEC_ID_HDMV_PGS_SUBTITLE = int(C.AV_CODEC_ID_HDMV_PGS_SUBTITLE) 163 | AV_CODEC_ID_HEVC = int(C.AV_CODEC_ID_HEVC) 164 | AV_CODEC_ID_HEVC_DEPRECATED = int(C.AV_CODEC_ID_HEVC) 165 | AV_CODEC_ID_HNM4_VIDEO = int(C.AV_CODEC_ID_HNM4_VIDEO) 166 | AV_CODEC_ID_HUFFYUV = int(C.AV_CODEC_ID_HUFFYUV) 167 | AV_CODEC_ID_IAC = int(C.AV_CODEC_ID_IAC) 168 | AV_CODEC_ID_IDCIN = int(C.AV_CODEC_ID_IDCIN) 169 | AV_CODEC_ID_IDF = int(C.AV_CODEC_ID_IDF) 170 | AV_CODEC_ID_IFF_BYTERUN1 = int(C.AV_CODEC_ID_IFF_BYTERUN1) 171 | AV_CODEC_ID_IFF_ILBM = int(C.AV_CODEC_ID_IFF_ILBM) 172 | AV_CODEC_ID_ILBC = int(C.AV_CODEC_ID_ILBC) 173 | AV_CODEC_ID_IMC = int(C.AV_CODEC_ID_IMC) 174 | AV_CODEC_ID_INDEO2 = int(C.AV_CODEC_ID_INDEO2) 175 | AV_CODEC_ID_INDEO3 = int(C.AV_CODEC_ID_INDEO3) 176 | AV_CODEC_ID_INDEO4 = int(C.AV_CODEC_ID_INDEO4) 177 | AV_CODEC_ID_INDEO5 = int(C.AV_CODEC_ID_INDEO5) 178 | AV_CODEC_ID_INTERPLAY_DPCM = int(C.AV_CODEC_ID_INTERPLAY_DPCM) 179 | AV_CODEC_ID_INTERPLAY_VIDEO = int(C.AV_CODEC_ID_INTERPLAY_VIDEO) 180 | AV_CODEC_ID_JACOSUB = int(C.AV_CODEC_ID_JACOSUB) 181 | AV_CODEC_ID_JPEG2000 = int(C.AV_CODEC_ID_JPEG2000) 182 | AV_CODEC_ID_JPEGLS = int(C.AV_CODEC_ID_JPEGLS) 183 | AV_CODEC_ID_JV = int(C.AV_CODEC_ID_JV) 184 | AV_CODEC_ID_KGV1 = int(C.AV_CODEC_ID_KGV1) 185 | AV_CODEC_ID_KMVC = int(C.AV_CODEC_ID_KMVC) 186 | AV_CODEC_ID_LAGARITH = int(C.AV_CODEC_ID_LAGARITH) 187 | AV_CODEC_ID_LJPEG = int(C.AV_CODEC_ID_LJPEG) 188 | AV_CODEC_ID_LOCO = int(C.AV_CODEC_ID_LOCO) 189 | AV_CODEC_ID_MACE3 = int(C.AV_CODEC_ID_MACE3) 190 | AV_CODEC_ID_MACE6 = int(C.AV_CODEC_ID_MACE6) 191 | AV_CODEC_ID_MAD = int(C.AV_CODEC_ID_MAD) 192 | AV_CODEC_ID_MDEC = int(C.AV_CODEC_ID_MDEC) 193 | AV_CODEC_ID_METASOUND = int(C.AV_CODEC_ID_METASOUND) 194 | AV_CODEC_ID_MICRODVD = int(C.AV_CODEC_ID_MICRODVD) 195 | AV_CODEC_ID_MIMIC = int(C.AV_CODEC_ID_MIMIC) 196 | AV_CODEC_ID_MJPEG = int(C.AV_CODEC_ID_MJPEG) 197 | AV_CODEC_ID_MJPEGB = int(C.AV_CODEC_ID_MJPEGB) 198 | AV_CODEC_ID_MLP = int(C.AV_CODEC_ID_MLP) 199 | AV_CODEC_ID_MMVIDEO = int(C.AV_CODEC_ID_MMVIDEO) 200 | AV_CODEC_ID_MOTIONPIXELS = int(C.AV_CODEC_ID_MOTIONPIXELS) 201 | AV_CODEC_ID_MOV_TEXT = int(C.AV_CODEC_ID_MOV_TEXT) 202 | AV_CODEC_ID_MP1 = int(C.AV_CODEC_ID_MP1) 203 | AV_CODEC_ID_MP2 = int(C.AV_CODEC_ID_MP2) 204 | AV_CODEC_ID_MP3 = int(C.AV_CODEC_ID_MP3) 205 | AV_CODEC_ID_MP3ADU = int(C.AV_CODEC_ID_MP3ADU) 206 | AV_CODEC_ID_MP3ON4 = int(C.AV_CODEC_ID_MP3ON4) 207 | AV_CODEC_ID_MP4ALS = int(C.AV_CODEC_ID_MP4ALS) 208 | AV_CODEC_ID_MPEG1VIDEO = int(C.AV_CODEC_ID_MPEG1VIDEO) 209 | AV_CODEC_ID_MPEG2TS = int(C.AV_CODEC_ID_MPEG2TS) 210 | AV_CODEC_ID_MPEG2VIDEO = int(C.AV_CODEC_ID_MPEG2VIDEO) 211 | AV_CODEC_ID_MPEG4 = int(C.AV_CODEC_ID_MPEG4) 212 | AV_CODEC_ID_MPEG4SYSTEMS = int(C.AV_CODEC_ID_MPEG4SYSTEMS) 213 | AV_CODEC_ID_MPL2 = int(C.AV_CODEC_ID_MPL2) 214 | AV_CODEC_ID_MSA1 = int(C.AV_CODEC_ID_MSA1) 215 | AV_CODEC_ID_MSMPEG4V1 = int(C.AV_CODEC_ID_MSMPEG4V1) 216 | AV_CODEC_ID_MSMPEG4V2 = int(C.AV_CODEC_ID_MSMPEG4V2) 217 | AV_CODEC_ID_MSMPEG4V3 = int(C.AV_CODEC_ID_MSMPEG4V3) 218 | AV_CODEC_ID_MSRLE = int(C.AV_CODEC_ID_MSRLE) 219 | AV_CODEC_ID_MSS1 = int(C.AV_CODEC_ID_MSS1) 220 | AV_CODEC_ID_MSS2 = int(C.AV_CODEC_ID_MSS2) 221 | AV_CODEC_ID_MSVIDEO1 = int(C.AV_CODEC_ID_MSVIDEO1) 222 | AV_CODEC_ID_MSZH = int(C.AV_CODEC_ID_MSZH) 223 | AV_CODEC_ID_MTS2 = int(C.AV_CODEC_ID_MTS2) 224 | AV_CODEC_ID_MUSEPACK7 = int(C.AV_CODEC_ID_MUSEPACK7) 225 | AV_CODEC_ID_MUSEPACK8 = int(C.AV_CODEC_ID_MUSEPACK8) 226 | AV_CODEC_ID_MVC1 = int(C.AV_CODEC_ID_MVC1) 227 | AV_CODEC_ID_MVC1_DEPRECATED = int(C.AV_CODEC_ID_MVC1) 228 | AV_CODEC_ID_MVC2 = int(C.AV_CODEC_ID_MVC2) 229 | AV_CODEC_ID_MVC2_DEPRECATED = int(C.AV_CODEC_ID_MVC2) 230 | AV_CODEC_ID_MXPEG = int(C.AV_CODEC_ID_MXPEG) 231 | AV_CODEC_ID_NELLYMOSER = int(C.AV_CODEC_ID_NELLYMOSER) 232 | AV_CODEC_ID_NONE = int(C.AV_CODEC_ID_NONE) 233 | AV_CODEC_ID_NUV = int(C.AV_CODEC_ID_NUV) 234 | AV_CODEC_ID_ON2AVC = int(C.AV_CODEC_ID_ON2AVC) 235 | AV_CODEC_ID_OPUS = int(C.AV_CODEC_ID_OPUS) 236 | AV_CODEC_ID_OPUS_DEPRECATED = int(C.AV_CODEC_ID_OPUS) 237 | AV_CODEC_ID_OTF = int(C.AV_CODEC_ID_OTF) 238 | AV_CODEC_ID_PAF_AUDIO = int(C.AV_CODEC_ID_PAF_AUDIO) 239 | AV_CODEC_ID_PAF_AUDIO_DEPRECATED = int(C.AV_CODEC_ID_PAF_AUDIO) 240 | AV_CODEC_ID_PAF_VIDEO = int(C.AV_CODEC_ID_PAF_VIDEO) 241 | AV_CODEC_ID_PAF_VIDEO_DEPRECATED = int(C.AV_CODEC_ID_PAF_VIDEO) 242 | AV_CODEC_ID_PAM = int(C.AV_CODEC_ID_PAM) 243 | AV_CODEC_ID_PBM = int(C.AV_CODEC_ID_PBM) 244 | AV_CODEC_ID_PCM_ALAW = int(C.AV_CODEC_ID_PCM_ALAW) 245 | AV_CODEC_ID_PCM_BLURAY = int(C.AV_CODEC_ID_PCM_BLURAY) 246 | AV_CODEC_ID_PCM_DVD = int(C.AV_CODEC_ID_PCM_DVD) 247 | AV_CODEC_ID_PCM_F32BE = int(C.AV_CODEC_ID_PCM_F32BE) 248 | AV_CODEC_ID_PCM_F32LE = int(C.AV_CODEC_ID_PCM_F32LE) 249 | AV_CODEC_ID_PCM_F64BE = int(C.AV_CODEC_ID_PCM_F64BE) 250 | AV_CODEC_ID_PCM_F64LE = int(C.AV_CODEC_ID_PCM_F64LE) 251 | AV_CODEC_ID_PCM_LXF = int(C.AV_CODEC_ID_PCM_LXF) 252 | AV_CODEC_ID_PCM_MULAW = int(C.AV_CODEC_ID_PCM_MULAW) 253 | AV_CODEC_ID_PCM_S16BE = int(C.AV_CODEC_ID_PCM_S16BE) 254 | AV_CODEC_ID_PCM_S16BE_PLANAR = int(C.AV_CODEC_ID_PCM_S16BE_PLANAR) 255 | AV_CODEC_ID_PCM_S16LE = int(C.AV_CODEC_ID_PCM_S16LE) 256 | AV_CODEC_ID_PCM_S16LE_PLANAR = int(C.AV_CODEC_ID_PCM_S16LE_PLANAR) 257 | AV_CODEC_ID_PCM_S24BE = int(C.AV_CODEC_ID_PCM_S24BE) 258 | AV_CODEC_ID_PCM_S24DAUD = int(C.AV_CODEC_ID_PCM_S24DAUD) 259 | AV_CODEC_ID_PCM_S24LE = int(C.AV_CODEC_ID_PCM_S24LE) 260 | AV_CODEC_ID_PCM_S24LE_PLANAR = int(C.AV_CODEC_ID_PCM_S24LE_PLANAR) 261 | AV_CODEC_ID_PCM_S24LE_PLANAR_DEPRECATED = int(C.AV_CODEC_ID_PCM_S24LE_PLANAR) 262 | AV_CODEC_ID_PCM_S32BE = int(C.AV_CODEC_ID_PCM_S32BE) 263 | AV_CODEC_ID_PCM_S32LE = int(C.AV_CODEC_ID_PCM_S32LE) 264 | AV_CODEC_ID_PCM_S32LE_PLANAR = int(C.AV_CODEC_ID_PCM_S32LE_PLANAR) 265 | AV_CODEC_ID_PCM_S32LE_PLANAR_DEPRECATED = int(C.AV_CODEC_ID_PCM_S32LE_PLANAR) 266 | AV_CODEC_ID_PCM_S8 = int(C.AV_CODEC_ID_PCM_S8) 267 | AV_CODEC_ID_PCM_S8_PLANAR = int(C.AV_CODEC_ID_PCM_S8_PLANAR) 268 | AV_CODEC_ID_PCM_U16BE = int(C.AV_CODEC_ID_PCM_U16BE) 269 | AV_CODEC_ID_PCM_U16LE = int(C.AV_CODEC_ID_PCM_U16LE) 270 | AV_CODEC_ID_PCM_U24BE = int(C.AV_CODEC_ID_PCM_U24BE) 271 | AV_CODEC_ID_PCM_U24LE = int(C.AV_CODEC_ID_PCM_U24LE) 272 | AV_CODEC_ID_PCM_U32BE = int(C.AV_CODEC_ID_PCM_U32BE) 273 | AV_CODEC_ID_PCM_U32LE = int(C.AV_CODEC_ID_PCM_U32LE) 274 | AV_CODEC_ID_PCM_U8 = int(C.AV_CODEC_ID_PCM_U8) 275 | AV_CODEC_ID_PCM_ZORK = int(C.AV_CODEC_ID_PCM_ZORK) 276 | AV_CODEC_ID_PCX = int(C.AV_CODEC_ID_PCX) 277 | AV_CODEC_ID_PGM = int(C.AV_CODEC_ID_PGM) 278 | AV_CODEC_ID_PGMYUV = int(C.AV_CODEC_ID_PGMYUV) 279 | AV_CODEC_ID_PICTOR = int(C.AV_CODEC_ID_PICTOR) 280 | AV_CODEC_ID_PJS = int(C.AV_CODEC_ID_PJS) 281 | AV_CODEC_ID_PNG = int(C.AV_CODEC_ID_PNG) 282 | AV_CODEC_ID_PPM = int(C.AV_CODEC_ID_PPM) 283 | AV_CODEC_ID_PROBE = int(C.AV_CODEC_ID_PROBE) 284 | AV_CODEC_ID_PRORES = int(C.AV_CODEC_ID_PRORES) 285 | AV_CODEC_ID_PTX = int(C.AV_CODEC_ID_PTX) 286 | AV_CODEC_ID_QCELP = int(C.AV_CODEC_ID_QCELP) 287 | AV_CODEC_ID_QDM2 = int(C.AV_CODEC_ID_QDM2) 288 | AV_CODEC_ID_QDMC = int(C.AV_CODEC_ID_QDMC) 289 | AV_CODEC_ID_QDRAW = int(C.AV_CODEC_ID_QDRAW) 290 | AV_CODEC_ID_QPEG = int(C.AV_CODEC_ID_QPEG) 291 | AV_CODEC_ID_QTRLE = int(C.AV_CODEC_ID_QTRLE) 292 | AV_CODEC_ID_R10K = int(C.AV_CODEC_ID_R10K) 293 | AV_CODEC_ID_R210 = int(C.AV_CODEC_ID_R210) 294 | AV_CODEC_ID_RALF = int(C.AV_CODEC_ID_RALF) 295 | AV_CODEC_ID_RAWVIDEO = int(C.AV_CODEC_ID_RAWVIDEO) 296 | AV_CODEC_ID_RA_144 = int(C.AV_CODEC_ID_RA_144) 297 | AV_CODEC_ID_RA_288 = int(C.AV_CODEC_ID_RA_288) 298 | AV_CODEC_ID_REALTEXT = int(C.AV_CODEC_ID_REALTEXT) 299 | AV_CODEC_ID_RL2 = int(C.AV_CODEC_ID_RL2) 300 | AV_CODEC_ID_ROQ = int(C.AV_CODEC_ID_ROQ) 301 | AV_CODEC_ID_ROQ_DPCM = int(C.AV_CODEC_ID_ROQ_DPCM) 302 | AV_CODEC_ID_RPZA = int(C.AV_CODEC_ID_RPZA) 303 | AV_CODEC_ID_RV10 = int(C.AV_CODEC_ID_RV10) 304 | AV_CODEC_ID_RV20 = int(C.AV_CODEC_ID_RV20) 305 | AV_CODEC_ID_RV30 = int(C.AV_CODEC_ID_RV30) 306 | AV_CODEC_ID_RV40 = int(C.AV_CODEC_ID_RV40) 307 | AV_CODEC_ID_S302M = int(C.AV_CODEC_ID_S302M) 308 | AV_CODEC_ID_SAMI = int(C.AV_CODEC_ID_SAMI) 309 | AV_CODEC_ID_SANM = int(C.AV_CODEC_ID_SANM) 310 | AV_CODEC_ID_SANM_DEPRECATED = int(C.AV_CODEC_ID_SANM) 311 | AV_CODEC_ID_SGI = int(C.AV_CODEC_ID_SGI) 312 | AV_CODEC_ID_SGIRLE = int(C.AV_CODEC_ID_SGIRLE) 313 | AV_CODEC_ID_SGIRLE_DEPRECATED = int(C.AV_CODEC_ID_SGIRLE) 314 | AV_CODEC_ID_SHORTEN = int(C.AV_CODEC_ID_SHORTEN) 315 | AV_CODEC_ID_SIPR = int(C.AV_CODEC_ID_SIPR) 316 | AV_CODEC_ID_SMACKAUDIO = int(C.AV_CODEC_ID_SMACKAUDIO) 317 | AV_CODEC_ID_SMACKVIDEO = int(C.AV_CODEC_ID_SMACKVIDEO) 318 | AV_CODEC_ID_SMC = int(C.AV_CODEC_ID_SMC) 319 | AV_CODEC_ID_SMPTE_KLV = int(C.AV_CODEC_ID_SMPTE_KLV) 320 | AV_CODEC_ID_SMV = int(C.AV_CODEC_ID_SMV) 321 | AV_CODEC_ID_SMVJPEG = int(C.AV_CODEC_ID_SMVJPEG) 322 | AV_CODEC_ID_SNOW = int(C.AV_CODEC_ID_SNOW) 323 | AV_CODEC_ID_SOL_DPCM = int(C.AV_CODEC_ID_SOL_DPCM) 324 | AV_CODEC_ID_SONIC = int(C.AV_CODEC_ID_SONIC) 325 | AV_CODEC_ID_SONIC_LS = int(C.AV_CODEC_ID_SONIC_LS) 326 | AV_CODEC_ID_SP5X = int(C.AV_CODEC_ID_SP5X) 327 | AV_CODEC_ID_SPEEX = int(C.AV_CODEC_ID_SPEEX) 328 | AV_CODEC_ID_SRT = int(C.AV_CODEC_ID_SRT) 329 | AV_CODEC_ID_SSA = int(C.AV_CODEC_ID_SSA) 330 | AV_CODEC_ID_SUBRIP = int(C.AV_CODEC_ID_SUBRIP) 331 | AV_CODEC_ID_SUBVIEWER = int(C.AV_CODEC_ID_SUBVIEWER) 332 | AV_CODEC_ID_SUBVIEWER1 = int(C.AV_CODEC_ID_SUBVIEWER1) 333 | AV_CODEC_ID_SUNRAST = int(C.AV_CODEC_ID_SUNRAST) 334 | AV_CODEC_ID_SVQ1 = int(C.AV_CODEC_ID_SVQ1) 335 | AV_CODEC_ID_SVQ3 = int(C.AV_CODEC_ID_SVQ3) 336 | AV_CODEC_ID_TAK = int(C.AV_CODEC_ID_TAK) 337 | AV_CODEC_ID_TAK_DEPRECATED = int(C.AV_CODEC_ID_TAK) 338 | AV_CODEC_ID_TARGA = int(C.AV_CODEC_ID_TARGA) 339 | AV_CODEC_ID_TARGA_Y216 = int(C.AV_CODEC_ID_TARGA_Y216) 340 | AV_CODEC_ID_TEXT = int(C.AV_CODEC_ID_TEXT) 341 | AV_CODEC_ID_TGQ = int(C.AV_CODEC_ID_TGQ) 342 | AV_CODEC_ID_TGV = int(C.AV_CODEC_ID_TGV) 343 | AV_CODEC_ID_THEORA = int(C.AV_CODEC_ID_THEORA) 344 | AV_CODEC_ID_THP = int(C.AV_CODEC_ID_THP) 345 | AV_CODEC_ID_TIERTEXSEQVIDEO = int(C.AV_CODEC_ID_TIERTEXSEQVIDEO) 346 | AV_CODEC_ID_TIFF = int(C.AV_CODEC_ID_TIFF) 347 | AV_CODEC_ID_TIMED_ID3 = int(C.AV_CODEC_ID_TIMED_ID3) 348 | AV_CODEC_ID_TMV = int(C.AV_CODEC_ID_TMV) 349 | AV_CODEC_ID_TQI = int(C.AV_CODEC_ID_TQI) 350 | AV_CODEC_ID_TRUEHD = int(C.AV_CODEC_ID_TRUEHD) 351 | AV_CODEC_ID_TRUEMOTION1 = int(C.AV_CODEC_ID_TRUEMOTION1) 352 | AV_CODEC_ID_TRUEMOTION2 = int(C.AV_CODEC_ID_TRUEMOTION2) 353 | AV_CODEC_ID_TRUESPEECH = int(C.AV_CODEC_ID_TRUESPEECH) 354 | AV_CODEC_ID_TSCC = int(C.AV_CODEC_ID_TSCC) 355 | AV_CODEC_ID_TSCC2 = int(C.AV_CODEC_ID_TSCC2) 356 | AV_CODEC_ID_TTA = int(C.AV_CODEC_ID_TTA) 357 | AV_CODEC_ID_TTF = int(C.AV_CODEC_ID_TTF) 358 | AV_CODEC_ID_TWINVQ = int(C.AV_CODEC_ID_TWINVQ) 359 | AV_CODEC_ID_TXD = int(C.AV_CODEC_ID_TXD) 360 | AV_CODEC_ID_ULTI = int(C.AV_CODEC_ID_ULTI) 361 | AV_CODEC_ID_UTVIDEO = int(C.AV_CODEC_ID_UTVIDEO) 362 | AV_CODEC_ID_V210 = int(C.AV_CODEC_ID_V210) 363 | AV_CODEC_ID_V210X = int(C.AV_CODEC_ID_V210X) 364 | AV_CODEC_ID_V308 = int(C.AV_CODEC_ID_V308) 365 | AV_CODEC_ID_V408 = int(C.AV_CODEC_ID_V408) 366 | AV_CODEC_ID_V410 = int(C.AV_CODEC_ID_V410) 367 | AV_CODEC_ID_VB = int(C.AV_CODEC_ID_VB) 368 | AV_CODEC_ID_VBLE = int(C.AV_CODEC_ID_VBLE) 369 | AV_CODEC_ID_VC1 = int(C.AV_CODEC_ID_VC1) 370 | AV_CODEC_ID_VC1IMAGE = int(C.AV_CODEC_ID_VC1IMAGE) 371 | AV_CODEC_ID_VCR1 = int(C.AV_CODEC_ID_VCR1) 372 | AV_CODEC_ID_VIXL = int(C.AV_CODEC_ID_VIXL) 373 | AV_CODEC_ID_VMDAUDIO = int(C.AV_CODEC_ID_VMDAUDIO) 374 | AV_CODEC_ID_VMDVIDEO = int(C.AV_CODEC_ID_VMDVIDEO) 375 | AV_CODEC_ID_VMNC = int(C.AV_CODEC_ID_VMNC) 376 | AV_CODEC_ID_VORBIS = int(C.AV_CODEC_ID_VORBIS) 377 | AV_CODEC_ID_VP3 = int(C.AV_CODEC_ID_VP3) 378 | AV_CODEC_ID_VP5 = int(C.AV_CODEC_ID_VP5) 379 | AV_CODEC_ID_VP6 = int(C.AV_CODEC_ID_VP6) 380 | AV_CODEC_ID_VP6A = int(C.AV_CODEC_ID_VP6A) 381 | AV_CODEC_ID_VP6F = int(C.AV_CODEC_ID_VP6F) 382 | AV_CODEC_ID_VP7 = int(C.AV_CODEC_ID_VP7) 383 | AV_CODEC_ID_VP7_DEPRECATED = int(C.AV_CODEC_ID_VP7) 384 | AV_CODEC_ID_VP8 = int(C.AV_CODEC_ID_VP8) 385 | AV_CODEC_ID_VP9 = int(C.AV_CODEC_ID_VP9) 386 | AV_CODEC_ID_VPLAYER = int(C.AV_CODEC_ID_VPLAYER) 387 | AV_CODEC_ID_WAVPACK = int(C.AV_CODEC_ID_WAVPACK) 388 | AV_CODEC_ID_WEBP = int(C.AV_CODEC_ID_WEBP) 389 | AV_CODEC_ID_WEBP_DEPRECATED = int(C.AV_CODEC_ID_WEBP) 390 | AV_CODEC_ID_WEBVTT = int(C.AV_CODEC_ID_WEBVTT) 391 | AV_CODEC_ID_WESTWOOD_SND1 = int(C.AV_CODEC_ID_WESTWOOD_SND1) 392 | AV_CODEC_ID_WMALOSSLESS = int(C.AV_CODEC_ID_WMALOSSLESS) 393 | AV_CODEC_ID_WMAPRO = int(C.AV_CODEC_ID_WMAPRO) 394 | AV_CODEC_ID_WMAV1 = int(C.AV_CODEC_ID_WMAV1) 395 | AV_CODEC_ID_WMAV2 = int(C.AV_CODEC_ID_WMAV2) 396 | AV_CODEC_ID_WMAVOICE = int(C.AV_CODEC_ID_WMAVOICE) 397 | AV_CODEC_ID_WMV1 = int(C.AV_CODEC_ID_WMV1) 398 | AV_CODEC_ID_WMV2 = int(C.AV_CODEC_ID_WMV2) 399 | AV_CODEC_ID_WMV3 = int(C.AV_CODEC_ID_WMV3) 400 | AV_CODEC_ID_WMV3IMAGE = int(C.AV_CODEC_ID_WMV3IMAGE) 401 | AV_CODEC_ID_WNV1 = int(C.AV_CODEC_ID_WNV1) 402 | AV_CODEC_ID_WS_VQA = int(C.AV_CODEC_ID_WS_VQA) 403 | AV_CODEC_ID_XAN_DPCM = int(C.AV_CODEC_ID_XAN_DPCM) 404 | AV_CODEC_ID_XAN_WC3 = int(C.AV_CODEC_ID_XAN_WC3) 405 | AV_CODEC_ID_XAN_WC4 = int(C.AV_CODEC_ID_XAN_WC4) 406 | AV_CODEC_ID_XBIN = int(C.AV_CODEC_ID_XBIN) 407 | AV_CODEC_ID_XBM = int(C.AV_CODEC_ID_XBM) 408 | AV_CODEC_ID_XFACE = int(C.AV_CODEC_ID_XFACE) 409 | AV_CODEC_ID_XSUB = int(C.AV_CODEC_ID_XSUB) 410 | AV_CODEC_ID_XWD = int(C.AV_CODEC_ID_XWD) 411 | AV_CODEC_ID_Y41P = int(C.AV_CODEC_ID_Y41P) 412 | AV_CODEC_ID_YOP = int(C.AV_CODEC_ID_YOP) 413 | AV_CODEC_ID_YUV4 = int(C.AV_CODEC_ID_YUV4) 414 | AV_CODEC_ID_ZEROCODEC = int(C.AV_CODEC_ID_ZEROCODEC) 415 | AV_CODEC_ID_ZLIB = int(C.AV_CODEC_ID_ZLIB) 416 | AV_CODEC_ID_ZMBV = int(C.AV_CODEC_ID_ZMBV) 417 | 418 | //Flags 419 | AV_CODEC_FLAG_GLOBAL_HEADER = (1 << 22) 420 | ) 421 | -------------------------------------------------------------------------------- /avcodec/context.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avcodec 5 | 6 | //#cgo pkg-config: libavcodec 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avutil" 13 | ) 14 | 15 | func (ctxt *Context) AvCodecGetPktTimebase() Rational { 16 | panic("deprecated") 17 | return Rational{} 18 | //return (Rational)(C.av_codec_get_pkt_timebase((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 19 | } 20 | 21 | func (ctxt *Context) AvCodecSetPktTimebase(r Rational) { 22 | panic("deprecated") 23 | //C.av_codec_set_pkt_timebase((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (C.struct_AVRational)(r)) 24 | } 25 | 26 | func (ctxt *Context) AvCodecGetCodecDescriptor() *Descriptor { 27 | panic("deprecated") 28 | return nil 29 | //return (*Descriptor)(C.av_codec_get_codec_descriptor((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 30 | } 31 | 32 | func (ctxt *Context) AvCodecSetCodecDescriptor(d *Descriptor) { 33 | panic("deprecated") 34 | //C.av_codec_set_codec_descriptor((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVCodecDescriptor)(d)) 35 | } 36 | 37 | func (ctxt *Context) AvCodecGetLowres() int { 38 | panic("deprecated") 39 | return 0 40 | //return int(C.av_codec_get_lowres((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 41 | } 42 | 43 | func (ctxt *Context) AvCodecSetLowres(i int) { 44 | panic("deprecated") 45 | //C.av_codec_set_lowres((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), C.int(i)) 46 | } 47 | 48 | func (ctxt *Context) AvCodecGetSeekPreroll() int { 49 | panic("deprecated") 50 | return 0 51 | //return int(C.av_codec_get_seek_preroll((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 52 | } 53 | 54 | func (ctxt *Context) AvCodecSetSeekPreroll(i int) { 55 | panic("deprecated") 56 | //C.av_codec_set_seek_preroll((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), C.int(i)) 57 | } 58 | 59 | func (ctxt *Context) AvCodecGetChromaIntraMatrix() *uint16 { 60 | panic("deprecated") 61 | return nil 62 | //return (*uint16)(C.av_codec_get_chroma_intra_matrix((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 63 | } 64 | 65 | func (ctxt *Context) AvCodecSetChromaIntraMatrix(t *uint16) { 66 | panic("deprecated") 67 | //C.av_codec_set_chroma_intra_matrix((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.uint16_t)(t)) 68 | } 69 | 70 | //Free the codec context and everything associated with it and write NULL to the provided pointer. 71 | func AvcodecFreeContext(ctxt *Context) { 72 | var ptr *C.struct_AVCodecContext = (*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)) 73 | C.avcodec_free_context(&ptr) 74 | } 75 | 76 | //Set the fields of the given Context to default values corresponding to the given codec (defaults may be codec-dependent). 77 | func (ctxt *Context) AvcodecGetContextDefaults3(c *Codec) int { 78 | return int(C.avcodec_get_context_defaults3((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVCodec)(c))) 79 | } 80 | 81 | //Copy the settings of the source Context into the destination Context. 82 | // func (ctxt *Context) AvcodecCopyContext(ctxt2 *Context) int { 83 | // return int(C.avcodec_copy_context((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVCodecContext)(unsafe.Pointer(ctxt2)))) 84 | // } 85 | 86 | //Initialize the Context to use the given Codec 87 | func (ctxt *Context) AvcodecOpen2(c *Codec, d **avutil.Dictionary) int { 88 | return int(C.avcodec_open2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVCodec)(c), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) 89 | } 90 | 91 | //Close a given Context and free all the data associated with it (but not the Context itself). 92 | func (ctxt *Context) AvcodecClose() int { 93 | return int(C.avcodec_close((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 94 | } 95 | 96 | //The default callback for Context.get_buffer2(). 97 | func (ctxt *Context) AvcodecDefaultGetBuffer2(f *Frame, l int) int { 98 | return int(C.avcodec_default_get_buffer2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVFrame)(f), C.int(l))) 99 | } 100 | 101 | //Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you do not use any horizontal padding. 102 | func (ctxt *Context) AvcodecAlignDimensions(w, h *int) { 103 | C.avcodec_align_dimensions((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.int)(unsafe.Pointer(w)), (*C.int)(unsafe.Pointer(h))) 104 | } 105 | 106 | //Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you also ensure that all line sizes are a multiple of the respective linesize_align[i]. 107 | func (ctxt *Context) AvcodecAlignDimensions2(w, h *int, l int) { 108 | C.avcodec_align_dimensions2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.int)(unsafe.Pointer(w)), (*C.int)(unsafe.Pointer(h)), (*C.int)(unsafe.Pointer(&l))) 109 | } 110 | 111 | //Decode the audio frame of size avpkt->size from avpkt->data into frame. 112 | // func (ctxt *Context) AvcodecDecodeAudio4(f *Frame, g *int, a *Packet) int { 113 | // return int(C.avcodec_decode_audio4((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVFrame)(f), (*C.int)(unsafe.Pointer(g)), (*C.struct_AVPacket)(a))) 114 | // } 115 | 116 | //Decode the video frame of size avpkt->size from avpkt->data into picture. 117 | // func (ctxt *Context) AvcodecDecodeVideo2(p *Frame, g *int, a *Packet) int { 118 | // return int(C.avcodec_decode_video2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVFrame)(p), (*C.int)(unsafe.Pointer(g)), (*C.struct_AVPacket)(a))) 119 | // } 120 | 121 | func (ctxt *Context) ReceivePacket(a *Packet) int { 122 | return AvcodecReceivePacket(ctxt, a) 123 | } 124 | 125 | // SendPacket sends a packet to the context for decoding 126 | // OO form of AvcodecSendPacket 127 | func (ctxt *Context) SendPacket(a *Packet) int { 128 | return AvcodecSendPacket(ctxt, a) 129 | } 130 | 131 | // ReceiveFrame receives a decoded from from a context 132 | // OO form of AvcodecReceiveFrame 133 | func (ctxt *Context) ReceiveFrame(f *avutil.Frame) int { 134 | return AvcodecReceiveFrame(ctxt, f) 135 | } 136 | 137 | func (ctxt *Context) SendFrame(f *avutil.Frame) int { 138 | return AvcodecSendFrame(ctxt, f) 139 | } 140 | 141 | //Decode a subtitle message. 142 | func (ctxt *Context) AvcodecDecodeSubtitle2(s *AvSubtitle, g *int, a *Packet) int { 143 | return int(C.avcodec_decode_subtitle2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVSubtitle)(s), (*C.int)(unsafe.Pointer(g)), (*C.struct_AVPacket)(a))) 144 | } 145 | 146 | //Encode a frame of audio. 147 | // func (ctxt *Context) AvcodecEncodeAudio2(p *Packet, f *Frame, gp *int) int { 148 | // return int(C.avcodec_encode_audio2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVPacket)(p), (*C.struct_AVFrame)(f), (*C.int)(unsafe.Pointer(gp)))) 149 | // } 150 | 151 | //Encode a frame of video 152 | // func (ctxt *Context) AvcodecEncodeVideo2(p *Packet, f *Frame, gp *int) int { 153 | // return int(C.avcodec_encode_video2((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.struct_AVPacket)(p), (*C.struct_AVFrame)(f), (*C.int)(unsafe.Pointer(gp)))) 154 | // } 155 | 156 | func (ctxt *Context) AvcodecEncodeSubtitle(b *uint8, bs int, s *AvSubtitle) int { 157 | return int(C.avcodec_encode_subtitle((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.uint8_t)(b), C.int(bs), (*C.struct_AVSubtitle)(s))) 158 | } 159 | 160 | func (ctxt *Context) AvcodecDefaultGetFormat(f *avutil.PixelFormat) avutil.PixelFormat { 161 | return (avutil.PixelFormat)(C.avcodec_default_get_format((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (*C.enum_AVPixelFormat)(f))) 162 | } 163 | 164 | //Reset the internal decoder state / flush internal buffers. 165 | func (ctxt *Context) AvcodecFlushBuffers() { 166 | C.avcodec_flush_buffers((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt))) 167 | } 168 | 169 | //Return audio frame duration. 170 | func (ctxt *Context) AvGetAudioFrameDuration(f int) int { 171 | return int(C.av_get_audio_frame_duration((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), C.int(f))) 172 | } 173 | 174 | func (ctxt *Context) AvcodecIsOpen() int { 175 | return int(C.avcodec_is_open((*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)))) 176 | } 177 | 178 | //Parse a packet. 179 | func (ctxt *Context) AvParserParse2(ctxtp *ParserContext, p **uint8, ps *int, b *uint8, bs int, pt, dt, po int64) int { 180 | return int(C.av_parser_parse2((*C.struct_AVCodecParserContext)(ctxtp), (*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (**C.uint8_t)(unsafe.Pointer(p)), (*C.int)(unsafe.Pointer(ps)), (*C.uint8_t)(b), C.int(bs), (C.int64_t)(pt), (C.int64_t)(dt), (C.int64_t)(po))) 181 | } 182 | 183 | func (ctxt *Context) AvParserChange(ctxtp *ParserContext, pb **uint8, pbs *int, b *uint8, bs, k int) int { 184 | return int(C.av_parser_change((*C.struct_AVCodecParserContext)(ctxtp), (*C.struct_AVCodecContext)(unsafe.Pointer(ctxt)), (**C.uint8_t)(unsafe.Pointer(pb)), (*C.int)(unsafe.Pointer(pbs)), (*C.uint8_t)(b), C.int(bs), C.int(k))) 185 | } 186 | 187 | func AvParserInit(c int) *ParserContext { 188 | return (*ParserContext)(C.av_parser_init(C.int(c))) 189 | } 190 | 191 | func AvParserClose(ctxtp *ParserContext) { 192 | C.av_parser_close((*C.struct_AVCodecParserContext)(ctxtp)) 193 | } 194 | 195 | func (p *Parser) AvParserNext() *Parser { 196 | panic("deprecated") 197 | return nil 198 | //return (*Parser)(C.av_parser_next((*C.struct_AVCodecParser)(p))) 199 | } 200 | 201 | func (p *Parser) AvRegisterCodecParser() { 202 | panic("deprecated") 203 | //C.av_register_codec_parser((*C.struct_AVCodecParser)(p)) 204 | } 205 | -------------------------------------------------------------------------------- /avcodec/context_struct.go: -------------------------------------------------------------------------------- 1 | package avcodec 2 | 3 | /* 4 | #cgo pkg-config: libavcodec 5 | #include 6 | */ 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avutil" 13 | ) 14 | 15 | func (ctxt *Context) ActiveThreadType() int { 16 | return int(ctxt.active_thread_type) 17 | } 18 | 19 | func (ctxt *Context) BFrameStrategy() int { 20 | return int(ctxt.b_frame_strategy) 21 | } 22 | 23 | func (ctxt *Context) BQuantFactor() float64 { 24 | return float64(ctxt.b_quant_factor) 25 | } 26 | 27 | func (ctxt *Context) BQuantOffset() float64 { 28 | return float64(ctxt.b_quant_offset) 29 | } 30 | 31 | func (ctxt *Context) BSensitivity() int { 32 | return int(ctxt.b_sensitivity) 33 | } 34 | 35 | func (ctxt *Context) BidirRefine() int { 36 | return int(ctxt.bidir_refine) 37 | } 38 | 39 | func (ctxt *Context) BitRate() int { 40 | return int(ctxt.bit_rate) 41 | } 42 | 43 | func (ctxt *Context) BitRateTolerance() int { 44 | return int(ctxt.bit_rate_tolerance) 45 | } 46 | 47 | func (ctxt *Context) BitsPerCodedSample() int { 48 | return int(ctxt.bits_per_coded_sample) 49 | } 50 | 51 | func (ctxt *Context) BitsPerRawSample() int { 52 | return int(ctxt.bits_per_raw_sample) 53 | } 54 | 55 | func (ctxt *Context) BlockAlign() int { 56 | return int(ctxt.block_align) 57 | } 58 | 59 | func (ctxt *Context) BrdScale() int { 60 | return int(ctxt.brd_scale) 61 | } 62 | 63 | func (ctxt *Context) Channels() int { 64 | return int(ctxt.channels) 65 | } 66 | 67 | func (ctxt *Context) SetChannels(channels int) { 68 | ctxt.channels = C.int(channels) 69 | } 70 | 71 | func (ctxt *Context) ChannelLayout() uint64 { 72 | return uint64(ctxt.channel_layout) 73 | } 74 | 75 | func (ctxt *Context) SetChannelLayout(channelLayout uint64) { 76 | ctxt.channel_layout = C.uint64_t(channelLayout) 77 | } 78 | 79 | func (ctxt *Context) Chromaoffset() int { 80 | return int(ctxt.chromaoffset) 81 | } 82 | 83 | func (ctxt *Context) CodedHeight() int { 84 | return int(ctxt.coded_height) 85 | } 86 | 87 | func (ctxt *Context) CodedWidth() int { 88 | return int(ctxt.coded_width) 89 | } 90 | 91 | func (ctxt *Context) CoderType() int { 92 | return int(ctxt.coder_type) 93 | } 94 | 95 | func (ctxt *Context) CompressionLevel() int { 96 | return int(ctxt.compression_level) 97 | } 98 | 99 | func (ctxt *Context) ContextModel() int { 100 | return int(ctxt.context_model) 101 | } 102 | 103 | func (ctxt *Context) Cutoff() int { 104 | return int(ctxt.cutoff) 105 | } 106 | 107 | func (ctxt *Context) DarkMasking() float64 { 108 | return float64(ctxt.dark_masking) 109 | } 110 | 111 | func (ctxt *Context) DctAlgo() int { 112 | return int(ctxt.dct_algo) 113 | } 114 | 115 | func (ctxt *Context) Debug() int { 116 | return int(ctxt.debug) 117 | } 118 | 119 | func (ctxt *Context) DebugMv() int { 120 | return int(ctxt.debug_mv) 121 | } 122 | 123 | func (ctxt *Context) Delay() int { 124 | return int(ctxt.delay) 125 | } 126 | 127 | func (ctxt *Context) DiaSize() int { 128 | return int(ctxt.dia_size) 129 | } 130 | 131 | func (ctxt *Context) ErrRecognition() int { 132 | return int(ctxt.err_recognition) 133 | } 134 | 135 | func (ctxt *Context) ErrorConcealment() int { 136 | return int(ctxt.error_concealment) 137 | } 138 | 139 | func (ctxt *Context) ExtradataSize() int { 140 | return int(ctxt.extradata_size) 141 | } 142 | 143 | func (ctxt *Context) Flags() int { 144 | return int(ctxt.flags) 145 | } 146 | 147 | func (ctxt *Context) SetFlags(flags int) { 148 | ctxt.flags = C.int(flags) 149 | } 150 | 151 | func (ctxt *Context) Flags2() int { 152 | return int(ctxt.flags2) 153 | } 154 | 155 | func (ctxt *Context) FrameBits() int { 156 | return int(ctxt.frame_bits) 157 | } 158 | 159 | func (ctxt *Context) FrameNumber() int { 160 | return int(ctxt.frame_number) 161 | } 162 | 163 | func (ctxt *Context) Framerate() avutil.Rational { 164 | return *(*avutil.Rational)(unsafe.Pointer(&ctxt.framerate)) 165 | } 166 | 167 | func (ctxt *Context) SetFramerate(framerate avutil.Rational) { 168 | ctxt.framerate = *((*C.struct_AVRational)(unsafe.Pointer(&framerate))) 169 | } 170 | 171 | func (ctxt *Context) FrameSize() int { 172 | return int(ctxt.frame_size) 173 | } 174 | 175 | func (ctxt *Context) FrameSkipCmp() int { 176 | return int(ctxt.frame_skip_cmp) 177 | } 178 | 179 | func (ctxt *Context) FrameSkipExp() int { 180 | return int(ctxt.frame_skip_exp) 181 | } 182 | 183 | func (ctxt *Context) FrameSkipFactor() int { 184 | return int(ctxt.frame_skip_factor) 185 | } 186 | 187 | func (ctxt *Context) FrameSkipThreshold() int { 188 | return int(ctxt.frame_skip_threshold) 189 | } 190 | 191 | func (ctxt *Context) GlobalQuality() int { 192 | return int(ctxt.global_quality) 193 | } 194 | 195 | func (ctxt *Context) GopSize() int { 196 | return int(ctxt.gop_size) 197 | } 198 | 199 | func (ctxt *Context) SetGopSize(gopSize int) { 200 | ctxt.gop_size = C.int(gopSize) 201 | } 202 | 203 | func (ctxt *Context) HasBFrames() int { 204 | return int(ctxt.has_b_frames) 205 | } 206 | 207 | func (ctxt *Context) HeaderBits() int { 208 | return int(ctxt.header_bits) 209 | } 210 | 211 | func (ctxt *Context) Height() int { 212 | return int(ctxt.height) 213 | } 214 | 215 | func (ctxt *Context) SetHeight(height int) { 216 | ctxt.height = C.int(height) 217 | } 218 | 219 | func (ctxt *Context) ICount() int { 220 | return int(ctxt.i_count) 221 | } 222 | 223 | func (ctxt *Context) IQuantFactor() float64 { 224 | return float64(ctxt.i_quant_factor) 225 | } 226 | 227 | func (ctxt *Context) IQuantOffset() float64 { 228 | return float64(ctxt.i_quant_offset) 229 | } 230 | 231 | func (ctxt *Context) ITexBits() int { 232 | return int(ctxt.i_tex_bits) 233 | } 234 | 235 | func (ctxt *Context) IdctAlgo() int { 236 | return int(ctxt.idct_algo) 237 | } 238 | 239 | func (ctxt *Context) IldctCmp() int { 240 | return int(ctxt.ildct_cmp) 241 | } 242 | 243 | func (ctxt *Context) IntraDcPrecision() int { 244 | return int(ctxt.intra_dc_precision) 245 | } 246 | 247 | func (ctxt *Context) KeyintMin() int { 248 | return int(ctxt.keyint_min) 249 | } 250 | 251 | func (ctxt *Context) LastPredictorCount() int { 252 | return int(ctxt.last_predictor_count) 253 | } 254 | 255 | func (ctxt *Context) Level() int { 256 | return int(ctxt.level) 257 | } 258 | 259 | func (ctxt *Context) LogLevelOffset() int { 260 | return int(ctxt.log_level_offset) 261 | } 262 | 263 | func (ctxt *Context) Lowres() int { 264 | return int(ctxt.lowres) 265 | } 266 | 267 | func (ctxt *Context) LumiMasking() float64 { 268 | return float64(ctxt.lumi_masking) 269 | } 270 | 271 | func (ctxt *Context) MaxBFrames() int { 272 | return int(ctxt.max_b_frames) 273 | } 274 | 275 | func (ctxt *Context) SetMaxBFrames(maxBFrames int) { 276 | ctxt.max_b_frames = C.int(maxBFrames) 277 | } 278 | 279 | func (ctxt *Context) MaxPredictionOrder() int { 280 | return int(ctxt.max_prediction_order) 281 | } 282 | 283 | func (ctxt *Context) MaxQdiff() int { 284 | return int(ctxt.max_qdiff) 285 | } 286 | 287 | func (ctxt *Context) MbCmp() int { 288 | return int(ctxt.mb_cmp) 289 | } 290 | 291 | func (ctxt *Context) MbDecision() int { 292 | return int(ctxt.mb_decision) 293 | } 294 | 295 | func (ctxt *Context) MbLmax() int { 296 | return int(ctxt.mb_lmax) 297 | } 298 | 299 | func (ctxt *Context) MbLmin() int { 300 | return int(ctxt.mb_lmin) 301 | } 302 | 303 | func (ctxt *Context) MeCmp() int { 304 | return int(ctxt.me_cmp) 305 | } 306 | 307 | func (ctxt *Context) MePenaltyCompensation() int { 308 | return int(ctxt.me_penalty_compensation) 309 | } 310 | 311 | func (ctxt *Context) MePreCmp() int { 312 | return int(ctxt.me_pre_cmp) 313 | } 314 | 315 | func (ctxt *Context) MeRange() int { 316 | return int(ctxt.me_range) 317 | } 318 | 319 | func (ctxt *Context) MeSubCmp() int { 320 | return int(ctxt.me_sub_cmp) 321 | } 322 | 323 | func (ctxt *Context) MeSubpelQuality() int { 324 | return int(ctxt.me_subpel_quality) 325 | } 326 | 327 | func (ctxt *Context) MinPredictionOrder() int { 328 | return int(ctxt.min_prediction_order) 329 | } 330 | 331 | func (ctxt *Context) MiscBits() int { 332 | return int(ctxt.misc_bits) 333 | } 334 | 335 | func (ctxt *Context) MpegQuant() int { 336 | return int(ctxt.mpeg_quant) 337 | } 338 | 339 | func (ctxt *Context) Mv0Threshold() int { 340 | return int(ctxt.mv0_threshold) 341 | } 342 | 343 | func (ctxt *Context) MvBits() int { 344 | return int(ctxt.mv_bits) 345 | } 346 | 347 | func (ctxt *Context) NoiseReduction() int { 348 | return int(ctxt.noise_reduction) 349 | } 350 | 351 | func (ctxt *Context) NsseWeight() int { 352 | return int(ctxt.nsse_weight) 353 | } 354 | 355 | func (ctxt *Context) PCount() int { 356 | return int(ctxt.p_count) 357 | } 358 | 359 | func (ctxt *Context) PMasking() float64 { 360 | return float64(ctxt.p_masking) 361 | } 362 | 363 | func (ctxt *Context) PTexBits() int { 364 | return int(ctxt.p_tex_bits) 365 | } 366 | 367 | func (ctxt *Context) PreDiaSize() int { 368 | return int(ctxt.pre_dia_size) 369 | } 370 | 371 | func (ctxt *Context) PreMe() int { 372 | return int(ctxt.pre_me) 373 | } 374 | 375 | func (ctxt *Context) PredictionMethod() int { 376 | return int(ctxt.prediction_method) 377 | } 378 | 379 | func (ctxt *Context) Profile() int { 380 | return int(ctxt.profile) 381 | } 382 | 383 | func (ctxt *Context) Qblur() float64 { 384 | return float64(ctxt.qblur) 385 | } 386 | 387 | func (ctxt *Context) Qcompress() float64 { 388 | return float64(ctxt.qcompress) 389 | } 390 | 391 | func (ctxt *Context) Qmax() int { 392 | return int(ctxt.qmax) 393 | } 394 | 395 | func (ctxt *Context) Qmin() int { 396 | return int(ctxt.qmin) 397 | } 398 | 399 | func (ctxt *Context) RcBufferSize() int { 400 | return int(ctxt.rc_buffer_size) 401 | } 402 | 403 | func (ctxt *Context) RcInitialBufferOccupancy() int { 404 | return int(ctxt.rc_initial_buffer_occupancy) 405 | } 406 | 407 | func (ctxt *Context) RcMaxAvailableVbvUse() float64 { 408 | return float64(ctxt.rc_max_available_vbv_use) 409 | } 410 | 411 | func (ctxt *Context) RcMaxRate() int { 412 | return int(ctxt.rc_max_rate) 413 | } 414 | 415 | func (ctxt *Context) RcMinRate() int { 416 | return int(ctxt.rc_min_rate) 417 | } 418 | 419 | func (ctxt *Context) RcMinVbvOverflowUse() float64 { 420 | return float64(ctxt.rc_min_vbv_overflow_use) 421 | } 422 | 423 | func (ctxt *Context) RcOverrideCount() int { 424 | return int(ctxt.rc_override_count) 425 | } 426 | 427 | func (ctxt *Context) RefcountedFrames() int { 428 | return int(ctxt.refcounted_frames) 429 | } 430 | 431 | func (ctxt *Context) Refs() int { 432 | return int(ctxt.refs) 433 | } 434 | 435 | func (ctxt *Context) RtpPayloadSize() int { 436 | return int(ctxt.rtp_payload_size) 437 | } 438 | 439 | func (ctxt *Context) SampleRate() int { 440 | return int(ctxt.sample_rate) 441 | } 442 | 443 | func (ctxt *Context) SetSampleRate(sampleRate int) { 444 | ctxt.sample_rate = C.int(sampleRate) 445 | } 446 | 447 | func (ctxt *Context) ScenechangeThreshold() int { 448 | return int(ctxt.scenechange_threshold) 449 | } 450 | 451 | func (ctxt *Context) SeekPreroll() int { 452 | return int(ctxt.seek_preroll) 453 | } 454 | 455 | func (ctxt *Context) SideDataOnlyPackets() int { 456 | return int(ctxt.side_data_only_packets) 457 | } 458 | 459 | func (ctxt *Context) SkipAlpha() int { 460 | return int(ctxt.skip_alpha) 461 | } 462 | 463 | func (ctxt *Context) SkipBottom() int { 464 | return int(ctxt.skip_bottom) 465 | } 466 | 467 | func (ctxt *Context) SkipCount() int { 468 | return int(ctxt.skip_count) 469 | } 470 | 471 | func (ctxt *Context) SkipTop() int { 472 | return int(ctxt.skip_top) 473 | } 474 | 475 | func (ctxt *Context) SliceCount() int { 476 | return int(ctxt.slice_count) 477 | } 478 | 479 | func (ctxt *Context) SliceFlags() int { 480 | return int(ctxt.slice_flags) 481 | } 482 | 483 | func (ctxt *Context) Slices() int { 484 | return int(ctxt.slices) 485 | } 486 | 487 | func (ctxt *Context) SpatialCplxMasking() float64 { 488 | return float64(ctxt.spatial_cplx_masking) 489 | } 490 | 491 | func (ctxt *Context) SetStrictStdCompliance(strictStdCompliance int) { 492 | ctxt.strict_std_compliance = C.int(strictStdCompliance) 493 | } 494 | 495 | func (ctxt *Context) StrictStdCompliance() int { 496 | return int(ctxt.strict_std_compliance) 497 | } 498 | 499 | func (ctxt *Context) SubCharencMode() int { 500 | return int(ctxt.sub_charenc_mode) 501 | } 502 | 503 | func (ctxt *Context) SubtitleHeaderSize() int { 504 | return int(ctxt.subtitle_header_size) 505 | } 506 | 507 | func (ctxt *Context) TemporalCplxMasking() float64 { 508 | return float64(ctxt.temporal_cplx_masking) 509 | } 510 | 511 | func (ctxt *Context) ThreadCount() int { 512 | return int(ctxt.thread_count) 513 | } 514 | 515 | func (ctxt *Context) SetThreadCount(threadCount int) { 516 | ctxt.thread_count = C.int(threadCount) 517 | } 518 | 519 | func (ctxt *Context) SetBitRate(bitRate int64) { 520 | ctxt.bit_rate = C.int64_t(bitRate) 521 | } 522 | 523 | func (ctxt *Context) ThreadSafeCallbacks() int { 524 | return int(ctxt.thread_safe_callbacks) 525 | } 526 | 527 | func (ctxt *Context) ThreadType() int { 528 | return int(ctxt.thread_type) 529 | } 530 | 531 | // Look for FF_THREAD_* constants 532 | func (ctxt *Context) SetThreadType(threadType int) { 533 | ctxt.thread_type = C.int(threadType) 534 | } 535 | 536 | func (ctxt *Context) TicksPerFrame() int { 537 | return int(ctxt.ticks_per_frame) 538 | } 539 | 540 | func (ctxt *Context) Trellis() int { 541 | return int(ctxt.trellis) 542 | } 543 | 544 | func (ctxt *Context) Width() int { 545 | return int(ctxt.width) 546 | } 547 | 548 | func (ctxt *Context) SetWidth(width int) { 549 | ctxt.width = C.int(width) 550 | } 551 | 552 | func (ctxt *Context) WorkaroundBugs() int { 553 | return int(ctxt.workaround_bugs) 554 | } 555 | 556 | func (ctxt *Context) AudioServiceType() AvAudioServiceType { 557 | return (AvAudioServiceType)(ctxt.audio_service_type) 558 | } 559 | 560 | func (ctxt *Context) ChromaSampleLocation() AvChromaLocation { 561 | return (AvChromaLocation)(ctxt.chroma_sample_location) 562 | } 563 | 564 | func (ctxt *Context) CodecDescriptor() *Descriptor { 565 | return (*Descriptor)(ctxt.codec_descriptor) 566 | } 567 | 568 | func (ctxt *Context) CodecId() CodecId { 569 | return (CodecId)(ctxt.codec_id) 570 | } 571 | 572 | func (ctxt *Context) CodecType() MediaType { 573 | return (MediaType)(ctxt.codec_type) 574 | } 575 | 576 | func (ctxt *Context) ColorPrimaries() AvColorPrimaries { 577 | return (AvColorPrimaries)(ctxt.color_primaries) 578 | } 579 | 580 | func (ctxt *Context) ColorRange() AvColorRange { 581 | return (AvColorRange)(ctxt.color_range) 582 | } 583 | 584 | func (ctxt *Context) ColorTrc() AvColorTransferCharacteristic { 585 | return (AvColorTransferCharacteristic)(ctxt.color_trc) 586 | } 587 | 588 | func (ctxt *Context) Colorspace() AvColorSpace { 589 | return (AvColorSpace)(ctxt.colorspace) 590 | } 591 | 592 | func (ctxt *Context) FieldOrder() AvFieldOrder { 593 | return (AvFieldOrder)(ctxt.field_order) 594 | } 595 | 596 | func (ctxt *Context) PixFmt() avutil.PixelFormat { 597 | return (avutil.PixelFormat)(ctxt.pix_fmt) 598 | } 599 | 600 | func (ctxt *Context) SetPixFmt(pixFmt avutil.PixelFormat) { 601 | ctxt.pix_fmt = C.enum_AVPixelFormat(pixFmt) 602 | } 603 | 604 | func (ctxt *Context) RequestSampleFmt() AvSampleFormat { 605 | return (AvSampleFormat)(ctxt.request_sample_fmt) 606 | } 607 | 608 | func (ctxt *Context) SampleFmt() AvSampleFormat { 609 | return (AvSampleFormat)(ctxt.sample_fmt) 610 | } 611 | 612 | func (ctxt *Context) SetSampleFmt(sampleFormat AvSampleFormat) { 613 | ctxt.sample_fmt = C.enum_AVSampleFormat(sampleFormat) 614 | } 615 | func (ctxt *Context) SkipFrame() AvDiscard { 616 | return (AvDiscard)(ctxt.skip_frame) 617 | } 618 | 619 | func (ctxt *Context) SetSkipFrame(d AvDiscard) { 620 | ctxt.skip_frame = C.enum_AVDiscard(d) 621 | } 622 | 623 | func (ctxt *Context) SkipIdct() AvDiscard { 624 | return (AvDiscard)(ctxt.skip_idct) 625 | } 626 | 627 | func (ctxt *Context) SkipLoopFilter() AvDiscard { 628 | return (AvDiscard)(ctxt.skip_loop_filter) 629 | } 630 | 631 | func (ctxt *Context) TimeBase() avutil.Rational { 632 | return *(*avutil.Rational)(unsafe.Pointer(&ctxt.time_base)) 633 | } 634 | 635 | func (ctxt *Context) SetTimeBase(timeBase avutil.Rational) { 636 | ctxt.time_base = *((*C.struct_AVRational)(unsafe.Pointer(&timeBase))) 637 | } 638 | 639 | func (ctxt *Context) SampleAspectRatio() avutil.Rational { 640 | return *(*avutil.Rational)(unsafe.Pointer(&ctxt.sample_aspect_ratio)) 641 | } 642 | 643 | func (ctxt *Context) SetSampleAspectRatio(r avutil.Rational) { 644 | ctxt.sample_aspect_ratio = *((*C.struct_AVRational)(unsafe.Pointer(&r))) 645 | } 646 | -------------------------------------------------------------------------------- /avcodec/packet.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avcodec 5 | 6 | //#cgo pkg-config: libavcodec 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avutil" 13 | ) 14 | 15 | func AvPacketAlloc() *Packet { 16 | return (*Packet)(C.av_packet_alloc()) 17 | } 18 | 19 | //Initialize optional fields of a packet with default values. 20 | func (p *Packet) AvInitPacket() { 21 | C.av_init_packet((*C.struct_AVPacket)(p)) 22 | } 23 | 24 | //Allocate the payload of a packet and initialize its fields with default values. 25 | func (p *Packet) AvNewPacket(s int) int { 26 | return int(C.av_new_packet((*C.struct_AVPacket)(p), C.int(s))) 27 | } 28 | 29 | //Reduce packet size, correctly zeroing padding. 30 | func (p *Packet) AvShrinkPacket(s int) { 31 | C.av_shrink_packet((*C.struct_AVPacket)(p), C.int(s)) 32 | } 33 | 34 | //Increase packet size, correctly zeroing padding. 35 | func (p *Packet) AvGrowPacket(s int) int { 36 | return int(C.av_grow_packet((*C.struct_AVPacket)(p), C.int(s))) 37 | } 38 | 39 | //Initialize a reference-counted packet from av_malloc()ed data. 40 | func (p *Packet) AvPacketFromData(d *uint8, s int) int { 41 | return int(C.av_packet_from_data((*C.struct_AVPacket)(p), (*C.uint8_t)(d), C.int(s))) 42 | } 43 | 44 | // By definition this needs to perform a byte copy. libav takes ownership 45 | // of the buf and frees it when the AvPacket is freed 46 | func (p *Packet) AvPacketFromByteSlice(buf []byte) int { 47 | ptr := C.malloc(C.size_t(len(buf))) 48 | cBuf := (*[1 << 30]byte)(ptr) 49 | copy(cBuf[:], buf) 50 | return p.AvPacketFromData((*uint8)(ptr), len(buf)) 51 | } 52 | 53 | //Copy packet, including contents. 54 | func (p *Packet) AvCopyPacket(r *Packet) int { 55 | panic("deprecated") 56 | return 0 57 | //return int(C.av_copy_packet((*C.struct_AVPacket)(p), (*C.struct_AVPacket)(r))) 58 | 59 | } 60 | 61 | //Copy packet side data. 62 | func (p *Packet) AvCopyPacketSideData(r *Packet) int { 63 | panic("deprecated") 64 | return 0 65 | //return int(C.av_copy_packet_side_data((*C.struct_AVPacket)(p), (*C.struct_AVPacket)(r))) 66 | 67 | } 68 | 69 | //Free a packet. 70 | func AvPacketFree(p *Packet) { 71 | var ptr *C.struct_AVPacket = (*C.struct_AVPacket)(p) 72 | C.av_packet_free(&ptr) 73 | } 74 | 75 | //Allocate new information of a packet. 76 | func (p *Packet) AvPacketNewSideData(t AvPacketSideDataType, s int) *uint8 { 77 | return (*uint8)(C.av_packet_new_side_data((*C.struct_AVPacket)(p), (C.enum_AVPacketSideDataType)(t), C.int(s))) 78 | } 79 | 80 | //Shrink the already allocated side data buffer. 81 | func (p *Packet) AvPacketShrinkSideData(t AvPacketSideDataType, s int) int { 82 | return int(C.av_packet_shrink_side_data((*C.struct_AVPacket)(p), (C.enum_AVPacketSideDataType)(t), C.int(s))) 83 | } 84 | 85 | //Get side information from packet. 86 | func (p *Packet) AvPacketGetSideData(t AvPacketSideDataType, s *int) *uint8 { 87 | return (*uint8)(C.av_packet_get_side_data((*C.struct_AVPacket)(p), (C.enum_AVPacketSideDataType)(t), (*C.int)(unsafe.Pointer(s)))) 88 | } 89 | 90 | //int av_packet_merge_side_data (Packet *pkt) 91 | // deprecated 92 | // func (p *Packet) AvPacketMergeSideData() int { 93 | // return int(C.av_packet_merge_side_data((*C.struct_AVPacket)(p))) 94 | // } 95 | 96 | //int av_packet_split_side_data (Packet *pkt) 97 | // deprecated 98 | // func (p *Packet) AvPacketSplitSideData() int { 99 | // return int(C.av_packet_split_side_data((*C.struct_AVPacket)(p))) 100 | // } 101 | 102 | //Convenience function to free all the side data stored. 103 | func (p *Packet) AvPacketFreeSideData() { 104 | C.av_packet_free_side_data((*C.struct_AVPacket)(p)) 105 | } 106 | 107 | //Setup a new reference to the data described by a given packet. 108 | func (p *Packet) AvPacketRef(s *Packet) int { 109 | return int(C.av_packet_ref((*C.struct_AVPacket)(p), (*C.struct_AVPacket)(s))) 110 | } 111 | 112 | //Wipe the packet. 113 | func (p *Packet) AvPacketUnref() { 114 | C.av_packet_unref((*C.struct_AVPacket)(p)) 115 | } 116 | 117 | //Move every field in src to dst and reset src. 118 | func (p *Packet) AvPacketMoveRef(s *Packet) { 119 | C.av_packet_move_ref((*C.struct_AVPacket)(p), (*C.struct_AVPacket)(s)) 120 | } 121 | 122 | //Copy only "properties" fields from src to dst. 123 | func (p *Packet) AvPacketCopyProps(s *Packet) int { 124 | return int(C.av_packet_copy_props((*C.struct_AVPacket)(p), (*C.struct_AVPacket)(s))) 125 | } 126 | 127 | //Convert valid timing fields (timestamps / durations) in a packet from one timebase to another. 128 | func (p *Packet) AvPacketRescaleTs(r, r2 avutil.Rational) { 129 | C.av_packet_rescale_ts((*C.struct_AVPacket)(p), *(*C.struct_AVRational)(unsafe.Pointer(&r)), *(*C.struct_AVRational)(unsafe.Pointer(&r2))) 130 | } 131 | -------------------------------------------------------------------------------- /avcodec/packet_struct.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avcodec 5 | 6 | //#cgo pkg-config: libavcodec 7 | //#include 8 | import "C" 9 | 10 | func (p *Packet) Buf() *AvBufferRef { 11 | return (*AvBufferRef)(p.buf) 12 | } 13 | 14 | func (p *Packet) Duration() int64 { 15 | return int64(p.duration) 16 | } 17 | 18 | func (p *Packet) SetDuration(d int64) { 19 | p.duration = C.int64_t(d) 20 | } 21 | 22 | func (p *Packet) Flags() int { 23 | return int(p.flags) 24 | } 25 | 26 | func (p *Packet) SetFlags(f int64) { 27 | p.flags = C.int(f) 28 | } 29 | 30 | func (p *Packet) SideDataElems() int { 31 | return int(p.side_data_elems) 32 | } 33 | 34 | func (p *Packet) Size() int { 35 | return int(p.size) 36 | } 37 | 38 | func (p *Packet) SetSize(s int) { 39 | p.size = C.int(s) 40 | } 41 | 42 | func (p *Packet) StreamIndex() int { 43 | return int(p.stream_index) 44 | } 45 | 46 | func (p *Packet) SetStreamIndex(i int) { 47 | p.stream_index = C.int(i) 48 | } 49 | 50 | func (p *Packet) ConvergenceDuration() int64 { 51 | return int64(p.convergence_duration) 52 | } 53 | 54 | func (p *Packet) Dts() int64 { 55 | return int64(p.dts) 56 | } 57 | 58 | func (p *Packet) SetDts(v int64) { 59 | p.dts = C.int64_t(v) 60 | } 61 | 62 | func (p *Packet) Pos() int64 { 63 | return int64(p.pos) 64 | } 65 | 66 | func (p *Packet) SetPos(v int64) { 67 | p.pos = C.int64_t(v) 68 | } 69 | 70 | func (p *Packet) Pts() int64 { 71 | return int64(p.pts) 72 | } 73 | 74 | func (p *Packet) SetPts(v int64) { 75 | p.pts = C.int64_t(v) 76 | } 77 | 78 | func (p *Packet) Data() *uint8 { 79 | return (*uint8)(p.data) 80 | } 81 | 82 | func (p *Packet) SetData(d *uint8) { 83 | p.data = (*C.uint8_t)(d) 84 | } 85 | -------------------------------------------------------------------------------- /avcodec/pixelformat.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avcodec 5 | 6 | //#cgo pkg-config: libavcodec 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avutil" 13 | ) 14 | 15 | //Utility function to access log2_chroma_w log2_chroma_h from the pixel format AvPixFmtDescriptor. 16 | func AvcodecGetChromaSubSample(pix_fmt avutil.PixelFormat, h, v *int) { 17 | panic("deprecated") 18 | //C.avcodec_get_chroma_sub_sample((C.enum_AVPixelFormat)(pix_fmt), (*C.int)(unsafe.Pointer(h)), (*C.int)(unsafe.Pointer(v))) 19 | } 20 | 21 | //Return a value representing the fourCC code associated to the pixel format pix_fmt, or 0 if no associated fourCC code can be found. 22 | func AvcodecPixFmtToCodecTag(pix_fmt avutil.PixelFormat) uint { 23 | return uint(C.avcodec_pix_fmt_to_codec_tag((C.enum_AVPixelFormat)(pix_fmt))) 24 | } 25 | 26 | //Find the best pixel format to convert to given a certain source pixel format. 27 | func AvcodecFindBestPixFmtOfList(pix_fmt_list *avutil.PixelFormat, src_pix_fmt avutil.PixelFormat, a int, l *int) avutil.PixelFormat { 28 | return (avutil.PixelFormat)(C.avcodec_find_best_pix_fmt_of_list((*C.enum_AVPixelFormat)(pix_fmt_list), (C.enum_AVPixelFormat)(src_pix_fmt), C.int(a), (*C.int)(unsafe.Pointer(l)))) 29 | } 30 | 31 | func AvcodecFindBestPixFmtOf2(dst1, dst2, src avutil.PixelFormat, a int, l *int) avutil.PixelFormat { 32 | return (avutil.PixelFormat)(C.avcodec_find_best_pix_fmt_of_2((C.enum_AVPixelFormat)(dst1), (C.enum_AVPixelFormat)(dst2), (C.enum_AVPixelFormat)(src), C.int(a), (*C.int)(unsafe.Pointer(l)))) 33 | } 34 | -------------------------------------------------------------------------------- /avdevice/avdevice.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | // Package avdevice deals with the input and output devices provided by the libavdevice library 5 | // The libavdevice library provides the same interface as libavformat. 6 | // Namely, an input device is considered like a demuxer, and an output device like a muxer, 7 | // and the interface and generic device options are the same provided by libavformat 8 | package avdevice 9 | 10 | /* 11 | #cgo pkg-config: libavdevice 12 | #include 13 | */ 14 | import "C" 15 | import ( 16 | "unsafe" 17 | 18 | "github.com/asticode/goav/avutil" 19 | ) 20 | 21 | type ( 22 | AvDeviceRect C.struct_AVDeviceRect 23 | AvDeviceCapabilitiesQuery C.struct_AVDeviceCapabilitiesQuery 24 | AvDeviceInfo C.struct_AVDeviceInfo 25 | AvDeviceInfoList C.struct_AVDeviceInfoList 26 | InputFormat C.struct_AVInputFormat 27 | OutputFormat C.struct_AVOutputFormat 28 | AvFormatContext C.struct_AVFormatContext 29 | AvAppToDevMessageType C.enum_AVAppToDevMessageType 30 | AvDevToAppMessageType C.enum_AVDevToAppMessageType 31 | ) 32 | 33 | //unsigned avdevice_version (void) 34 | func AvdeviceVersion() uint { 35 | return uint(C.avdevice_version()) 36 | } 37 | 38 | //Return the libavdevice build-time configuration. 39 | func AvdeviceConfiguration() string { 40 | return C.GoString(C.avdevice_configuration()) 41 | } 42 | 43 | //Return the libavdevice license. 44 | func AvdeviceLicense() string { 45 | return C.GoString(C.avdevice_license()) 46 | } 47 | 48 | //Initialize libavdevice and register all the input and output devices. 49 | func AvdeviceRegisterAll() { 50 | C.avdevice_register_all() 51 | } 52 | 53 | //Send control message from application to device. 54 | func AvdeviceAppToDevControlMessage(s *AvFormatContext, m AvAppToDevMessageType, da int, d uintptr) int { 55 | return int(C.avdevice_app_to_dev_control_message((*C.struct_AVFormatContext)(s), (C.enum_AVAppToDevMessageType)(m), unsafe.Pointer(&da), C.size_t(d))) 56 | } 57 | 58 | //Send control message from device to application. 59 | func AvdeviceDevToAppControlMessage(fcxt *AvFormatContext, m AvDevToAppMessageType, da int, d uintptr) int { 60 | return int(C.avdevice_dev_to_app_control_message((*C.struct_AVFormatContext)(fcxt), (C.enum_AVDevToAppMessageType)(m), unsafe.Pointer(&da), C.size_t(d))) 61 | } 62 | 63 | //Initialize capabilities probing API based on AvOption API. 64 | func AvdeviceCapabilitiesCreate(c **AvDeviceCapabilitiesQuery, s *AvFormatContext, d **avutil.Dictionary) int { 65 | return int(C.avdevice_capabilities_create((**C.struct_AVDeviceCapabilitiesQuery)(unsafe.Pointer(c)), (*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) 66 | } 67 | 68 | //Free resources created by avdevice_capabilities_create() 69 | func AvdeviceCapabilitiesFree(c **AvDeviceCapabilitiesQuery, s *AvFormatContext) { 70 | C.avdevice_capabilities_free((**C.struct_AVDeviceCapabilitiesQuery)(unsafe.Pointer(c)), (*C.struct_AVFormatContext)(s)) 71 | } 72 | 73 | //List devices. 74 | func AvdeviceListDevices(s *AvFormatContext, d **AvDeviceInfoList) int { 75 | return int(C.avdevice_list_devices((*C.struct_AVFormatContext)(s), (**C.struct_AVDeviceInfoList)(unsafe.Pointer(d)))) 76 | } 77 | 78 | //Convenient function to free result of avdeviceListDevices(). 79 | func AvdeviceFreeListDevices(d **AvDeviceInfoList) { 80 | C.avdevice_free_list_devices((**C.struct_AVDeviceInfoList)(unsafe.Pointer(d))) 81 | } 82 | 83 | // //int avdevice_list_input_sources (struct InputFormat *device, const char *device_name, Dictionary *device_options, AvDeviceInfoList **device_list) 84 | // //List devices. 85 | // func AvdeviceListInputSources(d *InputFormat, dv string, do *avutil.Dictionary, dl **AvDeviceInfoList) int { 86 | // return int(C.avdevice_list_input_sources((*C.struct_AVInputFormat)(d), C.CString(dv), (*C.struct_AVDictionary)(do), (**C.struct_AVDeviceInfoList)(unsafe.Pointer(dl)))) 87 | // } 88 | 89 | // //int avdevice_list_output_sinks (struct OutputFormat *device, const char *device_name, Dictionary *device_options, AvDeviceInfoList **device_list) 90 | // func AvdeviceListOutputSinks(d *OutputFormat, dn string, di *avutil.Dictionary, dl **AvDeviceInfoList) int { 91 | // return int(C.avdevice_list_output_sinks((*C.struct_AVOutputFormat)(d), C.CString(dn), (*C.struct_AVDictionary)(di), (**C.struct_AVDeviceInfoList)(unsafe.Pointer(dl)))) 92 | // } 93 | -------------------------------------------------------------------------------- /avdevice/format.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avdevice 5 | 6 | /* 7 | #cgo pkg-config: libavdevice 8 | #include 9 | */ 10 | import "C" 11 | 12 | //Audio input devices iterator. 13 | func (d *InputFormat) AvInputAudioDeviceNext() *InputFormat { 14 | return (*InputFormat)(C.av_input_audio_device_next((*C.struct_AVInputFormat)(d))) 15 | } 16 | 17 | //Video input devices iterator. 18 | func (d *InputFormat) AvInputVideoDeviceNext() *InputFormat { 19 | return (*InputFormat)(C.av_input_video_device_next((*C.struct_AVInputFormat)(d))) 20 | } 21 | 22 | //Audio output devices iterator. 23 | func (d *OutputFormat) AvOutputAudioDeviceNext() *OutputFormat { 24 | return (*OutputFormat)(C.av_output_audio_device_next((*C.struct_AVOutputFormat)(d))) 25 | } 26 | 27 | //Video output devices iterator. 28 | func (d *OutputFormat) AvOutputVideoDeviceNext() *OutputFormat { 29 | return (*OutputFormat)(C.av_output_video_device_next((*C.struct_AVOutputFormat)(d))) 30 | } 31 | -------------------------------------------------------------------------------- /avfilter/avfilter.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | //Package avfilter contains methods that deal with ffmpeg filters 5 | //filters in the same linear chain are separated by commas, and distinct linear chains of filters are separated by semicolons. 6 | //FFmpeg is enabled through the "C" libavfilter library 7 | package avfilter 8 | 9 | /* 10 | #cgo pkg-config: libavfilter 11 | #include 12 | */ 13 | import "C" 14 | import ( 15 | "unsafe" 16 | 17 | "github.com/asticode/goav/avutil" 18 | ) 19 | 20 | type ( 21 | Filter C.struct_AVFilter 22 | Context C.struct_AVFilterContext 23 | Link C.struct_AVFilterLink 24 | Graph C.struct_AVFilterGraph 25 | Input C.struct_AVFilterInOut 26 | Pad C.struct_AVFilterPad 27 | Class C.struct_AVClass 28 | MediaType C.enum_AVMediaType 29 | ) 30 | 31 | const ( 32 | MAX_ARRAY_SIZE = 1<<29 - 1 33 | ) 34 | 35 | //Return the LIBAvFILTER_VERSION_INT constant. 36 | func AvfilterVersion() uint { 37 | return uint(C.avfilter_version()) 38 | } 39 | 40 | //Return the libavfilter build-time configuration. 41 | func AvfilterConfiguration() string { 42 | return C.GoString(C.avfilter_configuration()) 43 | } 44 | 45 | //Return the libavfilter license. 46 | func AvfilterLicense() string { 47 | return C.GoString(C.avfilter_license()) 48 | } 49 | 50 | //Get the number of elements in a NULL-terminated array of Pads (e.g. 51 | func AvfilterPadCount(p *Pad) int { 52 | return int(C.avfilter_pad_count((*C.struct_AVFilterPad)(p))) 53 | } 54 | 55 | //Get the name of an Pad. 56 | func AvfilterPadGetName(p *Pad, pi int) string { 57 | return C.GoString(C.avfilter_pad_get_name((*C.struct_AVFilterPad)(p), C.int(pi))) 58 | } 59 | 60 | //Get the type of an Pad. 61 | func AvfilterPadGetType(p *Pad, pi int) MediaType { 62 | return (MediaType)(C.avfilter_pad_get_type((*C.struct_AVFilterPad)(p), C.int(pi))) 63 | } 64 | 65 | //Link two filters together. 66 | func AvfilterLink(s *Context, sp uint, d *Context, dp uint) int { 67 | return int(C.avfilter_link((*C.struct_AVFilterContext)(s), C.uint(sp), (*C.struct_AVFilterContext)(d), C.uint(dp))) 68 | } 69 | 70 | //Free the link in *link, and set its pointer to NULL. 71 | func AvfilterLinkFree(l **Link) { 72 | C.avfilter_link_free((**C.struct_AVFilterLink)(unsafe.Pointer(l))) 73 | } 74 | 75 | //Get the number of channels of a link. 76 | func AvfilterLinkGetChannels(l *Link) int { 77 | panic("deprecated") 78 | return 0 79 | //return int(C.avfilter_link_get_channels((*C.struct_AVFilterLink)(l))) 80 | } 81 | 82 | //Set the closed field of a link. 83 | // deprecated 84 | // func AvfilterLinkSetClosed(l *Link, c int) { 85 | // C.avfilter_link_set_closed((*C.struct_AVFilterLink)(l), C.int(c)) 86 | // } 87 | 88 | //Negotiate the media format, dimensions, etc of all inputs to a filter. 89 | func AvfilterConfigLinks(f *Context) int { 90 | return int(C.avfilter_config_links((*C.struct_AVFilterContext)(f))) 91 | } 92 | 93 | //Make the filter instance process a command. 94 | func AvfilterProcessCommand(f *Context, cmd, arg, res string, l, fl int) int { 95 | cc := C.CString(cmd) 96 | defer C.free(unsafe.Pointer(cc)) 97 | ca := C.CString(arg) 98 | defer C.free(unsafe.Pointer(ca)) 99 | cr := C.CString(res) 100 | defer C.free(unsafe.Pointer(cr)) 101 | return int(C.avfilter_process_command((*C.struct_AVFilterContext)(f), cc, ca, cr, C.int(l), C.int(fl))) 102 | } 103 | 104 | //Initialize the filter system. 105 | func AvfilterRegisterAll() { 106 | panic("deprecated") 107 | //C.avfilter_register_all() 108 | } 109 | 110 | //Initialize a filter with the supplied parameters. 111 | func (ctx *Context) AvfilterInitStr(args string) int { 112 | ca := C.CString(args) 113 | defer C.free(unsafe.Pointer(ca)) 114 | return int(C.avfilter_init_str((*C.struct_AVFilterContext)(ctx), ca)) 115 | } 116 | 117 | //Initialize a filter with the supplied dictionary of options. 118 | func (ctx *Context) AvfilterInitDict(o **avutil.Dictionary) int { 119 | return int(C.avfilter_init_dict((*C.struct_AVFilterContext)(ctx), (**C.struct_AVDictionary)(unsafe.Pointer(o)))) 120 | } 121 | 122 | //Free a filter context. 123 | func (ctx *Context) AvfilterFree() { 124 | C.avfilter_free((*C.struct_AVFilterContext)(ctx)) 125 | } 126 | 127 | func (ctx *Context) NbInputs() uint { 128 | return uint(ctx.nb_inputs) 129 | } 130 | 131 | func (ctx *Context) NbOutputs() uint { 132 | return uint(ctx.nb_outputs) 133 | } 134 | 135 | func (ctx *Context) Inputs() []*Link { 136 | if ctx.NbInputs() == 0 { 137 | return nil 138 | } 139 | 140 | arr := (*[MAX_ARRAY_SIZE](*Link))(unsafe.Pointer(ctx.inputs)) 141 | 142 | if arr == nil { 143 | return nil 144 | } 145 | 146 | return arr[:ctx.NbInputs()] 147 | } 148 | 149 | func (ctx *Context) Outputs() []*Link { 150 | if ctx.NbOutputs() == 0 { 151 | return nil 152 | } 153 | 154 | arr := (*[MAX_ARRAY_SIZE](*Link))(unsafe.Pointer(ctx.outputs)) 155 | 156 | return arr[:ctx.NbOutputs()] 157 | } 158 | 159 | //Insert a filter in the middle of an existing link. 160 | func AvfilterInsertFilter(l *Link, f *Context, fsi, fdi uint) int { 161 | return int(C.avfilter_insert_filter((*C.struct_AVFilterLink)(l), (*C.struct_AVFilterContext)(f), C.uint(fsi), C.uint(fdi))) 162 | } 163 | 164 | //avfilter_get_class 165 | func AvfilterGetClass() *Class { 166 | return (*Class)(C.avfilter_get_class()) 167 | } 168 | 169 | //Allocate a single Input entry. 170 | func AvfilterInoutAlloc() *Input { 171 | return (*Input)(C.avfilter_inout_alloc()) 172 | } 173 | 174 | //Free the supplied list of Input and set *inout to NULL. 175 | func AvfilterInoutFree(i **Input) { 176 | C.avfilter_inout_free((**C.struct_AVFilterInOut)(unsafe.Pointer(i))) 177 | } 178 | 179 | func (i *Input) SetName(n string) { 180 | i.name = C.CString(n) 181 | } 182 | 183 | func (i *Input) SetFilterCtx(ctx *Context) { 184 | i.filter_ctx = (*C.struct_AVFilterContext)(ctx) 185 | } 186 | 187 | func (i *Input) SetPadIdx(idx int) { 188 | i.pad_idx = C.int(idx) 189 | } 190 | 191 | func (i *Input) SetNext(n *Input) { 192 | i.next = (*C.struct_AVFilterInOut)(n) 193 | } 194 | 195 | func (l *Link) TimeBase() avutil.Rational { 196 | return *(*avutil.Rational)(unsafe.Pointer(&l.time_base)) 197 | } 198 | -------------------------------------------------------------------------------- /avfilter/filter.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avfilter 5 | 6 | /* 7 | #cgo pkg-config: libavfilter 8 | #include 9 | */ 10 | import "C" 11 | import "unsafe" 12 | 13 | //Get a filter definition matching the given name. 14 | func AvfilterGetByName(n string) *Filter { 15 | cn := C.CString(n) 16 | defer C.free(unsafe.Pointer(cn)) 17 | return (*Filter)(C.avfilter_get_by_name(cn)) 18 | } 19 | 20 | //Register a filter. 21 | func (f *Filter) AvfilterRegister() int { 22 | panic("deprecated") 23 | return 0 24 | //return int(C.avfilter_register((*C.struct_AVFilter)(f))) 25 | } 26 | 27 | //Iterate over all registered filters. 28 | func (f *Filter) AvfilterNext() *Filter { 29 | panic("deprecated") 30 | return nil 31 | //return (*Filter)(C.avfilter_next((*C.struct_AVFilter)(f))) 32 | } 33 | -------------------------------------------------------------------------------- /avfilter/graph.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avfilter 5 | 6 | /* 7 | #cgo pkg-config: libavfilter 8 | #include 9 | #include 10 | #include 11 | */ 12 | import "C" 13 | import ( 14 | "unsafe" 15 | "github.com/asticode/goav/avutil" 16 | ) 17 | 18 | const ( 19 | AV_BUFFERSRC_FLAG_KEEP_REF = C.AV_BUFFERSRC_FLAG_KEEP_REF 20 | ) 21 | 22 | //Allocate a filter graph. 23 | func AvfilterGraphAlloc() *Graph { 24 | return (*Graph)(C.avfilter_graph_alloc()) 25 | } 26 | 27 | //Create a new filter instance in a filter graph. 28 | func (g *Graph) AvfilterGraphAllocFilter(f *Filter, n string) *Context { 29 | cn := C.CString(n) 30 | defer C.free(unsafe.Pointer(cn)) 31 | return (*Context)(C.avfilter_graph_alloc_filter((*C.struct_AVFilterGraph)(g), (*C.struct_AVFilter)(f), cn)) 32 | } 33 | 34 | //Get a filter instance identified by instance name from graph. 35 | func (g *Graph) AvfilterGraphGetFilter(n string) *Context { 36 | cn := C.CString(n) 37 | defer C.free(unsafe.Pointer(cn)) 38 | return (*Context)(C.avfilter_graph_get_filter((*C.struct_AVFilterGraph)(g), cn)) 39 | } 40 | 41 | //Enable or disable automatic format conversion inside the graph. 42 | func (g *Graph) AvfilterGraphSetAutoConvert(f uint) { 43 | C.avfilter_graph_set_auto_convert((*C.struct_AVFilterGraph)(g), C.uint(f)) 44 | } 45 | 46 | //Check validity and configure all the links and formats in the graph. 47 | func (g *Graph) AvfilterGraphConfig(l *int) int { 48 | return int(C.avfilter_graph_config((*C.struct_AVFilterGraph)(g), unsafe.Pointer(l))) 49 | } 50 | 51 | //Free a graph, destroy its links, and set *graph to NULL. 52 | func (g *Graph) AvfilterGraphFree() { 53 | C.avfilter_graph_free((**C.struct_AVFilterGraph)(unsafe.Pointer(&g))) 54 | } 55 | 56 | //Add a graph described by a string to a graph. 57 | func (g *Graph) AvfilterGraphParse(f string, i, o *Input, l int) int { 58 | cf := C.CString(f) 59 | defer C.free(unsafe.Pointer(cf)) 60 | return int(C.avfilter_graph_parse((*C.struct_AVFilterGraph)(g), cf, (*C.struct_AVFilterInOut)(i), (*C.struct_AVFilterInOut)(o), unsafe.Pointer(&l))) 61 | } 62 | 63 | //Add a graph described by a string to a graph. 64 | func (g *Graph) AvfilterGraphParsePtr(f string, i, o **Input, l *int) int { 65 | cf := C.CString(f) 66 | defer C.free(unsafe.Pointer(cf)) 67 | return int(C.avfilter_graph_parse_ptr((*C.struct_AVFilterGraph)(g), cf, (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o)), unsafe.Pointer(l))) 68 | } 69 | 70 | //Add a graph described by a string to a graph. 71 | func (g *Graph) AvfilterGraphParse2(f string, i, o **Input) int { 72 | cf := C.CString(f) 73 | defer C.free(unsafe.Pointer(cf)) 74 | return int(C.avfilter_graph_parse2((*C.struct_AVFilterGraph)(g), cf, (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o)))) 75 | } 76 | 77 | //Send a command to one or more filter instances. 78 | func (g *Graph) AvfilterGraphSendCommand(t, cmd, arg, res string, resl, f int) int { 79 | ct := C.CString(t) 80 | defer C.free(unsafe.Pointer(ct)) 81 | cc := C.CString(cmd) 82 | defer C.free(unsafe.Pointer(cc)) 83 | ca := C.CString(arg) 84 | defer C.free(unsafe.Pointer(ca)) 85 | cr := C.CString(res) 86 | defer C.free(unsafe.Pointer(cr)) 87 | return int(C.avfilter_graph_send_command((*C.struct_AVFilterGraph)(g), ct, cc, ca, cr, C.int(resl), C.int(f))) 88 | } 89 | 90 | //Queue a command for one or more filter instances. 91 | func (g *Graph) AvfilterGraphQueueCommand(t, cmd, arg string, f int, ts C.double) int { 92 | ct := C.CString(t) 93 | defer C.free(unsafe.Pointer(ct)) 94 | cc := C.CString(cmd) 95 | defer C.free(unsafe.Pointer(cc)) 96 | ca := C.CString(arg) 97 | defer C.free(unsafe.Pointer(ca)) 98 | return int(C.avfilter_graph_queue_command((*C.struct_AVFilterGraph)(g), ct, cc, ca, C.int(f), ts)) 99 | } 100 | 101 | //Dump a graph into a human-readable string representation. 102 | func (g *Graph) AvfilterGraphDump(o string) string { 103 | co := C.CString(o) 104 | defer C.free(unsafe.Pointer(co)) 105 | return C.GoString(C.avfilter_graph_dump((*C.struct_AVFilterGraph)(g), co)) 106 | } 107 | 108 | //Request a frame on the oldest sink 109 | func (g *Graph) AvfilterGraphRequestOldestlink() int { 110 | return int(C.avfilter_graph_request_oldest((*C.struct_AVFilterGraph)(g))) 111 | } 112 | 113 | //Create and add a filter instance into an existing graph. 114 | func AvfilterGraphCreateFilter(cx **Context, f *Filter, n, a string, o *int, g *Graph) int { 115 | ca := (*C.char)(nil) 116 | if len(a) > 0 { 117 | ca = C.CString(a) 118 | defer C.free(unsafe.Pointer(ca)) 119 | } 120 | cn := C.CString(n) 121 | defer C.free(unsafe.Pointer(cn)) 122 | return int(C.avfilter_graph_create_filter((**C.struct_AVFilterContext)(unsafe.Pointer(cx)), (*C.struct_AVFilter)(f), cn, ca, unsafe.Pointer(o), (*C.struct_AVFilterGraph)(g))) 123 | } 124 | 125 | func (g *Graph) AvBuffersrcAddFrameFlags(cx *Context, frame *avutil.Frame, flags int) int { 126 | return int(C.av_buffersrc_add_frame_flags((*C.struct_AVFilterContext)(cx), (*C.struct_AVFrame)(unsafe.Pointer(frame)), C.int(flags))) 127 | } 128 | 129 | func (g *Graph) AvBuffersinkGetFrame(cx *Context, frame *avutil.Frame) int { 130 | return int(C.av_buffersink_get_frame((*C.struct_AVFilterContext)(cx), (*C.struct_AVFrame)(unsafe.Pointer(frame)))) 131 | } 132 | -------------------------------------------------------------------------------- /avformat/avformat.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | //Package avformat provides some generic global options, which can be set on all the muxers and demuxers. 5 | //In addition each muxer or demuxer may support so-called private options, which are specific for that component. 6 | //Supported formats (muxers and demuxers) provided by the libavformat library 7 | package avformat 8 | 9 | //#cgo pkg-config: libavformat libavcodec libavutil libavdevice libavfilter libswresample libswscale 10 | //#include 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | //#include 20 | //#include 21 | import "C" 22 | import ( 23 | "unsafe" 24 | 25 | "github.com/asticode/goav/avutil" 26 | ) 27 | 28 | type ( 29 | AvProbeData C.struct_AVProbeData 30 | InputFormat C.struct_AVInputFormat 31 | OutputFormat C.struct_AVOutputFormat 32 | Context C.struct_AVFormatContext 33 | Frame C.struct_AVFrame 34 | CodecContext C.struct_AVCodecContext 35 | AvIndexEntry C.struct_AVIndexEntry 36 | Stream C.struct_AVStream 37 | AvProgram C.struct_AVProgram 38 | AvChapter C.struct_AVChapter 39 | AvPacketList C.struct_AVPacketList 40 | Packet C.struct_AVPacket 41 | CodecParserContext C.struct_AVCodecParserContext 42 | AvIOContext C.struct_AVIOContext 43 | AvCodec C.struct_AVCodec 44 | AvCodecTag C.struct_AVCodecTag 45 | Class C.struct_AVClass 46 | AvFormatInternal C.struct_AVFormatInternal 47 | AvIOInterruptCB C.struct_AVIOInterruptCB 48 | AvPacketSideData C.struct_AVPacketSideData 49 | FFFrac C.struct_FFFrac 50 | AvStreamParseType C.enum_AVStreamParseType 51 | AvDiscard C.enum_AVDiscard 52 | MediaType C.enum_AVMediaType 53 | AvDurationEstimationMethod C.enum_AVDurationEstimationMethod 54 | AvPacketSideDataType C.enum_AVPacketSideDataType 55 | CodecId C.enum_AVCodecID 56 | ) 57 | 58 | const ( 59 | MAX_ARRAY_SIZE = 1<<29 - 1 60 | AVFMT_NOFILE = C.AVFMT_NOFILE 61 | AVFMT_GLOBALHEADER = C.AVFMT_GLOBALHEADER 62 | AVFMT_FLAG_CUSTOM_IO = C.AVFMT_FLAG_CUSTOM_IO 63 | AVIO_FLAG_WRITE = C.AVIO_FLAG_WRITE 64 | FF_FDEBUG_TS = C.FF_FDEBUG_TS 65 | ) 66 | 67 | const ( 68 | AVSEEK_FLAG_ANY = C.AVSEEK_FLAG_ANY 69 | AVSEEK_FLAG_BACKWARD = C.AVSEEK_FLAG_BACKWARD 70 | AVSEEK_FLAG_BYTE = C.AVSEEK_FLAG_BYTE 71 | AVSEEK_FLAG_FRAME = C.AVSEEK_FLAG_FRAME 72 | ) 73 | 74 | type File C.FILE 75 | 76 | //Allocate and read the payload of a packet and initialize its fields with default values. 77 | func (ctxt *AvIOContext) AvGetPacket(pkt *Packet, s int) int { 78 | return int(C.av_get_packet((*C.struct_AVIOContext)(ctxt), (*C.struct_AVPacket)(pkt), C.int(s))) 79 | } 80 | 81 | //Read data and append it to the current content of the Packet. 82 | func (ctxt *AvIOContext) AvAppendPacket(pkt *Packet, s int) int { 83 | return int(C.av_append_packet((*C.struct_AVIOContext)(ctxt), (*C.struct_AVPacket)(pkt), C.int(s))) 84 | } 85 | 86 | func (f *InputFormat) AvRegisterInputFormat() { 87 | panic("deprecated") 88 | //C.av_register_input_format((*C.struct_AVInputFormat)(f)) 89 | } 90 | 91 | func (f *OutputFormat) AvRegisterOutputFormat() { 92 | panic("deprecated") 93 | //C.av_register_output_format((*C.struct_AVOutputFormat)(f)) 94 | } 95 | 96 | //If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registered input format after f or NULL if f is the last one. 97 | func (f *InputFormat) AvIformatNext() *InputFormat { 98 | panic("deprecated") 99 | return nil 100 | //return (*InputFormat)(C.av_iformat_next((*C.struct_AVInputFormat)(f))) 101 | } 102 | 103 | //If f is NULL, returns the first registered output format, if f is non-NULL, returns the next registered output format after f or NULL if f is the last one. 104 | func (f *OutputFormat) AvOformatNext() *OutputFormat { 105 | panic("deprecated") 106 | return nil 107 | //return (*OutputFormat)(C.av_oformat_next((*C.struct_AVOutputFormat)(f))) 108 | } 109 | 110 | func (f *OutputFormat) Flags() int { 111 | return int(f.flags) 112 | } 113 | 114 | //Return the LIBAvFORMAT_VERSION_INT constant. 115 | func AvformatVersion() uint { 116 | return uint(C.avformat_version()) 117 | } 118 | 119 | //Return the libavformat build-time configuration. 120 | func AvformatConfiguration() string { 121 | return C.GoString(C.avformat_configuration()) 122 | } 123 | 124 | //Return the libavformat license. 125 | func AvformatLicense() string { 126 | return C.GoString(C.avformat_license()) 127 | } 128 | 129 | //Do global initialization of network components. 130 | func AvformatNetworkInit() int { 131 | return int(C.avformat_network_init()) 132 | } 133 | 134 | //Undo the initialization done by avformat_network_init. 135 | func AvformatNetworkDeinit() int { 136 | return int(C.avformat_network_deinit()) 137 | } 138 | 139 | //Allocate an Context. 140 | func AvformatAllocContext() *Context { 141 | return (*Context)(C.avformat_alloc_context()) 142 | } 143 | 144 | //Get the Class for Context. 145 | func AvformatGetClass() *Class { 146 | return (*Class)(C.avformat_get_class()) 147 | } 148 | 149 | //Get side information from stream. 150 | func (s *Stream) AvStreamGetSideData(t AvPacketSideDataType, z int) *uint8 { 151 | return (*uint8)(C.av_stream_get_side_data((*C.struct_AVStream)(s), (C.enum_AVPacketSideDataType)(t), (*C.int)(unsafe.Pointer(&z)))) 152 | } 153 | 154 | //Allocate an Context for an output format. 155 | func AvformatAllocOutputContext2(ctx **Context, o *OutputFormat, fo, fi string) int { 156 | cfo := (*C.char)(nil) 157 | if len(fo) > 0 { 158 | cfo = C.CString(fo) 159 | defer C.free(unsafe.Pointer(cfo)) 160 | } 161 | cfi := C.CString(fi) 162 | defer C.free(unsafe.Pointer(cfi)) 163 | return int(C.avformat_alloc_output_context2((**C.struct_AVFormatContext)(unsafe.Pointer(ctx)), (*C.struct_AVOutputFormat)(o), cfo, cfi)) 164 | } 165 | 166 | //Find InputFormat based on the short name of the input format. 167 | func AvFindInputFormat(s string) *InputFormat { 168 | cs := C.CString(s) 169 | defer C.free(unsafe.Pointer(cs)) 170 | return (*InputFormat)(C.av_find_input_format(cs)) 171 | } 172 | 173 | //Guess the file format. 174 | func AvProbeInputFormat(pd *AvProbeData, i int) *InputFormat { 175 | return (*InputFormat)(C.av_probe_input_format((*C.struct_AVProbeData)(pd), C.int(i))) 176 | } 177 | 178 | //Guess the file format. 179 | func AvProbeInputFormat2(pd *AvProbeData, o int, sm *int) *InputFormat { 180 | return (*InputFormat)(C.av_probe_input_format2((*C.struct_AVProbeData)(pd), C.int(o), (*C.int)(unsafe.Pointer(sm)))) 181 | } 182 | 183 | //Guess the file format. 184 | func AvProbeInputFormat3(pd *AvProbeData, o int, sl *int) *InputFormat { 185 | return (*InputFormat)(C.av_probe_input_format3((*C.struct_AVProbeData)(pd), C.int(o), (*C.int)(unsafe.Pointer(sl)))) 186 | } 187 | 188 | //Probe a bytestream to determine the input format. 189 | func AvProbeInputBuffer2(pb *AvIOContext, f **InputFormat, fi string, l int, o, m uint) int { 190 | cfi := C.CString(fi) 191 | defer C.free(unsafe.Pointer(cfi)) 192 | return int(C.av_probe_input_buffer2((*C.struct_AVIOContext)(pb), (**C.struct_AVInputFormat)(unsafe.Pointer(f)), cfi, unsafe.Pointer(&l), C.uint(o), C.uint(m))) 193 | } 194 | 195 | //Like av_probe_input_buffer2() but returns 0 on success. 196 | func AvProbeInputBuffer(pb *AvIOContext, f **InputFormat, fi string, l int, o, m uint) int { 197 | cfi := C.CString(fi) 198 | defer C.free(unsafe.Pointer(cfi)) 199 | return int(C.av_probe_input_buffer((*C.struct_AVIOContext)(pb), (**C.struct_AVInputFormat)(unsafe.Pointer(f)), cfi, unsafe.Pointer(&l), C.uint(o), C.uint(m))) 200 | } 201 | 202 | //Create and initialize a AVIOContext for accessing the resource indicated by url. 203 | func AvIOOpen(pb **AvIOContext, fi string, flags int) int { 204 | cfi := C.CString(fi) 205 | defer C.free(unsafe.Pointer(cfi)) 206 | return int(C.avio_open((**C.struct_AVIOContext)(unsafe.Pointer(pb)), cfi, C.int(flags))) 207 | } 208 | 209 | //Force flushing of buffered data. 210 | func AvIOFlush(pb *AvIOContext) { 211 | C.avio_flush((*C.struct_AVIOContext)(unsafe.Pointer(pb))) 212 | } 213 | 214 | //Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL. 215 | func AvIOClosep(pb **AvIOContext) int { 216 | return int(C.avio_closep((**C.struct_AVIOContext)(unsafe.Pointer(pb)))) 217 | } 218 | 219 | //Open an input stream and read the header. 220 | func AvformatOpenInput(ps **Context, fi string, fmt *InputFormat, d **avutil.Dictionary) int { 221 | cfi := C.CString(fi) 222 | defer C.free(unsafe.Pointer(cfi)) 223 | return int(C.avformat_open_input((**C.struct_AVFormatContext)(unsafe.Pointer(ps)), cfi, (*C.struct_AVInputFormat)(fmt), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) 224 | } 225 | 226 | //Return the output format in the list of registered output formats which best matches the provided parameters, or return NULL if there is no match. 227 | func AvGuessFormat(sn, f, mt string) *OutputFormat { 228 | csn := C.CString(sn) 229 | defer C.free(unsafe.Pointer(csn)) 230 | cf := C.CString(f) 231 | defer C.free(unsafe.Pointer(cf)) 232 | cmt := C.CString(mt) 233 | defer C.free(unsafe.Pointer(cmt)) 234 | return (*OutputFormat)(C.av_guess_format(csn, cf, cmt)) 235 | } 236 | 237 | //Guess the codec ID based upon muxer and filename. 238 | func AvGuessCodec(fmt *OutputFormat, sn, f, mt string, t MediaType) CodecId { 239 | csn := C.CString(sn) 240 | defer C.free(unsafe.Pointer(csn)) 241 | cf := C.CString(f) 242 | defer C.free(unsafe.Pointer(cf)) 243 | cmt := C.CString(mt) 244 | defer C.free(unsafe.Pointer(cmt)) 245 | return (CodecId)(C.av_guess_codec((*C.struct_AVOutputFormat)(fmt), csn, cf, cmt, (C.enum_AVMediaType)(t))) 246 | } 247 | 248 | //Send a nice hexadecimal dump of a buffer to the specified file stream. 249 | func AvHexDump(f *File, b *uint8, s int) { 250 | C.av_hex_dump((*C.FILE)(f), (*C.uint8_t)(b), C.int(s)) 251 | } 252 | 253 | //Send a nice hexadecimal dump of a buffer to the log. 254 | func AvHexDumpLog(a, l int, b *uint8, s int) { 255 | C.av_hex_dump_log(unsafe.Pointer(&a), C.int(l), (*C.uint8_t)(b), C.int(s)) 256 | } 257 | 258 | //Send a nice dump of a packet to the specified file stream. 259 | func AvPktDump2(f *File, pkt *Packet, dp int, st *Stream) { 260 | C.av_pkt_dump2((*C.FILE)(f), (*C.struct_AVPacket)(pkt), C.int(dp), (*C.struct_AVStream)(st)) 261 | } 262 | 263 | //Send a nice dump of a packet to the log. 264 | func AvPktDumpLog2(a int, l int, pkt *Packet, dp int, st *Stream) { 265 | C.av_pkt_dump_log2(unsafe.Pointer(&a), C.int(l), (*C.struct_AVPacket)(pkt), C.int(dp), (*C.struct_AVStream)(st)) 266 | } 267 | 268 | //enum CodecId av_codec_get_id (const struct AvCodecTag *const *tags, unsigned int tag) 269 | //Get the CodecId for the given codec tag tag. 270 | func AvCodecGetId(t **AvCodecTag, tag uint) CodecId { 271 | return (CodecId)(C.av_codec_get_id((**C.struct_AVCodecTag)(unsafe.Pointer(t)), C.uint(tag))) 272 | } 273 | 274 | //Get the codec tag for the given codec id id. 275 | func AvCodecGetTag(t **AvCodecTag, id CodecId) uint { 276 | return uint(C.av_codec_get_tag((**C.struct_AVCodecTag)(unsafe.Pointer(t)), (C.enum_AVCodecID)(id))) 277 | } 278 | 279 | //Get the codec tag for the given codec id. 280 | func AvCodecGetTag2(t **AvCodecTag, id CodecId, tag *uint) int { 281 | return int(C.av_codec_get_tag2((**C.struct_AVCodecTag)(unsafe.Pointer(t)), (C.enum_AVCodecID)(id), (*C.uint)(unsafe.Pointer(tag)))) 282 | } 283 | 284 | //Get the index for a specific timestamp. 285 | func AvIndexSearchTimestamp(st *Stream, t int64, f int) int { 286 | return int(C.av_index_search_timestamp((*C.struct_AVStream)(st), C.int64_t(t), C.int(f))) 287 | } 288 | 289 | //Add an index entry into a sorted list. 290 | func AvAddIndexEntry(st *Stream, pos, t, int64, s, d, f int) int { 291 | return int(C.av_add_index_entry((*C.struct_AVStream)(st), C.int64_t(pos), C.int64_t(t), C.int(s), C.int(d), C.int(f))) 292 | } 293 | 294 | //Split a URL string into components. 295 | func AvUrlSplit(p string, ps int, a string, as int, h string, hs int, pp *int, path string, psize int, url string) { 296 | cp := C.CString(p) 297 | defer C.free(unsafe.Pointer(cp)) 298 | ca := C.CString(a) 299 | defer C.free(unsafe.Pointer(ca)) 300 | ch := C.CString(h) 301 | defer C.free(unsafe.Pointer(ch)) 302 | cpa := C.CString(path) 303 | defer C.free(unsafe.Pointer(cpa)) 304 | cu := C.CString(url) 305 | defer C.free(unsafe.Pointer(cu)) 306 | C.av_url_split(cp, C.int(ps), ca, C.int(as), ch, C.int(hs), (*C.int)(unsafe.Pointer(pp)), cpa, C.int(psize), cu) 307 | } 308 | 309 | //int av_get_frame_filename (char *buf, int buf_size, const char *path, int number) 310 | //Return in 'buf' the path with 'd' replaced by a number. 311 | func AvGetFrameFilename(b string, bs int, pa string, n int) int { 312 | cb := C.CString(b) 313 | defer C.free(unsafe.Pointer(cb)) 314 | cpa := C.CString(pa) 315 | defer C.free(unsafe.Pointer(cpa)) 316 | return int(C.av_get_frame_filename(cb, C.int(bs), cpa, C.int(n))) 317 | } 318 | 319 | //Check whether filename actually is a numbered sequence generator. 320 | func AvFilenameNumberTest(f string) int { 321 | cf := C.CString(f) 322 | defer C.free(unsafe.Pointer(cf)) 323 | return int(C.av_filename_number_test(cf)) 324 | } 325 | 326 | //Generate an SDP for an RTP session. 327 | func AvSdpCreate(ac **Context, nf int, b string, s int) int { 328 | cb := C.CString(b) 329 | defer C.free(unsafe.Pointer(cb)) 330 | return int(C.av_sdp_create((**C.struct_AVFormatContext)(unsafe.Pointer(ac)), C.int(nf), cb, C.int(s))) 331 | } 332 | 333 | //int av_match_ext (const char *filename, const char *extensions) 334 | //Return a positive value if the given filename has one of the given extensions, 0 otherwise. 335 | func AvMatchExt(f, e string) int { 336 | cf := C.CString(f) 337 | defer C.free(unsafe.Pointer(cf)) 338 | ce := C.CString(e) 339 | defer C.free(unsafe.Pointer(ce)) 340 | return int(C.av_match_ext(cf, ce)) 341 | } 342 | 343 | //Test if the given container can store a codec. 344 | func AvformatQueryCodec(o *OutputFormat, cd CodecId, sc int) int { 345 | return int(C.avformat_query_codec((*C.struct_AVOutputFormat)(o), (C.enum_AVCodecID)(cd), C.int(sc))) 346 | } 347 | 348 | func AvformatGetRiffVideoTags() *AvCodecTag { 349 | return (*AvCodecTag)(C.avformat_get_riff_video_tags()) 350 | } 351 | 352 | //struct AvCodecTag * avformat_get_riff_audio_tags (void) 353 | func AvformatGetRiffAudioTags() *AvCodecTag { 354 | return (*AvCodecTag)(C.avformat_get_riff_audio_tags()) 355 | } 356 | 357 | func AvformatGetMovVideoTags() *AvCodecTag { 358 | return (*AvCodecTag)(C.avformat_get_mov_video_tags()) 359 | } 360 | 361 | func AvformatGetMovAudioTags() *AvCodecTag { 362 | return (*AvCodecTag)(C.avformat_get_mov_audio_tags()) 363 | } 364 | -------------------------------------------------------------------------------- /avformat/context.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avformat 5 | 6 | //#cgo pkg-config: libavformat 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avcodec" 13 | "github.com/asticode/goav/avutil" 14 | ) 15 | 16 | //Close an opened input Context. 17 | func AvformatCloseInput(ctxt *Context) { 18 | var ptr *C.struct_AVFormatContext = (*C.struct_AVFormatContext)(unsafe.Pointer(ctxt)) 19 | C.avformat_close_input((**C.struct_AVFormatContext)(&ptr)) 20 | } 21 | 22 | func (s *Context) AvFormatGetProbeScore() int { 23 | panic("deprecated") 24 | return 0 25 | //return int(C.av_format_get_probe_score((*C.struct_AVFormatContext)(s))) 26 | } 27 | 28 | func (s *Context) AvFormatGetVideoCodec() *AvCodec { 29 | panic("deprecated") 30 | return nil 31 | //return (*AvCodec)(C.av_format_get_video_codec((*C.struct_AVFormatContext)(s))) 32 | } 33 | 34 | func (s *Context) AvFormatSetVideoCodec(c *AvCodec) { 35 | panic("deprecated") 36 | //C.av_format_set_video_codec((*C.struct_AVFormatContext)(s), (*C.struct_AVCodec)(c)) 37 | } 38 | 39 | func (s *Context) AvFormatGetAudioCodec() *AvCodec { 40 | panic("deprecated") 41 | return nil 42 | //return (*AvCodec)(C.av_format_get_audio_codec((*C.struct_AVFormatContext)(s))) 43 | } 44 | 45 | func (s *Context) AvFormatSetAudioCodec(c *AvCodec) { 46 | panic("deprecated") 47 | //C.av_format_set_audio_codec((*C.struct_AVFormatContext)(s), (*C.struct_AVCodec)(c)) 48 | } 49 | 50 | func (s *Context) AvFormatGetSubtitleCodec() *AvCodec { 51 | panic("deprecated") 52 | return nil 53 | //return (*AvCodec)(C.av_format_get_subtitle_codec((*C.struct_AVFormatContext)(s))) 54 | } 55 | 56 | func (s *Context) AvFormatSetSubtitleCodec(c *AvCodec) { 57 | panic("deprecated") 58 | //C.av_format_set_subtitle_codec((*C.struct_AVFormatContext)(s), (*C.struct_AVCodec)(c)) 59 | } 60 | 61 | func (s *Context) AvFormatGetMetadataHeaderPadding() int { 62 | panic("deprecated") 63 | return 0 64 | //return int(C.av_format_get_metadata_header_padding((*C.struct_AVFormatContext)(s))) 65 | } 66 | 67 | func (s *Context) AvFormatSetMetadataHeaderPadding(c int) { 68 | panic("deprecated") 69 | //C.av_format_set_metadata_header_padding((*C.struct_AVFormatContext)(s), C.int(c)) 70 | } 71 | 72 | func (s *Context) AvFormatGetOpaque() { 73 | panic("deprecated") 74 | //C.av_format_get_opaque((*C.struct_AVFormatContext)(s)) 75 | } 76 | 77 | func (s *Context) AvFormatSetOpaque(o int) { 78 | panic("deprecated") 79 | //C.av_format_set_opaque((*C.struct_AVFormatContext)(s), unsafe.Pointer(&o)) 80 | } 81 | 82 | //This function will cause global side data to be injected in the next packet of each stream as well as after any subsequent seek. 83 | func (s *Context) AvFormatInjectGlobalSideData() { 84 | C.av_format_inject_global_side_data((*C.struct_AVFormatContext)(s)) 85 | } 86 | 87 | //Returns the method used to set ctx->duration. 88 | func (s *Context) AvFmtCtxGetDurationEstimationMethod() AvDurationEstimationMethod { 89 | return (AvDurationEstimationMethod)(C.av_fmt_ctx_get_duration_estimation_method((*C.struct_AVFormatContext)(s))) 90 | } 91 | 92 | //Free an Context and all its streams. 93 | func (s *Context) AvformatFreeContext() { 94 | C.avformat_free_context((*C.struct_AVFormatContext)(s)) 95 | } 96 | 97 | //Add a new stream to a media file. 98 | func (s *Context) AvformatNewStream(c *AvCodec) *Stream { 99 | return (*Stream)(C.avformat_new_stream((*C.struct_AVFormatContext)(s), (*C.struct_AVCodec)(c))) 100 | } 101 | 102 | func (s *Context) AvNewProgram(id int) *AvProgram { 103 | return (*AvProgram)(C.av_new_program((*C.struct_AVFormatContext)(s), C.int(id))) 104 | } 105 | 106 | //Read packets of a media file to get stream information. 107 | func (s *Context) AvformatFindStreamInfo(d **avutil.Dictionary) int { 108 | return int(C.avformat_find_stream_info((*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(d)))) 109 | } 110 | 111 | //Find the programs which belong to a given stream. 112 | func (s *Context) AvFindProgramFromStream(l *AvProgram, su int) *AvProgram { 113 | return (*AvProgram)(C.av_find_program_from_stream((*C.struct_AVFormatContext)(s), (*C.struct_AVProgram)(l), C.int(su))) 114 | } 115 | 116 | //Find the "best" stream in the file. 117 | func AvFindBestStream(ic *Context, t MediaType, ws, rs int, c **AvCodec, f int) int { 118 | return int(C.av_find_best_stream((*C.struct_AVFormatContext)(ic), (C.enum_AVMediaType)(t), C.int(ws), C.int(rs), (**C.struct_AVCodec)(unsafe.Pointer(c)), C.int(f))) 119 | } 120 | 121 | //Return the next frame of a stream. 122 | func (s *Context) AvReadFrame(pkt *avcodec.Packet) int { 123 | return int(C.av_read_frame((*C.struct_AVFormatContext)(unsafe.Pointer(s)), (*C.struct_AVPacket)(unsafe.Pointer(pkt)))) 124 | } 125 | 126 | //Seek to the keyframe at timestamp. 127 | func (s *Context) AvSeekFrame(st int, t int64, f int) int { 128 | return int(C.av_seek_frame((*C.struct_AVFormatContext)(s), C.int(st), C.int64_t(t), C.int(f))) 129 | } 130 | 131 | //Seek to timestamp ts. 132 | func (s *Context) AvformatSeekFile(si int, mit, ts, mat int64, f int) int { 133 | return int(C.avformat_seek_file((*C.struct_AVFormatContext)(s), C.int(si), C.int64_t(mit), C.int64_t(ts), C.int64_t(mat), C.int(f))) 134 | } 135 | 136 | //Discard all internally buffered data. 137 | func (s *Context) AvformatFlush() int { 138 | return int(C.avformat_flush((*C.struct_AVFormatContext)(s))) 139 | } 140 | 141 | //Start playing a network-based stream (e.g. 142 | func (s *Context) AvReadPlay() int { 143 | return int(C.av_read_play((*C.struct_AVFormatContext)(s))) 144 | } 145 | 146 | //Pause a network-based stream (e.g. 147 | func (s *Context) AvReadPause() int { 148 | return int(C.av_read_pause((*C.struct_AVFormatContext)(s))) 149 | } 150 | 151 | //Allocate the stream private data and write the stream header to an output media file. 152 | func (s *Context) AvformatWriteHeader(o **avutil.Dictionary) int { 153 | return int(C.avformat_write_header((*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(o)))) 154 | } 155 | 156 | //Write a packet to an output media file. 157 | func (s *Context) AvWriteFrame(pkt *Packet) int { 158 | return int(C.av_write_frame((*C.struct_AVFormatContext)(s), (*C.struct_AVPacket)(pkt))) 159 | } 160 | 161 | //Write a packet to an output media file ensuring correct interleaving. 162 | func (s *Context) AvInterleavedWriteFrame(pkt *Packet) int { 163 | return int(C.av_interleaved_write_frame((*C.struct_AVFormatContext)(s), (*C.struct_AVPacket)(pkt))) 164 | } 165 | 166 | //Write a uncoded frame to an output media file. 167 | func (s *Context) AvWriteUncodedFrame(si int, f *Frame) int { 168 | return int(C.av_write_uncoded_frame((*C.struct_AVFormatContext)(s), C.int(si), (*C.struct_AVFrame)(f))) 169 | } 170 | 171 | //Write a uncoded frame to an output media file. 172 | func (s *Context) AvInterleavedWriteUncodedFrame(si int, f *Frame) int { 173 | return int(C.av_interleaved_write_uncoded_frame((*C.struct_AVFormatContext)(s), C.int(si), (*C.struct_AVFrame)(f))) 174 | } 175 | 176 | //Test whether a muxer supports uncoded frame. 177 | func (s *Context) AvWriteUncodedFrameQuery(si int) int { 178 | return int(C.av_write_uncoded_frame_query((*C.struct_AVFormatContext)(s), C.int(si))) 179 | } 180 | 181 | //Write the stream trailer to an output media file and free the file private data. 182 | func (s *Context) AvWriteTrailer() int { 183 | return int(C.av_write_trailer((*C.struct_AVFormatContext)(s))) 184 | } 185 | 186 | //Get timing information for the data currently output. 187 | func (s *Context) AvGetOutputTimestamp(st int, dts, wall *int) int { 188 | return int(C.av_get_output_timestamp((*C.struct_AVFormatContext)(s), C.int(st), (*C.int64_t)(unsafe.Pointer(&dts)), (*C.int64_t)(unsafe.Pointer(&wall)))) 189 | } 190 | 191 | func (s *Context) AvFindDefaultStreamIndex() int { 192 | return int(C.av_find_default_stream_index((*C.struct_AVFormatContext)(s))) 193 | } 194 | 195 | //Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base. 196 | func (s *Context) AvDumpFormat(i int, url string, io int) { 197 | cu := C.CString(url) 198 | defer C.free(unsafe.Pointer(cu)) 199 | C.av_dump_format((*C.struct_AVFormatContext)(unsafe.Pointer(s)), C.int(i), cu, C.int(io)) 200 | } 201 | 202 | //Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio. 203 | func (s *Context) AvGuessSampleAspectRatio(st *Stream, fr *Frame) avutil.Rational { 204 | r := (C.struct_AVRational)(C.av_guess_sample_aspect_ratio((*C.struct_AVFormatContext)(s), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) 205 | 206 | return *(*avutil.Rational)(unsafe.Pointer(&r)) 207 | } 208 | 209 | //Guess the frame rate, based on both the container and codec information. 210 | func (s *Context) AvGuessFrameRate(st *Stream, fr *Frame) avutil.Rational { 211 | r := (C.struct_AVRational)(C.av_guess_frame_rate((*C.struct_AVFormatContext)(s), (*C.struct_AVStream)(st), (*C.struct_AVFrame)(fr))) 212 | 213 | return *(*avutil.Rational)(unsafe.Pointer(&r)) 214 | } 215 | 216 | //Check if the stream st contained in s is matched by the stream specifier spec. 217 | func (s *Context) AvformatMatchStreamSpecifier(st *Stream, spec string) int { 218 | cs := C.CString(spec) 219 | defer C.free(unsafe.Pointer(cs)) 220 | return int(C.avformat_match_stream_specifier((*C.struct_AVFormatContext)(s), (*C.struct_AVStream)(st), cs)) 221 | } 222 | 223 | func (s *Context) AvformatQueueAttachedPictures() int { 224 | return int(C.avformat_queue_attached_pictures((*C.struct_AVFormatContext)(s))) 225 | } 226 | 227 | // //av_format_control_message av_format_get_control_message_cb (const Context *s) 228 | // func (s *Context) AvFormatControlMessage() C.av_format_get_control_message_cb { 229 | // return C.av_format_get_control_message_cb((*C.struct_AVFormatContext)(s)) 230 | // } 231 | 232 | // //void av_format_set_control_message_cb (Context *s, av_format_control_message callback) 233 | // func (s *Context) AvFormatSetControlMessageCb(c AvFormatControlMessage) C.av_format_get_control_message_cb { 234 | // C.av_format_set_control_message_cb((*C.struct_AVFormatContext)(s), (C.struct_AVFormatControlMessage)(c)) 235 | // } 236 | 237 | // //AvCodec * av_format_get_data_codec (const Context *s) 238 | // func (s *Context)AvFormatGetDataCodec() *AvCodec { 239 | // return (*AvCodec)(C.av_format_get_data_codec((*C.struct_AVFormatContext)(s))) 240 | // } 241 | 242 | // //void av_format_set_data_codec (Context *s, AvCodec *c) 243 | // func (s *Context)AvFormatSetDataCodec( c *AvCodec) { 244 | // C.av_format_set_data_codec((*C.struct_AVFormatContext)(s), (*C.struct_AVCodec)(c)) 245 | // } 246 | -------------------------------------------------------------------------------- /avformat/context_struct.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avformat 5 | 6 | //#cgo pkg-config: libavformat 7 | //#include 8 | /* 9 | int interruptCallback(void *ret) 10 | { 11 | return *((int*)ret); 12 | } 13 | AVIOInterruptCB newInterruptCallback(int *ret) 14 | { 15 | AVIOInterruptCB c = { interruptCallback, ret }; 16 | return c; 17 | } 18 | */ 19 | import "C" 20 | import ( 21 | "unsafe" 22 | 23 | "github.com/asticode/goav/avutil" 24 | ) 25 | 26 | func (ctxt *Context) Chapters() **AvChapter { 27 | return (**AvChapter)(unsafe.Pointer(ctxt.chapters)) 28 | } 29 | 30 | func (ctxt *Context) AudioCodec() *AvCodec { 31 | return (*AvCodec)(unsafe.Pointer(ctxt.audio_codec)) 32 | } 33 | 34 | func (ctxt *Context) SubtitleCodec() *AvCodec { 35 | return (*AvCodec)(unsafe.Pointer(ctxt.subtitle_codec)) 36 | } 37 | 38 | func (ctxt *Context) VideoCodec() *AvCodec { 39 | return (*AvCodec)(unsafe.Pointer(ctxt.video_codec)) 40 | } 41 | 42 | func (ctxt *Context) Metadata() *avutil.Dictionary { 43 | return (*avutil.Dictionary)(unsafe.Pointer(ctxt.metadata)) 44 | } 45 | 46 | func (ctxt *Context) Internal() *AvFormatInternal { 47 | return (*AvFormatInternal)(unsafe.Pointer(ctxt.internal)) 48 | } 49 | 50 | func (ctxt *Context) Pb() *AvIOContext { 51 | return (*AvIOContext)(unsafe.Pointer(ctxt.pb)) 52 | } 53 | 54 | func (ctxt *Context) SetPb(ctxAvIO *AvIOContext) { 55 | ctxt.pb = (*C.struct_AVIOContext)(unsafe.Pointer(ctxAvIO)) 56 | } 57 | 58 | func (ctxt *Context) InterruptCallback() AvIOInterruptCB { 59 | return AvIOInterruptCB(ctxt.interrupt_callback) 60 | } 61 | 62 | func (ctxt *Context) SetInterruptCallback() *int { 63 | ret := 0 64 | ctxt.interrupt_callback = C.newInterruptCallback((*C.int)(unsafe.Pointer(&ret))) 65 | return &ret 66 | } 67 | 68 | func (ctxt *Context) Programs() **AvProgram { 69 | return (**AvProgram)(unsafe.Pointer(ctxt.programs)) 70 | } 71 | 72 | func (ctxt *Context) Streams() []*Stream { 73 | arr := (*[MAX_ARRAY_SIZE](*Stream))(unsafe.Pointer(ctxt.streams)) 74 | 75 | return arr[:ctxt.NbStreams()] 76 | } 77 | 78 | func (ctxt *Context) Filename() string { 79 | return C.GoString((*C.char)(unsafe.Pointer(&ctxt.filename[0]))) 80 | } 81 | 82 | // func (ctxt *Context) CodecWhitelist() string { 83 | // return C.GoString(ctxt.codec_whitelist) 84 | // } 85 | 86 | // func (ctxt *Context) FormatWhitelist() string { 87 | // return C.GoString(ctxt.format_whitelist) 88 | // } 89 | 90 | func (ctxt *Context) AudioCodecId() CodecId { 91 | return CodecId(ctxt.audio_codec_id) 92 | } 93 | 94 | func (ctxt *Context) SubtitleCodecId() CodecId { 95 | return CodecId(ctxt.subtitle_codec_id) 96 | } 97 | 98 | func (ctxt *Context) VideoCodecId() CodecId { 99 | return CodecId(ctxt.video_codec_id) 100 | } 101 | 102 | func (ctxt *Context) DurationEstimationMethod() AvDurationEstimationMethod { 103 | return AvDurationEstimationMethod(ctxt.duration_estimation_method) 104 | } 105 | 106 | func (ctxt *Context) AudioPreload() int { 107 | return int(ctxt.audio_preload) 108 | } 109 | 110 | func (ctxt *Context) AvioFlags() int { 111 | return int(ctxt.avio_flags) 112 | } 113 | 114 | func (ctxt *Context) AvoidNegativeTs() int { 115 | return int(ctxt.avoid_negative_ts) 116 | } 117 | 118 | func (ctxt *Context) BitRate() int { 119 | return int(ctxt.bit_rate) 120 | } 121 | 122 | func (ctxt *Context) CtxFlags() int { 123 | return int(ctxt.ctx_flags) 124 | } 125 | 126 | func (ctxt *Context) Debug() int { 127 | return int(ctxt.debug) 128 | } 129 | 130 | func (ctxt *Context) ErrorRecognition() int { 131 | return int(ctxt.error_recognition) 132 | } 133 | 134 | func (ctxt *Context) EventFlags() int { 135 | return int(ctxt.event_flags) 136 | } 137 | 138 | func (ctxt *Context) Flags() int { 139 | return int(ctxt.flags) 140 | } 141 | 142 | func (ctxt *Context) FlushPackets() int { 143 | return int(ctxt.flush_packets) 144 | } 145 | 146 | func (ctxt *Context) FormatProbesize() int { 147 | return int(ctxt.format_probesize) 148 | } 149 | 150 | func (ctxt *Context) FpsProbeSize() int { 151 | return int(ctxt.fps_probe_size) 152 | } 153 | 154 | func (ctxt *Context) IoRepositioned() int { 155 | return int(ctxt.io_repositioned) 156 | } 157 | 158 | func (ctxt *Context) Keylen() int { 159 | return int(ctxt.keylen) 160 | } 161 | 162 | func (ctxt *Context) MaxChunkDuration() int { 163 | return int(ctxt.max_chunk_duration) 164 | } 165 | 166 | func (ctxt *Context) MaxChunkSize() int { 167 | return int(ctxt.max_chunk_size) 168 | } 169 | 170 | func (ctxt *Context) MaxDelay() int { 171 | return int(ctxt.max_delay) 172 | } 173 | 174 | func (ctxt *Context) MaxTsProbe() int { 175 | return int(ctxt.max_ts_probe) 176 | } 177 | 178 | func (ctxt *Context) MetadataHeaderPadding() int { 179 | return int(ctxt.metadata_header_padding) 180 | } 181 | 182 | func (ctxt *Context) ProbeScore() int { 183 | return int(ctxt.probe_score) 184 | } 185 | 186 | func (ctxt *Context) Seek2any() int { 187 | return int(ctxt.seek2any) 188 | } 189 | 190 | func (ctxt *Context) SetStrictStdCompliance(strictStdCompliance int) { 191 | ctxt.strict_std_compliance = C.int(strictStdCompliance) 192 | } 193 | 194 | func (ctxt *Context) StrictStdCompliance() int { 195 | return int(ctxt.strict_std_compliance) 196 | } 197 | 198 | func (ctxt *Context) TsId() int { 199 | return int(ctxt.ts_id) 200 | } 201 | 202 | func (ctxt *Context) UseWallclockAsTimestamps() int { 203 | return int(ctxt.use_wallclock_as_timestamps) 204 | } 205 | 206 | func (ctxt *Context) Duration() int64 { 207 | return int64(ctxt.duration) 208 | } 209 | 210 | func (ctxt *Context) MaxAnalyzeDuration2() int64 { 211 | return int64(ctxt.max_analyze_duration) 212 | } 213 | 214 | func (ctxt *Context) MaxInterleaveDelta() int64 { 215 | return int64(ctxt.max_interleave_delta) 216 | } 217 | 218 | func (ctxt *Context) OutputTsOffset() int64 { 219 | return int64(ctxt.output_ts_offset) 220 | } 221 | 222 | func (ctxt *Context) Probesize2() int64 { 223 | return int64(ctxt.probesize) 224 | } 225 | 226 | func (ctxt *Context) SkipInitialBytes() int64 { 227 | return int64(ctxt.skip_initial_bytes) 228 | } 229 | 230 | func (ctxt *Context) StartTime() int64 { 231 | return int64(ctxt.start_time) 232 | } 233 | 234 | func (ctxt *Context) StartTimeRealtime() int64 { 235 | return int64(ctxt.start_time_realtime) 236 | } 237 | 238 | func (ctxt *Context) Iformat() *InputFormat { 239 | return (*InputFormat)(unsafe.Pointer(ctxt.iformat)) 240 | } 241 | 242 | func (ctxt *Context) Oformat() *OutputFormat { 243 | return (*OutputFormat)(unsafe.Pointer(ctxt.oformat)) 244 | } 245 | 246 | // func (ctxt *Context) DumpSeparator() uint8 { 247 | // return uint8(ctxt.dump_separator) 248 | // } 249 | 250 | func (ctxt *Context) CorrectTsOverflow() int { 251 | return int(ctxt.correct_ts_overflow) 252 | } 253 | 254 | func (ctxt *Context) MaxIndexSize() uint { 255 | return uint(ctxt.max_index_size) 256 | } 257 | 258 | func (ctxt *Context) MaxPictureBuffer() uint { 259 | return uint(ctxt.max_picture_buffer) 260 | } 261 | 262 | func (ctxt *Context) NbChapters() uint { 263 | return uint(ctxt.nb_chapters) 264 | } 265 | 266 | func (ctxt *Context) NbPrograms() uint { 267 | return uint(ctxt.nb_programs) 268 | } 269 | 270 | func (ctxt *Context) NbStreams() uint { 271 | return uint(ctxt.nb_streams) 272 | } 273 | 274 | func (ctxt *Context) PacketSize() uint { 275 | return uint(ctxt.packet_size) 276 | } 277 | 278 | func (ctxt *Context) Probesize() uint { 279 | return uint(ctxt.probesize) 280 | } 281 | -------------------------------------------------------------------------------- /avformat/stream.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avformat 5 | 6 | //#cgo pkg-config: libavformat 7 | //#include 8 | import "C" 9 | import ( 10 | "github.com/asticode/goav/avutil" 11 | ) 12 | 13 | //Rational av_stream_get_r_frame_rate (const Stream *s) 14 | func (s *Stream) AvStreamGetRFrameRate() avutil.Rational { 15 | panic("deprecated") 16 | return avutil.Rational{} 17 | /* 18 | r := (C.struct_AVRational)(C.av_stream_get_r_frame_rate((*C.struct_AVStream)(s))) 19 | 20 | return *(*avutil.Rational)(unsafe.Pointer(&r)) 21 | */ 22 | } 23 | 24 | //struct CodecParserContext * av_stream_get_parser (const Stream *s) 25 | func (s *Stream) AvStreamGetParser() *CodecParserContext { 26 | return (*CodecParserContext)(C.av_stream_get_parser((*C.struct_AVStream)(s))) 27 | } 28 | 29 | // //char * av_stream_get_recommended_encoder_configuration (const Stream *s) 30 | // func (s *Stream) AvStreamGetRecommendedEncoderConfiguration() string { 31 | // return C.GoString(C.av_stream_get_recommended_encoder_configuration((*C.struct_AVStream)(s))) 32 | // } 33 | 34 | // //void av_stream_set_recommended_encoder_configuration (Stream *s, char *configuration) 35 | // func (s *Stream) AvStreamSetRecommendedEncoderConfiguration( c string) { 36 | // C.av_stream_set_recommended_encoder_configuration((*C.struct_AVStream)(s), C.CString(c)) 37 | // } 38 | 39 | //int64_t av_stream_get_end_pts (const Stream *st) 40 | //Returns the pts of the last muxed packet + its duration. 41 | func (s *Stream) AvStreamGetEndPts() int64 { 42 | return int64(C.av_stream_get_end_pts((*C.struct_AVStream)(s))) 43 | } 44 | -------------------------------------------------------------------------------- /avformat/stream_struct.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avformat 5 | 6 | //#cgo pkg-config: libavformat 7 | //#include 8 | //#include 9 | import "C" 10 | import ( 11 | "unsafe" 12 | 13 | "github.com/asticode/goav/avcodec" 14 | "github.com/asticode/goav/avutil" 15 | ) 16 | 17 | func (avs *Stream) Codec() *CodecContext { 18 | return (*CodecContext)(unsafe.Pointer(avs.codec)) 19 | } 20 | 21 | func (avs *Stream) CodecParameters() *avcodec.CodecParameters { 22 | return (*avcodec.CodecParameters)(unsafe.Pointer(avs.codecpar)) 23 | } 24 | 25 | func (avs *Stream) Metadata() *avutil.Dictionary { 26 | return (*avutil.Dictionary)(unsafe.Pointer(avs.metadata)) 27 | } 28 | 29 | func (avs *Stream) IndexEntries() *AvIndexEntry { 30 | return (*AvIndexEntry)(unsafe.Pointer(avs.index_entries)) 31 | } 32 | 33 | func (avs *Stream) AttachedPic() Packet { 34 | return Packet(avs.attached_pic) 35 | } 36 | 37 | func (avs *Stream) SideData() *AvPacketSideData { 38 | return (*AvPacketSideData)(unsafe.Pointer(avs.side_data)) 39 | } 40 | 41 | func (avs *Stream) ProbeData() AvProbeData { 42 | return AvProbeData(avs.probe_data) 43 | } 44 | 45 | func (avs *Stream) AvgFrameRate() avutil.Rational { 46 | return *(*avutil.Rational)(unsafe.Pointer(&avs.avg_frame_rate)) 47 | } 48 | 49 | // func (avs *Stream) DisplayAspectRatio() *Rational { 50 | // return (*Rational)(unsafe.Pointer(avs.display_aspect_ratio)) 51 | // } 52 | 53 | func (avs *Stream) RFrameRate() avutil.Rational { 54 | return *(*avutil.Rational)(unsafe.Pointer(&avs.r_frame_rate)) 55 | } 56 | 57 | func (avs *Stream) SampleAspectRatio() avutil.Rational { 58 | return *(*avutil.Rational)(unsafe.Pointer(&avs.sample_aspect_ratio)) 59 | } 60 | 61 | func (avs *Stream) TimeBase() avutil.Rational { 62 | return *(*avutil.Rational)(unsafe.Pointer(&avs.time_base)) 63 | } 64 | 65 | func (avs *Stream) SetTimeBase(r avutil.Rational) { 66 | avs.time_base = *((*C.struct_AVRational)(unsafe.Pointer(&r))) 67 | } 68 | 69 | // func (avs *Stream) RecommendedEncoderConfiguration() string { 70 | // return C.GoString(avs.recommended_encoder_configuration) 71 | // } 72 | 73 | func (avs *Stream) Discard() AvDiscard { 74 | return AvDiscard(avs.discard) 75 | } 76 | 77 | func (avs *Stream) NeedParsing() AvStreamParseType { 78 | return AvStreamParseType(avs.need_parsing) 79 | } 80 | 81 | func (avs *Stream) CodecInfoNbFrames() int { 82 | return int(avs.codec_info_nb_frames) 83 | } 84 | 85 | func (avs *Stream) Disposition() int { 86 | return int(avs.disposition) 87 | } 88 | 89 | func (avs *Stream) EventFlags() int { 90 | return int(avs.event_flags) 91 | } 92 | 93 | func (avs *Stream) Id() int { 94 | return int(avs.id) 95 | } 96 | 97 | func (avs *Stream) Index() int { 98 | return int(avs.index) 99 | } 100 | 101 | func (avs *Stream) InjectGlobalSideData() int { 102 | return int(avs.inject_global_side_data) 103 | } 104 | 105 | func (avs *Stream) LastIpDuration() int { 106 | return int(avs.last_IP_duration) 107 | } 108 | 109 | func (avs *Stream) NbDecodedFrames() int { 110 | return int(avs.nb_decoded_frames) 111 | } 112 | 113 | func (avs *Stream) NbIndexEntries() int { 114 | return int(avs.nb_index_entries) 115 | } 116 | 117 | func (avs *Stream) NbSideData() int { 118 | return int(avs.nb_side_data) 119 | } 120 | 121 | func (avs *Stream) ProbePackets() int { 122 | return int(avs.probe_packets) 123 | } 124 | 125 | func (avs *Stream) PtsWrapBehavior() int { 126 | return int(avs.pts_wrap_behavior) 127 | } 128 | 129 | func (avs *Stream) RequestProbe() int { 130 | return int(avs.request_probe) 131 | } 132 | 133 | func (avs *Stream) SkipSamples() int { 134 | return int(avs.skip_samples) 135 | } 136 | 137 | func (avs *Stream) SkipToKeyframe() int { 138 | return int(avs.skip_to_keyframe) 139 | } 140 | 141 | func (avs *Stream) StreamIdentifier() int { 142 | return int(avs.stream_identifier) 143 | } 144 | 145 | func (avs *Stream) UpdateInitialDurationsDone() int { 146 | return int(avs.update_initial_durations_done) 147 | } 148 | 149 | func (avs *Stream) CurDts() int64 { 150 | return int64(avs.cur_dts) 151 | } 152 | 153 | func (avs *Stream) Duration() int64 { 154 | return int64(avs.duration) 155 | } 156 | 157 | // func (avs *Stream) FirstDiscardSample() int64 { 158 | // return int64(avs.first_discard_sample) 159 | // } 160 | 161 | func (avs *Stream) FirstDts() int64 { 162 | return int64(avs.first_dts) 163 | } 164 | 165 | func (avs *Stream) InterleaverChunkDuration() int64 { 166 | return int64(avs.interleaver_chunk_duration) 167 | } 168 | 169 | func (avs *Stream) InterleaverChunkSize() int64 { 170 | return int64(avs.interleaver_chunk_size) 171 | } 172 | 173 | // func (avs *Stream) LastDiscardSample() int64 { 174 | // return int64(avs.last_discard_sample) 175 | // } 176 | 177 | func (avs *Stream) LastDtsForOrderCheck() int64 { 178 | return int64(avs.last_dts_for_order_check) 179 | } 180 | 181 | func (avs *Stream) LastIpPts() int64 { 182 | return int64(avs.last_IP_pts) 183 | } 184 | 185 | func (avs *Stream) MuxTsOffset() int64 { 186 | return int64(avs.mux_ts_offset) 187 | } 188 | 189 | func (avs *Stream) NbFrames() int64 { 190 | return int64(avs.nb_frames) 191 | } 192 | 193 | func (avs *Stream) PtsBuffer() int64 { 194 | return int64(avs.pts_buffer[0]) 195 | } 196 | 197 | func (avs *Stream) PtsReorderError() int64 { 198 | return int64(avs.pts_reorder_error[0]) 199 | } 200 | 201 | func (avs *Stream) PtsWrapReference() int64 { 202 | return int64(avs.pts_wrap_reference) 203 | } 204 | 205 | // func (avs *Stream) StartSkipSamples() int64 { 206 | // return int64(avs.start_skip_samples) 207 | // } 208 | 209 | func (avs *Stream) StartTime() int64 { 210 | return int64(avs.start_time) 211 | } 212 | 213 | func (avs *Stream) Parser() *CodecParserContext { 214 | return (*CodecParserContext)(unsafe.Pointer(avs.parser)) 215 | } 216 | 217 | func (avs *Stream) LastInPacketBuffer() *AvPacketList { 218 | return (*AvPacketList)(unsafe.Pointer(avs.last_in_packet_buffer)) 219 | } 220 | 221 | // func (avs *Stream) PrivPts() *FFFrac { 222 | // return (*FFFrac)(unsafe.Pointer(avs.priv_pts)) 223 | // } 224 | 225 | func (avs *Stream) DtsMisordered() uint8 { 226 | return uint8(avs.dts_misordered) 227 | } 228 | 229 | func (avs *Stream) DtsOrdered() uint8 { 230 | return uint8(avs.dts_ordered) 231 | } 232 | 233 | func (avs *Stream) PtsReorderErrorCount() uint8 { 234 | return uint8(avs.pts_reorder_error_count[0]) 235 | } 236 | 237 | func (avs *Stream) IndexEntriesAllocatedSize() uint { 238 | return uint(avs.index_entries_allocated_size) 239 | } 240 | -------------------------------------------------------------------------------- /avutil/avutil.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | // Package avutil is a utility library to aid portable multimedia programming. 5 | // It contains safe portable string functions, random number generators, data structures, 6 | // additional mathematics functions, cryptography and multimedia related functionality. 7 | // Some generic features and utilities provided by the libavutil library 8 | package avutil 9 | 10 | //#cgo pkg-config: libavutil 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | import "C" 17 | import ( 18 | "fmt" 19 | "unsafe" 20 | ) 21 | 22 | type ( 23 | Options C.struct_AVOptions 24 | AvTree C.struct_AVTree 25 | Rational C.struct_AVRational 26 | MediaType C.enum_AVMediaType 27 | AvPictureType C.enum_AVPictureType 28 | PixelFormat C.enum_AVPixelFormat 29 | File C.FILE 30 | ) 31 | 32 | const ( 33 | AV_TIME_BASE = C.AV_TIME_BASE 34 | AV_NOPTS_VALUE = C.AV_NOPTS_VALUE 35 | ) 36 | 37 | var AV_TIME_BASE_Q Rational = NewRational(1, AV_TIME_BASE) 38 | 39 | const ( 40 | AVMEDIA_TYPE_UNKNOWN = C.AVMEDIA_TYPE_UNKNOWN 41 | AVMEDIA_TYPE_VIDEO = C.AVMEDIA_TYPE_VIDEO 42 | AVMEDIA_TYPE_AUDIO = C.AVMEDIA_TYPE_AUDIO 43 | AVMEDIA_TYPE_DATA = C.AVMEDIA_TYPE_DATA 44 | AVMEDIA_TYPE_SUBTITLE = C.AVMEDIA_TYPE_SUBTITLE 45 | AVMEDIA_TYPE_ATTACHMENT = C.AVMEDIA_TYPE_ATTACHMENT 46 | AVMEDIA_TYPE_NB = C.AVMEDIA_TYPE_NB 47 | ) 48 | 49 | // MediaTypeFromString returns a media type from a string 50 | func MediaTypeFromString(i string) MediaType { 51 | switch i { 52 | case "audio": 53 | return AVMEDIA_TYPE_AUDIO 54 | case "subtitle": 55 | return AVMEDIA_TYPE_SUBTITLE 56 | case "video": 57 | return AVMEDIA_TYPE_VIDEO 58 | default: 59 | return -1 60 | } 61 | } 62 | 63 | const ( 64 | AV_CH_FRONT_LEFT = 0x1 65 | AV_CH_FRONT_RIGHT = 0x2 66 | AV_CH_LAYOUT_STEREO = 0x3 //(AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT) 67 | ) 68 | 69 | const ( 70 | AVERROR_EAGAIN = -(C.EAGAIN) 71 | AVERROR_EIO = -(C.EIO) 72 | AVERROR_EOF = C.AVERROR_EOF 73 | AVERROR_EPERM = -(C.EPERM) 74 | AVERROR_EPIPE = -(C.EPIPE) 75 | AVERROR_ETIMEDOUT = -(C.ETIMEDOUT) 76 | ) 77 | 78 | const ( 79 | MAX_AVERROR_STR_LEN = 255 80 | MAX_CHANNEL_LAYOUT_STR_LEN = 64 81 | ) 82 | 83 | const ( 84 | AV_PICTURE_TYPE_NONE = C.AV_PICTURE_TYPE_NONE 85 | AV_PICTURE_TYPE_I = C.AV_PICTURE_TYPE_I 86 | AV_PICTURE_TYPE_B = C.AV_PICTURE_TYPE_B 87 | AV_PICTURE_TYPE_P = C.AV_PICTURE_TYPE_P 88 | ) 89 | 90 | //Return the LIBAvUTIL_VERSION_INT constant. 91 | func AvutilVersion() uint { 92 | return uint(C.avutil_version()) 93 | } 94 | 95 | //Return the libavutil build-time configuration. 96 | func AvutilConfiguration() string { 97 | return C.GoString(C.avutil_configuration()) 98 | } 99 | 100 | //Return the libavutil license. 101 | func AvutilLicense() string { 102 | return C.GoString(C.avutil_license()) 103 | } 104 | 105 | //Return a string describing the media_type enum, NULL if media_type is unknown. 106 | func AvGetMediaTypeString(mt MediaType) string { 107 | return C.GoString(C.av_get_media_type_string((C.enum_AVMediaType)(mt))) 108 | } 109 | 110 | //Return a single letter to describe the given picture type pict_type. 111 | func AvGetPictureTypeChar(pt AvPictureType) string { 112 | return string(C.av_get_picture_type_char((C.enum_AVPictureType)(pt))) 113 | } 114 | 115 | //Return x default pointer in case p is NULL. 116 | func AvXIfNull(p, x int) { 117 | C.av_x_if_null(unsafe.Pointer(&p), unsafe.Pointer(&x)) 118 | } 119 | 120 | //Compute the length of an integer list. 121 | func AvIntListLengthForSize(e uint, l int, t uint64) uint { 122 | return uint(C.av_int_list_length_for_size(C.uint(e), unsafe.Pointer(&l), (C.uint64_t)(t))) 123 | } 124 | 125 | //Open a file using a UTF-8 filename. 126 | func AvFopenUtf8(p, m string) *File { 127 | cp := C.CString(p) 128 | defer C.free(unsafe.Pointer(cp)) 129 | cm := C.CString(m) 130 | defer C.free(unsafe.Pointer(cm)) 131 | f := C.av_fopen_utf8(cp, cm) 132 | return (*File)(f) 133 | } 134 | 135 | //Return the fractional representation of the internal time base. 136 | func AvGetTimeBaseQ() Rational { 137 | return (Rational)(C.av_get_time_base_q()) 138 | } 139 | 140 | func AvGetChannelLayoutNbChannels(channelLayout uint64) int { 141 | return int(C.av_get_channel_layout_nb_channels(C.uint64_t(channelLayout))) 142 | } 143 | 144 | func AvGetPixFmtName(pixFmt PixelFormat) string { 145 | s := C.av_get_pix_fmt_name((C.enum_AVPixelFormat)(pixFmt)) 146 | if s == nil { 147 | return fmt.Sprintf("unknown pixel format with value %d", pixFmt) 148 | } 149 | return C.GoString(s) 150 | } 151 | 152 | func AvGetChannelLayoutString(nbChannels int, channelLayout uint64) string { 153 | bufSize := C.size_t(MAX_CHANNEL_LAYOUT_STR_LEN) 154 | buf := (*C.char)(C.malloc(bufSize)) 155 | if buf == nil { 156 | return fmt.Sprintf("unknown channel layout with code %d", channelLayout) 157 | } 158 | defer C.free(unsafe.Pointer(buf)) 159 | C.av_get_channel_layout_string(buf, C.int(bufSize), C.int(nbChannels), C.uint64_t(channelLayout)) 160 | return C.GoString(buf) 161 | } 162 | 163 | func AvStrerr(errcode int) string { 164 | errbufSize := C.size_t(MAX_AVERROR_STR_LEN) 165 | errbuf := (*C.char)(C.malloc(errbufSize)) 166 | if errbuf == nil { 167 | return fmt.Sprintf("unknown error with code %d", errcode) 168 | } 169 | defer C.free(unsafe.Pointer(errbuf)) 170 | ret := C.av_strerror(C.int(errcode), errbuf, errbufSize) 171 | if ret < 0 { 172 | return fmt.Sprintf("unknown error with code %d", errcode) 173 | } 174 | return C.GoString(errbuf) 175 | } 176 | -------------------------------------------------------------------------------- /avutil/dictionary.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | //#include 6 | import "C" 7 | import ( 8 | "unsafe" 9 | ) 10 | 11 | type ( 12 | Dictionary C.struct_AVDictionary 13 | DictionaryEntry C.struct_AVDictionaryEntry 14 | ) 15 | 16 | func AvDictSet(d **Dictionary, key, value string, flags int) int { 17 | ck := C.CString(key) 18 | defer C.free(unsafe.Pointer(ck)) 19 | cv := C.CString(value) 20 | defer C.free(unsafe.Pointer(cv)) 21 | return int(C.av_dict_set((**C.struct_AVDictionary)(unsafe.Pointer(d)), ck, cv, C.int(flags))) 22 | } 23 | 24 | func AvDictParseString(d **Dictionary, i, keyValSep, pairsSep string, flags int) int { 25 | ci := C.CString(i) 26 | defer C.free(unsafe.Pointer(ci)) 27 | ck := C.CString(keyValSep) 28 | defer C.free(unsafe.Pointer(ck)) 29 | cp := C.CString(pairsSep) 30 | defer C.free(unsafe.Pointer(cp)) 31 | return int(C.av_dict_parse_string((**C.struct_AVDictionary)(unsafe.Pointer(d)), ci, ck, cp, C.int(flags))) 32 | } 33 | 34 | func AvDictGet(d *Dictionary, key string, prev *DictionaryEntry, flags int) *DictionaryEntry { 35 | ck := C.CString(key) 36 | defer C.free(unsafe.Pointer(ck)) 37 | return (*DictionaryEntry)(C.av_dict_get((*C.struct_AVDictionary)(d), ck, (*C.struct_AVDictionaryEntry)(prev), C.int(flags))) 38 | } 39 | 40 | func AvDictFree(d **Dictionary) { 41 | C.av_dict_free((**C.struct_AVDictionary)(unsafe.Pointer(d))) 42 | } 43 | 44 | func (e *DictionaryEntry) Key() string { 45 | return C.GoString(e.key) 46 | } 47 | 48 | func (e *DictionaryEntry) Value() string { 49 | return C.GoString(e.value) 50 | } 51 | -------------------------------------------------------------------------------- /avutil/frame.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avutil 5 | 6 | //#cgo pkg-config: libavutil 7 | //#include 8 | //#include 9 | import "C" 10 | import "unsafe" 11 | 12 | type ( 13 | AvBuffer C.struct_AVBuffer 14 | AvBufferRef C.struct_AVBufferRef 15 | AvBufferPool C.struct_AVBufferPool 16 | Frame C.struct_AVFrame 17 | AvFrameSideData C.struct_AVFrameSideData 18 | AvFrameSideDataType C.enum_AVFrameSideDataType 19 | ) 20 | 21 | func AvFrameGetBestEffortTimestamp(f *Frame) int64 { 22 | panic("deprecated") 23 | return 0 24 | //return int64(C.av_frame_get_best_effort_timestamp((*C.struct_AVFrame)(unsafe.Pointer(f)))) 25 | } 26 | 27 | func AvFrameSetQpTable(f *Frame, b *AvBufferRef, s, q int) int { 28 | panic("deprecated") 29 | return 0 30 | //return int(C.av_frame_set_qp_table((*C.struct_AVFrame)(unsafe.Pointer(f)), (*C.struct_AVBufferRef)(unsafe.Pointer(b)), C.int(s), C.int(q))) 31 | } 32 | 33 | func AvFrameGetQpTable(f *Frame, s, t *int) int8 { 34 | panic("deprecated") 35 | return 0 36 | //return int8(*C.av_frame_get_qp_table((*C.struct_AVFrame)(unsafe.Pointer(f)), (*C.int)(unsafe.Pointer(s)), (*C.int)(unsafe.Pointer(t)))) 37 | } 38 | 39 | //Allocate an Frame and set its fields to default values. 40 | func AvFrameAlloc() *Frame { 41 | return (*Frame)(unsafe.Pointer(C.av_frame_alloc())) 42 | } 43 | 44 | //Free the frame and any dynamically allocated objects in it, e.g. 45 | func AvFrameFree(f *Frame) { 46 | var ptr *C.struct_AVFrame = (*C.struct_AVFrame)(unsafe.Pointer(f)) 47 | C.av_frame_free(&ptr) 48 | } 49 | 50 | //Allocate new buffer(s) for audio or video data. 51 | func AvFrameGetBuffer(f *Frame, a int) int { 52 | return int(C.av_frame_get_buffer((*C.struct_AVFrame)(unsafe.Pointer(f)), C.int(a))) 53 | } 54 | 55 | //Setup a new reference to the data described by an given frame. 56 | func AvFrameRef(d, s *Frame) int { 57 | return int(C.av_frame_ref((*C.struct_AVFrame)(unsafe.Pointer(d)), (*C.struct_AVFrame)(unsafe.Pointer(s)))) 58 | } 59 | 60 | //Create a new frame that references the same data as src. 61 | func AvFrameClone(f *Frame) *Frame { 62 | return (*Frame)(unsafe.Pointer(C.av_frame_clone((*C.struct_AVFrame)(unsafe.Pointer(f))))) 63 | } 64 | 65 | //Unreference all the buffers referenced by frame and reset the frame fields. 66 | func AvFrameUnref(f *Frame) { 67 | cf := (*C.struct_AVFrame)(unsafe.Pointer(f)) 68 | C.av_frame_unref(cf) 69 | } 70 | 71 | //Move everythnig contained in src to dst and reset src. 72 | func AvFrameMoveRef(d, s *Frame) { 73 | C.av_frame_move_ref((*C.struct_AVFrame)(unsafe.Pointer(d)), (*C.struct_AVFrame)(unsafe.Pointer(s))) 74 | } 75 | 76 | //Check if the frame data is writable. 77 | func AvFrameIsWritable(f *Frame) int { 78 | return int(C.av_frame_is_writable((*C.struct_AVFrame)(unsafe.Pointer(f)))) 79 | } 80 | 81 | //Ensure that the frame data is writable, avoiding data copy if possible. 82 | func AvFrameMakeWritable(f *Frame) int { 83 | return int(C.av_frame_make_writable((*C.struct_AVFrame)(unsafe.Pointer(f)))) 84 | } 85 | 86 | //Copy only "metadata" fields from src to dst. 87 | func AvFrameCopyProps(d, s *Frame) int { 88 | return int(C.av_frame_copy_props((*C.struct_AVFrame)(unsafe.Pointer(d)), (*C.struct_AVFrame)(unsafe.Pointer(s)))) 89 | } 90 | 91 | //Get the buffer reference a given data plane is stored in. 92 | func AvFrameGetPlaneBuffer(f *Frame, p int) *AvBufferRef { 93 | return (*AvBufferRef)(unsafe.Pointer(C.av_frame_get_plane_buffer((*C.struct_AVFrame)(unsafe.Pointer(f)), C.int(p)))) 94 | } 95 | 96 | //Add a new side data to a frame. 97 | func AvFrameNewSideData(f *Frame, d AvFrameSideDataType, s int) *AvFrameSideData { 98 | return (*AvFrameSideData)(unsafe.Pointer(C.av_frame_new_side_data((*C.struct_AVFrame)(unsafe.Pointer(f)), (C.enum_AVFrameSideDataType)(d), C.int(s)))) 99 | } 100 | 101 | func AvFrameGetSideData(f *Frame, t AvFrameSideDataType) *AvFrameSideData { 102 | return (*AvFrameSideData)(unsafe.Pointer(C.av_frame_get_side_data((*C.struct_AVFrame)(unsafe.Pointer(f)), (C.enum_AVFrameSideDataType)(t)))) 103 | } 104 | 105 | // //static int get_video_buffer (Frame *frame, int align) 106 | // func GetVideoBuffer(f *Frame, a int) int { 107 | // return int(C.get_video_buffer(f, C.int(a))) 108 | // } 109 | 110 | // //static int get_audio_buffer (Frame *frame, int align) 111 | // func GetAudioBuffer(f *Frame, a int) int { 112 | // return C.get_audio_buffer(f, C.int(a)) 113 | // } 114 | 115 | // //static void get_frame_defaults (Frame *frame) 116 | // func GetFrameDefaults(f *Frame) { 117 | // C.get_frame_defaults(*C.struct_AVFrame(f)) 118 | // } 119 | -------------------------------------------------------------------------------- /avutil/frame_struct.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | //#include 6 | /* 7 | static inline uint8_t ** dataItem(uint8_t * data, int idx) 8 | { 9 | return (uint8_t **)&data[idx]; 10 | } 11 | */ 12 | import "C" 13 | import "unsafe" 14 | 15 | func (f *Frame) Data() *uint8 { 16 | return (*uint8)(unsafe.Pointer((*C.uint8_t)(unsafe.Pointer(&f.data)))) 17 | } 18 | 19 | func (f *Frame) DataItem(idx int) **uint8 { 20 | return (**uint8)(unsafe.Pointer(C.dataItem((*C.uint8_t)(unsafe.Pointer(&f.data)), C.int(idx)))) 21 | } 22 | 23 | func (f *Frame) Linesize() int { 24 | return int(*(*C.int)(unsafe.Pointer(&f.linesize))) 25 | } 26 | 27 | func (f *Frame) LinesizePtr() *int { 28 | return (*int)(unsafe.Pointer((*C.int)(unsafe.Pointer(&f.linesize)))) 29 | } 30 | 31 | func (f *Frame) Width() int { 32 | return int(f.width) 33 | } 34 | 35 | func (f *Frame) SetWidth(w int) { 36 | f.width = C.int(w) 37 | } 38 | 39 | func (f *Frame) Height() int { 40 | return int(f.height) 41 | } 42 | 43 | func (f *Frame) SetHeight(h int) { 44 | f.height = C.int(h) 45 | } 46 | 47 | func (f *Frame) Format() int { 48 | return int(f.format) 49 | } 50 | 51 | func (f *Frame) SetFormat(fmt int) { 52 | f.format = C.int(fmt) 53 | } 54 | 55 | func (f *Frame) NbSamples() int { 56 | return int(f.nb_samples) 57 | } 58 | 59 | func (f *Frame) SetNbSamples(n int) { 60 | f.nb_samples = C.int(n) 61 | } 62 | 63 | func (f *Frame) SetKeyFrame(k int) { 64 | f.key_frame = C.int(k) 65 | } 66 | 67 | func (f *Frame) SetPictType(t AvPictureType) { 68 | f.pict_type = C.enum_AVPictureType(t) 69 | } 70 | 71 | func (f *Frame) Pts() int64 { 72 | return int64(f.pts) 73 | } 74 | 75 | func (f *Frame) SetPts(i int64) { 76 | f.pts = C.int64_t(i) 77 | } 78 | 79 | func (f *Frame) PktPts() int64 { 80 | return int64(f.pkt_pts) 81 | } 82 | 83 | func (f *Frame) PktDts() int64 { 84 | return int64(f.pkt_dts) 85 | } 86 | 87 | func (f *Frame) SampleRate() int { 88 | return int(f.sample_rate) 89 | } 90 | 91 | func (f *Frame) SetChannelLayout(l uint64) { 92 | f.channel_layout = C.uint64_t(l) 93 | } 94 | 95 | func (f *Frame) SetSampleRate(r int) { 96 | f.sample_rate = C.int(r) 97 | } 98 | 99 | // TODO Create getters and setters 100 | // https://ffmpeg.org/doxygen/4.0/structAVFrame.html 101 | /* 102 | type Frame struct { 103 | Coded_picture_number int32 104 | Data [8]*uint8 105 | Extended_data **uint8 106 | Format int32 107 | Height int32 108 | Key_frame int32 109 | Linesize [8]int32 110 | Nb_samples int32 111 | Pict_type uint32 112 | Pts int64 113 | Pkt_pts int64 114 | Pkt_dts int64 115 | Sample_aspect_ratio Rational 116 | Width int32 117 | Display_picture_number int32 118 | Quality int32 119 | Pad_cgo_0 [4]byte 120 | Opaque *byte 121 | Error [8]uint64 122 | Repeat_pict int32 123 | Interlaced_frame int32 124 | Top_field_first int32 125 | Palette_has_changed int32 126 | Reordered_opaque int64 127 | Sample_rate int32 128 | Pad_cgo_1 [4]byte 129 | Channel_layout uint64 130 | Buf [8]*AvBufferRef 131 | Extended_buf **AvBufferRef 132 | Nb_extended_buf int32 133 | Pad_cgo_2 [4]byte 134 | Side_data **AvFrameSideData 135 | Nb_side_data int32 136 | Flags int32 137 | Color_range uint32 138 | Color_primaries uint32 139 | Color_trc uint32 140 | Colorspace uint32 141 | Chroma_location uint32 142 | Pad_cgo_3 [4]byte 143 | Best_effort_timestamp int64 144 | Pkt_pos int64 145 | Pkt_duration int64 146 | Metadata *Dictionary 147 | Decode_error_flags int32 148 | Channels int32 149 | Pkt_size int32 150 | Pad_cgo_4 [4]byte 151 | Qscale_table *int8 152 | Qstride int32 153 | Qscale_type int32 154 | Qp_table_buf *AvBufferRef 155 | Hw_frames_ctx *AvBufferRef 156 | } 157 | */ 158 | -------------------------------------------------------------------------------- /avutil/intreadwrite.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#include 4 | /* 5 | uint32_t avRL32(uint8_t *i, int o) { 6 | return AV_RL32(i+o); 7 | } 8 | */ 9 | import "C" 10 | 11 | func AV_RL32(i *uint8, offset uint) uint32 { 12 | return uint32(C.avRL32((*C.uint8_t)(i), C.int(offset))) 13 | } 14 | -------------------------------------------------------------------------------- /avutil/log.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | /* 6 | extern void goAvLogCustomCallback(int level, char* msg, char* parent); 7 | 8 | static inline void avLogCustomCallback(void *avcl, int level, const char *fmt, va_list vl) 9 | { 10 | if (level > av_log_get_level()) return; 11 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; 12 | char parent[1024]; 13 | if (avc) { 14 | sprintf(parent, "%p", avcl); 15 | } 16 | char msg[1024]; 17 | vsprintf(msg, fmt, vl); 18 | goAvLogCustomCallback(level, msg, parent); 19 | } 20 | static inline void setAvLogCustomCallback() 21 | { 22 | av_log_set_callback(avLogCustomCallback); 23 | } 24 | static inline void resetAvLogCallback() 25 | { 26 | av_log_set_callback(av_log_default_callback); 27 | } 28 | */ 29 | import "C" 30 | 31 | // Logging constants 32 | const ( 33 | AV_LOG_QUIET = C.AV_LOG_QUIET 34 | AV_LOG_PANIC = C.AV_LOG_PANIC 35 | AV_LOG_FATAL = C.AV_LOG_FATAL 36 | AV_LOG_ERROR = C.AV_LOG_ERROR 37 | AV_LOG_WARNING = C.AV_LOG_WARNING 38 | AV_LOG_INFO = C.AV_LOG_INFO 39 | AV_LOG_VERBOSE = C.AV_LOG_VERBOSE 40 | AV_LOG_DEBUG = C.AV_LOG_DEBUG 41 | ) 42 | 43 | // AvLogGetLevel returns the current log level. 44 | func AvLogGetLevel() int { 45 | return int(C.av_log_get_level()) 46 | } 47 | 48 | // AvLogSetLevel sets the log level. 49 | func AvLogSetLevel(level int) { 50 | C.av_log_set_level(C.int(level)) 51 | } 52 | 53 | // AvLogCallback represents a log callback 54 | type AvLogCallback func(level int, msg, parent string) 55 | 56 | var avLogCallback AvLogCallback 57 | 58 | // AvLogSetCallback sets the log callback to a custom callback 59 | func AvLogSetCallback(c AvLogCallback) { 60 | avLogCallback = c 61 | C.setAvLogCustomCallback() 62 | } 63 | 64 | //export goAvLogCustomCallback 65 | func goAvLogCustomCallback(level C.int, msg, parent *C.char) { 66 | if avLogCallback == nil { 67 | return 68 | } 69 | avLogCallback(int(level), C.GoString(msg), C.GoString(parent)) 70 | } 71 | 72 | // AvLogResetCallback resets the log callback to the default callback 73 | func AvLogResetCallback() { 74 | C.resetAvLogCallback() 75 | } 76 | -------------------------------------------------------------------------------- /avutil/mathematics.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#include 4 | import "C" 5 | 6 | const ( 7 | AV_ROUND_NEAR_INF = C.AV_ROUND_NEAR_INF 8 | AV_ROUND_PASS_MINMAX = C.AV_ROUND_PASS_MINMAX 9 | ) 10 | 11 | func AvRescaleQ(a int64, bq Rational, cq Rational) int64 { 12 | return (int64)(C.av_rescale_q(C.int64_t(a), (C.struct_AVRational)(bq), (C.struct_AVRational)(cq))) 13 | } 14 | 15 | func AvRescaleQRnd(a int64, bq Rational, cq Rational, flags uint32) int64 { 16 | return (int64)(C.av_rescale_q_rnd(C.int64_t(a), (C.struct_AVRational)(bq), (C.struct_AVRational)(cq), flags)) 17 | } 18 | -------------------------------------------------------------------------------- /avutil/memory.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package avutil 5 | 6 | /* 7 | #cgo pkg-config: libavutil 8 | #include 9 | #include 10 | #include 11 | */ 12 | import "C" 13 | import ( 14 | "unsafe" 15 | ) 16 | 17 | //Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU). 18 | func AvMalloc(s uintptr) unsafe.Pointer { 19 | return C.av_malloc(C.size_t(s)) 20 | } 21 | 22 | func AvMallocArray(n, s uintptr) unsafe.Pointer { 23 | return C.av_malloc_array(C.size_t(n), C.size_t(s)) 24 | } 25 | 26 | //Allocate or reallocate a block of memory. 27 | func AvRealloc(p *int, s uintptr) unsafe.Pointer { 28 | return C.av_realloc(unsafe.Pointer(&p), C.size_t(s)) 29 | } 30 | 31 | //Allocate or reallocate a block of memory. 32 | func AvReallocF(p int, n, e uintptr) unsafe.Pointer { 33 | return C.av_realloc_f(unsafe.Pointer(&p), C.size_t(n), C.size_t(e)) 34 | } 35 | 36 | //Allocate or reallocate a block of memory. 37 | func AvReallocp(p int, s uintptr) int { 38 | return int(C.av_reallocp(unsafe.Pointer(&p), C.size_t(s))) 39 | } 40 | 41 | func AvReallocArray(p int, n, s uintptr) unsafe.Pointer { 42 | return C.av_realloc_array(unsafe.Pointer(&p), C.size_t(n), C.size_t(s)) 43 | } 44 | 45 | func AvReallocpArray(p int, n, s uintptr) int { 46 | return int(C.av_reallocp_array(unsafe.Pointer(&p), C.size_t(n), C.size_t(s))) 47 | } 48 | 49 | //Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). 50 | func AvFree(p unsafe.Pointer) { 51 | C.av_free(p) 52 | } 53 | 54 | //Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. 55 | func AvMallocz(s uintptr) unsafe.Pointer { 56 | return C.av_mallocz(C.size_t(s)) 57 | } 58 | 59 | //Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. 60 | func AvCalloc(n, s uintptr) unsafe.Pointer { 61 | return C.av_calloc(C.size_t(n), C.size_t(s)) 62 | } 63 | 64 | func AvMalloczArray(n, s uintptr) unsafe.Pointer { 65 | return C.av_mallocz_array(C.size_t(n), C.size_t(s)) 66 | } 67 | 68 | //Duplicate the string s. 69 | func AvStrdup(s string) string { 70 | cs := C.CString(s) 71 | defer C.free(unsafe.Pointer(cs)) 72 | return C.GoString(C.av_strdup(cs)) 73 | } 74 | 75 | //char * av_strndup (const char *s, size_t len) av_malloc_attrib 76 | //Duplicate a substring of the string s. 77 | func AvStrndup(s string, l uintptr) string { 78 | cs := C.CString(s) 79 | defer C.free(unsafe.Pointer(cs)) 80 | return C.GoString(C.av_strndup(cs, C.size_t(l))) 81 | } 82 | 83 | //Duplicate the buffer p. 84 | func AvMemdup(p *int, s uintptr) unsafe.Pointer { 85 | return C.av_memdup(unsafe.Pointer(p), C.size_t(s)) 86 | } 87 | 88 | //Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer pointing to it to NULL. 89 | func AvFreep(p unsafe.Pointer) { 90 | C.av_freep(p) 91 | } 92 | 93 | //Add an element to a dynamic array. 94 | func AvDynarrayAdd(t unsafe.Pointer, n *int, e unsafe.Pointer) { 95 | C.av_dynarray_add(t, (*C.int)(unsafe.Pointer(n)), e) 96 | } 97 | 98 | //Add an element to a dynamic array. 99 | func AvDynarrayAddNofree(p unsafe.Pointer, n *int, e unsafe.Pointer) int { 100 | return int(C.av_dynarray_add_nofree(p, (*C.int)(unsafe.Pointer(&n)), e)) 101 | } 102 | 103 | //Add an element of size elem_size to a dynamic array. 104 | func AvDynarray2Add(t *unsafe.Pointer, n *int, e uintptr, d uint8) unsafe.Pointer { 105 | return C.av_dynarray2_add(t, (*C.int)(unsafe.Pointer(&n)), (C.size_t)(e), (*C.uint8_t)(unsafe.Pointer(&d))) 106 | } 107 | 108 | //Multiply two size_t values checking for overflow. 109 | func AvSizeMult(a, b uintptr, r *uintptr) int { 110 | return int(C.av_size_mult((C.size_t)(a), (C.size_t)(b), (*C.size_t)(unsafe.Pointer(r)))) 111 | } 112 | 113 | //Set the maximum size that may me allocated in one block. 114 | func AvMaxAlloc(m uintptr) { 115 | C.av_max_alloc(C.size_t(m)) 116 | } 117 | 118 | //deliberately overlapping memcpy implementation 119 | func AvMemcpyBackptr(d *uintptr, b, c int) { 120 | C.av_memcpy_backptr((*C.uint8_t)(unsafe.Pointer(d)), C.int(b), C.int(c)) 121 | } 122 | 123 | //Reallocate the given block if it is not large enough, otherwise do nothing. 124 | func AvFastRealloc(p unsafe.Pointer, s *uint, m uintptr) unsafe.Pointer { 125 | return C.av_fast_realloc(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(m)) 126 | } 127 | 128 | //Allocate a buffer, reusing the given one if large enough. 129 | func AvFastMalloc(p unsafe.Pointer, s *uint, m uintptr) { 130 | C.av_fast_malloc(p, (*C.uint)(unsafe.Pointer(s)), (C.size_t)(m)) 131 | } 132 | -------------------------------------------------------------------------------- /avutil/picture.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | import "C" 6 | import "unsafe" 7 | 8 | func AvAllocateImageBuffer(size int) []uint8 { 9 | p := AvMalloc(uintptr(size)) 10 | if p == nil { 11 | return nil 12 | } 13 | return (*[1 << 30]uint8)(p)[:size] 14 | } 15 | 16 | func AvFreeImageBuffer(buffer []uint8) { 17 | AvFree(unsafe.Pointer(&buffer[0])) 18 | } 19 | 20 | //Return the size in bytes of the amount of data required to store an image with the given parameters. 21 | func AvImageGetBufferSize(pixFmt PixelFormat, width, height, align int) int { 22 | return int(C.av_image_get_buffer_size((C.enum_AVPixelFormat)(pixFmt), C.int(width), C.int(height), C.int(align))) 23 | } 24 | 25 | //Setup the data pointers and linesizes based on the specified image parameters and the provided array. 26 | func AvImageFillArrays(dstData [8]*uint8, dstLinesize [8]int32, src []uint8, 27 | pixFmt PixelFormat, width, height, align int) int { 28 | cData := (**C.uint8_t)(unsafe.Pointer(&dstData[0])) 29 | cLinesize := (*C.int)(unsafe.Pointer(&dstLinesize[0])) 30 | cSrc := (*C.uint8_t)(unsafe.Pointer(&src[0])) 31 | cPixFmt := (C.enum_AVPixelFormat)(pixFmt) 32 | 33 | return int(C.av_image_fill_arrays(cData, cLinesize, cSrc, cPixFmt, C.int(width), C.int(height), C.int(align))) 34 | } 35 | 36 | // Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordingly. 37 | // 38 | // The allocated image buffer has to be freed by using AvFreeP(&pointers[0]). 39 | func AvImageAlloc(pointers [8]*uint8, linesizes [8]int32, w, h int, pix_fmt PixelFormat, align int) int { 40 | cPointers := (**C.uint8_t)(unsafe.Pointer(&pointers[0])) 41 | cLinesizes := (*C.int)(unsafe.Pointer(&linesizes[0])) 42 | cPixFmt := (C.enum_AVPixelFormat)(pix_fmt) 43 | 44 | return int(C.av_image_alloc(cPointers, cLinesizes, C.int(w), C.int(h), cPixFmt, C.int(align))) 45 | } 46 | -------------------------------------------------------------------------------- /avutil/pixel_format.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | import "C" 6 | 7 | const ( 8 | AV_PIX_FMT_BGR24 = C.AV_PIX_FMT_BGR24 9 | AV_PIX_FMT_NONE = C.AV_PIX_FMT_NONE 10 | AV_PIX_FMT_RGB24 = C.AV_PIX_FMT_RGB24 11 | AV_PIX_FMT_RGBA = C.AV_PIX_FMT_RGBA 12 | AV_PIX_FMT_YUV420P = C.AV_PIX_FMT_YUV420P 13 | AV_PIX_FMT_YUVA420P = C.AV_PIX_FMT_YUVA420P 14 | AV_PIX_FMT_YUVJ420P = C.AV_PIX_FMT_YUVJ420P 15 | ) 16 | 17 | // PixelFormatFromString returns a pixel format from a string 18 | func PixelFormatFromString(i string) PixelFormat { 19 | switch i { 20 | case "bgr24": 21 | return AV_PIX_FMT_BGR24 22 | case "rgb24": 23 | return AV_PIX_FMT_RGB24 24 | case "rgba": 25 | return AV_PIX_FMT_RGBA 26 | case "yuv420p": 27 | return AV_PIX_FMT_YUV420P 28 | case "yuva420p": 29 | return AV_PIX_FMT_YUVA420P 30 | case "yuvj420p": 31 | return AV_PIX_FMT_YUVJ420P 32 | default: 33 | return -1 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /avutil/rational_struct.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#include 4 | import "C" 5 | import "strconv" 6 | 7 | func (r Rational) Num() int { 8 | return int(r.num) 9 | } 10 | 11 | func (r *Rational) SetNum(num int) { 12 | r.num = C.int(num) 13 | } 14 | 15 | func (r Rational) Den() int { 16 | return int(r.den) 17 | } 18 | 19 | func (r *Rational) SetDen(den int) { 20 | r.den = C.int(den) 21 | } 22 | 23 | func (r Rational) ToDouble() float64 { 24 | if r.Num() == 0 || r.Den() == 0 { 25 | return 0 26 | } 27 | return float64(r.Num()) / float64(r.Den()) 28 | } 29 | 30 | func (r Rational) String() string { 31 | if r.Num() == 0 || r.Den() == 0 { 32 | return "0" 33 | } 34 | return strconv.Itoa(r.Num()) + "/" + strconv.Itoa(r.Den()) 35 | } 36 | 37 | func NewRational(num, den int) Rational { 38 | var r Rational 39 | r.SetNum(num) 40 | r.SetDen(den) 41 | return r 42 | } 43 | -------------------------------------------------------------------------------- /avutil/samplefmt.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | import "C" 6 | import "unsafe" 7 | 8 | const ( 9 | AV_SAMPLE_FMT_NONE = int(C.AV_SAMPLE_FMT_NONE) 10 | AV_SAMPLE_FMT_U8 = int(C.AV_SAMPLE_FMT_U8) 11 | AV_SAMPLE_FMT_S16 = int(C.AV_SAMPLE_FMT_S16) 12 | AV_SAMPLE_FMT_S32 = int(C.AV_SAMPLE_FMT_S32) 13 | AV_SAMPLE_FMT_FLT = int(C.AV_SAMPLE_FMT_FLT) 14 | AV_SAMPLE_FMT_DBL = int(C.AV_SAMPLE_FMT_DBL) 15 | 16 | AV_SAMPLE_FMT_U8P = int(C.AV_SAMPLE_FMT_U8P) 17 | AV_SAMPLE_FMT_S16P = int(C.AV_SAMPLE_FMT_S16P) 18 | AV_SAMPLE_FMT_S32P = int(C.AV_SAMPLE_FMT_S32P) 19 | AV_SAMPLE_FMT_FLTP = int(C.AV_SAMPLE_FMT_FLTP) 20 | AV_SAMPLE_FMT_DBLP = int(C.AV_SAMPLE_FMT_DBLP) 21 | AV_SAMPLE_FMT_S64 = int(C.AV_SAMPLE_FMT_S64) 22 | AV_SAMPLE_FMT_S64P = int(C.AV_SAMPLE_FMT_S64P) 23 | 24 | AV_SAMPLE_FMT_NB = int(C.AV_SAMPLE_FMT_NB) 25 | ) 26 | 27 | func AvGetSampleFmtName(sampleFmt int) string { 28 | return C.GoString(C.av_get_sample_fmt_name((C.enum_AVSampleFormat)(sampleFmt))) 29 | } 30 | 31 | func AvSamplesAlloc(data **uint8, linesize *int, nbChannels, nbSamples, sampleFmt, align int) int { 32 | return int(C.av_samples_alloc((**C.uint8_t)(unsafe.Pointer(data)), (*C.int)(unsafe.Pointer(linesize)), C.int(nbChannels), C.int(nbSamples), (C.enum_AVSampleFormat)(sampleFmt), C.int(align))) 33 | } 34 | -------------------------------------------------------------------------------- /avutil/time.go: -------------------------------------------------------------------------------- 1 | package avutil 2 | 3 | //#cgo pkg-config: libavutil 4 | //#include 5 | import "C" 6 | 7 | func AvGetTimeRelative() int64 { 8 | return int64(C.av_gettime_relative()) 9 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/asticode/goav 2 | 3 | go 1.13 4 | -------------------------------------------------------------------------------- /goav.go: -------------------------------------------------------------------------------- 1 | //Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | //Giorgis (habtom@giorgis.io) 3 | 4 | /* 5 | Package goav contains golang binding for FFmpeg. 6 | 7 | A comprehensive binding to the ffmpeg video/audio manipulation library: 8 | https://www.ffmpeg.org/ 9 | 10 | Contains: 11 | 12 | libavcodec: encoding/decoding library 13 | libavfilter: graph-based frame editing library 14 | libavformat: I/O and muxing/demuxing library 15 | libavdevice: special devices muxing/demuxing library 16 | libavutil: common utility library 17 | libswresample: audio resampling, format conversion and mixing 18 | libpostproc: post processing library 19 | libswscale: color conversion and scaling library 20 | */ 21 | package goav 22 | -------------------------------------------------------------------------------- /swresample/context.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package swresample 5 | 6 | /* 7 | #cgo pkg-config: libswresample 8 | #include 9 | */ 10 | import "C" 11 | import ( 12 | "unsafe" 13 | ) 14 | 15 | //Initialize context after user parameters have been set. 16 | func (s *Context) SwrInit() int { 17 | return int(C.swr_init((*C.struct_SwrContext)(s))) 18 | } 19 | 20 | //Check whether an swr context has been initialized or not. 21 | func (s *Context) SwrIsInitialized() int { 22 | return int(C.swr_is_initialized((*C.struct_SwrContext)(s))) 23 | } 24 | 25 | //Allocate Context if needed and set/reset common parameters. 26 | func (s *Context) SwrAllocSetOpts(ocl int64, osf AvSampleFormat, osr int, icl int64, isf AvSampleFormat, isr, lo, lc int) *Context { 27 | return (*Context)(C.swr_alloc_set_opts((*C.struct_SwrContext)(s), C.int64_t(ocl), (C.enum_AVSampleFormat)(osf), C.int(osr), C.int64_t(icl), (C.enum_AVSampleFormat)(isf), C.int(isr), C.int(lo), unsafe.Pointer(&lc))) 28 | } 29 | 30 | //Context destructor functions. Free the given Context and set the pointer to NULL. 31 | func (s *Context) SwrFree() { 32 | C.swr_free((**C.struct_SwrContext)(unsafe.Pointer(&s))) 33 | } 34 | 35 | //Closes the context so that swr_is_initialized() returns 0. 36 | func (s *Context) SwrClose() { 37 | C.swr_close((*C.struct_SwrContext)(s)) 38 | } 39 | 40 | //Core conversion functions. Convert audio 41 | func (s *Context) SwrConvert(out **uint8, oc int, in **uint8, ic int) int { 42 | return int(C.swr_convert((*C.struct_SwrContext)(s), (**C.uint8_t)(unsafe.Pointer(out)), C.int(oc), (**C.uint8_t)(unsafe.Pointer(in)), C.int(ic))) 43 | } 44 | 45 | //Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate) units. 46 | func (s *Context) SwrNextPts(pts int64) int64 { 47 | return int64(C.swr_next_pts((*C.struct_SwrContext)(s), C.int64_t(pts))) 48 | } 49 | 50 | //Low-level option setting functions 51 | //These functons provide a means to set low-level options that is not possible with the AvOption API. 52 | //Activate resampling compensation ("soft" compensation). 53 | func (s *Context) SwrSetCompensation(sd, cd int) int { 54 | return int(C.swr_set_compensation((*C.struct_SwrContext)(s), C.int(sd), C.int(cd))) 55 | } 56 | 57 | //Set a customized input channel mapping. 58 | func (s *Context) SwrSetChannelMapping(cm *int) int { 59 | return int(C.swr_set_channel_mapping((*C.struct_SwrContext)(s), (*C.int)(unsafe.Pointer(cm)))) 60 | } 61 | 62 | //Set a customized remix matrix. 63 | func (s *Context) SwrSetMatrix(m *int, t int) int { 64 | return int(C.swr_set_matrix((*C.struct_SwrContext)(s), (*C.double)(unsafe.Pointer(m)), C.int(t))) 65 | } 66 | 67 | //Sample handling functions. Drops the specified number of output samples. 68 | func (s *Context) SwrDropOutput(c int) int { 69 | return int(C.swr_drop_output((*C.struct_SwrContext)(s), C.int(c))) 70 | } 71 | 72 | //Injects the specified number of silence samples. 73 | func (s *Context) SwrInjectSilence(c int) int { 74 | return int(C.swr_inject_silence((*C.struct_SwrContext)(s), C.int(c))) 75 | } 76 | 77 | //Gets the delay the next input sample will experience relative to the next output sample. 78 | func (s *Context) SwrGetDelay(b int64) int64 { 79 | return int64(C.swr_get_delay((*C.struct_SwrContext)(s), C.int64_t(b))) 80 | } 81 | 82 | //Frame based API. Convert the samples in the input Frame and write them to the output Frame. 83 | func (s *Context) SwrConvertFrame(o, i *Frame) int { 84 | return int(C.swr_convert_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) 85 | } 86 | 87 | //Configure or reconfigure the Context using the information provided by the AvFrames. 88 | func (s *Context) SwrConfigFrame(o, i *Frame) int { 89 | return int(C.swr_config_frame((*C.struct_SwrContext)(s), (*C.struct_AVFrame)(o), (*C.struct_AVFrame)(i))) 90 | } 91 | -------------------------------------------------------------------------------- /swresample/swresample.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | // Package swresample provides a high-level interface to the libswresample library audio resampling utilities 5 | // The process of changing the sampling rate of a discrete signal to obtain a new discrete representation of the underlying continuous signal. 6 | package swresample 7 | 8 | /* 9 | #cgo pkg-config: libswresample 10 | #include 11 | */ 12 | import "C" 13 | 14 | type ( 15 | Context C.struct_SwrContext 16 | Frame C.struct_AVFrame 17 | Class C.struct_AVClass 18 | AvSampleFormat C.enum_AVSampleFormat 19 | ) 20 | 21 | //Get the Class for Context. 22 | func SwrGetClass() *Class { 23 | return (*Class)(C.swr_get_class()) 24 | } 25 | 26 | //Context constructor functions.Allocate Context. 27 | func SwrAlloc() *Context { 28 | return (*Context)(C.swr_alloc()) 29 | } 30 | 31 | //Configuration accessors 32 | func SwresampleVersion() uint { 33 | return uint(C.swresample_version()) 34 | } 35 | 36 | func SwresampleConfiguration() string { 37 | return C.GoString(C.swresample_configuration()) 38 | } 39 | 40 | func SwresampleLicense() string { 41 | return C.GoString(C.swresample_license()) 42 | } 43 | -------------------------------------------------------------------------------- /swscale/context.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package swscale 5 | 6 | //#cgo pkg-config: libswscale libavutil 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/asticode/goav/avutil" 13 | ) 14 | 15 | //Allocate an empty Context. 16 | func SwsAllocContext() *Context { 17 | return (*Context)(C.sws_alloc_context()) 18 | } 19 | 20 | //Initialize the swscaler context sws_context. 21 | func SwsInitContext(ctxt *Context, sf, df *Filter) int { 22 | return int(C.sws_init_context((*C.struct_SwsContext)(ctxt), (*C.struct_SwsFilter)(sf), (*C.struct_SwsFilter)(df))) 23 | } 24 | 25 | //Free the swscaler context swsContext. 26 | func SwsFreecontext(ctxt *Context) { 27 | C.sws_freeContext((*C.struct_SwsContext)(ctxt)) 28 | } 29 | 30 | //Allocate and return an Context. 31 | func SwsGetcontext(sw, sh int, sf avutil.PixelFormat, dw, dh int, df avutil.PixelFormat, f int, sfl, dfl *Filter, p *int) *Context { 32 | return (*Context)(C.sws_getContext(C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(unsafe.Pointer(p)))) 33 | } 34 | 35 | //Check if context can be reused, otherwise reallocate a new one. 36 | func SwsGetcachedcontext(ctxt *Context, sw, sh int, sf avutil.PixelFormat, dw, dh int, df avutil.PixelFormat, f int, sfl, dfl *Filter, p *float64) *Context { 37 | return (*Context)(C.sws_getCachedContext((*C.struct_SwsContext)(ctxt), C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(p))) 38 | } 39 | -------------------------------------------------------------------------------- /swscale/swscale.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | //Package swscale performs highly optimized image scaling and colorspace and pixel format conversion operations. 5 | //Rescaling: is the process of changing the video size. Several rescaling options and algorithms are available. 6 | //Pixel format conversion: is the process of converting the image format and colorspace of the image. 7 | package swscale 8 | 9 | //#cgo pkg-config: libswscale libavutil 10 | //#include 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | import "C" 17 | import ( 18 | "unsafe" 19 | 20 | "github.com/asticode/goav/avutil" 21 | ) 22 | 23 | type ( 24 | Context C.struct_SwsContext 25 | Filter C.struct_SwsFilter 26 | Vector C.struct_SwsVector 27 | Class C.struct_AVClass 28 | ) 29 | 30 | const ( 31 | SWS_FAST_BILINEAR = 1 32 | SWS_BILINEAR = 2 33 | SWS_BICUBIC = 4 34 | SWS_X = 8 35 | SWS_POINT = 0x10 36 | SWS_AREA = 0x20 37 | SWS_BICUBLIN = 0x40 38 | SWS_GAUSS = 0x80 39 | SWS_SINC = 0x100 40 | SWS_LANCZOS = 0x200 41 | SWS_SPLINE = 0x400 42 | ) 43 | 44 | //Return the LIBSWSCALE_VERSION_INT constant. 45 | func SwscaleVersion() uint { 46 | return uint(C.swscale_version()) 47 | } 48 | 49 | //Return the libswscale build-time configuration. 50 | func SwscaleConfiguration() string { 51 | return C.GoString(C.swscale_configuration()) 52 | } 53 | 54 | //Return the libswscale license. 55 | func SwscaleLicense() string { 56 | return C.GoString(C.swscale_license()) 57 | } 58 | 59 | //Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDetails(). 60 | func SwsGetcoefficients(c int) *int { 61 | return (*int)(unsafe.Pointer(C.sws_getCoefficients(C.int(c)))) 62 | } 63 | 64 | //Return a positive value if pix_fmt is a supported input format, 0 otherwise. 65 | func SwsIssupportedinput(p avutil.PixelFormat) int { 66 | return int(C.sws_isSupportedInput((C.enum_AVPixelFormat)(p))) 67 | } 68 | 69 | //Return a positive value if pix_fmt is a supported output format, 0 otherwise. 70 | func SwsIssupportedoutput(p avutil.PixelFormat) int { 71 | return int(C.sws_isSupportedOutput((C.enum_AVPixelFormat)(p))) 72 | } 73 | 74 | func SwsIssupportedendiannessconversion(p avutil.PixelFormat) int { 75 | return int(C.sws_isSupportedEndiannessConversion((C.enum_AVPixelFormat)(p))) 76 | } 77 | 78 | ////Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst. 79 | func SwsScale(ctxt *Context, src [8]*uint8, str [8]int32, y, h int, d [8]*uint8, ds [8]int32) int { 80 | cctxt := (*C.struct_SwsContext)(unsafe.Pointer(ctxt)) 81 | csrc := (**C.uint8_t)(unsafe.Pointer(&src[0])) 82 | cstr := (*C.int)(unsafe.Pointer(&str)) 83 | cd := (**C.uint8_t)(unsafe.Pointer(&d[0])) 84 | cds := (*C.int)(unsafe.Pointer(&ds)) 85 | return int(C.sws_scale(cctxt, csrc, cstr, C.int(y), C.int(h), cd, cds)) 86 | } 87 | 88 | func SwsSetcolorspacedetails(ctxt *Context, it *int, sr int, t *int, dr, b, c, s int) int { 89 | cit := (*C.int)(unsafe.Pointer(it)) 90 | ct := (*C.int)(unsafe.Pointer(t)) 91 | return int(C.sws_setColorspaceDetails((*C.struct_SwsContext)(ctxt), cit, C.int(sr), ct, C.int(dr), C.int(b), C.int(c), C.int(s))) 92 | } 93 | 94 | func SwsGetcolorspacedetails(ctxt *Context, it, sr, t, dr, b, c, s *int) int { 95 | cit := (**C.int)(unsafe.Pointer(it)) 96 | csr := (*C.int)(unsafe.Pointer(sr)) 97 | ct := (**C.int)(unsafe.Pointer(t)) 98 | cdr := (*C.int)(unsafe.Pointer(dr)) 99 | cb := (*C.int)(unsafe.Pointer(b)) 100 | cc := (*C.int)(unsafe.Pointer(c)) 101 | cs := (*C.int)(unsafe.Pointer(s)) 102 | return int(C.sws_getColorspaceDetails((*C.struct_SwsContext)(ctxt), cit, csr, ct, cdr, cb, cc, cs)) 103 | } 104 | 105 | func SwsGetdefaultfilter(lb, cb, ls, cs, chs, cvs float32, v int) *Filter { 106 | return (*Filter)(unsafe.Pointer(C.sws_getDefaultFilter(C.float(lb), C.float(cb), C.float(ls), C.float(cs), C.float(chs), C.float(cvs), C.int(v)))) 107 | } 108 | 109 | func SwsFreefilter(f *Filter) { 110 | C.sws_freeFilter((*C.struct_SwsFilter)(f)) 111 | } 112 | 113 | //Convert an 8-bit paletted frame into a frame with a color depth of 32 bits. 114 | func SwsConvertpalette8topacked32(s, d *uint8, px int, p *uint8) { 115 | C.sws_convertPalette8ToPacked32((*C.uint8_t)(s), (*C.uint8_t)(d), C.int(px), (*C.uint8_t)(p)) 116 | } 117 | 118 | //Convert an 8-bit paletted frame into a frame with a color depth of 24 bits. 119 | func SwsConvertpalette8topacked24(s, d *uint8, px int, p *uint8) { 120 | C.sws_convertPalette8ToPacked24((*C.uint8_t)(s), (*C.uint8_t)(d), C.int(px), (*C.uint8_t)(p)) 121 | } 122 | 123 | //Get the Class for swsContext. 124 | func SwsGetClass() *Class { 125 | return (*Class)(C.sws_get_class()) 126 | } 127 | -------------------------------------------------------------------------------- /swscale/vector.go: -------------------------------------------------------------------------------- 1 | // Use of this source code is governed by a MIT license that can be found in the LICENSE file. 2 | // Giorgis (habtom@giorgis.io) 3 | 4 | package swscale 5 | 6 | //#cgo pkg-config: libswscale libavutil 7 | //#include 8 | import "C" 9 | import ( 10 | "unsafe" 11 | ) 12 | 13 | //Allocate and return an uninitialized vector with length coefficients. 14 | func SwsAllocvec(l int) *Vector { 15 | return (*Vector)(C.sws_allocVec(C.int(l))) 16 | } 17 | 18 | //Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality, lower is lower quality. 19 | func SwsGetgaussianvec(v, q float64) *Vector { 20 | return (*Vector)(unsafe.Pointer(C.sws_getGaussianVec(C.double(v), C.double(q)))) 21 | } 22 | 23 | // Deprecated in latest FFMpeg API 24 | //Allocate and return a vector with length coefficients, all with the same value c. 25 | // func SwsGetconstvec(c float64, l int) *Vector { 26 | // return (*Vector)(unsafe.Pointer(C.sws_getConstVec(C.double(c), C.int(l)))) 27 | // } 28 | 29 | // Deprecated in latest FFMpeg API 30 | //Allocate and return a vector with just one coefficient, with value 1.0. 31 | // func SwsGetidentityvec() *Vector { 32 | // return (*Vector)(unsafe.Pointer(C.sws_getIdentityVec())) 33 | // } 34 | 35 | //Scale all the coefficients of a by the scalar value. 36 | func (a *Vector) SwsScalevec(s float64) { 37 | C.sws_scaleVec((*C.struct_SwsVector)(unsafe.Pointer(a)), C.double(s)) 38 | } 39 | 40 | //Scale all the coefficients of a so that their sum equals height. 41 | func (a *Vector) SwsNormalizevec(h float64) { 42 | C.sws_normalizeVec((*C.struct_SwsVector)(a), C.double(h)) 43 | } 44 | 45 | // Deprecated in latest FFMpeg API 46 | // func (a *Vector) SwsConvvec(b *Vector) { 47 | // C.sws_convVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b)) 48 | // } 49 | 50 | // Deprecated in latest FFMpeg API 51 | // func (a *Vector) SwsAddvec(b *Vector) { 52 | // C.sws_addVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b)) 53 | // } 54 | 55 | // Deprecated in latest FFMpeg API 56 | // func (a *Vector) SwsSubvec(b *Vector) { 57 | // C.sws_subVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b)) 58 | // } 59 | 60 | // Deprecated in latest FFMpeg API 61 | // func (a *Vector) SwsShiftvec(s int) { 62 | // C.sws_shiftVec((*C.struct_SwsVector)(a), C.int(s)) 63 | // } 64 | 65 | // Deprecated in latest FFMpeg API 66 | //Allocate and return a clone of the vector a, that is a vector with the same coefficients as a. 67 | // func (a *Vector) SwsClonevec() *Vector { 68 | // return (*Vector)(unsafe.Pointer(C.sws_cloneVec((*C.struct_SwsVector)(a)))) 69 | // } 70 | 71 | // Deprecated in latest FFMpeg API 72 | //Print with av_log() a textual representation of the vector a if log_level <= av_log_level. 73 | // func (a *Vector) SwsPrintvec2(lctx *Class, l int) { 74 | // C.sws_printVec2((*C.struct_SwsVector)(a), (*C.struct_AVClass)(lctx), C.int(l)) 75 | // } 76 | 77 | func (a *Vector) SwsFreevec() { 78 | C.sws_freeVec((*C.struct_SwsVector)(a)) 79 | } 80 | -------------------------------------------------------------------------------- /versions/versions.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/asticode/goav/avcodec" 7 | "github.com/asticode/goav/avdevice" 8 | "github.com/asticode/goav/avfilter" 9 | "github.com/asticode/goav/avutil" 10 | "github.com/asticode/goav/swresample" 11 | "github.com/asticode/goav/swscale" 12 | ) 13 | 14 | func main() { 15 | log.Printf("AvFilter Version:\t%v", avfilter.AvfilterVersion()) 16 | log.Printf("AvDevice Version:\t%v", avdevice.AvdeviceVersion()) 17 | log.Printf("SWScale Version:\t%v", swscale.SwscaleVersion()) 18 | log.Printf("AvUtil Version:\t%v", avutil.AvutilVersion()) 19 | log.Printf("AvCodec Version:\t%v", avcodec.AvcodecVersion()) 20 | log.Printf("Resample Version:\t%v", swresample.SwresampleLicense()) 21 | } 22 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | ## 2 | ## Need FFMPEG to test. 3 | box: amarburg/golang-ffmpeg:wheezy-1.8 4 | 5 | build: 6 | 7 | steps: 8 | - setup-go-workspace: 9 | package-dir: github.com/amarburg/goav 10 | 11 | #- wercker/golint 12 | 13 | # Gets the dependencies 14 | - script: 15 | name: go get 16 | code: | 17 | go get -t . 18 | 19 | # Build the project 20 | - script: 21 | name: go build 22 | code: | 23 | go build ./... 24 | 25 | # Test the project 26 | - script: 27 | name: go test 28 | code: | 29 | go test ./... 30 | --------------------------------------------------------------------------------