Skip to content

Commit

Permalink
added go modules, fixed mediafile and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xfrr committed Apr 3, 2020
1 parent eb404c9 commit 372fcc3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 134 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ var outputPath = "/data/testmp4.mp4"
func main() {

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

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

// Start transcoder process without checking progress
done := trans.Run(false)
Expand All @@ -53,11 +53,11 @@ func main() {
func main() {

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

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

// Start transcoder process with progress checking
done := trans.Run(true)
Expand All @@ -82,11 +82,11 @@ Creating an input pipe will return [\*io.PipeReader](https://golang.org/pkg/io/#
func main() {

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

// Initialize an empty transcoder
err := trans.InitializeEmptyTranscoder()
// Handle error...
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")
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/xfrr/goffmpeg

go 1.14

require github.com/stretchr/testify v1.5.1
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
164 changes: 48 additions & 116 deletions tests/transcoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,239 +13,174 @@ import (

func TestInputNotFound(t *testing.T) {

var inputPath = "/data/testmkv"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/nf"
var outputPath = "/tmp/ffmpeg/out/nf.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
return
}
assert.NotNil(t, err)
}

func TestTranscoding3GP(t *testing.T) {

var inputPath = "/data/test3gp"
var outputPath = "/data/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/3gp"
var outputPath = "/tmp/ffmpeg/out/3gp.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingAVI(t *testing.T) {

var inputPath = "/data/testavi"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/avi"
var outputPath = "/tmp/ffmpeg/out/avi.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingFLV(t *testing.T) {

var inputPath = "/data/testflv"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/flv"
var outputPath = "/tmp/ffmpeg/out/flv.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingMKV(t *testing.T) {

var inputPath = "/data/testmkv"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/mkv"
var outputPath = "/tmp/ffmpeg/out/mkv.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingMOV(t *testing.T) {

var inputPath = "/data/testmov"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/mov"
var outputPath = "/tmp/ffmpeg/out/mov.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingMPEG(t *testing.T) {

var inputPath = "/data/testmpeg"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/mpeg"
var outputPath = "/tmp/ffmpeg/out/mpeg.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingOGG(t *testing.T) {

var inputPath = "/data/testogg"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/ogg"
var outputPath = "/tmp/ffmpeg/out/ogg.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingWAV(t *testing.T) {

var inputPath = "/data/testwav"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/wav"
var outputPath = "/tmp/ffmpeg/out/wav.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingWEBM(t *testing.T) {

var inputPath = "/data/testwebm"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/webm"
var outputPath = "/tmp/ffmpeg/out/webm.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingWMV(t *testing.T) {

var inputPath = "/data/testwmv"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/wmv"
var outputPath = "/tmp/ffmpeg/out/wmv.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(false)
err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodingProgress(t *testing.T) {

var inputPath = "/data/testavi"
var outputPath = "/data/out/testmp4.mp4"
var inputPath = "/tmp/ffmpeg/avi"
var outputPath = "/tmp/ffmpeg/out/avi.mp4"

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)

done := trans.Run(true)
for val := range trans.Output() {
Expand All @@ -255,14 +190,11 @@ func TestTranscodingProgress(t *testing.T) {
}

err = <-done
if err != nil {
t.Error(err)
return
}
assert.Nil(t, err)
}

func TestTranscodePipes(t *testing.T) {
c1 := exec.Command("cat", "/tmp/data/testmkv")
c1 := exec.Command("cat", "/tmp/ffmpeg/mkv")

trans := new(transcoder.Transcoder)

Expand Down
12 changes: 3 additions & 9 deletions transcoder/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,18 @@ func (t *Transcoder) Run(progress bool) <-chan error {
err = proc.Start()

t.SetProcess(proc)

go func(err error) {
if err != nil {
done <- fmt.Errorf("Failed Start FFMPEG (%s) with %s, message %s %s", command, err, outb.String(), errb.String())
close(done)
return
}

// Run the pipe-in command if it has been set
if t.mediafile.InputPipeCommand() != nil {
if err := t.mediafile.InputPipeCommand().Run(); err != nil {
done <- fmt.Errorf("Failed execution of pipe-in command (%s) with %s", t.mediafile.InputPipeCommand().Args, err)
close(done)
return
}
}

err = proc.Wait()

go t.closePipes()

if err != nil {
err = fmt.Errorf("Failed Finish FFMPEG (%s) with %s message %s %s", command, err, outb.String(), errb.String())
}
Expand Down

0 comments on commit 372fcc3

Please sign in to comment.