static void Main(string[] args) { bool HasArg(string arg) => Array.IndexOf(args, arg) != -1; bool StreamStdout = HasArg("--stdout"); if (StreamStdout) { Console.SetOut(Console.Error); } Console.WriteLine($"SysDVR-Client - {VersionString()} by exelix"); Console.WriteLine("https://github.com/exelix11/SysDVR \r\n"); if (args.Length < 1) { PrintGuide(false); } else if (args[0].Contains("help")) { PrintGuide(true); return; } BaseStreamManager StreamManager; bool NoAudio, NoVideo; string ArgValue(string arg) { int index = Array.IndexOf(args, arg); if (index == -1) { return(null); } if (args.Length <= index + 1) { return(null); } string value = args[index + 1]; if (!value.Contains(' ') && value.StartsWith('"') && value.EndsWith('"')) { value = value.Substring(1, value.Length - 2); } return(value); } int?ArgValueInt(string arg) { var a = ArgValue(arg); if (int.TryParse(a, out int res)) { return(res); } return(null); } if (HasArg("--version")) { return; } else if (HasArg("--show-decoders")) { Player.LibavUtils.PrintAllCodecs(); return; } if (HasArg("--usb-warn")) { UsbContext.Logging = UsbContext.LogLevel.Warning; } if (HasArg("--usb-debug")) { UsbContext.Logging = UsbContext.LogLevel.Debug; } NoAudio = HasArg("--no-audio"); NoVideo = HasArg("--no-video"); StreamThread.Logging = HasArg("--print-stats"); UsbContext.ForceLibUsb = HasArg("--no-winusb"); if (NoVideo && NoAudio) { Console.WriteLine("Specify at least a video or audio output"); return; } if (StreamStdout) { if (!NoVideo && !NoAudio) { NoAudio = true; } StreamManager = new StdOutManager(NoAudio ? StreamKind.Video : StreamKind.Audio); } else if (HasArg("--mpv")) { string mpvPath = ArgValue("--mpv"); if (mpvPath == null || !File.Exists(mpvPath)) { Console.WriteLine("The specified mpv path is not valid"); return; } if (!NoVideo && !NoAudio) { NoAudio = true; } StreamManager = new MpvStdinManager(NoAudio ? StreamKind.Video : StreamKind.Audio, mpvPath); } else if (HasArg("--file")) { string filename = ArgValue("--file"); if (string.IsNullOrWhiteSpace(filename)) { Console.WriteLine("The specified path is not valid"); return; } StreamManager = new Mp4OutputManager(filename, !NoVideo, !NoAudio); } #if DEBUG else if (HasArg("--debug")) { string path = ArgValue("--debug"); StreamManager = new LoggingManager(NoVideo ? null : Path.Combine(path, "video.h264"), NoAudio ? null : Path.Combine(path, "audio.raw")); } #endif else if (HasArg("--rtsp")) { int port = ArgValueInt("--rtsp-port") ?? 6666; if (port <= 1024) { Console.WriteLine("Warning: ports lower than 1024 are usually reserved and may require administrator/root privileges"); } StreamManager = new RTSP.SysDvrRTSPManager(!NoVideo, !NoAudio, !HasArg("--rtsp-any-addr"), port); } else // Stream to the built-in player by default { StreamManager = new Player.PlayerManager(!NoVideo, !NoAudio, HasArg("--hw-acc"), ArgValue("--decoder"), ArgValue("--scale")); } if (args.Length == 0 || args[0] == "usb") { var ctx = UsbContext.GetInstance(); if (!NoVideo) { StreamManager.VideoSource = ctx.MakeStreamingSource(StreamKind.Video); } if (!NoAudio) { StreamManager.AudioSource = ctx.MakeStreamingSource(StreamKind.Audio); } } else if (args[0] == "bridge") { if (args.Length < 2) { Console.WriteLine("Specify an ip address for bridge mode"); return; } string ip = args[1]; if (!NoVideo) { StreamManager.VideoSource = new TCPBridgeSource(ip, StreamKind.Video); } if (!NoAudio) { StreamManager.AudioSource = new TCPBridgeSource(ip, StreamKind.Audio); } } #if DEBUG else if (args[0] == "stub") { StreamManager.VideoSource = new StubSource(); StreamManager.AudioSource = new StubSource(); } else if (args[0] == "record") { StreamManager.VideoSource = NoVideo ? null : new RecordedSource(StreamKind.Video); StreamManager.AudioSource = NoAudio ? null : new RecordedSource(StreamKind.Audio); } #endif else { Console.WriteLine("Invalid source"); return; } StartStreaming(StreamManager); Environment.Exit(0); }