Don't save broken subtitle files

This commit is contained in:
N00MKRAD
2021-02-25 19:21:11 +01:00
parent 6d1aca4714
commit e921beeffe
2 changed files with 14 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ namespace Flowframes
Logger.Log(trimmedLine, hidden, replaceLastLine, "ffmpeg");
if (line.Contains(".srt: Invalid data found"))
Logger.Log($"Warning: Failed to encode subtitle track {line.Split(':')[1]}. This track will be missing in the output file.");
Logger.Log($"Warning: Failed to encode subtitle track {line.Split(':')[2]}. This track will be missing in the output file.");
if (line.Contains("Could not open file"))
Interpolate.Cancel($"FFmpeg Error: {line}");

View File

@@ -97,6 +97,7 @@ namespace Flowframes.Media
List<SubtitleTrack> subtitleTracks = await GetSubtitleTracks(inputFile);
int counter = 1;
int extractedSuccessfully = 0;
foreach (SubtitleTrack subTrack in subtitleTracks)
{
@@ -104,13 +105,22 @@ namespace Flowframes.Media
string args = $" -loglevel error -sub_charenc {subTrack.encoding} -i {inputFile.Wrap()} -map 0:{subTrack.streamIndex} {outPath.Wrap()}";
await RunFfmpeg(args, LogMode.Hidden);
if (subtitleTracks.Count > 4) Program.mainForm.SetProgress(FormatUtils.RatioInt(counter, subtitleTracks.Count));
Logger.Log($"[FFCmds] Extracted subtitle track {subTrack.streamIndex} to {outPath} ({FormatUtils.Bytes(IOUtils.GetFilesize(outPath))})", true, false, "ffmpeg");
counter++;
if(IOUtils.GetFilesize(outPath) >= 32)
{
Logger.Log($"[FFCmds] Extracted subtitle track {subTrack.streamIndex} to {outPath} ({FormatUtils.Bytes(IOUtils.GetFilesize(outPath))})", true, false, "ffmpeg");
extractedSuccessfully++;
}
else
{
IOUtils.TryDeleteIfExists(outPath); // Delete if encode was not successful
}
}
if (subtitleTracks.Count > 0)
if (extractedSuccessfully > 0)
{
Logger.Log($"Extracted {subtitleTracks.Count} subtitle tracks from the input video.", false, Logger.GetLastLine().Contains(msg));
Logger.Log($"Extracted {extractedSuccessfully} subtitle tracks from the input video.", false, Logger.GetLastLine().Contains(msg));
Utils.ContainerSupportsSubs(Utils.GetExt(outMode), true);
}
}