Esempio n. 1
0
 public HardDiskCache(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
     fsCache   = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
     indexList = new List <LocationInfo>();
 }
Esempio n. 2
0
 public HardDiskCache(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
     fsCache = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
     indexList = new List<LocationInfo>();
 }
Esempio n. 3
0
        public ScreenRecorder(ScreencastOptions options, Rectangle captureRectangle, ScreenRecordOutput outputType)
        {
            if (string.IsNullOrEmpty(options.OutputPath))
            {
                throw new Exception("Screen recorder cache path is empty.");
            }

            FPS              = outputType == ScreenRecordOutput.GIF ? options.GIFFPS : options.ScreenRecordFPS;
            DurationSeconds  = options.Duration;
            CaptureRectangle = captureRectangle;
            CachePath        = options.OutputPath;
            OutputType       = outputType;

            Options = options;

            switch (OutputType)
            {
            case ScreenRecordOutput.AVI:
                imgCache = new AVICache(Options);
                break;

            case ScreenRecordOutput.FFmpeg:
                ffMpegCli = new FFmpegHelper(Options);
                break;

            case ScreenRecordOutput.GIF:
                imgCache = new HardDiskCache(Options);
                break;
            }
        }
Esempio n. 4
0
 public FFmpegHelper(ScreencastOptions options)
 {
     Output = new StringBuilder();
     OutputDataReceived += FFmpegHelper_DataReceived;
     ErrorDataReceived += FFmpegHelper_DataReceived;
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
 }
Esempio n. 5
0
 public FFmpegHelper(ScreencastOptions options)
 {
     Output              = new StringBuilder();
     OutputDataReceived += FFmpegHelper_DataReceived;
     ErrorDataReceived  += FFmpegHelper_DataReceived;
     Options             = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
 }
Esempio n. 6
0
        public FFmpegOptionsForm(ScreencastOptions options)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;
            Options = options;
            eiFFmpeg.ObjectType = typeof(FFmpegOptions);
            cboVideoCodec.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegVideoCodec>());
            cboAudioCodec.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegAudioCodec>());
            cbPreset.Items.AddRange(Helpers.GetEnumDescriptions<FFmpegPreset>());

            SettingsLoad();
        }
Esempio n. 7
0
        public FFmpegOptionsForm(ScreencastOptions options)
        {
            InitializeComponent();
            Icon                = ShareXResources.Icon;
            Options             = options;
            eiFFmpeg.ObjectType = typeof(FFmpegOptions);
            cboVideoCodec.Items.AddRange(Helpers.GetEnumDescriptions <FFmpegVideoCodec>());
            cboAudioCodec.Items.AddRange(Helpers.GetEnumDescriptions <FFmpegAudioCodec>());
            cbPreset.Items.AddRange(Helpers.GetEnumDescriptions <FFmpegPreset>());

            SettingsLoad();
        }
Esempio n. 8
0
        public FFmpegOptionsForm(ScreencastOptions options)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;

            Options = options;

            if (Options != null)
            {
                SettingsLoad();
                UpdateUI();
            }
        }
Esempio n. 9
0
        public FFmpegOptionsForm(ScreencastOptions options)
        {
            InitializeComponent();

            Icon = ShareXResources.Icon;
            Text = string.Format("{0} - FFmpeg Options", Application.ProductName);

            Options = options;

            if (Options != null)
            {
                SettingsLoad();
                BindUpdatePreview(Controls);
                UpdateUI();
            }
        }
Esempio n. 10
0
        public FFmpegOptionsForm(ScreencastOptions options)
        {
            InitializeComponent();

            Icon = ShareXResources.Icon;
            Text = string.Format("{0} - FFmpeg Options", Application.ProductName);

            Options = options;

            if (Options != null)
            {
                SettingsLoad();
                BindUpdatePreview(Controls);
                UpdateUI();
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AVIWriter"/> class.
 /// </summary>
 ///
 /// <remarks>Initializes Video for Windows library.</remarks>
 public AVIWriter(ScreencastOptions options)
 {
     NativeMethods.AVIFileInit();
     Options = options;
     Open();
 }
Esempio n. 12
0
 public FFmpegHelper(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AVIWriter"/> class.
 /// </summary>
 ///
 /// <remarks>Initializes Video for Windows library.</remarks>
 public AVIWriter(ScreencastOptions options)
 {
     NativeMethods.AVIFileInit();
     Options = options;
     Open();
 }
Esempio n. 14
0
 public AVICache(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
     aviWriter = new AVIWriter(options);
 }
Esempio n. 15
0
 public AVICache(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
     aviWriter = new AVIWriter(options);
 }
Esempio n. 16
0
 public FFmpegHelper(ScreencastOptions options)
 {
     Options = options;
     Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
 }
Esempio n. 17
0
        public void StartRecording(TaskSettings TaskSettings)
        {
            if (TaskSettings.CaptureSettings.RunScreencastCLI)
            {
                if (!Program.Settings.VideoEncoders.IsValidIndex(TaskSettings.CaptureSettings.VideoEncoderSelected))
                {
                    MessageBox.Show("There is no valid CLI video encoder selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (!Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected].IsValid())
                {
                    MessageBox.Show("CLI video encoder file does not exist: " + Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected].Path,
                        Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg && !File.Exists(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath))
            {
                string ffmpegText = string.IsNullOrEmpty(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath) ? "ffmpeg.exe" : TaskSettings.CaptureSettings.FFmpegOptions.CLIPath;

                if (MessageBox.Show(ffmpegText + " does not exist." + Environment.NewLine + Environment.NewLine + "Would you like to automatically download it?",
                    Application.ProductName + " - Missing ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
                    {
                        Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = TaskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
                           TaskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
                    }
                }
                else
                {
                    return;
                }
            }

            SelectRegion();

            if (IsRecording || captureRectangle.IsEmpty || screenRecorder != null)
            {
                return;
            }

            IsRecording = true;
            Screenshot.CaptureCursor = TaskSettings.CaptureSettings.ShowCursor;

            TrayIcon.Text = "ShareX - Waiting...";
            TrayIcon.Icon = Resources.control_record_yellow.ToIcon();
            TrayIcon.Visible = true;

            string path = "";

            ScreenRegionManager screenRegionManager = new ScreenRegionManager();
            screenRegionManager.Start(captureRectangle);

            TaskEx.Run(() =>
            {
                try
                {
                    if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI)
                    {
                        path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "avi"));
                    }
                    else if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg)
                    {
                        path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, TaskSettings.CaptureSettings.FFmpegOptions.Extension));
                    }
                    else
                    {
                        path = Program.ScreenRecorderCacheFilePath;
                    }

                    ScreencastOptions options = new ScreencastOptions()
                    {
                        CaptureArea = captureRectangle,
                        GIFFPS = TaskSettings.CaptureSettings.GIFFPS,
                        ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS,
                        OutputPath = path,
                        Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0,
                        AVI = TaskSettings.CaptureSettings.AVIOptions,
                        FFmpeg = TaskSettings.CaptureSettings.FFmpegOptions,
                        DrawCursor = TaskSettings.CaptureSettings.ShowCursor
                    };

                    screenRecorder = new ScreenRecorder(options, captureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput);

                    int delay = (int)(TaskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);

                    if (delay > 0)
                    {
                        Thread.Sleep(delay);
                    }

                    this.InvokeSafe(() =>
                    {
                        screenRegionManager.ChangeColor(Color.FromArgb(0, 255, 0));
                    });

                    TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
                    TrayIcon.Icon = Resources.control_record.ToIcon();

                    screenRecorder.StartRecording();
                }
                finally
                {
                    if (screenRegionManager != null)
                    {
                        this.InvokeSafe(() => screenRegionManager.Dispose());
                    }
                }

                try
                {
                    if (screenRecorder != null)
                    {
                        TrayIcon.Text = "ShareX - Encoding...";
                        TrayIcon.Icon = Resources.camcorder_pencil.ToIcon();

                        string sourceFilePath = path;

                        if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF)
                        {
                            if (TaskSettings.CaptureSettings.RunScreencastCLI)
                            {
                                sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif");
                            }
                            else
                            {
                                sourceFilePath = path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "gif"));
                            }

                            screenRecorder.SaveAsGIF(sourceFilePath, TaskSettings.ImageSettings.ImageGIFQuality);
                        }

                        if (TaskSettings.CaptureSettings.RunScreencastCLI)
                        {
                            VideoEncoder encoder = Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected];
                            path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, encoder.OutputExtension));
                            screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
                        }
                    }
                }
                finally
                {
                    if (screenRecorder != null)
                    {
                        if (TaskSettings.CaptureSettings.RunScreencastCLI && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath))
                        {
                            File.Delete(screenRecorder.CachePath);
                        }

                        screenRecorder.Dispose();
                        screenRecorder = null;
                    }
                }
            },
            () =>
            {
                if (TrayIcon.Visible)
                {
                    TrayIcon.Visible = false;
                }

                IsRecording = false;

                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
                    if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.UploadImageToHost))
                    {
                        UploadManager.UploadFile(path, TaskSettings);
                    }
                    else
                    {
                        if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.CopyFilePathToClipboard))
                        {
                            ClipboardHelpers.CopyText(path);
                        }

                        TaskHelpers.ShowResultNotifications(path, TaskSettings, path);
                    }
                }
            });
        }
Esempio n. 18
0
        public void StartRecording(TaskSettings taskSettings)
        {
            if (taskSettings.CaptureSettings.RunScreencastCLI)
            {
                if (!Program.Settings.VideoEncoders.IsValidIndex(taskSettings.CaptureSettings.VideoEncoderSelected))
                {
                    MessageBox.Show("There is no valid CLI video encoder selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (!Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].IsValid())
                {
                    MessageBox.Show("CLI video encoder file does not exist: " + Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].Path,
                        Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg)
            {
                if (!File.Exists(taskSettings.CaptureSettings.FFmpegOptions.CLIPath))
                {
                    string ffmpegText = string.IsNullOrEmpty(taskSettings.CaptureSettings.FFmpegOptions.CLIPath) ? "ffmpeg.exe" : taskSettings.CaptureSettings.FFmpegOptions.CLIPath;

                    if (MessageBox.Show(ffmpegText + " does not exist." + Environment.NewLine + Environment.NewLine + "Would you like to automatically download it?",
                        Application.ProductName + " - Missing ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
                        {
                            Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
                               taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected)
                {
                    MessageBox.Show("FFmpeg video and audio source both can't be \"None\".", Application.ProductName + " - FFmpeg error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            if (taskSettings.AdvancedSettings.ScreenRecorderUseActiveWindow)
            {
                ActiveWindowRegion(taskSettings);
            }
            else
            {
                SelectRegion();
            }

            captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle);

            if (IsRecording || !captureRectangle.IsValid() || screenRecorder != null)
            {
                return;
            }

            IsRecording = true;
            Screenshot.CaptureCursor = taskSettings.CaptureSettings.ShowCursor;

            TrayIcon.Text = "ShareX - Waiting...";
            TrayIcon.Icon = Resources.control_record_yellow.ToIcon();
            TrayIcon.Visible = true;

            string path = "";

            float duration = taskSettings.CaptureSettings.ScreenRecordFixedDuration ? taskSettings.CaptureSettings.ScreenRecordDuration : 0;
            regionForm = ScreenRegionForm.Show(captureRectangle, StopRecording, duration);

            TaskEx.Run(() =>
            {
                try
                {
                    if (taskSettings.CaptureSettings.ScreenRecordAutoDisableAero)
                    {
                        dwmManager = new DWMManager();
                        dwmManager.AutoDisable();
                    }

                    if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI)
                    {
                        path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "avi"));
                    }
                    else if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg)
                    {
                        path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension));
                    }
                    else
                    {
                        path = Program.ScreenRecorderCacheFilePath;
                    }

                    ScreencastOptions options = new ScreencastOptions()
                    {
                        FFmpeg = taskSettings.CaptureSettings.FFmpegOptions,
                        AVI = taskSettings.CaptureSettings.AVIOptions,
                        ScreenRecordFPS = taskSettings.CaptureSettings.ScreenRecordFPS,
                        GIFFPS = taskSettings.CaptureSettings.GIFFPS,
                        Duration = duration,
                        OutputPath = path,
                        CaptureArea = captureRectangle,
                        DrawCursor = taskSettings.CaptureSettings.ShowCursor
                    };

                    screenRecorder = new ScreenRecorder(options, captureRectangle, taskSettings.CaptureSettings.ScreenRecordOutput);

                    int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);

                    if (delay > 0)
                    {
                        Thread.Sleep(delay);
                    }

                    TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
                    TrayIcon.Icon = Resources.control_record.ToIcon();

                    if (regionForm != null)
                    {
                        this.InvokeSafe(() => regionForm.StartTimer());
                    }

                    screenRecorder.StartRecording();
                }
                finally
                {
                    if (dwmManager != null)
                    {
                        dwmManager.Dispose();
                        dwmManager = null;
                    }

                    if (regionForm != null)
                    {
                        this.InvokeSafe(() => regionForm.Close());
                    }
                }

                try
                {
                    if (screenRecorder != null)
                    {
                        TrayIcon.Text = "ShareX - Encoding...";
                        TrayIcon.Icon = Resources.camcorder_pencil.ToIcon();

                        string sourceFilePath = path;

                        if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF)
                        {
                            if (taskSettings.CaptureSettings.RunScreencastCLI)
                            {
                                sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif");
                            }
                            else
                            {
                                sourceFilePath = path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif"));
                            }

                            screenRecorder.SaveAsGIF(sourceFilePath, taskSettings.ImageSettings.ImageGIFQuality);
                        }

                        if (taskSettings.CaptureSettings.RunScreencastCLI)
                        {
                            VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected];
                            path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension));
                            screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
                        }
                    }
                }
                finally
                {
                    if (screenRecorder != null)
                    {
                        if (taskSettings.CaptureSettings.RunScreencastCLI && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath))
                        {
                            File.Delete(screenRecorder.CachePath);
                        }

                        screenRecorder.Dispose();
                        screenRecorder = null;
                    }
                }
            },
            () =>
            {
                if (TrayIcon.Visible)
                {
                    TrayIcon.Visible = false;
                }

                IsRecording = false;

                if (!string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings))
                {
                    UploadTask task = UploadTask.CreateFileJobTask(path, taskSettings);
                    TaskManager.Start(task);
                }
            });
        }
Esempio n. 19
0
        public ScreenRecorder(ScreencastOptions options, Rectangle captureRectangle, ScreenRecordOutput outputType)
        {
            if (string.IsNullOrEmpty(options.OutputPath))
            {
                throw new Exception("Screen recorder cache path is empty.");
            }

            FPS = outputType == ScreenRecordOutput.GIF ? options.GIFFPS : options.ScreenRecordFPS;
            DurationSeconds = options.Duration;
            CaptureRectangle = captureRectangle;
            CachePath = options.OutputPath;
            OutputType = outputType;

            Options = options;

            switch (OutputType)
            {
                case ScreenRecordOutput.AVI:
                    imgCache = new AVICache(Options);
                    break;
                case ScreenRecordOutput.FFmpeg:
                    ffMpegCli = new FFmpegHelper(Options);
                    break;
                case ScreenRecordOutput.GIF:
                    imgCache = new HardDiskCache(Options);
                    break;
            }
        }