--no-video flag
This commit is contained in:
+30
-9
@@ -47,6 +47,7 @@ type appArgs struct {
|
||||
videoHeight uint
|
||||
videoFPS string
|
||||
videoUUID string
|
||||
noVideo bool
|
||||
|
||||
audioChannels uint8
|
||||
audioSamplingFreq string
|
||||
@@ -84,6 +85,7 @@ func printHelp(w io.Writer, fs *pflag.FlagSet) {
|
||||
fmt.Fprintln(w, "Usage: mxl-gen -d <domain> [-v <flowDef.json>] [-a <flowDef.json>] [options]")
|
||||
fmt.Fprintln(w, " or: mxl-gen -d <domain> [--width <width px>] [--height <height px>] [--fps <framerate>] \\")
|
||||
fmt.Fprintln(w, " [-c <channels amount>] [-f <sample rate>]")
|
||||
fmt.Fprintln(w, " or: mxl-gen -d <domain> --no-video (-c <channels amount> | -a <flowDef.json>)")
|
||||
fmt.Fprintln(w, " or: mxl-gen -d <domain> with default params")
|
||||
fmt.Fprintln(w, "Video and audio feed parameters are ignored when a flow definition file is provided.")
|
||||
fmt.Fprintln(w)
|
||||
@@ -92,7 +94,7 @@ func printHelp(w io.Writer, fs *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func printUsage(w io.Writer) {
|
||||
fmt.Fprintln(w, "Usage: mxl-gen -d <domain> [-v <flowDef.json>] [-a <flowDef.json>] [options]")
|
||||
fmt.Fprintln(w, "Usage: mxl-gen -d <domain> [--no-video] [-v <flowDef.json>] [-a <flowDef.json>] [options]")
|
||||
fmt.Fprintln(w, "Try 'mxl-gen -h' for more information.")
|
||||
}
|
||||
|
||||
@@ -131,6 +133,9 @@ func validateFlowDefPath(label, path string) error {
|
||||
}
|
||||
|
||||
func validateVideoArgs(args *appArgs) error {
|
||||
if args.noVideo {
|
||||
return nil
|
||||
}
|
||||
if !video.HasPattern(args.pattern) {
|
||||
return fmt.Errorf("unknown video pattern %q (use --list-patterns to see available patterns)", args.pattern)
|
||||
}
|
||||
@@ -158,6 +163,16 @@ func validateVideoArgs(args *appArgs) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMediaSelection(args appArgs) error {
|
||||
if args.noVideo && args.videoFlowDefFile != "" {
|
||||
return fmt.Errorf("--no-video cannot be used with --video")
|
||||
}
|
||||
if args.noVideo && args.audioFlowDefFile == "" && args.audioChannels == 0 {
|
||||
return fmt.Errorf("--no-video requires audio enabled with --channel or --audio")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAudioArgs(args *appArgs) error {
|
||||
if args.audioFlowDefFile == "" && args.audioChannels == 0 {
|
||||
return nil
|
||||
@@ -189,6 +204,7 @@ func validateAudioArgs(args *appArgs) error {
|
||||
func validateArgs(args *appArgs) error {
|
||||
checks := []func() error{
|
||||
func() error { return validateDomain(args.domain) },
|
||||
func() error { return validateMediaSelection(*args) },
|
||||
func() error { return validateFlowDefPath("video", args.videoFlowDefFile) },
|
||||
func() error { return validateFlowDefPath("audio", args.audioFlowDefFile) },
|
||||
func() error { return validateVideoArgs(args) },
|
||||
@@ -263,10 +279,11 @@ func addFlags(fs *pflag.FlagSet, args *appArgs) {
|
||||
"br - bottom-right corner",
|
||||
)
|
||||
|
||||
fs.UintVar(&args.videoWidth, "width", 1920, "Video pattern width. Zero = no video [TODO: 0 width case]")
|
||||
fs.UintVar(&args.videoWidth, "width", 1920, "Video pattern width")
|
||||
fs.UintVar(&args.videoHeight, "height", 1080, "Video pattern height")
|
||||
fs.StringVar(&args.videoFPS, "fps", "25", "Video pattern FPS")
|
||||
fs.StringVar(&args.videoUUID, "video-id", "", "Video UUID. Will be created, if not provided")
|
||||
fs.BoolVar(&args.noVideo, "no-video", false, "Disable video generation; audio must be enabled")
|
||||
// Audio pattern flags
|
||||
fs.Uint8VarP(&args.audioChannels, "channel", "c", 0, "Amount of audio channels. Each channel: num * 1kHz")
|
||||
fs.StringVarP(&args.audioSamplingFreq, "freq", "f", "48", "Sampling frequency of test audio feed in kHz")
|
||||
@@ -302,12 +319,16 @@ func parseArgs(argv []string, stdout, stderr io.Writer) (parseResult, error) {
|
||||
return parseResult{args: args, shouldRun: true}, nil
|
||||
}
|
||||
|
||||
func buildVideoConfig(args appArgs) (video.Config, error) {
|
||||
func buildVideoConfig(args appArgs) (*video.Config, error) {
|
||||
if args.noVideo {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var definition flowdef.Video
|
||||
if args.videoFlowDefFile != "" {
|
||||
data, err := os.ReadFile(args.videoFlowDefFile)
|
||||
if err != nil {
|
||||
return video.Config{}, fmt.Errorf(
|
||||
return nil, fmt.Errorf(
|
||||
"read video flow definition %q: %w",
|
||||
args.videoFlowDefFile,
|
||||
err,
|
||||
@@ -316,7 +337,7 @@ func buildVideoConfig(args appArgs) (video.Config, error) {
|
||||
|
||||
definition, err = flowdef.ParseV210Video(data)
|
||||
if err != nil {
|
||||
return video.Config{}, fmt.Errorf(
|
||||
return nil, fmt.Errorf(
|
||||
"parse video flow definition %q: %w",
|
||||
args.videoFlowDefFile,
|
||||
err,
|
||||
@@ -325,7 +346,7 @@ func buildVideoConfig(args appArgs) (video.Config, error) {
|
||||
} else {
|
||||
rate, ok := frameRates[args.videoFPS]
|
||||
if !ok {
|
||||
return video.Config{}, fmt.Errorf("unsupported video FPS %q", args.videoFPS)
|
||||
return nil, fmt.Errorf("unsupported video FPS %q", args.videoFPS)
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -339,17 +360,17 @@ func buildVideoConfig(args appArgs) (video.Config, error) {
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return video.Config{}, fmt.Errorf(
|
||||
return nil, fmt.Errorf(
|
||||
"build video flow definition: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
if !video.HasPattern(args.pattern) {
|
||||
return video.Config{}, fmt.Errorf("unknown video pattern %q", args.pattern)
|
||||
return nil, fmt.Errorf("unknown video pattern %q", args.pattern)
|
||||
}
|
||||
|
||||
return video.Config{
|
||||
return &video.Config{
|
||||
Definition: definition,
|
||||
Pattern: args.pattern,
|
||||
Overlay: video.OverlayConfig{
|
||||
|
||||
Reference in New Issue
Block a user