diff --git a/README.md b/README.md index f7b11da..9487461 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,15 @@ FFMPEG wrapper written in GO which allows to obtain the progress. # Getting started How to transcode a media file +```shell +go get github.com/xfrr/goffmpeg +``` + ```go package main import ( - "goffmpeg/transcoder" + "github.com/xfrr/goffmpeg/transcoder" ) var inputPath = "/data/testmov" @@ -27,14 +31,14 @@ 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 done, err := trans.Run() - + // This channel is used to wait for the process to end <-done @@ -47,14 +51,14 @@ 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 done, err := trans.Run() - + // Returns a channel to get the transcoding progress progress, err := trans.Output() @@ -62,7 +66,7 @@ func main() { for msg := range progress { fmt.Println(msg) } - + // This channel is used to wait for the transcoding process to end <-done @@ -98,8 +102,14 @@ SetBufferSize SetThreads SetPreset SetDuration +SetDurationInput SetSeekTime +SetSeekTimeInput +SetSeekUsingTsInput SetQuality +SetCopyTs +SetInputPath +SetOutputPath ``` Example ```golang @@ -107,11 +117,11 @@ 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 @@ -119,7 +129,7 @@ func main() { // Start transcoder process done, err := trans.Run() - + // Returns a channel to get the transcoding progress progress, err := trans.Output() @@ -127,7 +137,7 @@ func main() { for msg := range progress { fmt.Println(msg) } - + // This channel is used to wait for the transcoding process to end <-done diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index a625e2f..3460bbb 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -4,7 +4,7 @@ import ( "os/exec" "bytes" "strings" - "goffmpeg/utils" + "github.com/xfrr/goffmpeg/utils" ) type Configuration struct { diff --git a/models/media.go b/models/media.go index 452623c..6aa48c7 100644 --- a/models/media.go +++ b/models/media.go @@ -35,6 +35,7 @@ type Mediafile struct { seekUsingTsInput bool seekTimeInput string inputPath string + outputPath string copyTs bool } @@ -140,6 +141,10 @@ func (m *Mediafile) SetInputPath(val string) { m.inputPath = val } +func (m *Mediafile) SetOutputPath(val string) { + m.outputPath = val +} + func (m *Mediafile) SetMetadata(v Metadata) { m.metadata = v } @@ -250,6 +255,10 @@ func (m Mediafile) InputPath() string { return m.inputPath } +func (m *Mediafile) OutputPath() string { + return m.outputPath +} + func (m Mediafile) Metadata() Metadata { return m.metadata } @@ -258,7 +267,7 @@ func (m Mediafile) Metadata() Metadata { func (m Mediafile) ToStrCommand() string { var strCommand string - opts := []string{"SeekTimeInput", "DurationInput", "SeekUsingTsInput", "InputPath", "Aspect", "VideoCodec", "FrameRate", "Resolution", "VideoBitRate", "VideoBitRateTolerance", "AudioCodec", "AudioBitRate", "AudioChannels", "VideoMaxBitRate", "VideoMinBitRate", "BufferSize", "Threads", "Preset", "Target", "Duration", "KeyframeInterval", "SeekTime", "Quality", "MuxDelay", "CopyTs"} + opts := []string{"SeekTimeInput", "DurationInput", "SeekUsingTsInput", "InputPath", "Aspect", "VideoCodec", "FrameRate", "Resolution", "VideoBitRate", "VideoBitRateTolerance", "AudioCodec", "AudioBitRate", "AudioChannels", "VideoMaxBitRate", "VideoMinBitRate", "BufferSize", "Threads", "Preset", "Target", "Duration", "KeyframeInterval", "SeekTime", "Quality", "MuxDelay", "CopyTs", "OutputPath"} for _, name := range opts { opt := reflect.ValueOf(&m).MethodByName(fmt.Sprintf("Obtain%s", name)) if (opt != reflect.Value{}) { @@ -298,12 +307,17 @@ func (m *Mediafile) ObtainInputPath() string { return fmt.Sprintf("-i \"%s\"", m.inputPath) } +func (m *Mediafile) ObtainOutputPath() string { + return fmt.Sprintf("\"%s\"", m.outputPath) +} + func (m *Mediafile) ObtainVideoCodec() string { if m.videoCodec != "" { return fmt.Sprintf("-vcodec %s", m.videoCodec) } return "" } + func (m *Mediafile) ObtainFrameRate() string { if m.frameRate != 0 { return fmt.Sprintf("-r %d", m.frameRate) diff --git a/transcoder/transcoder.go b/transcoder/transcoder.go index 0bb9360..10520f6 100644 --- a/transcoder/transcoder.go +++ b/transcoder/transcoder.go @@ -3,11 +3,11 @@ package transcoder import ( "errors" "os" - "goffmpeg/models" + "github.com/xfrr/goffmpeg/models" "os/exec" "fmt" - "goffmpeg/ffmpeg" - "goffmpeg/utils" + "github.com/xfrr/goffmpeg/ffmpeg" + "github.com/xfrr/goffmpeg/utils" "bytes" "encoding/json" "bufio" @@ -18,7 +18,6 @@ import ( type Transcoder struct { process *exec.Cmd - outputPath string mediafile *models.Mediafile configuration ffmpeg.Configuration } @@ -27,10 +26,6 @@ func (t *Transcoder) SetProccess(v *exec.Cmd) { t.process = v } -func (t *Transcoder) SetOutputPath(v string) { - t.outputPath = v -} - func (t *Transcoder) SetMediaFile(v *models.Mediafile) { t.mediafile = v } @@ -45,10 +40,6 @@ func (t Transcoder) Process() *exec.Cmd { return t.process } -func (t Transcoder) OutputPath() string { - return t.outputPath -} - func (t Transcoder) MediaFile() *models.Mediafile { return t.mediafile } @@ -70,8 +61,6 @@ func (t Transcoder) GetCommand() string { rcommand += media.ToStrCommand() - rcommand += " \"" + t.outputPath + "\"" - return rcommand } @@ -126,9 +115,9 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string) (error) { MediaFile := new(models.Mediafile) MediaFile.SetMetadata(Metadata) MediaFile.SetInputPath(inputPath) + MediaFile.SetOutputPath(outputPath) // Set transcoder configuration - t.SetOutputPath(outputPath) t.SetMediaFile(MediaFile) t.SetConfiguration(configuration) diff --git a/utils/utils.go b/utils/utils.go index e79660a..b12ff2c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -3,7 +3,7 @@ package utils import ( "strings" "strconv" - "goffmpeg/models" + "github.com/xfrr/goffmpeg/models" "runtime" )