Skip to content

Commit

Permalink
go modules added, fixed mediafile and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xfrr committed Apr 2, 2020
1 parent 4a0d2c8 commit b06797a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 114 deletions.
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=
23 changes: 17 additions & 6 deletions models/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"fmt"
"io"
"os/exec"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -48,6 +49,7 @@ type Mediafile struct {
inputPipeReader *io.PipeReader
inputPipeWriter *io.PipeWriter
outputPipe bool
inputPipeCommand *exec.Cmd
outputPipeReader *io.PipeReader
outputPipeWriter *io.PipeWriter
movFlags string
Expand Down Expand Up @@ -237,6 +239,10 @@ func (m *Mediafile) SetInputPipe(val bool) {
m.inputPipe = val
}

func (m *Mediafile) SetInputPipeCommand(command *exec.Cmd) {
m.inputPipeCommand = command
}

func (m *Mediafile) SetInputPipeReader(r *io.PipeReader) {
m.inputPipeReader = r
}
Expand Down Expand Up @@ -512,6 +518,10 @@ func (m *Mediafile) InputPipe() bool {
return m.inputPipe
}

func (m *Mediafile) InputPipeCommand() *exec.Cmd {
return m.inputPipeCommand
}

func (m *Mediafile) InputPipeReader() *io.PipeReader {
return m.inputPipeReader
}
Expand Down Expand Up @@ -642,6 +652,7 @@ func (m *Mediafile) ToStrCommand() []string {
"HardwareAcceleration",
"InputPath",
"InputPipe",
"InputPipeCommand",
"HideBanner",
"Aspect",
"Resolution",
Expand Down Expand Up @@ -755,7 +766,7 @@ func (m *Mediafile) ObtainInputPath() []string {
return nil
}

func (m *Mediafile) ObtainInputPipe() []string {
func (m *Mediafile) ObtainInputPipeCommand() []string {
if m.inputPipe {
return []string{"-i", "pipe:0"}
}
Expand Down Expand Up @@ -1133,10 +1144,10 @@ func (m *Mediafile) ObtainCompressionLevel() []string {
func (m *Mediafile) ObtainMapMetadata() []string {
if m.mapMetadata != "" {
return []string{"-map_metadata", m.mapMetadata}
}
return nil
}
return nil
}

func (m *Mediafile) ObtainEncryptionKey() []string {
return []string{"-hls_key_info_file", m.encryptionKey}
}
Expand All @@ -1155,6 +1166,6 @@ func (m *Mediafile) ObtainTags() []string {
result = append(result, []string{"-metadata", fmt.Sprintf("%s=%s", key, val)}...)
}
return result
}
return nil
}
return nil
}
154 changes: 46 additions & 108 deletions tests/transcoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,231 +13,169 @@ import (

func TestInputNotFound(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 {
return
}
assert.Nil(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)

Expand All @@ -262,7 +200,7 @@ func TestTranscodingProgress(t *testing.T) {
}

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

0 comments on commit b06797a

Please sign in to comment.