mirror of
https://github.com/xfrr/goffmpeg.git
synced 2025-10-18 05:50:44 +08:00
Go Gettable, Setting output path also from mediafile
This commit is contained in:
12
README.md
12
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"
|
||||
@@ -98,8 +102,14 @@ SetBufferSize
|
||||
SetThreads
|
||||
SetPreset
|
||||
SetDuration
|
||||
SetDurationInput
|
||||
SetSeekTime
|
||||
SetSeekTimeInput
|
||||
SetSeekUsingTsInput
|
||||
SetQuality
|
||||
SetCopyTs
|
||||
SetInputPath
|
||||
SetOutputPath
|
||||
```
|
||||
Example
|
||||
```golang
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"os/exec"
|
||||
"bytes"
|
||||
"strings"
|
||||
"goffmpeg/utils"
|
||||
"github.com/xfrr/goffmpeg/utils"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package utils
|
||||
import (
|
||||
"strings"
|
||||
"strconv"
|
||||
"goffmpeg/models"
|
||||
"github.com/xfrr/goffmpeg/models"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user