mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Screen record manager refactoring
This commit is contained in:
parent
dded3a11a0
commit
4e42de6dd5
3 changed files with 47 additions and 44 deletions
|
@ -270,7 +270,7 @@ public enum ImagePreviewLocation
|
|||
|
||||
public enum ScreenRecordState
|
||||
{
|
||||
Waiting, BeforeStart, AfterStart, AfterRecordingStart, AfterStop
|
||||
Waiting, BeforeStart, AfterStart, AfterRecordingStart, Encoding
|
||||
}
|
||||
|
||||
public enum RegionCaptureType
|
||||
|
|
|
@ -292,7 +292,7 @@ public void ChangeState(ScreenRecordState state)
|
|||
IsRecording = true;
|
||||
StartRecordingTimer();
|
||||
break;
|
||||
case ScreenRecordState.AfterStop:
|
||||
case ScreenRecordState.Encoding:
|
||||
Hide();
|
||||
string trayTextAfterStop = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Encoding___;
|
||||
niTray.Text = trayTextAfterStop.Truncate(63);
|
||||
|
|
|
@ -241,55 +241,31 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
|
|||
DebugHelper.WriteException(e);
|
||||
}
|
||||
|
||||
try
|
||||
if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding && !abortRequested && screenRecorder != null && File.Exists(path))
|
||||
{
|
||||
if (!abortRequested && screenRecorder != null && File.Exists(path))
|
||||
{
|
||||
recordForm.ChangeState(ScreenRecordState.AfterStop);
|
||||
recordForm.ChangeState(ScreenRecordState.Encoding);
|
||||
|
||||
string input = path;
|
||||
|
||||
if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding)
|
||||
{
|
||||
path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension));
|
||||
|
||||
if (taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif)
|
||||
{
|
||||
screenRecorder.FFmpegEncodeAsGIF(input, path, Program.ToolsFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
screenRecorder.FFmpegEncodeVideo(input, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
path = ProcessTwoPassEncoding(path, taskSettings);
|
||||
}
|
||||
finally
|
||||
|
||||
if (recordForm != null)
|
||||
{
|
||||
if (recordForm != null)
|
||||
recordForm.InvokeSafe(() =>
|
||||
{
|
||||
recordForm.InvokeSafe(() =>
|
||||
{
|
||||
recordForm.Close();
|
||||
recordForm.Dispose();
|
||||
recordForm = null;
|
||||
});
|
||||
}
|
||||
recordForm.Close();
|
||||
recordForm.Dispose();
|
||||
recordForm = null;
|
||||
});
|
||||
}
|
||||
|
||||
if (screenRecorder != null)
|
||||
if (screenRecorder != null)
|
||||
{
|
||||
screenRecorder.Dispose();
|
||||
screenRecorder = null;
|
||||
|
||||
if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path))
|
||||
{
|
||||
if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath))
|
||||
{
|
||||
File.Delete(screenRecorder.CachePath);
|
||||
}
|
||||
|
||||
screenRecorder.Dispose();
|
||||
screenRecorder = null;
|
||||
|
||||
if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}).ContinueInCurrentContext(() =>
|
||||
|
@ -317,5 +293,32 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
|
|||
IsRecording = false;
|
||||
});
|
||||
}
|
||||
|
||||
private static string ProcessTwoPassEncoding(string input, TaskSettings taskSettings, bool deleteInputFile = true)
|
||||
{
|
||||
string filename = TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension);
|
||||
string output = Path.Combine(taskSettings.CaptureFolder, filename);
|
||||
|
||||
try
|
||||
{
|
||||
if (taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif)
|
||||
{
|
||||
screenRecorder.FFmpegEncodeAsGIF(input, output, Program.ToolsFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
screenRecorder.FFmpegEncodeVideo(input, output);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (deleteInputFile && !input.Equals(output, StringComparison.InvariantCultureIgnoreCase) && File.Exists(input))
|
||||
{
|
||||
File.Delete(input);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue