/// <summary>
        /// Starts the recording process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartRecording_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(txtPath.Text))
            {
                //Create a new object of RecordSettings class
                RecordingSettings settings        = new RecordingSettings(new RecordingSettings.Resolution(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width), (int)slFPS.Value, (int)slBitrate.Value * 1000000, txtPath.Text, (int)(dudInterval.Value * 1000));
                Thread            recordingThread = new Thread(() => rec.startRecording(settings));

                //Hook the Rec_StartRecordSessionEvent to the event
                rec.StartRecordSessionEvent += Rec_StartRecordSessionEvent;

                //Optimize: Foreach loop in method with tags
                // Turn the GUI "DAU-Safe"
                btnStartRecording.IsEnabled = false;
                btnStopRecording.IsEnabled  = true;
                slBitrate.IsEnabled         = false;
                slFPS.IsEnabled             = false;
                btn_OpenFolder.IsEnabled    = false;
                dudInterval.IsEnabled       = false;
                btn_LoadSettings.IsEnabled  = false;
                btn_SaveSettings.IsEnabled  = false;

                lb_Timer.Foreground = Brushes.Red;


                recordingThread.Start();
            }

            else
            {
                System.Windows.MessageBox.Show("Path can't be null", _progname);
            }
        }
예제 #2
0
        /// <summary>
        /// Build ffmpeg args for Linux
        /// </summary>
        /// <returns>FFmpeg arguments for recording</returns>
        public Dictionary <string, string> ForLinux(Dictionary <string, string> d, RecordingSettings rs, DeviceManager dm)
        {
            #region Add Pulse Inputs
            // Add audio devices
            foreach (var ad in rs.AudioDevicesToRecord)
            {
                d.Add($"pulse{ad.SourceNumber}", $"-f pulse -i {ad.SourceNumber}");
            }
            #endregion

            #region Video Settings
            // Put video settings before x11grab device to make sure they actually apply

            // Recording FPS
            d.Add("fps", $"-framerate {GetFPS(rs.FPS)}");

            // Recording Resolution
            d.Add("res", $"-video_size {GetResolution(rs.Resolution)}");

            // Add x11grab
            d.Add("x11grab", $"-f x11grab");

            // Region on desktop to record
            d.Add("desktopRegion", "-i :0.0+0,0");
            #endregion

            #region Audio mapping
            d.Add("maps", GetAudioMaps((rs.SeperateAudioTracks == "true") ? true : false, rs.AudioDevicesToRecord));
            #endregion

            // Video output path
            d.Add("videoOutput", $"\"{GetVideoOutput(PathHelper.FolderPath(rs.VideoSaveFolder), DateTimeCodeConverter.Convert(rs.VideoSaveName), GetVideoFormat(rs.Format))}\"");

            return(d);
        }
예제 #3
0
    protected void OnSettingsActionActivated(object sender, EventArgs e)
    {
        RecordingSettings copy = new RecordingSettings(_settings);

        copy.Delay  = _settings.Recordings.Delay;
        copy.Folder = _settings.Recordings.Folder;

        SettingsDialog settings = new SettingsDialog(copy);
        ResponseType   r        = (ResponseType)(settings.Run());

        switch (r)
        {
        case ResponseType.Ok:
        {
            _settings.Recordings = copy;
        }
        break;

        case ResponseType.DeleteEvent:
        case ResponseType.Cancel:
            break;

        default:
        {
            throw new Exception("Unknown response");
        }
        }

        settings.Destroy();
    }
 /// <summary>
 /// Deserializes object from json
 /// </summary>
 /// <param name="path"></param>
 /// <param name="jschem">Schema object to check if deserialized object corresponds to it</param>
 private void deserializeFromJSON(string path, JSchema jschem)
 {
     using (StreamReader file = File.OpenText(path))
     {
         using (JsonTextReader reader = new JsonTextReader(file))
         {
             //Validates if JSON File is correct!
             JSchemaValidatingReader validatingReader = new JSchemaValidatingReader(reader);
             validatingReader.Schema = jschem;
             JsonSerializer serializer = new JsonSerializer();
             try
             {
                 settings = serializer.Deserialize <RecordingSettings>(validatingReader);
                 updateGUIValues();
                 System.Windows.MessageBox.Show($"Settings file succesfully loaded!", _progname);
             }
             catch (Exception ex) when(ex is JSchemaValidationException || ex is JsonReaderException)
             {
                 System.Windows.MessageBox.Show($"ERROR: File does not correspond to {_progname} settings format!", _progname);
             }
             finally
             {
                 validatingReader.Close();
             }
         }
     }
 }
예제 #5
0
        public void PutSettingsTest()
        {
            // TODO: add unit test for the method 'PutSettings'
            RecordingSettings body = null; // TODO: replace null with proper value
            var response           = instance.PutSettings(body);

            Assert.IsInstanceOf <RecordingSettings> (response, "response is RecordingSettings");
        }
 public MainWindow()
 {
     InitializeComponent();
     LabelUpdateTimer          = new DispatcherTimer();       //Initializes timer
     LabelUpdateTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); //Sets timer tick to 01 miliseconds
     LabelUpdateTimer.Tick    += LabelUpdaterTimer_Tick;
     settings = new RecordingSettings(new RecordingSettings.Resolution(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width), (int)slFPS.Value, (int)slBitrate.Value * 1000000, txtPath.Text, (int)(dudInterval.Value * 1000));
 }
예제 #7
0
 private bool ShouldStartCropImage(KeyEvent e, RecordingSettings props)
 {
     if (e.IsKeyDown() && e.keyCode == props.CropImage)
     {
         CroppingManager.StartCropImage(e.Point);
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// Saves the settings object state as JSON file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_SaveSettings_Click(object sender, RoutedEventArgs e)
        {
            settings = new RecordingSettings(new RecordingSettings.Resolution(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width), (int)slFPS.Value, (int)slBitrate.Value * 1000000, txtPath.Text, (int)(dudInterval.Value * 1000));
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter     = "JSON file | *.json";
            sfd.DefaultExt = "json";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && settings != null)
            {
                serializeTOJSON(sfd.FileName, settings);
            }
        }
예제 #9
0
        public static async Task <string> Create(string videoPath)
        {
            var process   = new ProcessManager();
            var sm        = new SettingsManager();
            var rs        = new RecordingSettings();
            var thumbPath = Path.Combine(PathHelper.FolderPath(rs.ThumbSaveFolder), (Path.GetFileName(videoPath) + ".png"));

            // Get settings
            sm.GetSettings(rs);

            // Get video thumbnail - closes automatically
            await process.StartProcess($"-i \"{videoPath}\" -frames:v 1 \"{thumbPath}\"");

            return(thumbPath);
        }
예제 #10
0
        public void StartRecording(RecordingSettings settings)
        {
            ViewRecording.ViewRecorder vr = new ViewRecording.ViewRecorder();
            ViewRecording rec             = new ViewRecording(vr);
            EncodingDlg   dlg             = new EncodingDlg(rec, RecordingSettings.DefaultsInstance, "c:/testOut.avi", renderContext);

            dlg.ShowDialog(this);

            // start recording actions
            //if (settings == null)
            //    this.rSettings = RecordingSettings.DefaultsInstance;
            //else
            //    this.rSettings = settings;

            //controlHandler.Recorder = new ViewRecording.ViewRecorder();
            //renderContext.Recording = true;
        }
예제 #11
0
        private void ImageFindOperations(KeyEvent e, Script activeScript, RecordingSettings props)
        {
            var timeOut = 2000;

            if (e.IsKeyDown())
            {
                if (e.keyCode == props.ForEachImage && m_ForImage == false)
                {
                    m_ImageAssetUnderCursor = FindImage(e.Point);
                    if (m_ImageAssetUnderCursor != null)
                    {
                        m_ParentCommand = new CommandForeachImage(m_ImageAssetUnderCursor.Guid, timeOut);
                        ScriptManager.ActiveScript.AddCommand(m_ParentCommand);
                        m_ForImage = true;
                    }
                }

                if (e.keyCode == props.ForImage && m_ForEachImage == false)
                {
                    m_ImageAssetUnderCursor = FindImage(e.Point);
                    if (m_ImageAssetUnderCursor != null)
                    {
                        m_ParentCommand = new CommandForImage(m_ImageAssetUnderCursor.Guid, timeOut);
                        ScriptManager.ActiveScript.AddCommand(m_ParentCommand);
                        m_ForEachImage = true;
                    }
                }

                if (e.keyCode == props.FindImage)
                {
                    FindImage(e.Point);
                }
            }
            else if (e.IsKeyUp())
            {
                if (e.keyCode == props.ForEachImage)
                {
                    m_ForImage = false;
                }

                if (e.keyCode == props.ForImage)
                {
                    m_ForEachImage = false;
                }
            }
        }
예제 #12
0
        private bool ShouldEndCropImage(KeyEvent e, RecordingSettings props)
        {
            if (e.IsKeyDown())
            {
                if (e.keyCode == props.CropImage)
                {
                    CroppingManager.EndCropImage(e.Point);
                }
                else
                {
                    CroppingManager.CancelCropImage();
                }

                return(true);
            }
            return(false);
        }
예제 #13
0
        static void Main(string[] args)
        {
            RecordingSettings settings = new RecordingSettings((new RecordingSettings.Resolution(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width)), 25, 8, "C:\\Users\\Michael\\Videos", 100);

            Recorder rec = new Recorder();

            Console.WriteLine("Start Recording | Enter");
            Console.ReadLine();
            Thread thread = new Thread(() => rec.startRecording(settings));

            thread.Start();

            Console.WriteLine("Stop Recording | Enter");
            Console.ReadLine();
            rec.stopRecording();
            Console.WriteLine("Finished recording!");



            Console.ReadKey();
        }
예제 #14
0
        /// <summary>
        /// Build arguments from RecordingSettings for ffmpeg
        /// </summary>
        public Dictionary <string, string> BuildArgs()
        {
            SettingsManager             sm = new SettingsManager();
            RecordingSettings           rs = new RecordingSettings();
            DeviceManager               dm = new DeviceManager();
            Dictionary <string, string> d  = new Dictionary <string, string>();

            // Get settings
            sm.GetSettings(rs);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(ForWindows(d, rs, dm));
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(ForLinux(d, rs, dm));
            }

            throw new Exception("Could not build args, OSX is not supported.");
        }
예제 #15
0
    void InitializeObjectsFromJson()
    {
        dynamic        VertexLFP         = ParseJson(FileManager.GetLFPFile(this.tissueInstance));
        dynamic        Vertexparams      = ParseJson(FileManager.GetParamsFile(this.tissueInstance));
        dynamic        Vertexspikes      = ParseJson(FileManager.GetSpikesFile(this.tissueInstance));
        List <dynamic> VertexConnections = new List <dynamic>();
        List <dynamic> VertexWeights     = new List <dynamic>();

        this.connectionMappings = new Dictionary <int, int>();
        List <string> connectionFiles = FileManager.GetConnectionsFiles(this.tissueInstance);

        for (int i = 0; i < connectionFiles.Count; i++)
        {
            //int indexOfConnections = connectionFiles[i].IndexOf("/connections")
            string   shortName = connectionFiles[i].Substring(connectionFiles[i].IndexOf("\\connections") + 1);
            string   conSub    = shortName.Substring("connections".Length, shortName.Length - ".json".Length - "connections".Length);
            string[] conMap    = conSub.Split('_');
            if (conMap.Length != 2)
            {
                throw new Exception("Incorrect connection filenames!");
            }
            this.connectionMappings.Add(Convert.ToInt32(conMap[0]), Convert.ToInt32(conMap[1]));

            VertexConnections.Add(ParseJson(connectionFiles[i]));
        }


        dynamic myTissueParams      = Vertexparams.TissueParams;
        dynamic myRecordingSettings = Vertexparams.RecordingSettings;

        //GameObject tissueSlice = GameObject.Find("TissueSlice");
        this.TissueData        = new TissueParams(myTissueParams);
        this.RecordingData     = new RecordingSettings(myRecordingSettings);
        this.LFPData           = new LocalFieldPotential(VertexLFP);
        this.ConnectionData    = new ConnectionInfo(VertexConnections);
        this.SpikeTimes        = new SpikeData(Vertexspikes);
        this.startTime         = Time.time;
        this.currentSpikeIndex = 0;
    }
 public void Init()
 {
     instance = new RecordingSettings();
 }
예제 #17
0
        private void RecordCommand(KeyEvent e, Script activeScript, RecordingSettings props)
        {
            var isMouseButtonUsed = e.keyCode == props.LeftMouseDownButton ||
                                    e.keyCode == props.RightMouseDownButton ||
                                    e.keyCode == props.MiddleMouseDownButton;

            var mouseButton = e.keyCode == props.LeftMouseDownButton ? MouseButton.Left :
                              e.keyCode == props.RightMouseDownButton ? MouseButton.Right :
                              MouseButton.Middle;

            if (e.IsKeyDown())
            {
                if (e.keyCode == props.DefaultSleepKey)
                {
                    AddCommand(new CommandSleep(props.DefaultSleepTime));
                }

                if (e.keyCode == props.SleepKey)
                {
                    m_SleepTimer.Restart();
                }

                if (e.keyCode == props.SmoothMouseMoveKey)
                {
                    AddCommand(new CommandMove(e.X, e.Y));
                    m_LastClickPos = e.Point;
                    // TODO: TIME ?
                }

                if (isMouseButtonUsed)
                {
                    if (!m_ForImage && props.AutomaticSmoothMoveBeforeMouseDown && Distance(m_LastClickPos, e.Point) > 20)
                    {
                        AddCommand(new CommandMove(e.X, e.Y)); // TODO: TIME ?
                    }
                    if (props.TreatMouseDownAsMouseClick)
                    {
                        AddCommand(new CommandPress(e.X, e.Y, false, mouseButton));
                    }
                    else
                    {
                        AddCommand(new CommandDown(e.X, e.Y, false, mouseButton));
                    }

                    m_LastClickPos = e.Point;
                }
            }
            else if (e.IsKeyUp())
            {
                if (e.keyCode == props.SleepKey)
                {
                    m_SleepTimer.Stop();
                    AddCommand(new CommandSleep((int)m_SleepTimer.ElapsedMilliseconds));
                }

                if (isMouseButtonUsed && !props.TreatMouseDownAsMouseClick)
                {
                    if (props.AutomaticSmoothMoveBeforeMouseUp && Distance(m_LastClickPos, e.Point) > 20)
                    {
                        AddCommand(new CommandMove(e.X, e.Y)); // TODO: TIME ?
                    }
                    if (props.ThresholdBetweenMouseDownAndMouseUp > 0)
                    {
                        AddCommand(new CommandSleep(props.ThresholdBetweenMouseDownAndMouseUp));
                    }

                    AddCommand(new CommandRelease(e.X, e.Y, false));

                    m_LastClickPos = e.Point;
                }
            }
            else
            {
                Logger.Log(LogType.Warning, "Key event was fired but neither KeyUp or KeyDown was true");
            }
        }
예제 #18
0
        /// <summary>
        /// Build ffmpeg args for Windows
        /// </summary>
        /// <returns>FFmpeg arguments for recording</returns>
        public Dictionary <string, string> ForWindows(Dictionary <string, string> d, RecordingSettings rs, DeviceManager dm)
        {
            #region Add audio devices
            string audioDevices = String.Empty;

            foreach (var ad in rs.AudioDevicesToRecord)
            {
                audioDevices += $" -f dshow -i audio=\"{ad.Name}\"";
            }

            d.Add($"audioDevices", audioDevices);
            #endregion

            #region Add video device
            // Add directshow
            d.Add("dshow", $"-f dshow");

            string videoDevice;

            if (rs.VideoDevice.ToLower().EqualsAnyOf("default", "desktop screen", dm.DesktopVideoDevice))
            {
                videoDevice = $"-i video=\"{dm.DesktopVideoDevice}\"";
            }
            else
            {
                videoDevice = $"-i video=\"{rs.VideoDevice}\"";
            }

            d.Add("videoDevice", videoDevice);
            #endregion

            #region Audio mapping
            d.Add("maps", GetAudioMaps((rs.SeperateAudioTracks == "true") ? true : false, rs.AudioDevicesToRecord));
            #endregion

            #region FPS
            // Add FPS if it's an integer, otherwise default to 30
            d.Add("fps", $"-framerate {GetFPS(rs.FPS)}");
            #endregion

            #region Resolution
            d.Add("res", $"-video_size {GetResolution(rs.Resolution)}");
            #endregion

            #region Other
            // Zero Latency
            if (rs.ZeroLatency == "true")
            {
                d.Add("tune", "-tune zerolatency");
            }

            // Ultra Fast
            if (rs.UltraFast == "true")
            {
                d.Add("preset", "-preset ultrafast");
            }
            #endregion

            #region Video Output Location & Format
            d.Add("videoOutput", $"\"{GetVideoOutput(PathHelper.FolderPath(rs.VideoSaveFolder), DateTimeCodeConverter.Convert(rs.VideoSaveName), GetVideoFormat(rs.Format))}\"");
            #endregion

            return(d);
        }
예제 #19
0
 public RecordingProperties(BaseSettings settings)
 {
     this.m_Settings = (RecordingSettings)settings;
 }
예제 #20
0
        public static async Task Add(string videoPath)
        {
            var ff = new ProcessManager();
            var rc = new Recording();
            var sm = new SettingsManager();
            var rs = new RecordingSettings();

            using var sw = new StreamWriter(sm.GetFilePath("PastRecordings.json"), true);

            sm.GetSettings(rs);

            // Video Path
            rc.VideoPath = videoPath;

            // Thumbnail Path
            rc.ThumbPath = await VideoThumbnailer.Create(videoPath);

            // File Size
            rc.FileSize = new FileInfo(videoPath).Length;

            #region Get Infro from ffprobe (fps, duration)
            // Query ffprobe to get video duration and fps
            // https://trac.ffmpeg.org/wiki/FFprobeTips
            var info = await ff.StartProcess(
                $"-v error -select_streams v:0 -show_entries format=duration:stream=avg_frame_rate -of default=noprint_wrappers=1 \"{videoPath}\"",
                "ffprobe",
                true,
                true
                );

            // Loop over each line in response from ffprobe
            foreach (var line in info.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
            {
                // Get framerate
                if (line.ToLower().Contains("avg_frame_rate"))
                {
                    var fps = line.ToLower().Replace("avg_frame_rate=", "").Split("/");

                    // Check that fps contains more than 1 item, 2 are needed
                    if (fps.Count() > 1)
                    {
                        // Make sure fps[0 & 1] are able to be parsed
                        if (int.TryParse(fps[0], out int res0) && int.TryParse(fps[1], out int res1))
                        {
                            rc.FPS = (res0 / res1).ToString();
                        }
                    }
                }

                // Get duration
                if (line.ToLower().Contains("duration"))
                {
                    // Try parsing duration of video into float, if can't don't set any duration
                    if (float.TryParse(line.ToLower().Replace("duration=", ""), out var res))
                    {
                        // Convert duration in seconds to TimeSpan
                        var t = TimeSpan.FromSeconds(res);

                        #region Set Readable Duration
                        // If t.Days > 0, then set Duration to it and append Day(s) ...
                        // ... and skip rest of foreach iteration

                        if (t.Days > 0)
                        {
                            rc.Duration = (t.Days > 1) ? $"{t.Days} Days" : $"{t.Days} Day";
                            continue;
                        }

                        if (t.Hours > 0)
                        {
                            rc.Duration = (t.Hours > 1) ? $"{t.Hours} Hours" : $"{t.Hours} Hour";
                            continue;
                        }

                        if (t.Minutes > 0)
                        {
                            rc.Duration = (t.Minutes > 1) ? $"{t.Minutes} Minutes" : $"{t.Minutes} Minute";
                            continue;
                        }

                        if (t.Seconds > 0)
                        {
                            rc.Duration = (t.Seconds > 1) ? $"{t.Seconds} Seconds" : $"{t.Seconds} Second";
                            continue;
                        }

                        if (t.Milliseconds > 0)
                        {
                            rc.Duration = (t.Milliseconds > 1) ? $"{t.Milliseconds} Milliseconds" : $"{t.Milliseconds} Milliseconds";
                            continue;
                        }
                        #endregion
                    }
                }
            }
            #endregion

            // Serialize json from Recording object
            var json = (JObject)JToken.FromObject(rc);

            // If file is empty then append json normally, if it isn't then append json starting with a ','
            sw.Write((new FileInfo(sm.GetFilePath("PastRecordings.json")).Length == 0) ? json.ToString() : $",{json}");
            sw.Close();
        }