private void buttonEditExtraInfo_Click(object sender, RoutedEventArgs e) { try { if (si.streamType == StreamType.Video) { VideoFileInfo vfi = new VideoFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { vfi = new VideoFileInfo(si.extraFileInfo); } EditVideoFileInfoWindow evfiw = new EditVideoFileInfoWindow(vfi); evfiw.ShowDialog(); if (evfiw.DialogResult == true) { si.extraFileInfo = new VideoFileInfo(evfiw.videoFileInfo); UpdateStatusInfo(); } } else if (si.streamType == StreamType.Subtitle) { SubtitleFileInfo sfi = new SubtitleFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { sfi = new SubtitleFileInfo(si.extraFileInfo); } EditSubtitleFileInfoWindow esfiw = new EditSubtitleFileInfoWindow(sfi); esfiw.ShowDialog(); if (esfiw.DialogResult == true) { si.extraFileInfo = new SubtitleFileInfo(esfiw.subtitleFileInfo); UpdateStatusInfo(); } } } catch (Exception) { } }
public EditSubtitleFileInfoWindow(SubtitleFileInfo sfi) { try { InitializeComponent(); this.sfi = new SubtitleFileInfo(sfi); textBoxForcedIdx.Text = sfi.forcedIdx; textBoxForcedIdxLowres.Text = sfi.forcedIdxLowRes; textBoxForcedSub.Text = sfi.forcedSub; textBoxForcedSubLowres.Text = sfi.forcedSubLowRes; textBoxForcedSup.Text = sfi.forcedSup; textBoxNormalIdx.Text = sfi.normalIdx; textBoxNormalIdxLowres.Text = sfi.normalIdxLowRes; textBoxNormalSub.Text = sfi.normalSub; textBoxNormalSubLowres.Text = sfi.normalSubLowRes; textBoxNormalSup.Text = sfi.normalSup; checkBoxIsSecond.IsChecked = sfi.isSecond; } catch (Exception) { } }
protected override void Process() { try { TitleInfo tmpList2 = new TitleInfo(); tmpList2.desc = streamList.desc; foreach (StreamInfo si in streamList.streams) { if (si.selected) { tmpList2.streams.Add(new StreamInfo(si)); } } //TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); // sort streamlist TitleInfo tmpList = new TitleInfo(); tmpList.desc = tmpList2.desc; // chapter first foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Chapter) { tmpList.streams.Add(new StreamInfo(si)); } } // video foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Video) { if (settings.untouchedVideo) { if (si.extraFileInfo.GetType() != typeof(VideoFileInfo)) { si.extraFileInfo = new VideoFileInfo(); } ((VideoFileInfo)si.extraFileInfo).encodedFile = si.filename; } tmpList.streams.Add(new StreamInfo(si)); } } // audio foreach (LanguageInfo li in settings.preferredAudioLanguages) { foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Audio) { if (si.language == li.language) { tmpList.streams.Add(new StreamInfo(si)); } } } } foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Audio) { if (!HasLanguage(si.language)) { tmpList.streams.Add(new StreamInfo(si)); } } } // subtitle foreach (LanguageInfo li in settings.preferredAudioLanguages) { foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Subtitle) { if (si.language == li.language) { tmpList.streams.Add(new StreamInfo(si)); } } } } foreach (StreamInfo si in tmpList2.streams) { if (si.streamType == StreamType.Subtitle) { if (!HasLanguage(si.language)) { tmpList.streams.Add(new StreamInfo(si)); } } } TitleInfo.SaveStreamInfoFile(tmpList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); foreach (StreamInfo si in tmpList.streams) demuxedStreamList.streams.Add(si); demuxedStreamList.desc = tmpList.desc; string res = Output; res = res.Replace("\b", ""); res = res.Replace("\r", ""); string[] tmp = res.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < tmp.Length; i++) { tmp[i] = tmp[i].Trim(); } for (int i = 0; i < tmp.Length; i++) { if (tmp[i].IndexOf("Subtitle track") != -1) { if (tmp[i].IndexOf("forced captions") != -1) { try { int startPos = tmp[i].IndexOf("Subtitle track") + 14; int endPos = tmp[i].IndexOf("contains", startPos); int subtitleNumber = Convert.ToInt32(tmp[i].Substring(startPos, endPos - startPos).Trim()); foreach (StreamInfo si in demuxedStreamList.streams) { if (si.number == subtitleNumber) { if (si.streamType == StreamType.Subtitle) { SubtitleFileInfo sfi = new SubtitleFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) sfi = new SubtitleFileInfo(si.extraFileInfo); sfi.containsForced = true; si.extraFileInfo = new SubtitleFileInfo(sfi); } } } } catch {} } } else if (tmp[i].IndexOf("Video track") != -1) { try { int startPos = tmp[i].IndexOf("Video track") + 11; int endPos = tmp[i].IndexOf("contains", startPos); int videoNumber = Convert.ToInt32(tmp[i].Substring(startPos, endPos - startPos).Trim()); startPos = tmp[i].IndexOf("contains") + 8; endPos = tmp[i].IndexOf("frames", startPos); string videoFrames = tmp[i].Substring(startPos, endPos - startPos).Trim(); foreach (StreamInfo si in demuxedStreamList.streams) { if (si.number == videoNumber) { if (si.streamType == StreamType.Video) { VideoFileInfo sfi = new VideoFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) sfi = new VideoFileInfo(si.extraFileInfo); sfi.frames = videoFrames; si.extraFileInfo = new VideoFileInfo(sfi); } } } } catch { } } } successfull = true; } catch (Exception) { } }
private long GetSize() { try { List <int> subsCount = new List <int>(); List <int> forcedSubsCount = new List <int>(); for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { subsCount.Add(0); forcedSubsCount.Add(0); } for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { subsCount[i] = 0; forcedSubsCount[i] = 0; } long totalSize = 0; foreach (StreamInfo si in titleInfo.streams) { if (si.streamType == StreamType.Audio) { try { FileInfo fi = new FileInfo(si.filename); totalSize += fi.Length; if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions)) { if (((AdvancedAudioOptions)si.advancedOptions).additionalAc3Track && ((AdvancedAudioOptions)si.advancedOptions).additionalFilename != "") { try { FileInfo fi2 = new FileInfo(((AdvancedAudioOptions)si.advancedOptions).additionalFilename); totalSize += fi2.Length; } catch (Exception) { } } } } catch (Exception) { } } else if (si.streamType == StreamType.Subtitle) { if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; long normalSize = 0; long forcedSize = 0; long normalSizeSup = 0; long forcedSizeSup = 0; long normalSizeLowres = 0; long forcedSizeLowres = 0; if (settings.muxUntouchedSubs) { if (!sfi.isSecond) { if (si.filename != "") { FileInfo fi = new FileInfo(si.filename); totalSize += fi.Length; } } } else { if (sfi.normalIdx != "" && sfi.normalSub != "") { try { FileInfo fi = new FileInfo(sfi.normalIdx); normalSize += fi.Length; fi = new FileInfo(sfi.normalSub); normalSize += fi.Length; } catch (Exception) { } } if (sfi.forcedIdx != "" && sfi.forcedSub != "") { try { FileInfo fi = new FileInfo(sfi.forcedIdx); forcedSize += fi.Length; fi = new FileInfo(sfi.forcedSub); forcedSize += fi.Length; } catch (Exception) { } } if (sfi.normalSup != "") { try { FileInfo fi = new FileInfo(sfi.normalSup); normalSizeSup += fi.Length; } catch (Exception) { } } if (sfi.forcedSup != "") { try { FileInfo fi = new FileInfo(sfi.forcedSup); forcedSizeSup += fi.Length; } catch (Exception) { } } if (sfi.normalIdxLowRes != "" && sfi.normalSubLowRes != "") { try { FileInfo fi = new FileInfo(sfi.normalIdxLowRes); normalSizeLowres += fi.Length; fi = new FileInfo(sfi.normalSubLowRes); normalSizeLowres += fi.Length; } catch (Exception) { } } if (sfi.forcedIdxLowRes != "" && sfi.forcedSubLowRes != "") { try { FileInfo fi = new FileInfo(sfi.forcedIdxLowRes); forcedSizeLowres += fi.Length; fi = new FileInfo(sfi.forcedSubLowRes); forcedSizeLowres += fi.Length; } catch (Exception) { } } // mux all subs if (settings.muxSubs == 1) { if (!settings.muxLowResSubs) { totalSize += normalSize; totalSize += forcedSize; } else { totalSize += normalSizeLowres; totalSize += forcedSizeLowres; } } // mux only forced else if (settings.muxSubs == 2) { if (!settings.muxLowResSubs) { totalSize += forcedSize; } else { totalSize += forcedSizeLowres; } } // only first normal/forced sub else if (settings.muxSubs == 3) { int lang = -1; for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { if (settings.preferredAudioLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (!settings.muxLowResSubs) { if (sfi.normalIdx != "") { if (subsCount[lang] == 0) { subsCount[lang]++; totalSize += normalSize; } } else if (sfi.forcedIdx != "") { if (forcedSubsCount[lang] == 0) { forcedSubsCount[lang]++; totalSize += forcedSize; } } } else { if (sfi.normalIdxLowRes != "") { if (subsCount[lang] == 0) { subsCount[lang]++; totalSize += normalSizeLowres; } } else if (sfi.forcedIdxLowRes != "") { if (forcedSubsCount[lang] == 0) { forcedSubsCount[lang]++; totalSize += forcedSizeLowres; } } } } } else if (settings.muxSubs == 4) { totalSize += normalSizeSup; totalSize += forcedSizeSup; } else if (settings.muxSubs == 5) { totalSize += forcedSizeSup; } else if (settings.muxSubs == 6) { int lang = -1; for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { if (settings.preferredAudioLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (sfi.normalSup != "") { if (subsCount[lang] == 0) { subsCount[lang]++; totalSize += normalSizeSup; } } else if (sfi.forcedSup != "") { if (forcedSubsCount[lang] == 0) { forcedSubsCount[lang]++; totalSize += forcedSizeSup; } } } } } } } } return(totalSize); } catch (Exception) { return(0); } }
private bool DoMux() { try { DoPlugin(PluginType.BeforeMux); int videoStream = 0; int audioStream = 0; int chapterStream = 0; int subtitleStream = 0; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Video) { if (si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { if (((VideoFileInfo)si.extraFileInfo).encodedFile != "") { if (File.Exists(((VideoFileInfo)si.extraFileInfo).encodedFile)) { videoStream++; } } } } else if (si.streamType == StreamType.Audio) { if (File.Exists(si.filename)) { audioStream++; } } else if (si.streamType == StreamType.Chapter) { chapterStream++; } else if (si.streamType == StreamType.Subtitle) { subtitleStream++; } } if (!Directory.Exists(settings.targetFolder)) { logWindow.MessageDemux(Global.Res("ErrorTargetDirectory")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorTargetDirectory")); } return(false); } if (videoStream == 0) { if (!silent) { Global.ErrorMsg(Global.Res("ErrorVideoFile")); } logWindow.MessageMux(Global.Res("ErrorVideoFile")); return(false); } if (audioStream == 0) { if (!silent) { Global.ErrorMsg(Global.Res("ErrorAudioFile")); } logWindow.MessageMux(Global.Res("ErrorAudioFile")); return(false); } if (chapterStream > 0) { bool error = false; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Chapter) { if (!File.Exists(si.filename)) { error = true; } } } if (error) { if (!silent) { Global.ErrorMsg(Global.Res("ErrorChapterFile")); } logWindow.MessageMux(Global.Res("ErrorChapterFile")); return(false); } } if (subtitleStream > 0) { bool error = false; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Subtitle) { if (si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; if (sfi.forcedIdx != "") { if (!File.Exists(sfi.forcedIdx)) { error = true; } } if (sfi.forcedSub != "") { if (!File.Exists(sfi.forcedSub)) { error = true; } } if (sfi.forcedSup != "") { if (!File.Exists(sfi.forcedSup)) { error = true; } } if (sfi.normalIdx != "") { if (!File.Exists(sfi.normalIdx)) { error = true; } } if (sfi.normalSub != "") { if (!File.Exists(sfi.normalSub)) { error = true; } } if (sfi.normalSup != "") { if (!File.Exists(sfi.normalSup)) { error = true; } } } else { error = false; } } } if (error) { if (!silent) { Global.ErrorMsg(Global.Res("ErrorSubtitleFile")); } logWindow.MessageMux(Global.Res("ErrorSubtitleFile")); return(false); } } progressBarMain.IsIndeterminate = false; progressBarMain.Maximum = 100; progressBarMain.Minimum = 0; maxProgressValue = 100; UpdateStatusBar(0); DisableControls(); UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarMux")); mt = new MuxTool(settings, demuxedStreamList); mt.OnInfoMsg += new ExternalTool.InfoEventHandler(MuxMsg); mt.OnLogMsg += new ExternalTool.LogEventHandler(MuxMsg); mt.Start(); mt.WaitForExit(); DoPlugin(PluginType.AfterMux); if (mt == null) { return(false); } else { return(mt.Successfull); } } catch (Exception ex) { logWindow.MessageMux(Global.Res("ErrorException") + " " + ex.Message); return(false); } finally { progressBarMain.IsIndeterminate = true; if (isWindows7) { WPFExtensions.SetTaskbarProgressState(this, Windows7Taskbar.ThumbnailProgressState.NoProgress); } EnableControls(); UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady")); } }
private bool DoSubtitle() { try { DoPlugin(PluginType.BeforeSubtitle); if (!Directory.Exists(settings.workingDir)) { logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorWorkingDirectory")); } return(false); } if (demuxedStreamList.streams.Count == 0) { logWindow.MessageSubtitle(Global.Res("ErrorNoDemuxedStreams")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorNoDemuxedStreams")); } return(false); } string fps = ""; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Video) { if (si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { fps = ((VideoFileInfo)si.extraFileInfo).fps; break; } } } if (fps == "") { logWindow.MessageSubtitle(Global.Res("ErrorSetFramerate")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorSetFramerate")); } return(false); } UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarSubtitle")); int subtitleCount = 0; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Subtitle) { subtitleCount++; if (si.extraFileInfo == null || si.extraFileInfo.GetType() != typeof(SubtitleFileInfo)) { si.extraFileInfo = new SubtitleFileInfo(); } } } if (subtitleCount == 0) { logWindow.MessageSubtitle(Global.Res("InfoNoSubtitles")); return(true); } bool suptitle = false; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Subtitle) { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) { if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle) { if (!suptitle) { suptitle = true; } } } } } int muxSubs = settings.muxSubs; if (suptitle) { muxSubs = 0; } // do not mux and copy subs if (muxSubs == 0 && settings.copySubs == 0) { logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing")); return(true); } // only untouched subs else if (settings.muxUntouchedSubs && settings.copyUntouchedSubs) { logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing")); return(true); } else if (settings.muxUntouchedSubs && settings.copySubs == 0) { logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing")); return(true); } else if (muxSubs == 0 && settings.copyUntouchedSubs) { logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing")); return(true); } DisableControls(); bool sub = false; bool sup = false; if (settings.muxSubs > 0 && settings.muxSubs < 4) { sub = true; } else if (settings.muxSubs >= 4) { sup = true; } if (settings.copySubs > 0 && settings.copySubs < 4) { sub = true; } else if (settings.copySubs >= 4) { sup = true; } bool error = false; int subtitle = 0; for (int i = 0; i < demuxedStreamList.streams.Count; i++) { if (demuxedStreamList.streams[i].streamType == StreamType.Subtitle) { if (demuxedStreamList.streams[i].extraFileInfo != null && demuxedStreamList.streams[i].extraFileInfo.GetType() == typeof(SubtitleFileInfo) && ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).isSecond) { continue; } subtitle++; StreamInfo si = demuxedStreamList.streams[i]; if (sub) { UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleNormal"), subtitle, subtitleCount)); st = new SubtitleTool(settings, fps, ref si, false, false, false); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleForced"), subtitle, subtitleCount)); st = new SubtitleTool(settings, fps, ref si, true, false, false); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } } if (sup) { UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleNormalPgs"), subtitle, subtitleCount)); st = new SubtitleTool(settings, fps, ref si, false, false, true); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleForcedPgs"), subtitle, subtitleCount)); st = new SubtitleTool(settings, fps, ref si, true, false, true); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } } if (settings.muxLowResSubs && (settings.muxSubs > 0 && settings.muxSubs < 4)) { UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleLowresNormal"), subtitle, subtitleCount)); si = demuxedStreamList.streams[i]; st = new SubtitleTool(settings, fps, ref si, false, true, false); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleLowresForced"), subtitle, subtitleCount)); st = new SubtitleTool(settings, fps, ref si, true, true, false); st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg); st.OnLogMsg += new ExternalTool.LogEventHandler(SubtitleMsg); st.Start(); st.WaitForExit(); if (st == null || !st.Successfull) { error = true; } } if (!error) { if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; if ((sfi.forcedIdx != "" && sfi.normalIdx != "") || (sfi.forcedSup != "" && sfi.normalSup != "")) { StreamInfo si2 = new StreamInfo(demuxedStreamList.streams[i]); if (demuxedStreamList.streams[i].extraFileInfo != null && demuxedStreamList.streams[i].extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedIdx = ""; ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSub = ""; ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSup = ""; ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedIdxLowRes = ""; ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSubLowRes = ""; ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).isSecond = false; } si2.desc += " (only forced)";; if (si2.extraFileInfo != null && si2.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { ((SubtitleFileInfo)si2.extraFileInfo).normalIdx = ""; ((SubtitleFileInfo)si2.extraFileInfo).normalSub = ""; ((SubtitleFileInfo)si2.extraFileInfo).normalSup = ""; ((SubtitleFileInfo)si2.extraFileInfo).normalIdxLowRes = ""; ((SubtitleFileInfo)si2.extraFileInfo).normalSubLowRes = ""; ((SubtitleFileInfo)si2.extraFileInfo).isSecond = true; } bool add = true; if (demuxedStreamList.streams.Count > i + 1) { if (demuxedStreamList.streams[i + 1].extraFileInfo != null && demuxedStreamList.streams[i + 1].extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo stfi = (SubtitleFileInfo)demuxedStreamList.streams[i + 1].extraFileInfo; if (stfi.normalIdx == ((SubtitleFileInfo)si2.extraFileInfo).normalIdx && stfi.normalSub == ((SubtitleFileInfo)si2.extraFileInfo).normalSub && stfi.normalSup == ((SubtitleFileInfo)si2.extraFileInfo).normalSup && stfi.normalIdxLowRes == ((SubtitleFileInfo)si2.extraFileInfo).normalIdxLowRes && stfi.normalSubLowRes == ((SubtitleFileInfo)si2.extraFileInfo).normalSubLowRes && stfi.forcedIdx == ((SubtitleFileInfo)si2.extraFileInfo).forcedIdx && stfi.forcedSub == ((SubtitleFileInfo)si2.extraFileInfo).forcedSub && stfi.forcedSup == ((SubtitleFileInfo)si2.extraFileInfo).forcedSup && stfi.forcedIdxLowRes == ((SubtitleFileInfo)si2.extraFileInfo).forcedIdxLowRes && stfi.forcedSubLowRes == ((SubtitleFileInfo)si2.extraFileInfo).forcedSubLowRes && demuxedStreamList.streams[i + 1].filename == si2.filename) { add = false; } } } if (add) { demuxedStreamList.streams.Insert(i + 1, si2); i++; } } // treat track as forced track even if it doesn't contain forced subs else if (sfi.normalIdx != "" || sfi.normalSup != "") { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) { if (((AdvancedSubtitleOptions)si.advancedOptions).isForced) { sfi.forcedIdx = sfi.normalIdx; sfi.forcedSub = sfi.normalSub; sfi.forcedSup = sfi.normalSup; sfi.forcedIdxLowRes = sfi.normalIdxLowRes; sfi.forcedSubLowRes = sfi.normalSubLowRes; sfi.normalIdx = ""; sfi.normalSub = ""; sfi.normalSup = ""; sfi.normalIdxLowRes = ""; sfi.normalSubLowRes = ""; } } } } } } demuxedStreamsWindow.UpdateDemuxedStreams(); } if (error) { logWindow.MessageSubtitle(Global.Res("ErrorSubtitle")); return(false); } DoPlugin(PluginType.AfterSubtitle); TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); demuxedStreamsWindow.UpdateDemuxedStreams(); return(true); } catch (Exception ex) { logWindow.MessageSubtitle(Global.Res("ErrorException") + " " + ex.Message); return(false); } finally { EnableControls(); UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady")); } }
protected override void Process() { try { if (si.extraFileInfo == null || si.extraFileInfo.GetType() != typeof(SubtitleFileInfo)) { si.extraFileInfo = new SubtitleFileInfo(); } SubtitleFileInfo sfi = null; sfi = (SubtitleFileInfo)si.extraFileInfo; if (!lowRes) { if (!onlyForced) { if (File.Exists(output)) { if (!pgs) { sfi.normalSub = output; } else { sfi.normalSup = output; } } if (File.Exists(outputIdx)) { if (!pgs) { sfi.normalIdx = outputIdx; } } } else { if (File.Exists(output)) { if (!pgs) { sfi.forcedSub = output; } else { sfi.forcedSup = output; } } if (File.Exists(outputIdx)) { if (!pgs) { sfi.forcedIdx = outputIdx; } } } try { if (sfi.normalIdx != "" && sfi.normalSub != "" && sfi.forcedIdx != "" && sfi.forcedSub != "") { FileInfo f1 = new FileInfo(sfi.normalSub); FileInfo f2 = new FileInfo(sfi.forcedSub); if (f1.Length == f2.Length) { File.Delete(sfi.normalSub); File.Delete(sfi.normalIdx); sfi.normalSub = ""; sfi.normalIdx = ""; } } if (sfi.normalSup != "" && sfi.forcedSup != "") { FileInfo f1 = new FileInfo(sfi.normalSup); FileInfo f2 = new FileInfo(sfi.forcedSup); if (f1.Length == f2.Length) { File.Delete(sfi.normalSup); sfi.normalSup = ""; } } successfull = true; } catch (Exception ex) { Info("Exception: " + ex.Message); } } else { if (!onlyForced) { if (File.Exists(output)) { sfi.normalSubLowRes = output; } if (File.Exists(outputIdx)) { sfi.normalIdxLowRes = outputIdx; } } else { if (File.Exists(output)) { sfi.forcedSubLowRes = output; } if (File.Exists(outputIdx)) { sfi.forcedIdxLowRes = outputIdx; } } try { if (sfi.normalIdxLowRes != "" && sfi.normalSubLowRes != "" && sfi.forcedIdxLowRes != "" && sfi.forcedSubLowRes != "") { FileInfo f1 = new FileInfo(sfi.normalSubLowRes); FileInfo f2 = new FileInfo(sfi.forcedSubLowRes); if (f1.Length == f2.Length) { File.Delete(sfi.normalSubLowRes); File.Delete(sfi.normalIdxLowRes); sfi.normalSubLowRes = ""; sfi.normalIdxLowRes = ""; } } successfull = true; } catch (Exception ex) { Info("Exception: " + ex.Message); } } } catch (Exception) { } }
private void buttonEditExtraInfo_Click(object sender, RoutedEventArgs e) { try { if (si.streamType == StreamType.Video) { VideoFileInfo vfi = new VideoFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) vfi = new VideoFileInfo(si.extraFileInfo); EditVideoFileInfoWindow evfiw = new EditVideoFileInfoWindow(vfi); evfiw.ShowDialog(); if (evfiw.DialogResult == true) { si.extraFileInfo = new VideoFileInfo(evfiw.videoFileInfo); UpdateStatusInfo(); } } else if (si.streamType == StreamType.Subtitle) { SubtitleFileInfo sfi = new SubtitleFileInfo(); if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) sfi = new SubtitleFileInfo(si.extraFileInfo); EditSubtitleFileInfoWindow esfiw = new EditSubtitleFileInfoWindow(sfi); esfiw.ShowDialog(); if (esfiw.DialogResult == true) { si.extraFileInfo = new SubtitleFileInfo(esfiw.subtitleFileInfo); UpdateStatusInfo(); } } } catch (Exception) { } }
protected override void Process() { try { List <int> subsCount = new List <int>(); List <int> forcedSubsCount = new List <int>(); for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { subsCount.Add(0); forcedSubsCount.Add(0); } for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { subsCount[i] = 0; forcedSubsCount[i] = 0; } if (settings.copySubs > 0 || settings.copyUntouchedSubs) { Info("Trying to copy subtitles..."); try { if (!Directory.Exists(settings.targetFolder + "\\Subs")) { Directory.CreateDirectory(settings.targetFolder + "\\Subs"); } } catch (Exception ex) { Info("Exception: " + ex.Message); } int sub = 1; int undefCount = 0; int undefForcedCount = 0; foreach (StreamInfo si in titleInfo.streams) { if (si.streamType == StreamType.Subtitle) { if (si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; bool copy = false; bool pgs = false; bool untouched = false; bool subidx = false; bool isForced = false; if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions) && ((AdvancedSubtitleOptions)si.advancedOptions).isForced) { isForced = true; } if (settings.copyUntouchedSubs) { if (!sfi.isSecond) { copy = true; untouched = true; } } if (settings.copySubs == 1) { copy = true; subidx = true; } else if (settings.copySubs == 2) { if (sfi.normalIdx != "") { copy = true; subidx = true; } } else if (settings.copySubs == 3) { int lang = -1; for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { if (settings.preferredAudioLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (sfi.normalIdx != "") { if (subsCount[lang] == 0) { copy = true; subidx = true; subsCount[lang]++; } } else if (sfi.forcedIdx != "") { if (forcedSubsCount[lang] == 0) { copy = true; subidx = true; forcedSubsCount[lang]++; } } } if (si.language == "undef") { if (sfi.normalIdx != "") { if (undefCount == 0) { copy = true; subidx = true; undefCount++; } } else if (sfi.forcedIdx != "") { if (undefForcedCount == 0) { copy = true; subidx = true; undefForcedCount++; } } } } else if (settings.copySubs == 4) { copy = true; pgs = true; } else if (settings.copySubs == 5) { if (sfi.normalSup != "") { copy = true; pgs = true; } } else if (settings.copySubs == 6) { int lang = -1; for (int i = 0; i < settings.preferredAudioLanguages.Count; i++) { if (settings.preferredAudioLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (sfi.normalSup != "") { if (subsCount[lang] == 0) { copy = true; pgs = true; subsCount[lang]++; } } else if (sfi.forcedSup != "") { if (forcedSubsCount[lang] == 0) { copy = true; pgs = true; forcedSubsCount[lang]++; } } } if (si.language == "undef") { if (sfi.normalSub != "") { if (undefCount == 0) { copy = true; pgs = true; undefCount++; } } else if (sfi.forcedSup != "") { if (undefForcedCount == 0) { copy = true; pgs = true; undefForcedCount++; } } } } if (copy) { try { string target = settings.targetFolder + "\\Subs\\" + settings.targetFilename; if (untouched) { if (si.filename != "") { if (File.Exists(si.filename)) { File.Copy(si.filename, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_original_pgs.sup", true); } } } if (!pgs && subidx) { if (sfi.normalIdx != "" && !isForced) { if (File.Exists(sfi.normalIdx)) { File.Copy(sfi.normalIdx, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + ".idx", true); } if (File.Exists(sfi.normalSub)) { File.Copy(sfi.normalSub, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + ".sub", true); } } else if (sfi.forcedIdx != "") { if (File.Exists(sfi.forcedIdx)) { File.Copy(sfi.forcedIdx, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced.idx", true); } if (File.Exists(sfi.forcedSub)) { File.Copy(sfi.forcedSub, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced.sub", true); } } else if (sfi.normalIdx != "" && isForced) { if (File.Exists(sfi.normalIdx)) { File.Copy(sfi.normalIdx, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced.idx", true); } if (File.Exists(sfi.normalSub)) { File.Copy(sfi.normalSub, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced.sub", true); } } } else if (pgs) { if (sfi.normalSup != "" && !isForced) { if (File.Exists(sfi.normalSup)) { File.Copy(sfi.normalSup, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_pgs.sup", true); } } else if (sfi.forcedSup != "") { if (File.Exists(sfi.forcedSup)) { File.Copy(sfi.forcedSup, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced_pgs.sup", true); } } else if (sfi.normalSup != "" && isForced) { if (File.Exists(sfi.normalSup)) { File.Copy(sfi.normalSup, target + "_" + sub.ToString("d2") + "_" + si.language.ToLower() + "_forced_pgs.sup", true); } } } } catch (Exception ex) { Info("Exception: " + ex.Message); } sub++; } } } } Info("Done."); } if (settings.deleteAfterEncode) { Info("Deleting source files..."); string filename = ""; foreach (StreamInfo si in titleInfo.streams) { try { if (File.Exists(si.filename)) { File.Delete(si.filename); } if (si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { if (File.Exists(((VideoFileInfo)si.extraFileInfo).encodedFile)) { File.Delete(((VideoFileInfo)si.extraFileInfo).encodedFile); } if (File.Exists(((VideoFileInfo)si.extraFileInfo).encodeAvs)) { File.Delete(((VideoFileInfo)si.extraFileInfo).encodeAvs); } filename = si.filename; } if (si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; if (sfi.forcedIdx != "") { if (File.Exists(sfi.forcedIdx)) { File.Delete(sfi.forcedIdx); } } if (sfi.forcedSub != "") { if (File.Exists(sfi.forcedSub)) { File.Delete(sfi.forcedSub); } } if (sfi.forcedSup != "") { if (File.Exists(sfi.forcedSup)) { File.Delete(sfi.forcedSup); } } if (sfi.normalIdx != "") { if (File.Exists(sfi.normalIdx)) { File.Delete(sfi.normalIdx); } } if (sfi.normalSub != "") { if (File.Exists(sfi.normalSub)) { File.Delete(sfi.normalSub); } } if (sfi.normalSup != "") { if (File.Exists(sfi.normalSup)) { File.Delete(sfi.normalSup); } } if (sfi.forcedIdxLowRes != "") { if (File.Exists(sfi.forcedIdxLowRes)) { File.Delete(sfi.forcedIdxLowRes); } } if (sfi.forcedSubLowRes != "") { if (File.Exists(sfi.forcedSubLowRes)) { File.Delete(sfi.forcedSubLowRes); } } if (sfi.normalIdxLowRes != "") { if (File.Exists(sfi.normalIdxLowRes)) { File.Delete(sfi.normalIdxLowRes); } } if (sfi.normalSubLowRes != "") { if (File.Exists(sfi.normalSubLowRes)) { File.Delete(sfi.normalSubLowRes); } } } } catch (Exception ex) { Info("Exception: " + ex.Message); } } try { if (File.Exists(settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml")) { File.Delete(settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); } if (File.Exists(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs")) { File.Delete(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs"); } } catch (Exception ex) { Info("Exception: " + ex.Message); } // delete index files try { if (File.Exists(filename + ".ffindex")) { File.Delete(filename + ".ffindex"); } } catch (Exception) { } try { string output = System.IO.Path.ChangeExtension(filename, "dgi"); if (File.Exists(output)) { File.Delete(output); } } catch (Exception) { } Info("Done."); } } catch (Exception) { } }
public MuxTool(UserSettings settings, TitleInfo titleInfo) : base() { try { this.settings = settings; this.titleInfo = titleInfo; this.Path = settings.mkvmergePath; this.Parameter += "--title \"" + settings.movieTitle + "\" -o \"" + settings.targetFolder + "\\" + settings.targetFilename + ".mkv\" "; int trackId = 0; // video + chapter foreach (StreamInfo si in titleInfo.streams) { string lan = ""; if (settings.preferredAudioLanguages.Count > 0) { lan = settings.preferredAudioLanguages[0].languageShort; } if (si.streamType == StreamType.Chapter) { if (lan != "") { this.Parameter += "--chapter-language " + lan + " "; } this.Parameter += "--chapters \"" + si.filename + "\" "; } else if (si.streamType == StreamType.Video) { trackId++; if (settings.disableVideoHeaderCompression) { this.Parameter += headerCompression; } if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions)) { avo = new AdvancedVideoOptions(si.advancedOptions); } if (avo != null && avo.manualAspectRatio) { this.Parameter += "--aspect-ratio 0:" + avo.aspectRatio + " "; } if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { this.Parameter += "\"" + ((VideoFileInfo)si.extraFileInfo).encodedFile + "\" "; } } } // audio bool defaultSet = false; foreach (StreamInfo si in titleInfo.streams) { if (si.streamType == StreamType.Audio) { trackId++; string st = ""; st = getShortAudioLanguage(si.language); if (st != "") { this.Parameter += "--language 0" + ":" + st + " "; } if (settings.disableAudioHeaderCompression) { this.Parameter += headerCompression; } if (!settings.defaultSubtitle) { this.Parameter += "--default-track 0:no "; } if (settings.preferredAudioLanguages.Count > 0 && settings.preferredAudioLanguages[0].language == si.language) { if (!defaultSet) { if (settings.defaultAudio) { this.Parameter += "--default-track 0:yes "; } defaultSet = true; } } this.Parameter += "\"" + si.filename + "\" "; // add additional ac3 track if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions)) { AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions; if (aao.additionalAc3Track && File.Exists(aao.additionalFilename)) { trackId++; if (st != "") { this.Parameter += "--language 0" + ":" + st + " "; } if (settings.disableAudioHeaderCompression) { this.Parameter += headerCompression; } this.Parameter += "\"" + aao.additionalFilename + "\" "; } } if (settings.addAc3ToAllDts) { // check if already added by advanced audiooptions bool ac3Added = false; if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions) && ((AdvancedAudioOptions)si.advancedOptions).additionalAc3Track) { ac3Added = true; } if (!ac3Added) { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions)) { AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions; if (File.Exists(aao.additionalFilename)) { trackId++; if (st != "") { this.Parameter += "--language 0" + ":" + st + " "; } if (settings.disableAudioHeaderCompression) { this.Parameter += headerCompression; } this.Parameter += "\"" + aao.additionalFilename + "\" "; } } } } } } List <int> subsCount = new List <int>(); List <int> forcedSubsCount = new List <int>(); for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++) { subsCount.Add(0); forcedSubsCount.Add(0); } // hardcode subs? do not mux subtitles even if selected bool suptitle = false; foreach (StreamInfo si in titleInfo.streams) { if (si.streamType == StreamType.Subtitle) { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) { if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle) { if (!suptitle) { suptitle = true; } } } } } if ((settings.muxSubs > 0 || settings.muxUntouchedSubs) && !suptitle) { // subtitle defaultSet = false; foreach (StreamInfo si in titleInfo.streams) { if (si.streamType == StreamType.Subtitle) { SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo; bool isForced = false; if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions) && ((AdvancedSubtitleOptions)si.advancedOptions).isForced) { isForced = true; } bool mux = false; bool pgs = false; bool untouched = false; if (settings.muxUntouchedSubs) { if (!sfi.isSecond) { mux = true; untouched = true; } } else if (settings.muxSubs == 1) { mux = true; } else if (settings.muxSubs == 2) { if (sfi.forcedIdx != "") { mux = true; } } else if (settings.muxSubs == 3) { int lang = -1; for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++) { if (settings.preferredSubtitleLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (sfi.normalIdx != "") { if (subsCount[lang] == 0) { mux = true; subsCount[lang]++; } } else if (sfi.forcedIdx != "") { if (forcedSubsCount[lang] == 0) { mux = true; forcedSubsCount[lang]++; } } } } else if (settings.muxSubs == 4) { mux = true; pgs = true; } else if (settings.muxSubs == 5) { if (sfi.forcedSup != "") { mux = true; pgs = true; } } else if (settings.muxSubs == 6) { int lang = -1; for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++) { if (settings.preferredSubtitleLanguages[i].language == si.language) { lang = i; } } if (lang > -1) { if (sfi.normalSup != "") { if (subsCount[lang] == 0) { mux = true; pgs = true; subsCount[lang]++; } } else if (sfi.forcedSup != "") { if (forcedSubsCount[lang] == 0) { mux = true; pgs = true; forcedSubsCount[lang]++; } } } } if (mux) { trackId++; string st = ""; st = getShortSubLanguage(si.language); if (st != "") { this.Parameter += "--language 0" + ":" + st + " "; } if (settings.preferredSubtitleLanguages.Count > 0 && settings.preferredSubtitleLanguages[0].language == si.language) { if (!defaultSet) { if (settings.defaultSubtitle) { if (!settings.defaultSubtitleForced) { this.Parameter += "--default-track 0:yes "; defaultSet = true; } else { if (hasForcedSub(si.language)) { if (!untouched && !pgs) { if (sfi.forcedIdx != "") { this.Parameter += "--default-track 0 "; if (settings.defaultForcedFlag) { this.Parameter += "--forced-track 0 "; } defaultSet = true; } } else if (!untouched && pgs) { if (sfi.forcedSup != "") { this.Parameter += "--default-track 0 "; if (settings.defaultForcedFlag) { this.Parameter += "--forced-track 0 "; } defaultSet = true; } } } } } } } if (!settings.defaultSubtitle) { this.Parameter += "--default-track 0:no "; } if (untouched) { if (si.filename != "") { this.Parameter += "\"" + si.filename + "\" "; } } else if (!settings.muxLowResSubs && !pgs) { if (sfi.normalIdx != "" && !isForced) { this.Parameter += "\"" + sfi.normalIdx + "\" "; } else if (sfi.forcedIdx != "") { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.forcedIdx + "\" "; } else if (sfi.normalIdx != "" && isForced) { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.normalIdx + "\" "; } } else if (!settings.muxLowResSubs && pgs) { if (sfi.normalSup != "" && !isForced) { this.Parameter += "\"" + sfi.normalSup + "\" "; } else if (sfi.forcedSup != "") { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.forcedSup + "\" "; } else if (sfi.normalSup != "") { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.normalSup + "\" "; } } else { if (sfi.normalIdxLowRes != "" && !isForced) { this.Parameter += "\"" + sfi.normalIdxLowRes + "\" "; } else if (sfi.forcedIdxLowRes != "") { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.forcedIdxLowRes + "\" "; } else if (sfi.normalIdxLowRes != "" && isForced) { this.Parameter += " --track-name 0:Forced "; this.Parameter += "\"" + sfi.normalIdxLowRes + "\" "; } } } } } } } catch (Exception ex) { Info("Exception: " + ex.Message); } }