public ProcessedSteps ( int steps ) : void | ||
steps | int | Steps. |
return | void |
public static void ExtractSnaphots(Settings settings, String path, List <Tuple <CardInfo, String> > allEntries, InfoProgress progress) { foreach (var entry in allEntries) { if (progress.Cancelled) { break; } progress.ProcessedSteps(1); var cardInfoNameTuple = entry; var cardInfo = cardInfoNameTuple.Item1; if (!cardInfo.HasImage()) { continue; } // create file at given path String outputSnapshotFilename = cardInfoNameTuple.Item2; String outputSnapshotFilepath = path + Path.DirectorySeparatorChar + outputSnapshotFilename; // get file with snapshot information -> video UtilsInputFiles.FileDesc videoFileDesc = cardInfo.episodeInfo.VideoFileDesc; // extract image double scaling = UtilsVideo.GetMaxScalingByStreamInfo(cardInfo.episodeInfo.VideoStreamInfo, settings.RescaleWidth, settings.RescaleHeight, settings.RescaleMode); double timeStamp = UtilsCommon.GetMiddleTime(cardInfo); UtilsImage.GetImage(videoFileDesc.filename, timeStamp, outputSnapshotFilepath, scaling); } }
public static void ExtractAudio(Settings settings, String path, List <Tuple <CardInfo, String> > allEntries, InfoProgress progress) { foreach (var entry in allEntries) { progress.ProcessedSteps(1); if (progress.Cancelled) { return; } CardInfo cardInfo = entry.Item1; if (!cardInfo.HasAudio()) { continue; } String outputAudioFilename = entry.Item2; String outputAudioFilepath = path + Path.DirectorySeparatorChar + outputAudioFilename; UtilsInputFiles.FileDesc audioFileDesc = cardInfo.episodeInfo.AudioFileDesc; var audioStreamInfo = cardInfo.episodeInfo.AudioStreamInfo; String arguments = String.Format("-v quiet -y -i \"{0}\" -map 0:{1} -ss \"{2}\" -to \"{3}\" -vn -c:a libvorbis \"{4}\"", audioFileDesc.filename, // input file audioStreamInfo.StreamIndex, // audio stream index UtilsCommon.ToTimeArg(cardInfo.audioStartTimestamp), // start time UtilsCommon.ToTimeArg(cardInfo.audioEndTimestamp), // end time outputAudioFilepath // output file ); UtilsCommon.StartProcessAndGetOutput(InstanceSettings.systemSettings.formatConvertCommand, arguments); } }
public static void ExtractSnaphots(Settings settings, String path, List<Tuple<CardInfo, String>> allEntries, InfoProgress progress) { foreach(var entry in allEntries) { if(progress.Cancelled) break; progress.ProcessedSteps(1); var cardInfoNameTuple = entry; var cardInfo = cardInfoNameTuple.Item1; if(!cardInfo.HasImage()) continue; // create file at given path String outputSnapshotFilename = cardInfoNameTuple.Item2; String outputSnapshotFilepath = path + Path.DirectorySeparatorChar + outputSnapshotFilename; // get file with snapshot information -> video UtilsInputFiles.FileDesc videoFileDesc = cardInfo.episodeInfo.VideoFileDesc; // extract image double scaling = UtilsVideo.GetMaxScalingByStreamInfo(cardInfo.episodeInfo.VideoStreamInfo, settings.RescaleWidth, settings.RescaleHeight, settings.RescaleMode); double timeStamp = UtilsCommon.GetMiddleTime (cardInfo); UtilsImage.GetImage (videoFileDesc.filename, timeStamp, outputSnapshotFilepath, scaling); } }
public static void ExtractAudio(Settings settings, String path, List<Tuple<CardInfo, String>> allEntries, InfoProgress progress) { foreach(var entry in allEntries) { progress.ProcessedSteps(1); if(progress.Cancelled) return; CardInfo cardInfo = entry.Item1; if(!cardInfo.HasAudio()) continue; String outputAudioFilename = entry.Item2; String outputAudioFilepath = path + Path.DirectorySeparatorChar + outputAudioFilename; UtilsInputFiles.FileDesc audioFileDesc = cardInfo.episodeInfo.AudioFileDesc; var audioStreamInfo = cardInfo.episodeInfo.AudioStreamInfo; String arguments = String.Format ("-v quiet -y -i \"{0}\" -map 0:{1} -ss \"{2}\" -to \"{3}\" -vn -c:a libvorbis \"{4}\"", audioFileDesc.filename, // input file audioStreamInfo.StreamIndex, // audio stream index UtilsCommon.ToTimeArg(cardInfo.audioStartTimestamp), // start time UtilsCommon.ToTimeArg(cardInfo.audioEndTimestamp), // end time outputAudioFilepath // output file ); UtilsCommon.StartProcessAndGetOutput(InstanceSettings.systemSettings.formatConvertCommand, arguments); } }
public void ExportData(Settings settings, InfoProgress progressInfo) { var activeCardList = GetActiveCards(); progressInfo.AddSection("Exporting text file", 1); progressInfo.AddSection("Exporting snapshots", activeCardList.Count); progressInfo.AddSection("Exporting audio files", activeCardList.Count); if (settings.NormalizeAudio) { progressInfo.AddSection("Normalize audio files", activeCardList.Count); } progressInfo.Update(); ExportTextFile(activeCardList, settings, progressInfo); progressInfo.ProcessedSteps(1); var cardSnapshotNameTupleList = new List <Tuple <CardInfo, String> >(activeCardList.Count); var cardAudioNameTupleList = new List <Tuple <CardInfo, String> >(activeCardList.Count); foreach (var cardInfo in activeCardList) { cardSnapshotNameTupleList.Add(new Tuple <CardInfo, String>(cardInfo, GetSnapshotFileName(settings, cardInfo))); cardAudioNameTupleList.Add(new Tuple <CardInfo, String>(cardInfo, GetAudioFileName(settings, cardInfo))); } if (progressInfo.Cancelled) { return; } // extract images String snapshotsPath = settings.OutputDirectoryPath + Path.DirectorySeparatorChar + settings.DeckName + "_snapshots" + Path.DirectorySeparatorChar; UtilsCommon.ClearDirectory(snapshotsPath); WorkerSnapshot.ExtractSnaphots(settings, snapshotsPath, cardSnapshotNameTupleList, progressInfo); if (progressInfo.Cancelled) { return; } // extract audio String audioPath = settings.OutputDirectoryPath + Path.DirectorySeparatorChar + settings.DeckName + "_audio" + Path.DirectorySeparatorChar; UtilsCommon.ClearDirectory(audioPath); WorkerAudio.ExtractAudio(settings, audioPath, cardAudioNameTupleList, progressInfo); if (progressInfo.Cancelled) { return; } if (settings.NormalizeAudio) { // normalize all audio files foreach (var entry in cardAudioNameTupleList) { if (progressInfo.Cancelled) { return; } progressInfo.ProcessedSteps(1); var cardInfo = entry.Item1; if (!cardInfo.HasAudio()) { continue; } var filepath = audioPath + entry.Item2; var audioStreamInfos = StreamInfo.ReadAllStreams(filepath); audioStreamInfos.RemoveAll(streamInfo => streamInfo.StreamTypeValue != StreamInfo.StreamType.ST_AUDIO); if (audioStreamInfos.Count != 1) { Console.WriteLine("Skipped normalizing file \"{0}\" because it contains {1} audio streams", filepath, audioStreamInfos.Count); continue; } try { UtilsAudio.NormalizeAudio(filepath, audioStreamInfos[0]); } catch (Exception e) { Console.WriteLine(e.ToString()); continue; } } } }
public void ExportData(Settings settings, InfoProgress progressInfo) { var activeCardList = GetActiveCards(); progressInfo.AddSection("Exporting text file", 1); progressInfo.AddSection("Exporting snapshots", activeCardList.Count); progressInfo.AddSection("Exporting audio files", activeCardList.Count); if(settings.NormalizeAudio) progressInfo.AddSection("Normalize audio files", activeCardList.Count); progressInfo.Update(); ExportTextFile(activeCardList, settings, progressInfo); progressInfo.ProcessedSteps(1); var cardSnapshotNameTupleList = new List<Tuple<CardInfo, String>>(activeCardList.Count); var cardAudioNameTupleList = new List<Tuple<CardInfo, String>>(activeCardList.Count); foreach(var cardInfo in activeCardList) { cardSnapshotNameTupleList.Add(new Tuple<CardInfo, String>(cardInfo, GetSnapshotFileName(settings, cardInfo))); cardAudioNameTupleList.Add(new Tuple<CardInfo, String>(cardInfo, GetAudioFileName(settings, cardInfo))); } if(progressInfo.Cancelled) return; // extract images String snapshotsPath = settings.OutputDirectoryPath + Path.DirectorySeparatorChar + settings.DeckName + "_snapshots" + Path.DirectorySeparatorChar; UtilsCommon.ClearDirectory(snapshotsPath); WorkerSnapshot.ExtractSnaphots(settings, snapshotsPath, cardSnapshotNameTupleList, progressInfo); if(progressInfo.Cancelled) return; // extract audio String audioPath = settings.OutputDirectoryPath + Path.DirectorySeparatorChar + settings.DeckName + "_audio" + Path.DirectorySeparatorChar; UtilsCommon.ClearDirectory(audioPath); WorkerAudio.ExtractAudio(settings, audioPath, cardAudioNameTupleList, progressInfo); if(progressInfo.Cancelled) return; if(settings.NormalizeAudio) { // normalize all audio files foreach(var entry in cardAudioNameTupleList) { if(progressInfo.Cancelled) return; progressInfo.ProcessedSteps(1); var cardInfo = entry.Item1; if(!cardInfo.HasAudio()) continue; var filepath = audioPath + entry.Item2; var audioStreamInfos = StreamInfo.ReadAllStreams(filepath); audioStreamInfos.RemoveAll(streamInfo => streamInfo.StreamTypeValue != StreamInfo.StreamType.ST_AUDIO); if(audioStreamInfos.Count != 1) { Console.WriteLine("Skipped normalizing file \"{0}\" because it contains {1} audio streams", filepath, audioStreamInfos.Count); continue; } try { UtilsAudio.NormalizeAudio(filepath, audioStreamInfos[0]); } catch(Exception e) { Console.WriteLine(e.ToString()); continue; } } } }
/// <summary> /// Reads all subtitle files. /// </summary> /// <returns>Every entry in the outer list refers to exactly one subtitle file and for every file there is a list of all lines in it.</returns> /// <param name="settings">Settings.</param> /// <param name="attributedFilePaths">Attributed file path string.</param> private static List<List<LineInfo>> ReadAllSubtitleFiles (Settings settings, PerSubtitleSettings thisSubtitleSettings, List<EpisodeInfo> episodeInfos, int subtileIndex, InfoProgress progressInfo) { // read all lines in every subtitle file List<List<LineInfo>> lineInfosPerEpisode = new List<List<LineInfo>> (); foreach (EpisodeInfo episodeInfo in episodeInfos) { UtilsInputFiles.FileDesc fileDesc = episodeInfo.SubsFileDesc [subtileIndex]; if (fileDesc == null || String.IsNullOrWhiteSpace (fileDesc.filename)) lineInfosPerEpisode.Add (null); else lineInfosPerEpisode.Add (UtilsSubtitle.ParseSubtitleWithPostProcessing (settings, thisSubtitleSettings, fileDesc.filename, fileDesc.properties)); progressInfo.ProcessedSteps (1); if (progressInfo.Cancelled) return null; } return lineInfosPerEpisode; }
/// <summary> /// This reads all subtitles, matches them and saves them to the "m_cardInfos" /// </summary> /// <param name="settings">Settings.</param> private static List<CardInfo> GenerateCardInfo(Settings settings, List<EpisodeInfo> episodeInfos, InfoProgress progressInfo) { // read subtitles List<List<LineInfo>> lineInfosPerEpisode_TargetLanguage = ReadAllSubtitleFiles(settings, settings.PerSubtitleSettings[0], episodeInfos, 0, progressInfo); List<List<LineInfo>> lineInfosPerEpisode_NativeLanguage = ReadAllSubtitleFiles(settings, settings.PerSubtitleSettings[1], episodeInfos, 1, progressInfo); if (progressInfo.Cancelled) return null; List<CardInfo> allCardInfos = new List<CardInfo> (); for(int episodeIndex = 0; episodeIndex < lineInfosPerEpisode_TargetLanguage.Count; episodeIndex++) { List<LineInfo> list1 = lineInfosPerEpisode_TargetLanguage[episodeIndex]; List<LineInfo> list2 = lineInfosPerEpisode_NativeLanguage[episodeIndex]; var episodeInfo = episodeInfos[episodeIndex]; if(episodeInfo.HasSub2()) { // make sure that "other" subtitle has been shifted when aligning "this" subtitle to it if(settings.PerSubtitleSettings[0].AlignMode == PerSubtitleSettings.AlignModes.ToSubtitle) { UtilsCommon.AlignSub(list2, list1, episodeInfo, settings, settings.PerSubtitleSettings[1]); UtilsCommon.AlignSub(list1, list2, episodeInfo, settings, settings.PerSubtitleSettings[0]); } else { UtilsCommon.AlignSub(list1, list2, episodeInfo, settings, settings.PerSubtitleSettings[0]); UtilsCommon.AlignSub(list2, list1, episodeInfo, settings, settings.PerSubtitleSettings[1]); } var subtitleMatcherParameters = SubtitleMatcher.GetParameterCache (list1, list2); var matchedLinesList = SubtitleMatcher.MatchSubtitles(subtitleMatcherParameters); var thisEpisodeCardInfos = UtilsSubtitle.GetCardInfo(settings, episodeInfo, matchedLinesList); allCardInfos.AddRange(thisEpisodeCardInfos); } else { UtilsCommon.AlignSub(list1, list2, episodeInfo, settings, settings.PerSubtitleSettings[0]); allCardInfos.AddRange(UtilsSubtitle.GetCardInfo(settings, episodeInfo, list1)); } progressInfo.ProcessedSteps (1); if (progressInfo.Cancelled) return null; } return allCardInfos; }
private void ComputationThread(Settings settings) { InfoProgress progressInfo = new InfoProgress(ProgressHandler); m_progressAndCancellable = progressInfo; // find sub1, sub2, audio and video file per episode var episodeInfo = new List<EpisodeInfo>(); episodeInfo.AddRange(GenerateEpisodeInfos(settings)); // fill in progress sections for(int i = 0; i < episodeInfo.Count; i++) progressInfo.AddSection(String.Format("Episode {0:00.}: Extracting Sub1", i + 1), 1); for(int i = 0; i < episodeInfo.Count; i++) progressInfo.AddSection(String.Format("Episode {0:00.}: Extracting Sub2", i + 1), 1); for(int i = 0; i < episodeInfo.Count; i++) progressInfo.AddSection(String.Format("Episode {0:00.}: Matching subtitles", i + 1), 1); progressInfo.AddSection("Preparing data presentation", 1); progressInfo.StartProgressing(); // read all sub-files, match them and create a list for user that can be presented in preview window var cardInfos = new List<CardInfo>(); cardInfos.AddRange(GenerateCardInfo(settings, episodeInfo, progressInfo) ?? new List<CardInfo>()); m_previewListModel = new PreviewListModel(cardInfos); if(!progressInfo.Cancelled) { // finish this last step progressInfo.ProcessedSteps(1); PopulatePreviewList(); } // close progress window, free pending operation variable CloseProgressWindow (); }