Need help with goffmpeg?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

xfrr
474 Stars 98 Forks MIT License 164 Commits 0 Opened issues

Description

FFMPEG wrapper written in GO

Services available

!
?

Need anything else?

Contributors list

# 262,997
golang
Go
ffmpeg
20 commits
# 245,795
golang
Go
ffmpeg
19 commits
# 140,489
Shell
mse
HTML
drm
18 commits
# 132,080
terrafo...
Terrafo...
HTML
golang
7 commits
# 247,935
Go
datadog
golang
amazon-...
4 commits
# 175,313
golang
Go
ffmpeg
redis-s...
4 commits
# 417,107
golang
ffmpeg
auth
C
3 commits
# 333,510
ffmpeg
Shell
tcl
pentest
3 commits
# 131,770
Ruby
Shell
HTML
React
2 commits
# 113,203
Go
sanitiz...
validat...
ffmpeg
2 commits
# 534,451
golang
Go
ffmpeg
1 commit
# 57,663
React
webrtc
golang
Flutter
1 commit
# 524,745
golang
ffmpeg
Shell
C++
1 commit
# 23,926
golang
ffmpeg
Vue.js
Electro...
1 commit
# 541,069
golang
Go
ffmpeg
1 commit
# 190,361
golang
ffmpeg
PHP
jquery-...
1 commit

Goffmpeg

Codacy Badge

FFMPEG wrapper written in GO which allows to obtain the progress.

V2

New implementation with an easy-to-use API and interfaces to extend the transcoding capabilities.

https://github.com/floostack/transcoder

Dependencies

Supported platforms

  • Linux
  • OS X
  • Windows

Getting started

How to transcode a media file

go get github.com/xfrr/goffmpeg
package main

import ( "github.com/xfrr/goffmpeg/transcoder" )

var inputPath = "/data/testmov" var outputPath = "/data/testmp4.mp4"

func main() {

// Create new instance of transcoder
trans := new(transcoder.Transcoder)

// Initialize transcoder passing the input file path and output file path
err := trans.Initialize( inputPath, outputPath )
// Handle error...

// Start transcoder process without checking progress
done := trans.Run(false)

// This channel is used to wait for the process to end
err = 

How to get the transcoding progress

...
func main() {

// Create new instance of transcoder
trans := new(transcoder.Transcoder)

// Initialize transcoder passing the input file path and output file path
err := trans.Initialize( inputPath, outputPath )
// Handle error...

// Start transcoder process with progress checking
done := trans.Run(true)

// Returns a channel to get the transcoding progress
progress := trans.Output()

// Example of printing transcoding progress
for msg := range progress {
    fmt.Println(msg)
}

// This channel is used to wait for the transcoding process to end
err = 

How to pipe in data using the pipe protocol

Creating an input pipe will return *io.PipeReader, and creating an output pipe will return *io.PipeWriter. An example is shown which uses

cat
to pipe in data, and ioutil.ReadAll to read data as bytes from the pipe. ```go func main() {
// Create new instance of transcoder
trans := new(transcoder.Transcoder)

// Initialize an empty transcoder err := trans.InitializeEmptyTranscoder() // Handle error...

// Create a command such that its output should be passed as stdin to ffmpeg cmd := exec.Command("cat", "/path/to/file")

// Create an input pipe to write to, which will return *io.PipeWriter w, err := trans.CreateInputPipe()

cmd.Stdout = w

// Create an output pipe to read from, which will return *io.PipeReader. // Must also specify the output container format r, err := trans.CreateOutputPipe("mp4")

wg := &sync.WaitGroup{} wg.Add(1) go func() { defer r.Close() defer wg.Done()

// Read data from output pipe
data, err := ioutil.ReadAll(r)
// Handle error and data...

}()

go func() { defer w.Close() err := cmd.Run() // Handle error... }()

// Start transcoder process without checking progress done := trans.Run(false)

// This channel is used to wait for the transcoding process to end err =

} ```

Progress properties

type Progress struct {
    FramesProcessed string
    CurrentTime     string
    CurrentBitrate  string
    Progress        float64
    Speed           string
}

Media setters

Those options can be set before starting the transcoding.

js
SetAspect
SetResolution
SetVideoBitRate
SetVideoBitRateTolerance
SetVideoMaxBitrate
SetVideoMinBitRate
SetVideoCodec
SetVframes
SetFrameRate
SetAudioRate
SetSkipAudio
SetSkipVideo
SetMaxKeyFrame
SetMinKeyFrame
SetKeyframeInterval
SetAudioCodec
SetAudioBitRate
SetAudioChannels
SetBufferSize
SetThreads
SetPreset
SetTune
SetAudioProfile
SetVideoProfile
SetDuration
SetDurationInput
SetSeekTime
SetSeekTimeInput
SetSeekUsingTsInput
SetQuality
SetStrict
SetCopyTs
SetMuxDelay
SetHideBanner
SetInputPath
SetNativeFramerateInput
SetRtmpLive
SetHlsListSize
SetHlsSegmentDuration
SetHlsPlaylistType
SetHlsMasterPlaylistName
SetHlsSegmentFilename
SetHttpMethod
SetHttpKeepAlive
SetOutputPath
SetOutputFormat
SetAudioFilter
SetAudioVariableBitrate
SetCompressionLevel
SetFilter
SetInputInitialOffset
SetInputPipeCommand
SetMapMetadata
SetMetadata
SetStreamIds
SetTags
SetVideoFilter
Example ```golang func main() {
// Create new instance of transcoder
trans := new(transcoder.Transcoder)

// Initialize transcoder passing the input file path and output file path err := trans.Initialize( inputPath, outputPath ) // Handle error...

// SET FRAME RATE TO MEDIAFILE trans.MediaFile().SetFrameRate(70) // SET ULTRAFAST PRESET TO MEDIAFILE trans.MediaFile().SetPreset("ultrafast")

// Start transcoder process to check progress done := trans.Run(true)

// Returns a channel to get the transcoding progress progress := trans.Output()

// Example of printing transcoding progress for msg := range progress { fmt.Println(msg) }

// This channel is used to wait for the transcoding process to end err =

} ```

Example with AES encryption :

More information about HLS encryption with FFMPEG

# Generate key
openssl rand 16 > enc.key

Create key file info :

Key URI
Path to key file
func main() {

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)

trans.MediaFile().SetVideoCodec("libx264")

trans.MediaFile().SetHlsSegmentDuration(4)

trans.MediaFile().SetEncryptionKey(keyinfoPath)

progress := trans.Output()

err = </pre></pre></pre></pre></pre>

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.