Пример #1
0
        public EditCropInfoWindow(CropInfo cropInfo)
        {
            try
            {
                InitializeComponent();
                this._cropInfo = new CropInfo(cropInfo);

                textBoxBorderBottom.Text = _cropInfo.borderBottom.ToString();
                textBoxBorderTop.Text = _cropInfo.borderTop.ToString();
                textBoxCropBottom.Text = _cropInfo.cropBottom.ToString();
                textBoxCropTop.Text = _cropInfo.cropTop.ToString();
                textBoxResizeX.Text = _cropInfo.resizeX.ToString();
                textBoxResizeY.Text = _cropInfo.resizeY.ToString();

                checkBoxAddBorders.IsChecked = _cropInfo.border;
                checkBoxResize.IsChecked = _cropInfo.resize;

                comboBoxResizeMethod.Items.Clear();
                foreach (string s in GlobalVars.resizeMethods) comboBoxResizeMethod.Items.Add(s);
                if (_cropInfo.resizeMethod > -1 && _cropInfo.resizeMethod < GlobalVars.resizeMethods.Count) comboBoxResizeMethod.SelectedIndex = _cropInfo.resizeMethod;
            }
            catch (Exception ex)
            {
                Global.ErrorMsg(ex);
            }
            
        }
Пример #2
0
        public EditCropInfoWindow(CropInfo cropInfo)
        {
            try
            {
                InitializeComponent();
                this._cropInfo = new CropInfo(cropInfo);

                textBoxBorderBottom.Text = _cropInfo.borderBottom.ToString();
                textBoxBorderTop.Text    = _cropInfo.borderTop.ToString();
                textBoxCropBottom.Text   = _cropInfo.cropBottom.ToString();
                textBoxCropTop.Text      = _cropInfo.cropTop.ToString();
                textBoxResizeX.Text      = _cropInfo.resizeX.ToString();
                textBoxResizeY.Text      = _cropInfo.resizeY.ToString();

                checkBoxAddBorders.IsChecked = _cropInfo.border;
                checkBoxResize.IsChecked     = _cropInfo.resize;

                comboBoxResizeMethod.Items.Clear();
                foreach (string s in GlobalVars.resizeMethods)
                {
                    comboBoxResizeMethod.Items.Add(s);
                }
                if (_cropInfo.resizeMethod > -1 && _cropInfo.resizeMethod < GlobalVars.resizeMethods.Count)
                {
                    comboBoxResizeMethod.SelectedIndex = _cropInfo.resizeMethod;
                }
            }
            catch (Exception ex)
            {
                Global.ErrorMsg(ex);
            }
        }
Пример #3
0
 private void buttonEditCropInfo_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         CropInfo cropInfo = null;
         if (vfi.cropInfo != null && vfi.cropInfo.GetType() == typeof(CropInfo))
         {
             cropInfo = new CropInfo(vfi.cropInfo);
         }
         else
         {
             cropInfo = new CropInfo();
         }
         EditCropInfoWindow eciw = new EditCropInfoWindow(cropInfo);
         eciw.ShowDialog();
         if (eciw.DialogResult == true)
         {
             vfi.cropInfo = new CropInfo(eciw.cropInfo);
         }
         UpdateStatusInfo();
     }
     catch (Exception)
     {
     }
 }
Пример #4
0
 public CropInfo(CropInfo orig)
 {
     this.cropTop = orig.cropTop;
     this.borderBottom = orig.borderBottom;
     this.resizeX = orig.resizeX;
     this.resizeY = orig.resizeY;
     this.resizeMethod = orig.resizeMethod;
     this.borderTop = orig.borderTop;
     this.cropBottom = orig.cropBottom;
     this.errorStr = orig.errorStr;
     this.error = orig.error;
     this.resize = orig.resize;
     this.border = orig.border;
 }
Пример #5
0
 public CropInfo(CropInfo orig)
 {
     this.cropTop      = orig.cropTop;
     this.borderBottom = orig.borderBottom;
     this.resizeX      = orig.resizeX;
     this.resizeY      = orig.resizeY;
     this.resizeMethod = orig.resizeMethod;
     this.borderTop    = orig.borderTop;
     this.cropBottom   = orig.cropBottom;
     this.errorStr     = orig.errorStr;
     this.error        = orig.error;
     this.resize       = orig.resize;
     this.border       = orig.border;
 }
Пример #6
0
        public AutoCrop(string filename, UserSettings settings, ref CropInfo cropInfo)
        {
            InitializeComponent();
            try
            {
                this.settings = settings;
                this.cropInfo = cropInfo;
                AviSynthScriptEnvironment asse = new AviSynthScriptEnvironment();
                asc = asse.OpenScriptFile(filename);

                if(asc.HasVideo)
                {
                    System.Drawing.Size s = new Size(asc.VideoWidth, asc.VideoHeight);
                    this.ClientSize = s;                    
                    maxFrames = asc.num_frames;
                    
                    // remove last ~10 minutes
                    if (maxFrames > 30000)
                    {
                        maxFrames -= 15000;
                    }
                    numericUpDownFrame.Maximum = maxFrames;
                    int step = 0;
                    step = maxFrames / nrFrames;
                    curFrame = step;
                    Monitor.Enter(drawLock);
                    bitmap = ReadFrameBitmap(asc, step);
                    bitmapCopy = new Bitmap(bitmap);
                    Monitor.Exit(drawLock);
                }
            }
            catch (Exception ex)
            {
                cropInfo.error = true;
                cropInfo.errorStr = ex.Message;
            }
        }
Пример #7
0
        private bool IndexCrop()
        {
            try
            {
                DoPlugin(PluginType.BeforeAutoCrop);

                string filename = "";
                AdvancedVideoOptions avo = null;
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        filename = si.filename;
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions)) avo = (AdvancedVideoOptions)si.advancedOptions;
                        break;
                    }
                }

                string fps = "";
                string resX = "";
                string resY = "";
                string length = "";
                string frames = "";

                try
                {
                    MediaInfoLib.MediaInfo mi2 = new MediaInfoLib.MediaInfo();
                    mi2.Open(filename);
                    mi2.Option("Complete", "1");
                    string[] tmpstr = mi2.Inform().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string s in tmpstr)
                    {
                        logWindow.MessageCrop(s.Trim());
                    }
                    if (mi2.Count_Get(StreamKind.Video) > 0)
                    {
                        fps = mi2.Get(StreamKind.Video, 0, "FrameRate");
                        resX = mi2.Get(StreamKind.Video, 0, "Width");
                        resY = mi2.Get(StreamKind.Video, 0, "Height");
                        length = mi2.Get(StreamKind.Video, 0, "Duration");
                        frames = mi2.Get(StreamKind.Video, 0, "FrameCount");
                    }
                    mi2.Close();
                }
                catch (Exception ex)
                {
                    logWindow.MessageCrop(Global.Res("ErrorMediaInfo") + " " + ex.Message);
                    return false;
                }

                if (avo != null && avo.disableFps)
                {
                    logWindow.MessageCrop(Global.Res("InfoManualFps"));
                    fps = avo.fps;
                    length = avo.length;
                    frames = avo.frames;
                }

                if (fps == "")
                {
                    logWindow.MessageCrop(Global.Res("ErrorFramerate"));
                    foreach (StreamInfo si in demuxedStreamList.streams)
                    {
                        if (si.streamType == StreamType.Video)
                        {
                            if (si.desc.Contains("24 /1.001"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 23.976"));
                                fps = "23.976";
                                break;
                            }
                            else if (si.desc.Contains("1080p24 (16:9)"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 24"));
                                fps = "24";
                                break;
                            }
                            // add other framerates here
                        }
                    }
                    if (fps == "")
                    {
                        logWindow.MessageCrop(Global.Res("ErrorNoFramerate"));
                        return false;
                    }
                }

                if (frames == "" || length == "")
                {
                    logWindow.MessageCrop(Global.Res("InfoFrames"));
                }

                CropInfo cropInfo = new CropInfo();
                if (!settings.untouchedVideo)
                {
                    if (settings.cropInput == 1 || settings.encodeInput == 1)
                    {
                        bool skip = false;
                        if (File.Exists(filename + ".ffindex") && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it = new IndexTool(settings, filename, IndexType.ffmsindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (it == null || !it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return false;
                            }
                        }
                    }

                    if (settings.cropInput == 2 || settings.encodeInput == 2)
                    {
                        string output = System.IO.Path.ChangeExtension(filename, "dgi");

                        bool skip = false;
                        if (File.Exists(output) && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it = new IndexTool(settings, filename, IndexType.dgindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (!it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return false;
                            }
                        }
                    }

                    if (avo == null || !avo.disableAutocrop)
                    {
                        if (settings.cropInput == 0)
                        {
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs",
                                "DirectShowSource(\"" + filename + "\")");
                        }
                        else if (settings.cropInput == 1)
                        {
                            string data = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath);
                            if (File.Exists(dlldir + "\\ffms2.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n";
                            }
                            data += "FFVideoSource(\"" + filename + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        else if (settings.cropInput == 2)
                        {
                            string output = System.IO.Path.ChangeExtension(filename, "dgi");
                            string data = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath);
                            if (File.Exists(dlldir + "\\DGDecodeNV.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n";
                            }
                            data += "DGSource(\"" + output + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        else if (settings.cropInput == 3)
                        {
                            string data = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.lsmashPath);
                            if (File.Exists(dlldir + "\\LSMASHSource.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\LSMASHSource.dll" + "\")\r\n";
                            }
                            data += "LWLibavVideoSource(\"" + filename + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        logWindow.MessageCrop(Global.Res("InfoStartCrop"));

                        AutoCrop ac = new AutoCrop(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", settings, ref cropInfo);
                        
                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return false;
                        }

                        if (settings.minimizeAutocrop && !settings.manualCrop)
                        {
                            ac.WindowState = FormWindowState.Minimized;
                        }

                        ac.NrFrames = settings.nrFrames;
                        ac.BlackValue = settings.blackValue;
                        ac.ShowDialog();

                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return false;
                        }
                        cropInfo.resizeMethod = settings.resizeMethod;
                    }
                    else
                    {
                        cropInfo.border = avo.manualBorders;
                        cropInfo.borderBottom = avo.borderBottom;
                        cropInfo.borderTop = avo.borderTop;
                        cropInfo.resize = avo.manualResize;
                        cropInfo.resizeX = avo.resizeX;
                        cropInfo.resizeY = avo.resizeY;
                        cropInfo.resizeMethod = avo.resizeMethod;
                        cropInfo.error = false;
                        if (avo.manualCrop)
                        {
                            cropInfo.cropBottom = avo.cropBottom;
                            cropInfo.cropTop = avo.cropTop;
                        }
                        else
                        {
                            cropInfo.cropBottom = 0;
                            cropInfo.cropTop = 0;
                        }
                    }

                    logWindow.MessageCrop("");
                    logWindow.MessageCrop(Global.ResFormat("InfoCropTop", cropInfo.cropTop));
                    logWindow.MessageCrop(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom));
                    if (cropInfo.border)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderTop", cropInfo.borderTop));
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom));
                    }
                    if (cropInfo.resize)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY));
                    }
                }
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                        {
                            si.extraFileInfo = new VideoFileInfo();
                        }
                        
                        ((VideoFileInfo)si.extraFileInfo).fps = fps;
                        ((VideoFileInfo)si.extraFileInfo).length = length;
                        if (frames != "")
                        {
                            ((VideoFileInfo)si.extraFileInfo).frames = frames;
                        }
                        ((VideoFileInfo)si.extraFileInfo).cropInfo = new CropInfo(cropInfo);
                    }
                }

                DoPlugin(PluginType.AfterAutoCrop);

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                demuxedStreamsWindow.UpdateDemuxedStreams();
                return true;
            }
            catch (Exception ex)
            {
                logWindow.MessageCrop(Global.Res("ErrorException") + " " + ex.Message);
                return false;
            }
            finally
            {

            }
        }
 private void buttonEditCropInfo_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         CropInfo cropInfo = null;
         if (vfi.cropInfo != null && vfi.cropInfo.GetType() == typeof(CropInfo))
         {
             cropInfo = new CropInfo(vfi.cropInfo);
         }
         else
         {
             cropInfo = new CropInfo();
         }
         EditCropInfoWindow eciw = new EditCropInfoWindow(cropInfo);
         eciw.ShowDialog();
         if (eciw.DialogResult == true)
         {
             vfi.cropInfo = new CropInfo(eciw.cropInfo);
         }
         UpdateStatusInfo();
     }
     catch (Exception)
     {
     }
 }
Пример #9
0
        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"));
            }
        }
Пример #10
0
        private bool IndexCrop()
        {
            try
            {
                DoPlugin(PluginType.BeforeAutoCrop);

                string filename          = "";
                AdvancedVideoOptions avo = null;
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        filename = si.filename;
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions))
                        {
                            avo = (AdvancedVideoOptions)si.advancedOptions;
                        }
                        break;
                    }
                }

                string fps    = "";
                string resX   = "";
                string resY   = "";
                string length = "";
                string frames = "";

                try
                {
                    MediaInfoLib.MediaInfo mi2 = new MediaInfoLib.MediaInfo();
                    mi2.Open(filename);
                    mi2.Option("Complete", "1");
                    string[] tmpstr = mi2.Inform().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string s in tmpstr)
                    {
                        logWindow.MessageCrop(s.Trim());
                    }
                    if (mi2.Count_Get(StreamKind.Video) > 0)
                    {
                        fps    = mi2.Get(StreamKind.Video, 0, "FrameRate");
                        resX   = mi2.Get(StreamKind.Video, 0, "Width");
                        resY   = mi2.Get(StreamKind.Video, 0, "Height");
                        length = mi2.Get(StreamKind.Video, 0, "Duration");
                        frames = mi2.Get(StreamKind.Video, 0, "FrameCount");
                    }
                    mi2.Close();
                }
                catch (Exception ex)
                {
                    logWindow.MessageCrop(Global.Res("ErrorMediaInfo") + " " + ex.Message);
                    return(false);
                }

                if (avo != null && avo.disableFps)
                {
                    logWindow.MessageCrop(Global.Res("InfoManualFps"));
                    fps    = avo.fps;
                    length = avo.length;
                    frames = avo.frames;
                }

                if (fps == "")
                {
                    logWindow.MessageCrop(Global.Res("ErrorFramerate"));
                    foreach (StreamInfo si in demuxedStreamList.streams)
                    {
                        if (si.streamType == StreamType.Video)
                        {
                            if (si.desc.Contains("24 /1.001"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 23.976"));
                                fps = "23.976";
                                break;
                            }
                            else if (si.desc.Contains("1080p24 (16:9)"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 24"));
                                fps = "24";
                                break;
                            }
                            // add other framerates here
                        }
                    }
                    if (fps == "")
                    {
                        logWindow.MessageCrop(Global.Res("ErrorNoFramerate"));
                        return(false);
                    }
                }

                if (frames == "" || length == "")
                {
                    logWindow.MessageCrop(Global.Res("InfoFrames"));
                }

                CropInfo cropInfo = new CropInfo();
                if (!settings.untouchedVideo)
                {
                    if (settings.cropInput == 1 || settings.encodeInput == 1)
                    {
                        bool skip = false;
                        if (File.Exists(filename + ".ffindex") && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it            = new IndexTool(settings, filename, IndexType.ffmsindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg  += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (it == null || !it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return(false);
                            }
                        }
                    }

                    if (settings.cropInput == 2 || settings.encodeInput == 2)
                    {
                        string output = System.IO.Path.ChangeExtension(filename, "dgi");

                        bool skip = false;
                        if (File.Exists(output) && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it            = new IndexTool(settings, filename, IndexType.dgindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg  += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (!it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return(false);
                            }
                        }
                    }

                    if (avo == null || !avo.disableAutocrop)
                    {
                        if (settings.cropInput == 0)
                        {
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs",
                                              "DirectShowSource(\"" + filename + "\")");
                        }
                        else if (settings.cropInput == 1)
                        {
                            string data   = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath);
                            if (File.Exists(dlldir + "\\ffms2.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n";
                            }
                            data += "FFVideoSource(\"" + filename + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        else if (settings.cropInput == 2)
                        {
                            string output = System.IO.Path.ChangeExtension(filename, "dgi");
                            string data   = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath);
                            if (File.Exists(dlldir + "\\DGDecodeNV.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n";
                            }
                            data += "DGSource(\"" + output + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        logWindow.MessageCrop(Global.Res("InfoStartCrop"));

                        AutoCrop ac = new AutoCrop(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", settings, ref cropInfo);

                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return(false);
                        }

                        if (settings.minimizeAutocrop && !settings.manualCrop)
                        {
                            ac.WindowState = FormWindowState.Minimized;
                        }

                        ac.NrFrames   = settings.nrFrames;
                        ac.BlackValue = settings.blackValue;
                        ac.ShowDialog();

                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return(false);
                        }
                        cropInfo.resizeMethod = settings.resizeMethod;
                    }
                    else
                    {
                        cropInfo.border       = avo.manualBorders;
                        cropInfo.borderBottom = avo.borderBottom;
                        cropInfo.borderTop    = avo.borderTop;
                        cropInfo.resize       = avo.manualResize;
                        cropInfo.resizeX      = avo.resizeX;
                        cropInfo.resizeY      = avo.resizeY;
                        cropInfo.resizeMethod = avo.resizeMethod;
                        cropInfo.error        = false;
                        if (avo.manualCrop)
                        {
                            cropInfo.cropBottom = avo.cropBottom;
                            cropInfo.cropTop    = avo.cropTop;
                        }
                        else
                        {
                            cropInfo.cropBottom = 0;
                            cropInfo.cropTop    = 0;
                        }
                    }

                    logWindow.MessageCrop("");
                    logWindow.MessageCrop(Global.ResFormat("InfoCropTop", cropInfo.cropTop));
                    logWindow.MessageCrop(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom));
                    if (cropInfo.border)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderTop", cropInfo.borderTop));
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom));
                    }
                    if (cropInfo.resize)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY));
                    }
                }
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                        {
                            si.extraFileInfo = new VideoFileInfo();
                        }

                        ((VideoFileInfo)si.extraFileInfo).fps    = fps;
                        ((VideoFileInfo)si.extraFileInfo).length = length;
                        ((VideoFileInfo)si.extraFileInfo).frames = frames;

                        ((VideoFileInfo)si.extraFileInfo).cropInfo = new CropInfo(cropInfo);
                    }
                }

                DoPlugin(PluginType.AfterAutoCrop);

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                demuxedStreamsWindow.UpdateDemuxedStreams();
                return(true);
            }
            catch (Exception ex)
            {
                logWindow.MessageCrop(Global.Res("ErrorException") + " " + ex.Message);
                return(false);
            }
            finally
            {
            }
        }