Golang bindings for FFmpeg

Overview

goav

Golang binding for FFmpeg

A comprehensive binding to the ffmpeg video/audio manipulation library.

GoDoc

Usage

import "github.com/giorgisio/goav/avformat"

func main() {

	filename := "sample.mp4"

	// Register all formats and codecs
	avformat.AvRegisterAll()

	ctx := avformat.AvformatAllocContext()

	// Open video file
	if avformat.AvformatOpenInput(&ctx, filename, nil, nil) != 0 {
		log.Println("Error: Couldn't open file.")
		return
	}

	// Retrieve stream information
	if ctx.AvformatFindStreamInfo(nil) < 0 {
		log.Println("Error: Couldn't find stream information.")

		// Close input file and free context
		ctx.AvformatCloseInput()
		return
	}

	//...

}

Libraries

  • avcodec corresponds to the ffmpeg library: libavcodec [provides implementation of a wider range of codecs]
  • avformat corresponds to the ffmpeg library: libavformat [implements streaming protocols, container formats and basic I/O access]
  • avutil corresponds to the ffmpeg library: libavutil [includes hashers, decompressors and miscellaneous utility functions]
  • avfilter corresponds to the ffmpeg library: libavfilter [provides a mean to alter decoded Audio and Video through chain of filters]
  • avdevice corresponds to the ffmpeg library: libavdevice [provides an abstraction to access capture and playback devices]
  • swresample corresponds to the ffmpeg library: libswresample [implements audio mixing and resampling routines]
  • swscale corresponds to the ffmpeg library: libswscale [implements color conversion and scaling routines]

Installation

FFMPEG INSTALL INSTRUCTIONS

sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev

sudo apt install -y libavdevice-dev libavfilter-dev libswscale-dev libavcodec-dev libavformat-dev libswresample-dev libavutil-dev

sudo apt-get install yasm

export FFMPEG_ROOT=$HOME/ffmpeg
export CGO_LDFLAGS="-L$FFMPEG_ROOT/lib/ -lavcodec -lavformat -lavutil -lswscale -lswresample -lavdevice -lavfilter"
export CGO_CFLAGS="-I$FFMPEG_ROOT/include"
export LD_LIBRARY_PATH=$HOME/ffmpeg/lib
go get github.com/giorgisio/goav

More Examples

Coding examples are available in the examples/ directory.

Note

  • Function names in Go are consistent with that of the libraries to help with easy search
  • cgo: Extending Go with C
  • goav comes with absolutely no warranty.

Contribute

  • Fork this repo and create your own feature branch.
  • Follow standard Go conventions
  • Test your code.
  • Create pull request

TODO

  • Returning Errors
  • Garbage Collection
  • Review included/excluded functions from each library
  • Go Tests
  • Possible restructuring packages
  • Tutorial01.c
  • More Tutorial

License

This library is under the MIT License

Issues
  • The tutorial01 example fails with ffmpeg 2.6.3 on Mac

    The tutorial01 example fails with ffmpeg 2.6.3 on Mac

    Hi, I tried running the tutorial01 example. After removing some AVFormatContext fields to fix compilation (see issue #5), the example runs but dumps seemingly bogus stream info and fails to locate the proper codec. I attempted to debug but was unable to locate the problem.

    go run tutorial01.go                                                                                                                                                                         [2:21:59]
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        creation_time   : 1970-01-01 00:00:00
        encoder         : Lavf53.24.2
      Duration: 00:00:05.31, start: 0.000000, bitrate: 1589 kb/s
        Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1205 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 384 kb/s (default)
        Metadata:
          creation_time   : 1970-01-01 00:00:00
          handler_name    : SoundHandler
    2015/09/10 02:22:02 Number of Streams:2
    2015/09/10 02:22:02 Stream Number: 0
    2015/09/10 02:22:02 Bit Rate: 537403504
    2015/09/10 02:22:02 Channels: 200
    2015/09/10 02:22:02 Coded_height: 537403568
    2015/09/10 02:22:02 Coded_width: 200
    2015/09/10 02:22:02 Coder_type: 200
    2015/09/10 02:22:02 Height: 537403560
    2015/09/10 02:22:02 Profile: 200
    2015/09/10 02:22:02 Width: 200
    2015/09/10 02:22:02 Codec ID: 537403464
    2015/09/10 02:22:02 Error: Unsupported codec!
    
    opened by bobziuchkovski 9
  • Error after updated ffmpeg

    Error after updated ffmpeg

    I've just updated ffmpeg and when I built my app, there were some errors:

    # github.com/giorgisio/goav/avcodec
    could not determine kind of name for C.AV_CODEC_ID_ADPCM_VIMA_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_BRENDER_PIX_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_ESCAPE130_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_EXR_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_G2M_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_HEVC_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_MVC1_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_MVC2_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_OPUS_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_PAF_AUDIO_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_PAF_VIDEO_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_PCM_S24LE_PLANAR_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_PCM_S32LE_PLANAR_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_SANM_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_SGIRLE_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_TAK_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_VP7_DEPRECATED
    could not determine kind of name for C.AV_CODEC_ID_WEBP_DEPRECATED
    

    I searched and found that from ffmpeg 3.0, it changed some things. Link: https://fossies.org/diffs/ffmpeg/2.8.6_vs_3.0/libavcodec/avcodec.h-diff.html

    Thanks,

    opened by khachung 9
  • Add missing Avcodec_encode_video2 func.

    Add missing Avcodec_encode_video2 func.

    Noticed this was missing.

    In issue #1, you wrote that major changes were coming. Should I avoid future updates like this?

    opened by stephenwithav 7
  • This repo is still alive?

    This repo is still alive?

    opened by tosone 7
  • [AvFormat] Initial implementation for Dictionary, Stream added GetRot…

    [AvFormat] Initial implementation for Dictionary, Stream added GetRot…

    Hey! Thanks you for this awesome library

    I was going to get Stream Rotation to use more perfect/custom scale alghoritm

    So, I didnt find anything for it

    I've added get GetRotation method for Stream aka (struct_AVStream) from ffmpeg And initial api for Dictionary (C.struct_AVDictionary) and DictionaryEntry (C.struct_AVDictionaryEntry)

    Thanks

    opened by ovr 7
  • goav can not run

    goav can not run

    when i run the useage code,It report like this: github.com/giorgisio/goav/avcodec ../github.com/giorgisio/goav/avcodec/codecs.go:57:48: could not determine kind of name for C.AV_CODEC_ID_ADPCM_VIMA_DEPRECATED

    opened by biij5698 7
  • Feature/stream codec and codec context

    Feature/stream codec and codec context

    Hey! Now I am using own fork and sync pull request for your base repo

    1. Implement method Codec for CodecContext
    2. Fixes for Stream getRotation method
    3. Codec implement methods getName, getLongName
    4. CodecContext implement CodecIsOpen method instead of AvcodecIsOpen (it is needed to be deprecated with unexpected name and not boolean return type)

    Thanks

    opened by ovr 6
  • Fix compilation errors and make the examples work

    Fix compilation errors and make the examples work

    Hello,

    This PR should resolve compilation errors for ffmpeg v3 and v4 described in #24 , #30 , #32 and #37. Plus, this PR is based on PR #23 , #25 and #31 .

    It has compilation warnings left but, it builds.

    opened by corebreaker 6
  • could not determine kind of name for C.av_packet_side_data_name

    could not determine kind of name for C.av_packet_side_data_name

    package main
    
    import "github.com/giorgisio/goav/avformat"
    
    func main() {
        avformat.Av_register_all()
    }
    

    For this I get:

    [[email protected] goav]$ go build ./goavt1.go
    # github.com/giorgisio/goav/avcodec
    could not determine kind of name for C.av_packet_side_data_name
    

    Where am I wrong?

    opened by w495 5
  •  C ctructs member access

    C ctructs member access

    How do I access members in C ctructs that are returned by things like avcodec.CodecContext.AvCodecGetCodecDescriptor like CodecDescriptor.long_name

    If i just do a fmt.Print(myDescriptor.long_name) I get a cannot refer to unexported field or method error which is fair enough because it is lower-case.

    I can see that there is data in there when I fmt.Printf("descriptor:%s", myDescriptor)` I get something like.

    descriptor:%!s(*avcodec.Descriptor=&{86018 1 0x7f7bf10e6a4b 0x7f7bf10e6a4f 2 <nil> 0x7f7bf1413340})

    Do I need to write some form of accessors code like the following. This doesn't work but it is my best attempt

    avcodec/descriptor_struct.go:

    package avcodec
    
    //#cgo pkg-config: libavcodec
    //#include <libavcodec/avcodec.h>
    import "C"
    
    func (d *Descriptor) Name() string {
    	return C.GoString(d.name)
    }
    func (d *Descriptor) LongName() string {
    	return C.GoString(d.long_name)
    }
    
    
    opened by timhughes 4
Releases(v0.1.0)
Owner
H. Giorgis
Linkedin: https://www.linkedin.com/in/giorgis-io Also @giorgis And @hwoldegiorgis
H. Giorgis
Go Media Framework

Go FFmpeg Bindings Installation Prerequisites Current master branch supports all major Go versions, starting from 1.6. Build/install FFmpeg build last

alex 695 Jul 23, 2021
Golang bindings for FFmpeg

goav Golang binding for FFmpeg A comprehensive binding to the ffmpeg video/audio manipulation library. Usage import "github.com/giorgisio/goav/avforma

H. Giorgis 1.7k Jul 24, 2021
A small program in Go that efficiently compresses videos using ffmpeg.

discordcompressor A small program in Go that efficiently compresses videos using ffmpeg. Dependencies FFmpeg including FFprobe Usage discordcompressor

null 5 Jul 16, 2021
Autocut the Twitch VODs based on Marker

Given the VOD of the stream and the markers that are exported as a CSV file, generate a video using ffmpeg that cuts out part of the VOD according to the provided markers.

Tsoding 12 Jul 24, 2021
Plays videos using Prometheus and Grafana, e.g. Bad Apple.

prometheus_video_renderer Plays videos using Prometheus and Grafana, e.g. Bad Apple. Modes Currently 3 different modes are supported. Bitmap The bitma

Jacob Colvin 44 Jul 11, 2021
Go bindings for libVLC and high-level media player interface

Go bindings for libVLC 2.X/3.X/4.X and high-level media player interface. The package can be useful for adding multimedia capabilities to applications

Adrian-George Bostan 224 Jul 20, 2021
一个直播录制工具

Bililive-go Bililive-go是一个支持多种直播平台的直播录制工具 支持网站 站点 url 支持情况 Acfun直播 live.acfun.cn 滋瓷 哔哩哔哩直播 live.bilibili.com 滋瓷 战旗直播 www.zhanqi.tv 滋瓷 斗鱼直播 www.douyu.c

Chigusa 639 Jul 26, 2021
👾 Annie is a fast, simple and clean video downloader built with Go.

?? Annie is a fast, simple and clean video downloader built with Go. Installation Prerequisites Install via go get Homebrew (macOS only) Arch Linux Vo

Xinzhao Xu 15.1k Jul 24, 2021
Go bindings for GStreamer (retired: currently I don't use/develop this package)

Retired. I don't use/develop this package anymore. Go bindings for GStreamer at a very early stage of maturity. This package is based on GLib bindings

Michał Derkacz 159 Apr 20, 2021
Personal video streaming server.

tube This is a Golang project to build a self hosted "tube"-style video player for watching your own video collection over HTTP or hosting your own ch

davy wybiral 199 Jul 15, 2021
Live on-demand transcoding in go using ffmpeg. Also with NVIDIA GPU hardware acceleration.

Go live HTTP on-demand transcoding Transcoding is expensive and resource consuming operation on CPU and GPU. For big companies with thousands of custo

Miroslav Šedivý 42 Jul 22, 2021
live video streaming server in golang

中文 Simple and efficient live broadcast server: Very simple to install and use; Pure Golang, high performance, and cross-platform; Supports commonly us

浩麟 6.8k Jul 19, 2021
Parse and generate m3u8 playlists for Apple HTTP Live Streaming (HLS) in Golang (ported from gem https://github.com/sethdeckard/m3u8)

go-m3u8 Golang package for m3u8 (ported m3u8 gem https://github.com/sethdeckard/m3u8) go-m3u8 provides easy generation and parsing of m3u8 playlists d

Tan Quang Ngo 75 Jun 2, 2021
golang library to read and write various subtitle formats

libgosubs Golang library to read and write subtitles in the following formats Advanced SubStation Alpha v4 SRT TTML v1.0 - This is based on the spec p

Wargarblgarbl 14 May 20, 2021