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

Comments
  • [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
  • 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
  • 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
  • Add codecs from avcodec.h

    Add codecs from avcodec.h

    From: https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/avcodec.h

    Generated with gcc: gcc -fdump-go-spec=out.go avcodec.h

    Extracted with: grep 'const AV_CODEC_ID' out.go

    Should I remove the leading _?

    opened by stephenwithav 3
  • Add support for ffmpeg 2.6-2.8.

    Add support for ffmpeg 2.6-2.8.

    All these properties were moved to an internal data structure instead of the public API. https://www.ffmpeg.org/doxygen/2.6/structAVFormatInternal.html

    Fixes https://github.com/giorgisio/goav/issues/5

    opened by nicks 2
  • Update to latest ffmpeg API

    Update to latest ffmpeg API

    Much of the ffmpeg API has been deprecated and does not allow the sample application to pull frames from a video. This PR resolves this by:

    • creating many new bindings to the updated ffmpeg libraries
    • reworking the sample program tutorial01.go to incorporate the new changes so that it now works.

    Special thanks to @corebreaker for some of the initial heavy lifting.

    In demonstration of the updated bindings and sample code that utilizes them, here is the first frame of the sample.mp4 video converted to JPEG: frame1

    opened by PaulWaldo 1
  • Implemented the error helpers from ffmpeg

    Implemented the error helpers from ffmpeg

    I have done part of what I mentioned in #26.

    I implemented the error codes and some of the little helper functions mentioned in the documentation.

    TODO: Wrap all the return codes with the function CodeToError in order to return errors.

    opened by targodan 1
  • fix AvformatCloseInput crash bug

    fix AvformatCloseInput crash bug

    avformat_close_input take a pointer to AVFormatContext * void avformat_close_input ( AVFormatContext ** s )

    so the previous code will crash.

    Fatal error: unexpected signal during runtime execution
    [signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x7fff8dc5db13]
    
    runtime stack:
    runtime.throw(0x4236760, 0x2a)
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/panic.go:527 +0x90
    runtime.sigpanic()
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/sigpanic_unix.go:12 +0x5a
    
    goroutine 6 [syscall, locked to thread]:
    runtime.cgocall(0x41315f0, 0xc820031e20, 0xc800000000)
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/cgocall.go:120 +0x11b fp=0xc820031df0 sp=0xc820031dc0
    github.com/giorgisio/goav/avformat._Cfunc_avformat_close_input(0x6011800)
        ??:0 +0x31 fp=0xc820031e20 sp=0xc820031df0
    github.com/giorgisio/goav/avformat.(*Context).AvformatCloseInput(0x6011800)
        /Users/zzz/go/src/github.com/giorgisio/goav/avformat/context.go:125 +0x21 fp=0xc820031e30 sp=0xc820031e20
    github.com/zwh8800/Love66/player.(*Player).playRoutine(0xc82000e6c0)
        /Users/zzz/go/src/github.com/zwh8800/Love66/player/player.go:195 +0x862 fp=0xc820031fb8 sp=0xc820031e30
    runtime.goexit()
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/asm_amd64.s:1721 +0x1 fp=0xc820031fc0 sp=0xc820031fb8
    created by github.com/zwh8800/Love66/player.(*Player).Play
        /Users/zzz/go/src/github.com/zwh8800/Love66/player/player.go:70 +0x40
    
    goroutine 1 [chan receive]:
    testing.RunTests(0x424a290, 0x42f35d0, 0x1, 0x1, 0x1)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:562 +0x8ad
    testing.(*M).Run(0xc820065ef8, 0x41ffa90)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:494 +0x70
    main.main()
        github.com/zwh8800/Love66/player/_test/_testmain.go:54 +0x116
    
    goroutine 17 [syscall, locked to thread]:
    runtime.goexit()
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/asm_amd64.s:1721 +0x1
    
    goroutine 5 [chan receive]:
    github.com/zwh8800/Love66/player.(*Player).Stop(0xc82000e6c0)
        /Users/zzz/go/src/github.com/zwh8800/Love66/player/player.go:75 +0x87
    github.com/zwh8800/Love66/player.TestPlay(0xc820096000)
        /Users/zzz/go/src/github.com/zwh8800/Love66/player/player_test.go:26 +0x604
    testing.tRunner(0xc820096000, 0x42f35d0)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:456 +0x98
    created by testing.RunTests
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:561 +0x86d
    
    goroutine 18 [syscall, locked to thread]:
    runtime.goexit()
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/asm_amd64.s:1721 +0x1
    exit status 2
    FAIL    github.com/zwh8800/Love66/player    6.097s
    
    opened by zwh8800 1
  • Additional changes - More changes as I work through examples

    Additional changes - More changes as I work through examples

    I'm basically trying to replicate : https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/transcoding.c (albeit a bit more golang idiomatic with defers)

    This change includes more fixes and missing functions for this example. Most notable is the inclusion of some setter methods.

    Please look them over.

    opened by fzakaria 1
  • Fix imports and redeclaration of structs

    Fix imports and redeclaration of structs

    Each sub-package was redefining each type for cgo causing them to not operate with each other.

    ex. a CodecContext created in the avformat package was not actually the same (and therefore could not use) the methods in the avcodec/context_struct.go file.

    This change includes removing a lot of the incorrect redefinitions. Also added another basic example thats correct and shows a bit more.

    opened by fzakaria 1
  • Fix avformat string leaks

    Fix avformat string leaks

    Most of the C.CString calls are not freed, which causes memory leaks.

    Some of the functions that take a char* and a size now only take a size, and return a string. Eg: AvUrlSplit, AvGetFrameFilename, AvSdpCreate.

    opened by jviney 0
  • Add methods required for encoding

    Add methods required for encoding

    These methods are used for encoding video. Usage of these methods is described here:

    https://libav.org/documentation/doxygen/master/group__lavc__encdec.html

    Example implementation:

    https://www.ffmpeg.org/doxygen/trunk/encode_video_8c-example.html

    opened by DianeLooney 0
Releases(v0.1.0)
Owner
H. Giorgis
Linkedin: https://www.linkedin.com/in/giorgis-io Also @giorgis And @hwoldegiorgis
H. Giorgis
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.9k Dec 27, 2022
ffmpeg core for golang

go-ffmpeg-core ffmpeg core for golang 基于ffmpeg命令封装简单功能,因此运行环境需事先安装有ffmpeg命令。 ffmpeg官方下载地址: http://ffmpeg.org/download.html 1. 剥离视频文件的音频/视频 package mai

Resynz 0 Nov 26, 2021
golang function that download a video from youtube, and convert it to a mp3 file using ffmpeg

echedwnmp3 echedwnmp3 is a function that download a video from youtube, and convert it to a mp3 file using ffmpeg example package main import(echedwn

pai 4 Dec 7, 2021
lmmp3 is a little golang library that download a video from youtube, and convert it to a mp3 file using ffmpeg

lmmp3 lmmp3 is a function that download a video from youtube, and convert it to a mp3 file using ffmpeg You need to have installed ffmpeg in your syst

pai 8 Aug 12, 2022
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ý 107 Dec 16, 2022
A Go implementation of fluent-ffmpeg

A Go implementation of fluent-ffmpeg

Modfy 321 Dec 7, 2022
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 29 Dec 18, 2022
Stream video from ffmpeg to webrtc

ffmpeg-to-webrtc demonstrates how to send video from ffmpeg to your browser using pion.

Artur Shellunts 877 Dec 28, 2022
Videncode - Media Encoder (with ffmpeg)

Videncode - Media Encoder (with ffmpeg) Powered by yellyoshua (With2 easy steps) - Build JSON with folder of videos > Process the videos to the new fo

Yoshua Lopez 1 Nov 19, 2022
ffcommander - An easy frontend to FFmpeg and Imagemagick to automatically process video and manipulate subtitles.

% FFCOMMANDER(1) ffcommander 2.39 % Mikael Hartzell (C) 2018 % 2021 Name ffcommander - An easy frontend to FFmpeg and Imagemagick to automatically pro

Mikael Hartzell 2 May 9, 2022
A go program that relies on back-end ffmpeg to process video-related content

Video Compress A go program that relies on back-end ffmpeg to process video-related content Installation v-go You can download the corresponding v-go

JokerHeyra 0 Dec 22, 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 166 Nov 10, 2022
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 328 Dec 31, 2022
Go4vl is Go library for working with the Video for Linux API (V4L2) natively, without any C bindings.

go4vl A Go library for working with the Video for Linux user API (V4L2). Gov4l hides all the complexities of working with V4L2 and exposes idiomatic G

Vladimir Vivien 143 Dec 23, 2022
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 102 Nov 19, 2022
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 20 Sep 27, 2022
🔥 Golang live stream lib/client/server. support RTMP/RTSP/HLS/HTTP[S]-FLV/HTTP-TS, H264/H265/AAC, relay, cluster, record, HTTP API/Notify, GOP cache. 官方文档见 https://pengrl.com/lal

lal是一个开源GoLang直播流媒体网络传输项目,包含三个主要组成部分: lalserver:流媒体转发服务器。类似于nginx-rtmp-module等应用,但支持更多的协议,提供更丰富的功能。lalserver简介 demo:一些小应用,比如推、拉流客户端,压测工具,流分析工具,调度示例程序等

yoko 1.8k Jan 1, 2023
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

浩麟 8.6k Jan 4, 2023
live 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

BigSillyBear 27 Nov 10, 2022