private bool DoEncode() { try { if (!Directory.Exists(settings.workingDir)) { logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory")); if (!silent) Global.ErrorMsg(Global.Res("ErrorWorkingDirectory")); return false; } if (settings.encodedMovieDir != "") { if (!Directory.Exists(settings.encodedMovieDir)) { logWindow.MessageDemux(Global.Res("ErrorEncodedMovieDirectory")); if (!silent) Global.ErrorMsg(Global.Res("ErrorEncodedMovieDirectory")); return false; } } if (demuxedStreamList.streams.Count == 0) { logWindow.MessageSubtitle(Global.Res("ErrorNoDemuxedStreams")); if (!silent) Global.ErrorMsg(Global.Res("ErrorNoDemuxedStreams")); return false; } VideoFileInfo vfi = null; StreamInfo vsi = null; bool suptitle = false; bool suptitleForced = false; StreamInfo ssi = null; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Video) { vsi = si; if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { vfi = (VideoFileInfo)si.extraFileInfo; } } else if (si.streamType == StreamType.Subtitle) { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) { if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle) { // take first hardcode track if (!suptitle) { suptitle = true; suptitleForced = ((AdvancedSubtitleOptions)si.advancedOptions).supTitleOnlyForced; ssi = si; } } } } } if (vfi == null || vfi.cropInfo == null) { logWindow.MessageEncode(Global.Res("ErrorCropInfoNotSet")); if (!silent) Global.ErrorMsg(Global.Res("ErrorCropInfoNotSet")); return false; } else { vfi.encodeAvs = settings.workingDir + "\\" + settings.filePrefix + "_encode.avs"; string filename = vsi.filename; CropInfo cropInfo = vfi.cropInfo; logWindow.MessageEncode(""); logWindow.MessageEncode(Global.ResFormat("InfoCropTop", cropInfo.cropTop)); logWindow.MessageEncode(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom)); if (cropInfo.border) { logWindow.MessageEncode(Global.ResFormat("InfoBorderTop", cropInfo.borderTop)); logWindow.MessageEncode(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom)); } if (cropInfo.resize) { logWindow.MessageEncode(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY)); } string encode = ""; if (suptitle) { if (File.Exists(settings.suptitlePath)) { encode += "LoadPlugin(\"" + settings.suptitlePath + "\")\r\n"; } } if (settings.encodeInput == 0) { encode = "DirectShowSource(\"" + filename + "\")\r\n"; } else if (settings.encodeInput == 1) { string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath); if (File.Exists(dlldir + "\\ffms2.dll")) { encode += "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n"; } encode += "FFVideoSource(\"" + filename + "\")\r\n"; } else if (settings.encodeInput == 2) { string output = System.IO.Path.ChangeExtension(filename, "dgi"); string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath); if (File.Exists(dlldir + "\\DGDecodeNV.dll")) { encode += "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n"; } encode += "DGSource(\"" + output + "\")\r\n"; } if (cropInfo.cropTop != 0 || cropInfo.cropBottom != 0) { encode += "Crop(0," + cropInfo.cropTop.ToString() + ",-0,-" + cropInfo.cropBottom.ToString() + ")\r\n"; } if (cropInfo.border) { encode += "AddBorders(0," + cropInfo.borderTop + ",0," + cropInfo.borderBottom + ")\r\n"; } else { logWindow.MessageEncode(Global.Res("InfoNoBorder")); } if (suptitle && ssi != null) { if (!suptitleForced) { if (File.Exists(ssi.filename)) { string forced = "false"; encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" + forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," + cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n"; } } else { if (File.Exists(ssi.filename)) { string forced = "true"; encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" + forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," + cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n"; } } } if (cropInfo.resize) { if (cropInfo.resizeMethod > -1 && cropInfo.resizeMethod < GlobalVars.resizeMethods.Count) { encode += GlobalVars.resizeMethods[cropInfo.resizeMethod] + "(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n"; } else { encode += "LanczosResize(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n"; } } else { logWindow.MessageEncode(Global.Res("InfoNoResize")); } int index = settings.lastAvisynthProfile; if (index > -1 && index < settings.avisynthSettings.Count) { string[] tmp = settings.avisynthSettings[index].commands.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in tmp) { encode += s.Trim() + "\r\n"; } } File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_encode.avs", encode); logWindow.MessageEncode(""); logWindow.MessageEncode(Global.Res("InfoAvsContent")); logWindow.MessageEncode(""); string[] tmpstr2 = encode.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in tmpstr2) { logWindow.MessageEncode(s); } } if (vfi == null || vfi.encodeAvs == "") { logWindow.MessageEncode(Global.Res("ErrorEncodeAvsNotSet")); if (!silent) Global.ErrorMsg(Global.Res("ErrorEncodeAvsNotSet")); //return false; } int profile = settings.lastProfile; if (profile < 0) { logWindow.MessageEncode(Global.Res("ErrorEncodingProfileNotSet")); if (!silent) Global.ErrorMsg(Global.Res("ErrorEncodingProfileNotSet")); return false; } UpdateStatus(Global.Res("StatusBar") + " " + Global.ResFormat("StatusBarEncode", "")); DisableControls(); lastMsg = ""; secondPass = false; if (settings.use64bit && GetMaxFrames() > 0) { if (!settings.encodingSettings[profile].pass2) { maxProgressValue = GetMaxFrames(); } else { maxProgressValue = 2 * GetMaxFrames(); } progressBarMain.IsIndeterminate = false; progressBarMain.Maximum = 100; progressBarMain.Minimum = 0; } else if (!settings.use64bit) { if (!settings.encodingSettings[profile].pass2) { maxProgressValue = 100; } else { maxProgressValue = 200; } progressBarMain.IsIndeterminate = false; progressBarMain.Maximum = 100; progressBarMain.Minimum = 0; } UpdateStatusBar(0); et = new EncodeTool(settings, demuxedStreamList, profile, false, vfi); et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg); et.OnLogMsg += new ExternalTool.LogEventHandler(EncodeMsg); et.Start(); et.WaitForExit(); if (et == null || !et.Successfull) { vfi.encodedFile = ""; logWindow.MessageEncode(Global.Res("ErrorEncodeFailed")); return false; } if (settings.encodingSettings[profile].pass2) { secondPass = true; et = new EncodeTool(settings, demuxedStreamList, profile, true, vfi); et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg); et.OnLogMsg += new ExternalTool.LogEventHandler(EncodeMsg); et.Start(); et.WaitForExit(); if (et == null || !et.Successfull) { vfi.encodedFile = ""; logWindow.MessageEncode(Global.Res("ErrorEncode2passFailed")); return false; } } return true; } catch (Exception ex) { logWindow.MessageEncode(Global.Res("ErrorException") + " " + ex.Message); return false; } finally { progressBarMain.IsIndeterminate = true; if (isWindows7) { WPFExtensions.SetTaskbarProgressState(this, Windows7Taskbar.ThumbnailProgressState.NoProgress); } TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); EnableControls(); UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady")); } }
public void UpdateBitrate() { try { if (settings.lastProfile > -1 && settings.lastProfile < settings.encodingSettings.Count && !settings.untouchedVideo) { EncodingSettings es = settings.encodingSettings[settings.lastProfile]; VideoFileInfo vfi = null; if (demuxedStreamList.streams.Count > 0) { foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Video && si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { vfi = new VideoFileInfo(si.extraFileInfo); break; } } } if (es.pass2 && vfi != null) { EncodeTool etTmp = new EncodeTool(settings, demuxedStreamList, settings.lastProfile, false, vfi); double size = etTmp.Get2passSizeValue(); if (size == 0) { labelBitrate.Visibility = System.Windows.Visibility.Hidden; } else { labelBitrate.Visibility = System.Windows.Visibility.Visible; if (es.sizeType == SizeType.Size) { labelBitrate.Content = Global.ResFormat("InfoExpectedBitrate", size); } else if (es.sizeType == SizeType.Bitrate) { labelBitrate.Content = Global.ResFormat("InfoExpectedSize", (size / 1024 / 1024).ToString("f2")); } } } else { labelBitrate.Visibility = System.Windows.Visibility.Hidden; } } else { labelBitrate.Visibility = System.Windows.Visibility.Hidden; } } catch (Exception) { } }
private bool DoEncode() { try { if (!Directory.Exists(settings.workingDir)) { logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorWorkingDirectory")); } return(false); } if (settings.encodedMovieDir != "") { if (!Directory.Exists(settings.encodedMovieDir)) { logWindow.MessageDemux(Global.Res("ErrorEncodedMovieDirectory")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorEncodedMovieDirectory")); } return(false); } } if (demuxedStreamList.streams.Count == 0) { logWindow.MessageSubtitle(Global.Res("ErrorNoDemuxedStreams")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorNoDemuxedStreams")); } return(false); } VideoFileInfo vfi = null; StreamInfo vsi = null; bool suptitle = false; bool suptitleForced = false; StreamInfo ssi = null; foreach (StreamInfo si in demuxedStreamList.streams) { if (si.streamType == StreamType.Video) { vsi = si; if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) { vfi = (VideoFileInfo)si.extraFileInfo; } } else if (si.streamType == StreamType.Subtitle) { if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) { if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle) { // take first hardcode track if (!suptitle) { suptitle = true; suptitleForced = ((AdvancedSubtitleOptions)si.advancedOptions).supTitleOnlyForced; ssi = si; } } } } } if (vfi == null || vfi.cropInfo == null) { logWindow.MessageEncode(Global.Res("ErrorCropInfoNotSet")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorCropInfoNotSet")); } return(false); } else { vfi.encodeAvs = settings.workingDir + "\\" + settings.filePrefix + "_encode.avs"; string filename = vsi.filename; CropInfo cropInfo = vfi.cropInfo; logWindow.MessageEncode(""); logWindow.MessageEncode(Global.ResFormat("InfoCropTop", cropInfo.cropTop)); logWindow.MessageEncode(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom)); if (cropInfo.border) { logWindow.MessageEncode(Global.ResFormat("InfoBorderTop", cropInfo.borderTop)); logWindow.MessageEncode(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom)); } if (cropInfo.resize) { logWindow.MessageEncode(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY)); } string encode = ""; if (suptitle) { if (File.Exists(settings.suptitlePath)) { encode += "LoadPlugin(\"" + settings.suptitlePath + "\")\r\n"; } } if (settings.encodeInput == 0) { encode = "DirectShowSource(\"" + filename + "\")\r\n"; } else if (settings.encodeInput == 1) { string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath); if (File.Exists(dlldir + "\\ffms2.dll")) { encode += "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n"; } encode += "FFVideoSource(\"" + filename + "\")\r\n"; } else if (settings.encodeInput == 2) { string output = System.IO.Path.ChangeExtension(filename, "dgi"); string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath); if (File.Exists(dlldir + "\\DGDecodeNV.dll")) { encode += "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n"; } encode += "DGSource(\"" + output + "\")\r\n"; } if (cropInfo.cropTop != 0 || cropInfo.cropBottom != 0) { encode += "Crop(0," + cropInfo.cropTop.ToString() + ",-0,-" + cropInfo.cropBottom.ToString() + ")\r\n"; } if (cropInfo.border) { encode += "AddBorders(0," + cropInfo.borderTop + ",0," + cropInfo.borderBottom + ")\r\n"; } else { logWindow.MessageEncode(Global.Res("InfoNoBorder")); } if (suptitle && ssi != null) { if (!suptitleForced) { if (File.Exists(ssi.filename)) { string forced = "false"; encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" + forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," + cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n"; } } else { if (File.Exists(ssi.filename)) { string forced = "true"; encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" + forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," + cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n"; } } } if (cropInfo.resize) { if (cropInfo.resizeMethod > -1 && cropInfo.resizeMethod < GlobalVars.resizeMethods.Count) { encode += GlobalVars.resizeMethods[cropInfo.resizeMethod] + "(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n"; } else { encode += "LanczosResize(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n"; } } else { logWindow.MessageEncode(Global.Res("InfoNoResize")); } int index = settings.lastAvisynthProfile; if (index > -1 && index < settings.avisynthSettings.Count) { string[] tmp = settings.avisynthSettings[index].commands.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in tmp) { encode += s.Trim() + "\r\n"; } } File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_encode.avs", encode); logWindow.MessageEncode(""); logWindow.MessageEncode(Global.Res("InfoAvsContent")); logWindow.MessageEncode(""); string[] tmpstr2 = encode.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in tmpstr2) { logWindow.MessageEncode(s); } } if (vfi == null || vfi.encodeAvs == "") { logWindow.MessageEncode(Global.Res("ErrorEncodeAvsNotSet")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorEncodeAvsNotSet")); } //return false; } int profile = settings.lastProfile; if (profile < 0) { logWindow.MessageEncode(Global.Res("ErrorEncodingProfileNotSet")); if (!silent) { Global.ErrorMsg(Global.Res("ErrorEncodingProfileNotSet")); } return(false); } UpdateStatus(Global.Res("StatusBar") + " " + Global.ResFormat("StatusBarEncode", "")); DisableControls(); lastMsg = ""; secondPass = false; if (settings.use64bit && GetMaxFrames() > 0) { if (!settings.encodingSettings[profile].pass2) { maxProgressValue = GetMaxFrames(); } else { maxProgressValue = 2 * GetMaxFrames(); } progressBarMain.IsIndeterminate = false; progressBarMain.Maximum = 100; progressBarMain.Minimum = 0; } else if (!settings.use64bit) { if (!settings.encodingSettings[profile].pass2) { maxProgressValue = 100; } else { maxProgressValue = 200; } progressBarMain.IsIndeterminate = false; progressBarMain.Maximum = 100; progressBarMain.Minimum = 0; } UpdateStatusBar(0); et = new EncodeTool(settings, demuxedStreamList, profile, false, vfi); et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg); et.OnLogMsg += new ExternalTool.LogEventHandler(EncodeMsg); et.Start(); et.WaitForExit(); if (et == null || !et.Successfull) { vfi.encodedFile = ""; logWindow.MessageEncode(Global.Res("ErrorEncodeFailed")); return(false); } if (settings.encodingSettings[profile].pass2) { secondPass = true; et = new EncodeTool(settings, demuxedStreamList, profile, true, vfi); et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg); et.OnLogMsg += new ExternalTool.LogEventHandler(EncodeMsg); et.Start(); et.WaitForExit(); if (et == null || !et.Successfull) { vfi.encodedFile = ""; logWindow.MessageEncode(Global.Res("ErrorEncode2passFailed")); return(false); } } return(true); } catch (Exception ex) { logWindow.MessageEncode(Global.Res("ErrorException") + " " + ex.Message); return(false); } finally { progressBarMain.IsIndeterminate = true; if (isWindows7) { WPFExtensions.SetTaskbarProgressState(this, Windows7Taskbar.ThumbnailProgressState.NoProgress); } TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml"); EnableControls(); UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady")); } }