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:
Jaex 2017-06-26 09:05:14 +03:00
parent 992ceb39b6
commit a78dffa9fd
3 changed files with 16 additions and 8 deletions

View file

@ -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);
return ffmpegCli.EncodeGIF(Options.OutputPath, path);
Helpers.CreateDirectoryFromFilePath(targetFilePath);
return ffmpegCli.EncodeGIF(sourceFilePath, targetFilePath);
}
public void EncodeUsingCommandLine(VideoEncoder encoder, string sourceFilePath, string targetFilePath)

View file

@ -37,6 +37,7 @@ public partial class ScreenRecordForm : Form
{
public event Action StopRequested;
public bool IsWorking { get; private set; }
public bool IsRecording { get; private set; }
public bool IsCountdown { get; set; }
public TimeSpan Countdown { get; set; }
@ -222,8 +223,13 @@ private void btnAbort_MouseClick(object sender, MouseEventArgs e)
public void StartStopRecording()
{
if (IsRecording)
if (IsWorking)
{
if (!IsRecording)
{
AbortRequested = true;
}
OnStopRequested();
}
else if (RecordResetEvent != null)
@ -258,14 +264,15 @@ public void ChangeState(ScreenRecordState state)
cmsMain.Enabled = true;
break;
case ScreenRecordState.AfterStart:
IsWorking = true;
string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_;
niTray.Text = trayTextAfterStart.Truncate(63);
niTray.Icon = Resources.control_record.ToIcon();
tsmiStart.Text = Resources.AutoCaptureForm_Execute_Stop;
btnStart.Text = Resources.AutoCaptureForm_Execute_Stop;
IsRecording = true;
break;
case ScreenRecordState.AfterRecordingStart:
IsRecording = true;
StartRecordingTimer();
break;
case ScreenRecordState.AfterStop:

View file

@ -242,20 +242,21 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
try
{
if (!abortRequested && screenRecorder != null)
if (!abortRequested && screenRecorder != null && File.Exists(path))
{
recordForm.ChangeState(ScreenRecordState.AfterStop);
string sourceFilePath = path;
if (outputType == ScreenRecordOutput.GIF)
{
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif"));
screenRecorder.FFmpegEncodeAsGIF(path);
screenRecorder.FFmpegEncodeAsGIF(sourceFilePath, path);
}
if (taskSettings.CaptureSettings.RunScreencastCLI)
{
VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected];
string sourceFilePath = path;
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension));
screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
}