mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
In screen recording if stop requested while recording is not started yet then abort recording to avoid gif encoding issues
This commit is contained in:
parent
992ceb39b6
commit
a78dffa9fd
3 changed files with 16 additions and 8 deletions
|
@ -230,10 +230,10 @@ public void SaveAsGIF(string path, GIFQuality quality)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FFmpegEncodeAsGIF(string path)
|
public bool FFmpegEncodeAsGIF(string sourceFilePath, string targetFilePath)
|
||||||
{
|
{
|
||||||
Helpers.CreateDirectoryFromFilePath(path);
|
Helpers.CreateDirectoryFromFilePath(targetFilePath);
|
||||||
return ffmpegCli.EncodeGIF(Options.OutputPath, path);
|
return ffmpegCli.EncodeGIF(sourceFilePath, targetFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EncodeUsingCommandLine(VideoEncoder encoder, string sourceFilePath, string targetFilePath)
|
public void EncodeUsingCommandLine(VideoEncoder encoder, string sourceFilePath, string targetFilePath)
|
||||||
|
|
|
@ -37,6 +37,7 @@ public partial class ScreenRecordForm : Form
|
||||||
{
|
{
|
||||||
public event Action StopRequested;
|
public event Action StopRequested;
|
||||||
|
|
||||||
|
public bool IsWorking { get; private set; }
|
||||||
public bool IsRecording { get; private set; }
|
public bool IsRecording { get; private set; }
|
||||||
public bool IsCountdown { get; set; }
|
public bool IsCountdown { get; set; }
|
||||||
public TimeSpan Countdown { get; set; }
|
public TimeSpan Countdown { get; set; }
|
||||||
|
@ -222,8 +223,13 @@ private void btnAbort_MouseClick(object sender, MouseEventArgs e)
|
||||||
|
|
||||||
public void StartStopRecording()
|
public void StartStopRecording()
|
||||||
{
|
{
|
||||||
if (IsRecording)
|
if (IsWorking)
|
||||||
{
|
{
|
||||||
|
if (!IsRecording)
|
||||||
|
{
|
||||||
|
AbortRequested = true;
|
||||||
|
}
|
||||||
|
|
||||||
OnStopRequested();
|
OnStopRequested();
|
||||||
}
|
}
|
||||||
else if (RecordResetEvent != null)
|
else if (RecordResetEvent != null)
|
||||||
|
@ -258,14 +264,15 @@ public void ChangeState(ScreenRecordState state)
|
||||||
cmsMain.Enabled = true;
|
cmsMain.Enabled = true;
|
||||||
break;
|
break;
|
||||||
case ScreenRecordState.AfterStart:
|
case ScreenRecordState.AfterStart:
|
||||||
|
IsWorking = true;
|
||||||
string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_;
|
string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_;
|
||||||
niTray.Text = trayTextAfterStart.Truncate(63);
|
niTray.Text = trayTextAfterStart.Truncate(63);
|
||||||
niTray.Icon = Resources.control_record.ToIcon();
|
niTray.Icon = Resources.control_record.ToIcon();
|
||||||
tsmiStart.Text = Resources.AutoCaptureForm_Execute_Stop;
|
tsmiStart.Text = Resources.AutoCaptureForm_Execute_Stop;
|
||||||
btnStart.Text = Resources.AutoCaptureForm_Execute_Stop;
|
btnStart.Text = Resources.AutoCaptureForm_Execute_Stop;
|
||||||
IsRecording = true;
|
|
||||||
break;
|
break;
|
||||||
case ScreenRecordState.AfterRecordingStart:
|
case ScreenRecordState.AfterRecordingStart:
|
||||||
|
IsRecording = true;
|
||||||
StartRecordingTimer();
|
StartRecordingTimer();
|
||||||
break;
|
break;
|
||||||
case ScreenRecordState.AfterStop:
|
case ScreenRecordState.AfterStop:
|
||||||
|
|
|
@ -242,20 +242,21 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!abortRequested && screenRecorder != null)
|
if (!abortRequested && screenRecorder != null && File.Exists(path))
|
||||||
{
|
{
|
||||||
recordForm.ChangeState(ScreenRecordState.AfterStop);
|
recordForm.ChangeState(ScreenRecordState.AfterStop);
|
||||||
|
|
||||||
|
string sourceFilePath = path;
|
||||||
|
|
||||||
if (outputType == ScreenRecordOutput.GIF)
|
if (outputType == ScreenRecordOutput.GIF)
|
||||||
{
|
{
|
||||||
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif"));
|
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif"));
|
||||||
screenRecorder.FFmpegEncodeAsGIF(path);
|
screenRecorder.FFmpegEncodeAsGIF(sourceFilePath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskSettings.CaptureSettings.RunScreencastCLI)
|
if (taskSettings.CaptureSettings.RunScreencastCLI)
|
||||||
{
|
{
|
||||||
VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected];
|
VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected];
|
||||||
string sourceFilePath = path;
|
|
||||||
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension));
|
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension));
|
||||||
screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
|
screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue