Go Media Framework

Related tags


Go FFmpeg Bindings



Current master branch supports all major Go versions, starting from 1.6.

Build/install FFmpeg

build lastest version of ffmpeg, obtained from https://github.com/FFmpeg/FFmpeg
There is one required option, which is disabled by default, you should turn on: --enable-shared


./configure --prefix=/usr/local/ffmpeg --enable-shared
make install

Add pkgconfig path:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/ffmpeg/lib/pkgconfig/

Ensure, that PKG_CONFIG_PATH contains path to ffmpeg's pkgconfig folder.

# check it by running
pkg-config --libs libavformat

It should print valid path to the avformat library.

Now, just run

go get github.com/3d0c/gmf
Other methods

This package uses pkg-config way to obtain flags, includes and libraries path, so if you have ffmpeg installed, just ensure, that your installation has them (pkgconfig/ folder with proper pc files).

Docker containers

Thanks to @ergoz you can try a docker container riftbit/ffalpine

Thanks to @denismakogon there is one more project, worth to mention https://github.com/denismakogon/ffmpeg-debian


Please see examples.

Support and Contribution

If something doesn't work, just fix it. Do not hesitate to pull request.


I borrowed the name from project, abandoned on code.google.com/p/gmf. Original code is available here in intitial commit from 03 Apr 2013.

  • mp4s-to-flv.go produce wrong video length

    mp4s-to-flv.go produce wrong video length

    i tried runing mp4s-to-flv.go from examples, with bbb.mp4 file from same folder , unexpectedly , it produces a longer video than the original one , 01:00 -> 01:45 . also the produced audio and video seems out of sync .

    opened by c1ngular 15
  • Go - Cross Compilation for ARM

    Go - Cross Compilation for ARM

    Everything working fine with amd64 but when we are compiling it for arm, after setting GOARCH=arm, it is giving it below error, please advise how to solve it

    src/Manager/MediaManager.go:28: undefined: FmtCtx src/MediaManager.go:28: undefined: Stream src/Manager/MediaManager.go:29: undefined: CodecCtx src/Manager/MediaManager.go:30: undefined: Stream src/Manager/MediaManager.go:32: undefined: FindEncoder src/Manager/MediaManager.go:32: undefined: Codec src/Manager/MediaManager.go:40: undefined: NewCodecCtx src/Manager/MediaManager.go:46: undefined: CODEC_FLAG_GLOBAL_HEADER src/Manager/MediaManager.go:50: undefined: FF_COMPLIANCE_EXPERIMENTAL src/Manager/MediaManager.go:53: undefined: AVMEDIA_TYPE_AUDIO


    opened by minhajakhterkhan199 12
  • C.av_codec_iterate


    Hi, I am trying to install Live Stream Analyzer on my Raspberry Pi 3B+ (Raspbian Kernel 4.14.98-v7+) for which gmf is a prerequisite. I installed ffmpeg Version 3.2.12-1 via apt-get including all development packages (libavutil-dev, libavcodec-dev, etc.)

    libavutil 55. 34.101 / 55. 34.101 libavcodec 57. 64.101 / 57. 64.101 libavformat 57. 56.101 / 57. 56.101 libavdevice 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100

    Unfortunately "go get" installation of gmf exit with the following error message:

    #github.com/3d0c/gmf could not determine kind of name for C.av_codec_iterate

    Thankful for any hints to solve this issue.

    Cheers Jens

    opened by jens-bongartz 11
  • [video-to-jpeg-avio] Broken example app

    [video-to-jpeg-avio] Broken example app

    Wrong path reference fix: ./tmp-img/ ----> tmp-img/ Current path reference ended up no such file

    opened by denismakogon 6
  • Looks like frame doesn't provide access to Audio data buffers

    Looks like frame doesn't provide access to Audio data buffers

    Would you be amenable to this. I'd like to be able to pull Audio with this.

    opened by gaffo 6
  • Possibility to return the data after ImgAlloc()

    Possibility to return the data after ImgAlloc()

    Is there any possibility to get the data of the frame, after I call Frame.ImgAlloc()? Only errors will returned if there any or does I not see the right point?

    func (this *Frame) ImgAlloc() error {
        if ret := int(C.av_image_alloc(
            C.int(this.Width()), C.int(this.Height()), int32(this.Format()), 32)); ret < 0 {
            return errors.New(fmt.Sprintf("Unable to allocate raw image buffer: %v", AvError(ret)))
        return nil
    opened by 0x46616c6b 5
  • Demo/example Request

    Demo/example Request

    Can you add an example of creating video from array of images?

    opened by Albinzr 5
  • Bugfixes


    This pull resolves the following compile errors/warnings:

    packet.go:61:2: warning: 'av_free_packet' is deprecated [-Wdeprecated-declarations]
    /usr/local/ffmpeg/include/libavcodec/avcodec.h:4040:6: note: 'av_free_packet' has been explicitly marked deprecated here
    codecCtx.go:285: cannot use C.int(val) (type C.int) as type C.int64_t in assignment
    packet.go:193: cannot use C.int(duration) (type C.int) as type C.int64_t in assignment
    opened by jasonmoo 5
  • Cleanup & Fixes

    Cleanup & Fixes

    See individual commits.

    opened by brandonbloom 4
  • Added a method to get Frame.avFrame

    Added a method to get Frame.avFrame

    Hi @3d0c, I needed to work with raw AVFrame, so I added Frame.GetRawFrame() which returns *AVFrame, raw pointer to C struct.

    It might be useful to work with FFMpeg APIs outside of gmf.

    For example, I needed to flip frames vertically while encoding to show frames in OpenGL window. In OpenGL the origin is located on left-bottom corner so basically we have to invert images.

    We can achieve this with filters, but I wanted to do it using sws_scale for performance sake. If we can get raw *AVFrame it can be done like this:

    #include "libavutil/frame.h"
    // Modify frame->data and frame->linesize so that images will flip vertically on sws_scale
    // ref. http://www.ffmpeg-archive.org/Flip-in-sws-scale-td939665.html
    void flip_y(uint8_t** data, int* linesize, int width, int height) {
    	for (int i = 0; i < AV_NUM_DATA_POINTERS; i++) {
    		int h = (int)(height * ((float)linesize[i] / width));
    		data[i] += linesize[i] * (h - 1);
    		linesize[i] = -linesize[i];
    import "C"
    func main() {
    	// Get raw pointer to AVFrame
    	avFrame := (*C.struct_AVFrame)(unsafe.Pointer(frame.GetRawFrame()))
    	// Do the flip
    	// Call sws_scale as usual
    	v.swsCtx.Scale(frame, v.dstFrame)
    opened by fand 4
  • Go Image to mp4

    Go Image to mp4

    There is an example of mp4 to Go image, is there an example on how to do it the other way around (go image to video)? Thank you!

    opened by Nv7-GitHub 0
  • Invalid NAL unit size (556795136 > 367).

    Invalid NAL unit size (556795136 > 367).

    I am using the Video to Go Image example, but whenever I try it with my own videos I get the error:

    [h264 @ 0xb069400] Invalid NAL unit size (556795136 > 367).
    [h264 @ 0xb069400] Error splitting the input into NAL units.

    Any ideas on how to fix this?

    opened by Nv7-GitHub 0
  • use av_new_packet replase av_init_packet

    use av_new_packet replase av_init_packet

    now ffmpeg deprecated av_init_packet function

    opened by Turing-Chu 0
  • Windows10, Resource temporarily unavailable

    Windows10, Resource temporarily unavailable

    Hi, I tested the video-to-image.go example in Windows 10, https://github.com/flutter/plugins/blob/master/packages/video_player/video_player/example/assets/Butterfly-209.mp4

    this video will report Resource temporarily unavailable error. the tests-sample.mp4 will work ok.

    opened by Leadrive 4
  • How Can I move mp4 moov , ( fastStart )

    How Can I move mp4 moov , ( fastStart )

    How Can I move mp4 moov , ( fastStart ) . is there an example ?

    opened by Hpsyche 2
  • Removing location metadata

    Removing location metadata

    With ffmpeg I achieve this with: ffmpeg -i in.FORMAT -map_metadata -1 -c:v copy -c:a copy out.FORMAT It leaves width/height/bitrate etc and removes GPS location, which is what I want. Can I achieve the same using gmf?

    I tried remuxing with the example, replaced CloseInput()/CloseOutput() with CloseInputAndRelease/CloseOutputAndRelease https://github.com/3d0c/gmf/blob/master/examples/remuxing.go

    Which did the job of removing that metadata but created a file 2 mb smaller than original and seems to be corrupt, vlc can't play it properly, video is skippy and vlc shows errors: [h264 @ 0x7fe894004e80] get_buffer() failed [h264 @ 0x7fe894004e80] thread_get_buffer() failed [h264 @ 0x7fe894004e80] decode_slice_header error [h264 @ 0x7fe894004e80] no frame!

    I'm trying to figure it out myself but if anyone could point me in the right direction it would be very helpful.

    opened by SandroJijavadze 1
  • Is there a way to convert a mjpeg stream to h264 video?

    Is there a way to convert a mjpeg stream to h264 video?

    I saw C.avformat_open_input(&this.avCtx, cfilename, nil, &options); in the source code. Now I have a mjpeg stream, which doesn't have filename but just the content of the image, since I have no experience in cgo or anything related to ffmpeg, so I have no idea how to use this repo to satisfy my need, how do I convert such a stream to video? Any suggestion is appreciated.

    opened by SolskGaer 0
  • Getting

    Getting "CloseInputAndRelease undefined, packet.Frames undefined" error when trying to run Transcode example


    I'm trying to run transcode.go example by following the installation guide. But I'm getting this error:

    # audio-extract-resample
    ./main.go:95:16: inputCtx.CloseInputAndRelease undefined (type *gmf.FmtCtx has no field or method CloseInputAndRelease)
    ./main.go:98:17: outputCtx.CloseOutputAndRelease undefined (type *gmf.FmtCtx has no field or method CloseOutputAndRelease)
    ./main.go:131:23: packet.Frames undefined (type *gmf.Packet has no field or method Frames)
    ./main.go:137:15: cannot use packet (type *gmf.Packet) as type gmf.CgoMemoryManager in argument to gmf.Release:
    	*gmf.Packet does not implement gmf.CgoMemoryManager (missing Release method)
    opened by cyantarek 3
  • how to set FmtCtx.OpenInput timeout?

    how to set FmtCtx.OpenInput timeout?

    How to set FmtCtx.OpenInput timeout when open rtsp stream?

    opened by ccsnake 0
Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. :cinema:

M3U8 This is the most complete opensource library for parsing and generating of M3U8 playlists used in HTTP Live Streaming (Apple HLS) for internet vi

Alexander I.Grafov 841 Jul 17, 2021
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
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
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
🔥 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 598 Jul 19, 2021
LiveKit - Open source, distributed video/audio rooms over WebRTC

LiveKit is an open source project that provides scalable, multi-user conferencing over WebRTC. It's designed to give you everything you need to build real time video/audio capabilities in your applications.

LiveKit 1.5k Jul 27, 2021