A Go implementation of fluent-ffmpeg

Overview

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

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?

    opened by jarrodhroberson 4
  • 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?

    opened by BrennaEpp 1
  • 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

    opened by david7482 1
  • 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

    opened by debasish-mihup 0
  • 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?

    opened by ProvisionlabTeam 0
  • 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`

    opened by mynameisnyke 0
Releases(v0.0.1)
  • v0.0.1(Jan 30, 2021)

    Initial release of go-fluent-ffmpeg. Have a look at the docs and try out the module to get familiar with what's possible!

    Don't hesitate to open new issues or PRs!

    Source code(tar.gz)
    Source code(zip)
Owner
Modfy
Organization responsible for building modfy.video
Modfy
[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

Mohammed Al Ashaal 10 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

H. Giorgis 1.9k Nov 19, 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ý 108 Nov 20, 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 27 Nov 20, 2022
Stream video from ffmpeg to webrtc

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

Artur Shellunts 870 Nov 24, 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
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
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
A Go implementation of fluent-ffmpeg

A Go implementation of fluent-ffmpeg

Modfy 321 Nov 9, 2022
Fluent.go - A pure Go implementation of Project Fluent

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

lukas 11 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

Robert van Alphen 0 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

Mohammed Al Ashaal 10 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

H. Giorgis 1.9k Nov 19, 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ý 108 Nov 20, 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 27 Nov 20, 2022
Stream video from ffmpeg to webrtc

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

Artur Shellunts 870 Nov 24, 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