Improve some error handling

This commit is contained in:
Nikolaj Olsson 2024-04-21 21:18:42 +02:00
parent 7726ed5eda
commit d3aa3cf126

View File

@ -451,7 +451,7 @@ namespace Nikse.SubtitleEdit.Forms
var failCount = 0; var failCount = 0;
for (var index = 0; index < _batchVideoAndSubList.Count; index++) for (var index = 0; index < _batchVideoAndSubList.Count; index++)
{ {
labelPleaseWait.Text = $"{index+1}/{_batchVideoAndSubList.Count} - {LanguageSettings.Current.General.PleaseWait}"; labelPleaseWait.Text = $"{index + 1}/{_batchVideoAndSubList.Count} - {LanguageSettings.Current.General.PleaseWait}";
var videoAndSub = _batchVideoAndSubList[index]; var videoAndSub = _batchVideoAndSubList[index];
_videoInfo = UiUtil.GetVideoInfo(videoAndSub.VideoFileName); _videoInfo = UiUtil.GetVideoInfo(videoAndSub.VideoFileName);
if (useSourceResolution) if (useSourceResolution)
@ -475,7 +475,12 @@ namespace Nikse.SubtitleEdit.Forms
} }
var nameNoExt = Path.GetFileNameWithoutExtension(videoAndSub.VideoFileName); var nameNoExt = Path.GetFileNameWithoutExtension(videoAndSub.VideoFileName);
var ext = Path.GetExtension(videoAndSub.VideoFileName); var ext = Path.GetExtension(videoAndSub.VideoFileName).ToLowerInvariant();
if (ext != ".mp4" && ext != ".mkv")
{
ext = ".mkv";
}
VideoFileName = Path.Combine(path, $"{nameNoExt.TrimEnd('.', '.')}{Configuration.Settings.Tools.GenVideoOutputFileSuffix}{ext}"); VideoFileName = Path.Combine(path, $"{nameNoExt.TrimEnd('.', '.')}{Configuration.Settings.Tools.GenVideoOutputFileSuffix}{ext}");
if (File.Exists(VideoFileName)) if (File.Exists(VideoFileName))
{ {
@ -504,6 +509,15 @@ namespace Nikse.SubtitleEdit.Forms
listViewBatch.Items[index].SubItems[ListViewBatchSubItemIndexColumnStatus].Text = "Error"; listViewBatch.Items[index].SubItems[ListViewBatchSubItemIndexColumnStatus].Text = "Error";
sbInfo.AppendLine($"{index + 1}: {videoAndSub.VideoFileName} -> Failed!"); sbInfo.AppendLine($"{index + 1}: {videoAndSub.VideoFileName} -> Failed!");
failCount++; failCount++;
try
{
File.Delete(VideoFileName);
}
catch
{
// ignore
}
} }
} }
@ -679,13 +693,14 @@ namespace Nikse.SubtitleEdit.Forms
_totalFrames = (long)Math.Round(_totalFrames / factor) + 10; _totalFrames = (long)Math.Round(_totalFrames / factor) + 10;
} }
var result = true;
if (checkBoxTargetFileSize.Checked) if (checkBoxTargetFileSize.Checked)
{ {
RunTwoPassEncoding(assaTempFileName, videoFileName); RunTwoPassEncoding(assaTempFileName, videoFileName);
} }
else else
{ {
RunOnePassEncoding(assaTempFileName, videoFileName); result = RunOnePassEncoding(assaTempFileName, videoFileName);
} }
try try
@ -697,7 +712,7 @@ namespace Nikse.SubtitleEdit.Forms
// ignore // ignore
} }
return true; return result;
} }
private TimeSpan GetCutEnd() private TimeSpan GetCutEnd()
@ -919,7 +934,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
private void RunOnePassEncoding(string assaTempFileName, string videoFileName) private bool RunOnePassEncoding(string assaTempFileName, string videoFileName)
{ {
var process = GetFfmpegProcess(videoFileName, VideoFileName, assaTempFileName); var process = GetFfmpegProcess(videoFileName, VideoFileName, assaTempFileName);
_log.AppendLine("ffmpeg arguments: " + process.StartInfo.Arguments); _log.AppendLine("ffmpeg arguments: " + process.StartInfo.Arguments);
@ -949,6 +964,14 @@ namespace Nikse.SubtitleEdit.Forms
var v = (int)_processedFrames; var v = (int)_processedFrames;
SetProgress(v); SetProgress(v);
} }
if (process.ExitCode != 0)
{
_log.AppendLine("ffmpeg exit code: " + process.ExitCode);
return false;
}
return true;
} }
private bool CheckForPromptParameters(Process process, string title) private bool CheckForPromptParameters(Process process, string title)