Example #1
0
        public bool TryFindCompatibleDevice(FFmpegStreamType streamType, out string device)  // string preferredDevice,
        {
            var devices = _ffmpeg.GetDevicesOfType(streamType).ToList();

            device = devices.FirstOrDefault()?.Name;

            return(String.IsNullOrWhiteSpace(device) == false);
        }
Example #2
0
        public bool StartRecordingProcess(FFmpegStreamType streamType, string device, string targetPath, string deviceArgs = null)
        {
            device.ThrowIf(String.IsNullOrWhiteSpace, nameof(device));

            string uniqueTargetPath = EnsureTargetPathIsUnique(targetPath);

            string inputArgs = _config.FFmpegStartRecordingArgs
                               .Replace("{streamType}", streamType)
                               .Replace("{deviceName}", device)
                               .Replace("{deviceArgs}", deviceArgs ?? String.Empty)
                               .Replace("{targetPath}", String.IsNullOrWhiteSpace(uniqueTargetPath) ? "-f null -" : $"\"{uniqueTargetPath}\"");

            bool window  = _config.ShowOutput;
            bool logging = window == false && _config.LogOutput;

            Process process = _ffmpeg.CreateFFmpegProcess(inputArgs, logging, window);


            // logger.Info(LogHelper.Prepare($"Starting streamer \"{device}\" with args: {inputArgs}"));

            try
            {
                process.EnableRaisingEvents = true;
                process.Exited += process_Exited;

                process.StartInfo.RedirectStandardInput = true; // so we can stop recording with writing "q" on the input

                if (process.StartInfo.RedirectStandardError)
                {
                    process.ErrorDataReceived += proc_ErrorDataReceived;
                }

                Process = process;

                process.Start();

                if (process.StartInfo.RedirectStandardError)
                {
                    process.BeginErrorReadLine();
                }

                // logger.Info(LogHelper.Prepare($"Streamer {device} started"));
                return(true);
            }
            catch (Exception ex)
            {
                //logger.Error(LogHelper.Prepare($"Streamer {device} failed."), ex);
            }
            return(false);
        }
Example #3
0
        public IEnumerable <FFmpegDevice> GetDevicesOfType(FFmpegStreamType type)
        {
            string deviceType;

            Regex regex = new Regex("\"[^@]*?\"", RegexOptions.Compiled | RegexOptions.CultureInvariant);

            IEnumerable <FFmpegDevice> devices = GetDevicesListOutput()
                                                 .SkipWhile(l => TryMatchDeviceTypeHeader(l, out deviceType) == false || deviceType.Equals(type) == false) // skip while the header does not match the type
                                                 .Skip(1)                                                                                                  // skip the header so it is not processed twice; alternative to check for the same device type in the next step with  '|| header.Equals(type)'
                                                 .TakeWhile(l => TryMatchDeviceTypeHeader(l, out deviceType) == false)                                     // take while other header is not reached
                                                 .Select(line => regex.Match(line))
                                                 .Where(match => match.Success)
                                                 .SelectMany(match => match.Captures.OfType <Capture>())
                                                 .Select(capture => capture.Value.Trim('\"'))
                                                 .Select(name => new FFmpegDevice(type, name));

            return(devices);
        }
Example #4
0
 public FFmpegDevice(FFmpegStreamType type, string name)
 {
     Type = type;
     Name = name;
 }