diff --git a/ffmpeg/audio_filter.go b/ffmpeg/audio_filter.go index 2693f63..9ca510e 100644 --- a/ffmpeg/audio_filter.go +++ b/ffmpeg/audio_filter.go @@ -5,7 +5,7 @@ import ( "github.com/Paxx-RnD/go-ffmpeg/arguments" ) -func (f *Ffmpeg) Flanger(delay float64) *Ffmpeg { +func (f *Ffmpeg) Flanger(delay float64) IFfmpeg { if delay < 0 { delay = 0 } else if delay > 30 { diff --git a/ffmpeg/bitrate.go b/ffmpeg/bitrate.go index e13d908..7f9dbe5 100644 --- a/ffmpeg/bitrate.go +++ b/ffmpeg/bitrate.go @@ -4,12 +4,12 @@ import ( "fmt" ) -func (f *Ffmpeg) BitrateVideo(bitrate int) *Ffmpeg { +func (f *Ffmpeg) BitrateVideo(bitrate int) IFfmpeg { f.arguments.Options.Append("-b:v", fmt.Sprintf("%d", bitrate)) return f } -func (f *Ffmpeg) BitrateAudio(bitrate int) *Ffmpeg { +func (f *Ffmpeg) BitrateAudio(bitrate int) IFfmpeg { f.arguments.Options.Append("-b:a", fmt.Sprintf("%d", bitrate)) return f } diff --git a/ffmpeg/builder.go b/ffmpeg/builder.go index 42fbbf2..1f8585d 100644 --- a/ffmpeg/builder.go +++ b/ffmpeg/builder.go @@ -7,9 +7,13 @@ import ( "strings" ) +type IBuilder interface { + Build() []string +} + type Builder Ffmpeg -func (f *Ffmpeg) Output(path string) *Builder { +func (f *Ffmpeg) Output(path string) IBuilder { f.arguments.Output.Append(path) return (*Builder)(f) } diff --git a/ffmpeg/chain.go b/ffmpeg/chain.go index 1cfce0b..5a5c9c6 100644 --- a/ffmpeg/chain.go +++ b/ffmpeg/chain.go @@ -6,51 +6,70 @@ import ( "github.com/Paxx-RnD/go-helper/helpers/boolean_helper" ) +type IChain interface { + Format(input string, format pixel_formats.PixelFormat, output string) IChain + Pad(input string, width int, height int, x int, y int, output string) IChain + Volume(input string, volume float64, output string) IChain + Fps(input string, fps float64, output string) IChain + Scale(input string, width float64, height float64, output string) IChain + Reverse(input string, output string) IChain + Trim(input string, start float64, end float64, output string) IChain + Split(input string, outputs ...string) IChain + ATrim(input string, start float64, end float64, output string) IChain + AlphaExtract(input string, output string) IChain + AlphaMerge(input string, mask string, shortest bool, output string) IChain + Concat(inputs []string, videoEnable bool, audioEnable bool, output string) IChain + Overlay(under string, over string, shortest bool, output string) IChain + ACrossFade(input1 string, input2 string, duration float64, output string) IChain + ADelay(input string, delay float64, output string) IChain + Map(output string) IMap +} + type Chain Ffmpeg -func (fg *Chain) Format(input string, format pixel_formats.PixelFormat, output string) *Chain { +func (fg *Chain) Format(input string, format pixel_formats.PixelFormat, output string) IChain { chain := fmt.Sprintf("[%s]format=%s[%s]", input, format, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Pad(input string, width int, height int, x int, y int, output string) *Chain { +func (fg *Chain) Pad(input string, width int, height int, x int, y int, output string) IChain { chain := fmt.Sprintf("[%s]pad=width=%d:height=%d:x=%d:y=%d[%s]", input, width, height, x, y, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Volume(input string, volume float64, output string) *Chain { +func (fg *Chain) Volume(input string, volume float64, output string) IChain { chain := fmt.Sprintf("[%s]volume=volume=%f[%s]", input, volume, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Fps(input string, fps float64, output string) *Chain { +func (fg *Chain) Fps(input string, fps float64, output string) IChain { chain := fmt.Sprintf("[%s]fps=fps=%f[%s]", input, fps, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Scale(input string, width float64, height float64, output string) *Chain { +func (fg *Chain) Scale(input string, width float64, height float64, output string) IChain { chain := fmt.Sprintf("[%s]scale=width=%f:height=%f[%s]", input, width, height, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Reverse(input string, output string) *Chain { +func (fg *Chain) Reverse(input string, output string) IChain { chain := fmt.Sprintf("[%s]reverse[%s]", input, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Trim(input string, start float64, end float64, output string) *Chain { +func (fg *Chain) Trim(input string, start float64, end float64, output string) IChain { chain := fmt.Sprintf("[%s]trim=start=%f:end=%f,setpts=PTS-STARTPTS[%s]", input, start, end, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Split(input string, outputs ...string) *Chain { +func (fg *Chain) Split(input string, outputs ...string) IChain { chain := fmt.Sprintf("[%s]split=n=%d", input, len(outputs)) for _, output := range outputs { chain += fmt.Sprintf("[%s]", output) @@ -59,26 +78,26 @@ func (fg *Chain) Split(input string, outputs ...string) *Chain { return fg } -func (fg *Chain) ATrim(input string, start float64, end float64, output string) *Chain { +func (fg *Chain) ATrim(input string, start float64, end float64, output string) IChain { chain := fmt.Sprintf("[%s]atrim=start=%f:end=%f,asetpts=PTS-STARTPTS[%s]", input, start, end, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) AlphaExtract(input string, output string) *Chain { +func (fg *Chain) AlphaExtract(input string, output string) IChain { chain := fmt.Sprintf("[%s]alphaextract[%s]", input, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) AlphaMerge(input string, mask string, shortest bool, output string) *Chain { +func (fg *Chain) AlphaMerge(input string, mask string, shortest bool, output string) IChain { short := boolean_helper.ToInt(shortest) chain := fmt.Sprintf("[%s][%s]alphamerge=shortest=%d[%s]", input, mask, short, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) Concat(inputs []string, videoEnable bool, audioEnable bool, output string) *Chain { +func (fg *Chain) Concat(inputs []string, videoEnable bool, audioEnable bool, output string) IChain { toConcat := make([]string, len(inputs)) for i, input := range inputs { toConcat[i] = fmt.Sprintf("[%s]", input) @@ -92,20 +111,20 @@ func (fg *Chain) Concat(inputs []string, videoEnable bool, audioEnable bool, out return fg } -func (fg *Chain) Overlay(under string, over string, shortest bool, output string) *Chain { +func (fg *Chain) Overlay(under string, over string, shortest bool, output string) IChain { short := boolean_helper.ToInt(shortest) chain := fmt.Sprintf("[%s][%s]overlay=shortest=%d[%s]", under, over, short, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) ACrossFade(input1 string, input2 string, duration float64, output string) *Chain { +func (fg *Chain) ACrossFade(input1 string, input2 string, duration float64, output string) IChain { chain := fmt.Sprintf("[%s][%s]acrossfade=d=%f[%s]", input1, input2, duration, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg } -func (fg *Chain) ADelay(input string, delay float64, output string) *Chain { +func (fg *Chain) ADelay(input string, delay float64, output string) IChain { chain := fmt.Sprintf("[%s]adelay=%f[%s]", input, delay, output) fg.arguments.FilterGraph.FilterChain = append(fg.arguments.FilterGraph.FilterChain, chain) return fg diff --git a/ffmpeg/codec.go b/ffmpeg/codec.go index fe04261..f74a91e 100644 --- a/ffmpeg/codec.go +++ b/ffmpeg/codec.go @@ -5,12 +5,12 @@ import ( "github.com/Paxx-RnD/go-ffmpeg/constants/codec_video" ) -func (f *Ffmpeg) CodecVideo(codec codec_video.CodecVideo) *Ffmpeg { +func (f *Ffmpeg) CodecVideo(codec codec_video.CodecVideo) IFfmpeg { f.arguments.Options.Append("-c:v", string(codec)) return f } -func (f *Ffmpeg) CodecAudio(codec codec_audio.CodecAudio) *Ffmpeg { +func (f *Ffmpeg) CodecAudio(codec codec_audio.CodecAudio) IFfmpeg { f.arguments.Options.Append("-c:a", string(codec)) return f } diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index a85e926..745a4a6 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -3,8 +3,25 @@ package ffmpeg import ( "github.com/Paxx-RnD/go-ffmpeg/arguments" "github.com/Paxx-RnD/go-ffmpeg/configuration" + "github.com/Paxx-RnD/go-ffmpeg/constants/codec_audio" + "github.com/Paxx-RnD/go-ffmpeg/constants/codec_video" ) +type IFfmpeg interface { + BitrateVideo(bitrate int) IFfmpeg + BitrateAudio(bitrate int) IFfmpeg + Flanger(delay float64) IFfmpeg + CodecVideo(codec codec_video.CodecVideo) IFfmpeg + CodecAudio(codec codec_audio.CodecAudio) IFfmpeg + Scale(width int, height int) IFfmpeg + Fps(fps float64) IFfmpeg + FilterGraph() IChain + Input(path string) IFfmpeg + Inputs(paths ...string) IFfmpeg + Output(path string) IBuilder + Run(args []string) error +} + type Ffmpeg struct { arguments Arguments Configuration *configuration.Configuration @@ -20,12 +37,12 @@ type Arguments struct { Options arguments.Options } -func (f *Ffmpeg) Input(path string) *Ffmpeg { +func (f *Ffmpeg) Input(path string) IFfmpeg { f.arguments.Inputs.Append(path) return f } -func (f *Ffmpeg) Inputs(paths ...string) *Ffmpeg { +func (f *Ffmpeg) Inputs(paths ...string) IFfmpeg { for _, p := range paths { f.arguments.Inputs.Append(p) } diff --git a/ffmpeg/filtergraph.go b/ffmpeg/filtergraph.go index 37e120c..fd844e4 100644 --- a/ffmpeg/filtergraph.go +++ b/ffmpeg/filtergraph.go @@ -7,7 +7,7 @@ type FilterGraph struct { MapChain []string } -func (f *Ffmpeg) FilterGraph() *Chain { +func (f *Ffmpeg) FilterGraph() IChain { return &Chain{ arguments: f.arguments, Configuration: f.Configuration, diff --git a/ffmpeg/map.go b/ffmpeg/map.go index cda05f0..cfb9195 100644 --- a/ffmpeg/map.go +++ b/ffmpeg/map.go @@ -2,9 +2,14 @@ package ffmpeg import "github.com/Paxx-RnD/go-ffmpeg/arguments" +type IMap interface { + Map(output string) IMap + Output(output string) IBuilder +} + type Map Ffmpeg -func (fg *Chain) Map(output string) *Map { +func (fg *Chain) Map(output string) IMap { m := Map{ arguments: fg.arguments, Configuration: fg.Configuration, @@ -14,12 +19,12 @@ func (fg *Chain) Map(output string) *Map { return &m } -func (m *Map) Map(output string) *Map { +func (m *Map) Map(output string) IMap { m.arguments.FilterGraph.MapChain = append(m.arguments.FilterGraph.MapChain, output) return m } -func (m *Map) Output(output string) *Builder { +func (m *Map) Output(output string) IBuilder { builder := Builder{ arguments: m.arguments, Configuration: m.Configuration, diff --git a/ffmpeg/video_filter.go b/ffmpeg/video_filter.go index 79eb6a5..489ac36 100644 --- a/ffmpeg/video_filter.go +++ b/ffmpeg/video_filter.go @@ -5,7 +5,7 @@ import ( "github.com/Paxx-RnD/go-ffmpeg/arguments" ) -func (f *Ffmpeg) Scale(width int, height int) *Ffmpeg { +func (f *Ffmpeg) Scale(width int, height int) IFfmpeg { filter := arguments.Filter{ Name: "scale", Args: []arguments.FilterArgs{ @@ -23,7 +23,7 @@ func (f *Ffmpeg) Scale(width int, height int) *Ffmpeg { return f } -func (f *Ffmpeg) Fps(fps float64) *Ffmpeg { +func (f *Ffmpeg) Fps(fps float64) IFfmpeg { filter := arguments.Filter{ Name: "fps", Args: []arguments.FilterArgs{ diff --git a/test/a_main_test.go b/test/a_main_test.go index 7db4f6a..ab0713c 100644 --- a/test/a_main_test.go +++ b/test/a_main_test.go @@ -26,7 +26,7 @@ func TestMain(m *testing.M) { m.Run() } -func GetFfmpeg() *ffmpeg.Ffmpeg { +func GetFfmpeg() ffmpeg.IFfmpeg { f := ffmpeg.Ffmpeg{ Configuration: configuration.GetConfiguration(), Headers: []string{