A Go implementation of fluent-ffmpeg

Go Fluent FFmpeg GoDoc

A Go version of node-fluent-ffmpeg.

Installation

go get -u github.com/modfy/fluent-ffmpeg

Requirements

You will need FFmpeg installed on your machine, or you can specify a path to a binary:

// Provide an empty string to use default FFmpeg path
cmd := fluentffmpeg.NewCommand("")

// Specify a path
cmd = fluentffmpeg.NewCommand("/path/to/ffmpeg/binary")

Quick Start

Create and run commands using an API similar to node-fluent-ffmpeg:

err := fluentffmpeg.NewCommand(""). 
		InputPath("/path/to/video.avi").
		OutputFormat("mp4").
		OutputPath("/path/to/video.mp4").
		Run()

You could use context to set the timeout:

ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5)
defer cancel()
err := fluentffmpeg.NewCommand(""). 
		InputPath("/path/to/video.avi").
		OutputFormat("mp4").
		OutputPath("/path/to/video.mp4").
		RunWithContext(ctx)

If you want to view the errors/logs returned from FFmpeg, provide an io.Writer to receive the data.

buf := &bytes.Buffer{}
err := fluentffmpeg.NewCommand("").
		InputPath("./video.avi").
		OutputFormat("mp4").
		OutputPath("./video.mp4").
		Overwrite(true).
		OutputLogs(buf). // provide a io.Writer
		Run()

out, _ := ioutil.ReadAll(buf) // read logs
fmt.Println(string(out))

You can also get the command in the form of an exec.Cmd struct, with which you can have better control over the running process. For example, you can conditionally kill the FFmpeg command:

done := make(chan error, 1)
cmd := fluentffmpeg.NewCommand("").
		InputPath("./video.avi").
		OutputFormat("mp4").
		OutputPath("./video.mp4").
		Overwrite(true).
		Build()
cmd.Start()

go func() {
    done <- cmd.Wait()
}()

select {
case <-time.After(time.Second * 5):
    fmt.Println("Timed out")
    cmd.Process.Kill()
case <-done:
}

FFprobe is also available for use and returns a map[string]interface{} of JSON data:

data := fluentffmpeg.Probe("./video.avi")

Credits

This repo was inspired by node-fluent-ffmpeg and was built upon the work done by @bitcodr in the https://github.com/bitcodr/gompeg

Managed Version

You can deploy this codebase yourself or you an entirely managed api from the creators at https://api.modfy.video

Owner
Modfy
Organization responsible for building modfy.video
Modfy
Comments
  • Please add an example on how to join (append) multiple videos.

    Please add an example on how to join (append) multiple videos.

    Can someone please add a working example on appending multiple videos together.

    I can not see how to accomplish this from reading the API and it is different enough than the JavaScript fluent-ffmpeg API to not be any help.

    Is this even possible with this library binding?

  • InputOptions help

    InputOptions help

    Hi, I'm not sure whether this is not working or if I am doing it wrong. I want to pass in options so I can trim the video.

    Here is the code:

    	buf := &bytes.Buffer{}
    	err := fluentffmpeg.NewCommand("./ffmpeg-binaries/ffmpeg").
    		InputOptions("-ss 00:00:10").
    		InputPath("./video.mp4").
    		OutputFormat("mp4").
    		OutputPath("./trim.mp4").
    		Overwrite(true).
    		OutputLogs(buf).
    		Run()
    
    	if err != nil {
    		log.Fatal(err)
    	}
    

    This returns exit status 1.

    The above does not return an error if InputOptions is empty, but even InputOptions("") returns an error. Is this working as intended?

  • Support context for cancellation

    Support context for cancellation

    Although the user could use Build to get the underlying command, it still makes sense to support context by adding a RunWithContext() function. If you agree with this, I am willing to help with the PR. Thx

  • Need instructions to convert file in memory to file in memory

    Need instructions to convert file in memory to file in memory

    Given Go is used primarily in server environment where the file might come in request and one might want to use the file in memory without writing it to disk and the output can also be in memory file format. Can you provide instructions how one can do that using this module?

    https://github.com/kkroening/ffmpeg-python/issues/49#issuecomment-355677082

  • Resolution option doesn't work

    Resolution option doesn't work

    trying to use err := fluentffmpeg. NewCommand(""). InputPath("http://"). OutputOptions("-movflags", "isml+frag_keyframe+empty_moov"). OutputFormat("mp4"). VideoCodec("h264"). KeyframeInterval(52). Resolution("640x360"). PipeOutput(w). Run() all is ok besides the output resolution. It is always the same as the original (FullHD for example) and the Resolution option doesn't work. Any ideas on how to fix it?

  • Two Pass Encoding ?

    Two Pass Encoding ?

    Anyone have any examples of doing a two pass encode in this library? I'm looking to convert my NodeJS transcoder to this library, here's and example of a job, also when trying to use the output options and submit a single string such as c:v libvpx-vp9 -pass 1 -b:v 1400K -crf 23 i get an error, is there a delimiter we should be using ?

    `ffmpeg -i -c:v libvpx-vp9 -pass 1 -b:v 1400K -crf 23 -threads 8 -speed 4
    -tile-columns 6 -frame-parallel 1
    -an -f webm /dev/null

    ffmpeg -i -c:v libvpx-vp9 -pass 2 -b:v 1400K -crf 23 -threads 8 -speed 2
    -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25
    -c:a libopus -b:a 64k -f webm out.webm`

[WIP] a very simple, tiny and intuitive ffmpeg wrapper with a cli interface for inspecting & transforming media files supported by the original ffmpeg software

About a very simple, tiny and intuitive ffmpeg wrapper with a cli interface for inspecting & transforming media files supported by the original ffmpeg

Oct 21, 2022
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

Dec 27, 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

Dec 16, 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

Dec 18, 2022
Stream video from ffmpeg to webrtc

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

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

Nov 19, 2022
ffmpeg core for golang

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

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

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

Aug 12, 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

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

Dec 22, 2021
A Go implementation of fluent-ffmpeg

A Go implementation of fluent-ffmpeg

Dec 7, 2022
Fluent.go - A pure Go implementation of Project Fluent

fluent.go fluent.go is a pure Go implementation of Project Fluent Important noti

Oct 2, 2022
Go-video-preview-ffmpeg-wrapper - A simple helper wrapper to generate small webm video previews using ffmpeg, useful for web previews.

Go-video-preview-ffmpeg-wrapper A simple helper wrapper to generate small webm video previews using ffmpeg, useful for web previews. Getting Started u

Jan 5, 2022
[WIP] a very simple, tiny and intuitive ffmpeg wrapper with a cli interface for inspecting & transforming media files supported by the original ffmpeg software

About a very simple, tiny and intuitive ffmpeg wrapper with a cli interface for inspecting & transforming media files supported by the original ffmpeg

Oct 21, 2022
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

Dec 27, 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

Dec 16, 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

Dec 18, 2022
Stream video from ffmpeg to webrtc

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

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

Nov 19, 2022