-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: standardized transforms / complex filters * chore: remove memfs * feat: api improvements to filter graphs * chore: code cleanup and refactoring * chore: cleanup method names on Graph * chore: remove unnecessary extra files * chore: remove unnecessary extra files * chore: more cleanup and refactoring
- Loading branch information
1 parent
b053831
commit 78070e7
Showing
53 changed files
with
788 additions
and
4,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ package spireav | |
var ( | ||
FfmpegPath = "ffmpeg" | ||
FfprobePath = "ffprobe" | ||
Mxf2RawPath = "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package spireav | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type FfmpegError struct { | ||
ExitCode int | ||
Logs []string | ||
child error | ||
} | ||
|
||
func (e *FfmpegError) Error() string { | ||
if len(e.Logs) > 0 { | ||
return fmt.Sprintf("ffmpeg exit code %d: %s", e.ExitCode, strings.Join(e.Logs, "\n")) | ||
} else { | ||
return fmt.Sprintf("ffmpeg exit code %d", e.ExitCode) | ||
} | ||
} | ||
|
||
func (e *FfmpegError) Unwrap() error { | ||
return e.child | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package amerge | ||
|
||
import ( | ||
"github.com/spiretechnology/spireav/filter" | ||
"github.com/spiretechnology/spireav/filter/expr" | ||
) | ||
|
||
// https://ffmpeg.org/ffmpeg-filters.html#amerge | ||
|
||
func AudioMerge(opts ...filter.Option) filter.Filter { | ||
return filter.New("amerge", 1, opts...) | ||
} | ||
|
||
func WithInputs(inputs int) filter.Option { | ||
return filter.WithOption("inputs", expr.Int(inputs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package crop | ||
|
||
import ( | ||
"github.com/spiretechnology/spireav/filter" | ||
"github.com/spiretechnology/spireav/filter/expr" | ||
) | ||
|
||
// https://ffmpeg.org/ffmpeg-filters.html#toc-crop | ||
|
||
func Crop(opts ...filter.Option) filter.Filter { | ||
return filter.New("crop", 1, opts...) | ||
} | ||
|
||
func WithWidth(width expr.Expr) filter.Option { | ||
return filter.WithOption("w", width) | ||
} | ||
|
||
func WithHeight(height expr.Expr) filter.Option { | ||
return filter.WithOption("h", height) | ||
} | ||
|
||
func WithX(x expr.Expr) filter.Option { | ||
return filter.WithOption("x", x) | ||
} | ||
|
||
func WithY(y expr.Expr) filter.Option { | ||
return filter.WithOption("y", y) | ||
} | ||
|
||
func WithKeepAspect(keepAspect bool) filter.Option { | ||
return filter.WithOption("keep_aspect", expr.Bool(keepAspect)) | ||
} | ||
|
||
func WithExact(exact bool) filter.Option { | ||
return filter.WithOption("exact", expr.Bool(exact)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package drawtext | ||
|
||
import ( | ||
"github.com/spiretechnology/spireav/filter" | ||
"github.com/spiretechnology/spireav/filter/expr" | ||
) | ||
|
||
func DrawText(opts ...filter.Option) filter.Filter { | ||
return filter.New("drawtext", 1, opts...) | ||
} | ||
|
||
func WithText(text string) filter.Option { | ||
return filter.WithOption("text", expr.String(text)) | ||
} | ||
|
||
func WithX(x expr.Expr) filter.Option { | ||
return filter.WithOption("x", x) | ||
} | ||
|
||
func WithY(y expr.Expr) filter.Option { | ||
return filter.WithOption("y", y) | ||
} | ||
|
||
func WithFontColor(color string) filter.Option { | ||
return filter.WithOption("fontcolor", expr.String(color)) | ||
} | ||
|
||
func WithFontFile(file string) filter.Option { | ||
return filter.WithOption("fontfile", expr.String(file)) | ||
} | ||
|
||
func WithFontSize(size expr.Expr) filter.Option { | ||
return filter.WithOption("fontsize", size) | ||
} | ||
|
||
func WithTimecode(tc, framerate string) filter.Option { | ||
if len(framerate) == 0 { | ||
framerate = "23.976" | ||
} | ||
return filter.WithMulti( | ||
filter.WithOption("timecode", expr.String(tc)), | ||
filter.WithOption("r", expr.String(framerate)), | ||
) | ||
} | ||
|
||
func WithBox(color string) filter.Option { | ||
return filter.WithMulti( | ||
filter.WithOption("box", expr.String("1")), | ||
filter.WithOption("boxcolor", expr.String(color)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package filter | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spiretechnology/spireav/filter/expr" | ||
) | ||
|
||
// Filter is a node that applies a filter to its inputs, producing one or more outputs. | ||
type Filter interface { | ||
String() string | ||
Outputs() int | ||
} | ||
|
||
// Option defines an output option middleware that populates some option string | ||
// into the slice of options for the output. | ||
type Option func() []OptionValue | ||
|
||
// New creates a new transform with the given name and some options. | ||
func New(name string, outputs int, opts ...Option) Filter { | ||
return &filterWithOpts{ | ||
name: name, | ||
outputs: outputs, | ||
opts: WithMulti(opts...)(), | ||
} | ||
} | ||
|
||
// WithOption creates a new option middleware with a key and value. | ||
func WithOption(key string, value expr.Expr) Option { | ||
return func() []OptionValue { | ||
return []OptionValue{ | ||
{ | ||
Key: key, | ||
Val: value, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
// WithMulti creates a new option middleware with multiple options. | ||
func WithMulti(opts ...Option) Option { | ||
return func() []OptionValue { | ||
var options []OptionValue | ||
for _, opt := range opts { | ||
options = append(options, opt()...) | ||
} | ||
return options | ||
} | ||
} | ||
|
||
// OptionValue defines a single option for a transform node. This includes only a single | ||
// key-value pair. | ||
type OptionValue struct { | ||
Key string | ||
Val expr.Expr | ||
} | ||
|
||
type filterWithOpts struct { | ||
name string | ||
outputs int | ||
opts []OptionValue | ||
} | ||
|
||
func (t *filterWithOpts) String() string { | ||
opts := make(map[string]string) | ||
for _, optValue := range t.opts { | ||
opts[optValue.Key] = optValue.Val.String() | ||
} | ||
return formatTransform(t.name, opts) | ||
} | ||
|
||
func (t *filterWithOpts) Outputs() int { | ||
return t.outputs | ||
} | ||
|
||
// formatTransform formats a filter transform so that it conforms to the FFMpeg format | ||
func formatTransform(filterName string, opts map[string]string) string { | ||
optsStr := formatTransformOptions(opts) | ||
if len(optsStr) == 0 { | ||
return filterName | ||
} | ||
return fmt.Sprintf("%s=%s", filterName, optsStr) | ||
} | ||
|
||
// formatTransformOptions converts a map of keys and values into a string of options | ||
func formatTransformOptions(opts map[string]string) string { | ||
var keyvals []string | ||
for k, v := range opts { | ||
pair := fmt.Sprintf("%s=%s", k, formatTransformOptionValue(v)) | ||
keyvals = append(keyvals, pair) | ||
} | ||
return strings.Join(keyvals, ":") | ||
} | ||
|
||
// formatTransformOptionValue formats a single value to ensure it's properly escaped and quote-wrapped | ||
func formatTransformOptionValue(value string) string { | ||
if strings.Contains(value, ":") && !strings.HasPrefix(value, "'") { | ||
return fmt.Sprintf("'%s'", value) | ||
} | ||
return value | ||
} |
Oops, something went wrong.