/// <summary> /// Creates a new instance of <see cref="IRecorder"/> writing to <see cref="IVideoFileWriter"/>. /// </summary> /// <param name="VideoWriter">The <see cref="IVideoFileWriter"/> to write to.</param> /// <param name="ImageProvider">The image source.</param> /// <param name="FrameRate">Video Frame Rate.</param> /// <param name="AudioProvider">The audio source. null = no audio.</param> public Recorder(IVideoFileWriter VideoWriter, IImageProvider ImageProvider, int FrameRate, IAudioProvider AudioProvider = null, KeyVector keyVector = null) { _videoWriter = VideoWriter ?? throw new ArgumentNullException(nameof(VideoWriter)); _imageProvider = ImageProvider ?? throw new ArgumentNullException(nameof(ImageProvider)); _audioProvider = AudioProvider; _keyVector = keyVector; if (FrameRate <= 0) { throw new ArgumentException("Frame Rate must be positive", nameof(FrameRate)); } _frameRate = FrameRate; _congestionFrameCount = _frameRate * 2; // 2 seconds _maxFrameCount = _frameRate * 4; // 4 seconds _continueCapturing = new ManualResetEvent(false); if (VideoWriter.SupportsAudio && AudioProvider != null) { AudioProvider.DataAvailable += AudioProvider_DataAvailable; } else { _audioProvider = null; } _sw = new Stopwatch(); _frames = new BlockingCollection <IBitmapFrame>(); _recordTask = Task.Factory.StartNew(async() => await DoRecord(), TaskCreationOptions.LongRunning); _writeTask = Task.Factory.StartNew(DoWrite, TaskCreationOptions.LongRunning); }
/// <summary> /// Creates a new instance of <see cref="FFmpegWriter"/>. /// </summary> public FFmpegWriter(FFmpegVideoWriterArgs Args) { var settings = ServiceProvider.Get <FFmpegSettings>(); _videoBuffer = new byte[Args.ImageProvider.Width * Args.ImageProvider.Height * 4]; frameCount = 0; _keyVector = Args.keyVector; _keyVector.CreateKeyOutputFile(); Console.WriteLine($"Video Buffer Allocated: {_videoBuffer.Length}"); var audioPipeName = GetPipeName(); var videoPipeName = GetPipeName(); var videoInArgs = $"-thread_queue_size 512 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt rgb32 -video_size {Args.ImageProvider.Width}x{Args.ImageProvider.Height} -i {PipePrefix}{videoPipeName}"; var videoOutArgs = $"{Args.VideoArgsProvider(Args.VideoQuality)} -r {Args.FrameRate}"; if (settings.Resize) { var width = settings.ResizeWidth; var height = settings.ResizeHeight; if (width % 2 == 1) { ++width; } if (height % 2 == 1) { ++height; } videoOutArgs += $" -vf scale={width}:{height}"; } string audioInArgs = "", audioOutArgs = ""; if (Args.AudioProvider != null) { audioInArgs = $"-thread_queue_size 512 -f s16le -acodec pcm_s16le -ar {Args.Frequency} -ac {Args.Channels} -i {PipePrefix}{audioPipeName}"; audioOutArgs = Args.AudioArgsProvider(Args.AudioQuality); // UpdatePeriod * Frequency * (Bytes per Second) * Channels * 2 var audioBufferSize = (int)((1000.0 / Args.FrameRate) * 44.1 * 2 * 2 * 2); _audioPipe = new NamedPipeServerStream(audioPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, audioBufferSize); } _ffmpegIn = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length); _ffmpegProcess = FFmpegService.StartFFmpeg($"{videoInArgs} {audioInArgs} {videoOutArgs} {audioOutArgs} {Args.OutputArgs} \"{Args.FileName}\"", Args.FileName); }
/// <summary> /// Creates a new instance of <see cref="MouseKeyHook"/>. /// </summary> public MouseKeyHook(MouseClickSettings MouseClickSettings, KeystrokesSettings KeystrokesSettings, KeymapViewModel Keymap, KeyVector keyVector) { _mouseClickSettings = MouseClickSettings; _keystrokesSettings = KeystrokesSettings; _keymap = Keymap; _keyVector = keyVector; _hook = Hook.GlobalEvents(); _hook.MouseDown += (S, E) => { _mouseClicked = true; _mouseButtons = E.Button; }; _hook.MouseUp += (S, E) => _mouseClicked = false; _records = new KeyRecords(KeystrokesSettings.HistoryCount); _hook.KeyDown += OnKeyDown; _hook.KeyUp += OnKeyUp; }
public RecordingViewModel(Settings Settings, LanguageManager LanguageManager, CustomOverlaysViewModel CustomOverlays, CustomImageOverlaysViewModel CustomImageOverlays, CensorOverlaysViewModel CensorOverlays, ISystemTray SystemTray, IRegionProvider RegionProvider, WebcamOverlay WebcamOverlay, IMainWindow MainWindow, IPreviewWindow PreviewWindow, VideoViewModel VideoViewModel, AudioSource AudioSource, RecentViewModel RecentViewModel, IWebCamProvider WebCamProvider, KeymapViewModel Keymap) : base(Settings, LanguageManager) { this.CustomOverlays = CustomOverlays; this.CustomImageOverlays = CustomImageOverlays; this.CensorOverlays = CensorOverlays; _systemTray = SystemTray; _regionProvider = RegionProvider; _webcamOverlay = WebcamOverlay; _mainWindow = MainWindow; _previewWindow = PreviewWindow; _videoViewModel = VideoViewModel; _audioSource = AudioSource; _recentViewModel = RecentViewModel; _webCamProvider = WebCamProvider; _keymap = Keymap; _keyVector = new KeyVector(); RecordCommand = new DelegateCommand(OnRecordExecute); PauseCommand = new DelegateCommand(OnPauseExecute, false); SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; }
/*void OnGUI() * { * if (LoggerOn) * { * Event e = Event.current; * if (e.character >= 'a' && e.character <= 'z' || e.character >= 'A' && e.character <= 'Z' || e.character >= '0' && e.character <= 9) * { * selectedKey = e.character; * //Debug.Log("Detected key code: " + e.keyCode + " "+e.character); * if (smallLetters.Contains(e.character)) * { * type = "small"; * keyId++; * } * if (capitalLetters.Contains(e.character)) * { * type = "capital"; * keyId++; * } * if (numbers.Contains(e.character)) * { * * type = "num"; * keyId++; * } * /*if ((e.keyCode >= KeyCode.A && e.keyCode <= KeyCode.Z) || (e.keyCode >= KeyCode.Alpha0 && e.keyCode <= KeyCode.Alpha9) || (e.keyCode >= KeyCode.Keypad0 && e.keyCode <= KeyCode.Keypad9)) * { * selectedKeyCode = e.keyCode; * } * anyKey = e.keyCode; * } * else * selectedKey = '*'; * * } * }*/ void Update() { if (LoggerOn && TouchScreenKeyboard.visible) { //Debug.Log(selectedKey); if (fingerFlying == true) { FT += Time.deltaTime; } if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { Debug.Log("begun"); fingerFlying = false; currentKey = new KeyVector(); timeKeyPressed += Time.deltaTime; currentKey.xCoordinate = Input.touches[0].position.x; currentKey.yCoordinate = Input.touches[0].position.y; currentKey.pressureDown = Input.touches[0].pressure; currentKey.sizeDown = Input.touches[0].radius; MeasureSensors(); updateCount++; currentKey.timeFT1 = FT; currentKey.pwdID = control.count; FT = 0; } if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { MeasureSensors(); updateCount++; timeKeyPressed += Time.deltaTime; } if (touch.phase == TouchPhase.Ended) { Debug.Log("Ended"); fingerFlying = true; currentKey.userName = control.username; currentKey.timestamp = DateTime.Now; currentKey.timeDT = timeKeyPressed; currentKey.keyId = keyId; if (lastKeyPressed != 0) { currentKey.timeFT2 = currentKey.timeFT1 + currentKey.timeDT; currentKey.timeFT3 = lastKeyPressed + currentKey.timeFT1; currentKey.timeFT4 = lastKeyPressed + currentKey.timeFT1 + currentKey.timeDT; currentKey.lastKey = lastKey; } currentKey.keyPressed = selectedKey; if (Input.touchCount > 0) { currentKey.pressureUp = Input.touches[0].pressure; currentKey.sizeUp = Input.touches[0].radius; } currentKey.gyroscopeX /= updateCount; currentKey.gyroscopeY /= updateCount; currentKey.gyroscopeZ /= updateCount; currentKey.accelX /= updateCount; currentKey.accelY /= updateCount; currentKey.accelZ /= updateCount; currentKey.rotX /= updateCount; currentKey.rotY /= updateCount; currentKey.rotZ /= updateCount; lastKeyPressed = timeKeyPressed; timeKeyPressed = 0; lastKey = selectedKey; updateCount = 0; Debug.Log(currentKey.keyPressed + " " + currentKey.timeDT + " " + currentKey.timeFT1); currentKey.keyPressed = selectedKey; lastKey = selectedKey; KeyLogs.Add(currentKey); } } } }
public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args, string OutputArgs, KeyVector keyVector = null) { var args = FFmpegVideoWriterArgs.FromVideoWriterArgs(Args, _videoArgsProvider, _audioArgsProvider); args.OutputArgs = OutputArgs; args.keyVector = keyVector; return(new FFmpegWriter(args)); }