Example #1
0
File: ff_test.go Project: xdave/ff
func TestInput(t *testing.T) {
	filename := "test.mp4"
	param := ff.NewParam("foo", "bar")
	set := ff.NewParamSet(param)
	var input ff.File = ff.NewInput(filename, set)
	Convey("ff.NewInput(string, *ff.ParamSet)", t, func() {
		Convey("should not return nil", func() {
			So(input, ShouldNotBeNil)
		})
	})
	Convey("ff.File.Slice() should return paramters in correct order", t, func() {
		expected := []string{"-foo", "bar", "-i", filename}
		So(input.Slice(), ShouldResemble, expected)
	})
}
Example #2
0
File: main.go Project: xdave/ff
func main() {
	flag.Parse()

	if len(flag.Args()) == 0 {
		fmt.Println("Usage: example INFILE")
		return
	}

	filename := flag.Args()[0]

	input := ff.NewInput(
		filename,
		ff.NewParamSet(
			ff.NewParam("v", "quiet"),
			ff.NewParam("print_format", "json"),
			ff.NewParam("show_format", nil),
			ff.NewParam("show_streams", nil),
		),
	)

	cmdline, err := ff.NewCommand("ffprobe", input)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Calling", cmdline.Path, cmdline.Slice())

	out, err := exec.Command(cmdline.Path, cmdline.Slice()...).CombinedOutput()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(out))
}
Example #3
0
File: ff_test.go Project: xdave/ff
func TestCommand(t *testing.T) {
	filename := "test.mp4"
	param := ff.NewParam("foo", "bar")
	set := ff.NewParamSet(param)
	var input ff.File = ff.NewInput(filename, set)
	var output ff.File = ff.NewOutput(filename, set)
	path := "ffmpeg"

	Convey("ff.NewCommand()", t, func() {
		Convey("Cannot call with empty command (input only)", func() {
			cmd, err := ff.NewCommand("", input)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Cannot call with empty command (input+output)", func() {
			cmd, err := ff.NewCommand("", input, output)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Can call with only input", func() {
			cmd, err := ff.NewCommand(path, input)
			So(cmd, ShouldNotBeNil)
			So(err, ShouldBeNil)
		})
		Convey("Returns error with no input", func() {
			cmd, err := ff.NewCommand(path, nil, output)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
			cmd, err = ff.NewCommand(path, nil)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Returns error no input or output", func() {
			cmd, err := ff.NewCommand(path, nil)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
	})
	Convey("ff.Command.Slice() input+output", t, func() {
		cmd, _ := ff.NewCommand(path, input, output)
		slice := cmd.Slice()
		Convey("Should not return nil", func() {
			So(slice, ShouldNotBeNil)
		})
		Convey("Should return a []string slice", func() {
			So(slice, ShouldHaveSameTypeAs, []string{})
		})
		Convey("Should resemble expected value", func() {
			expected := []string{
				"-foo", "bar", "-i", filename,
				"-foo", "bar", filename, "-y",
			}
			So(slice, ShouldResemble, expected)
		})
	})
	Convey("ff.Command.Slice() input only", t, func() {
		cmd, _ := ff.NewCommand(path, input)
		slice := cmd.Slice()
		Convey("Should not return nil", func() {
			So(slice, ShouldNotBeNil)
		})
		Convey("Should return a []string slice", func() {
			So(slice, ShouldHaveSameTypeAs, []string{})
		})
		Convey("Should resemble expected value", func() {
			expected := []string{
				"-foo", "bar", "-i", filename,
			}
			So(slice, ShouldResemble, expected)
		})
	})
}