public EditVideoFileInfoWindow(VideoFileInfo vfi)
        {
            try
            {
                InitializeComponent();
                this.vfi = new VideoFileInfo(vfi);

                textBoxEncodeAvs.Text = vfi.encodeAvs;
                textBoxEncodedFile.Text = vfi.encodedFile;
                textBoxFps.Text = vfi.fps;
                textBoxFrames.Text = vfi.frames;
                textBoxLength.Text = vfi.length;

                UpdateStatusInfo();
            }
            catch (Exception)
            {
            }
        }
Esempio n. 2
0
        public EditVideoFileInfoWindow(VideoFileInfo vfi)
        {
            try
            {
                InitializeComponent();
                this.vfi = new VideoFileInfo(vfi);

                textBoxEncodeAvs.Text   = vfi.encodeAvs;
                textBoxEncodedFile.Text = vfi.encodedFile;
                textBoxFps.Text         = vfi.fps;
                textBoxFrames.Text      = vfi.frames;
                textBoxLength.Text      = vfi.length;

                UpdateStatusInfo();
            }
            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)
     {
     }
 }
Esempio n. 4
0
 private int GetMaxFrames()
 {
     try
     {
         foreach (StreamInfo si in demuxedStreamList.streams)
         {
             if (si.streamType == StreamType.Video)
             {
                 if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo))
                 {
                     VideoFileInfo vfi = (VideoFileInfo)si.extraFileInfo;
                     return(Convert.ToInt32(vfi.frames));
                 }
             }
         }
         return(0);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Esempio n. 5
0
        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)
            {
            }
        }
Esempio n. 6
0
        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)
            {
            }
        }
Esempio n. 7
0
        public EncodeTool(UserSettings settings, TitleInfo titleInfo, int profile, bool secondPass, VideoFileInfo vfi)
            : base()
        {
            try
            {
                this.settings   = settings;
                this.secondPass = secondPass;
                this.Priority   = settings.x264Priority;
                this.vfi        = vfi;
                this.titleInfo  = titleInfo;
                this.profile    = profile;

                bool is2pass = settings.encodingSettings[profile].pass2;

                if (settings.encodingSettings[profile].pass2)
                {
                    if (settings.encodingSettings[profile].sizeType == SizeType.Bitrate)
                    {
                        bitrate = (int)settings.encodingSettings[profile].sizeValue;
                    }
                    else if (settings.encodingSettings[profile].sizeType == SizeType.Size)
                    {
                        try
                        {
                            length = Convert.ToInt32(vfi.length);
                            length = (int)(length / 1000);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            frames = Convert.ToInt32(vfi.frames);
                        }
                        catch (Exception)
                        {
                        }

                        // use frame count to calculate overhead
                        // to be done...

                        totalSize  = GetSize();
                        targetSize = Convert.ToInt64(settings.encodingSettings[profile].sizeValue * 1024.0 * 1024.0);
                        bitrate    = (int)((targetSize - totalSize) / 1024 / length); //kbyte/s
                        bitrate   *= 8;                                               //kbit/s

                        // no mkv overhead used yet
                    }
                }

                string outdir = settings.workingDir;
                if (settings.encodedMovieDir != "")
                {
                    outdir = settings.encodedMovieDir;
                }

                string statsFile = outdir + "\\" + settings.filePrefix + "_stats";

                if (!secondPass)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        if (!settings.use64bit)
                        {
                            this.Path      = settings.x264Path;
                            this.Parameter = settings.encodingSettings[profile].GetParam + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                             "\\" + settings.filePrefix + "_video.mkv\"";
                        }
                        else
                        {
                            this.Path      = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                             settings.x264x64Path + "\" " + settings.encodingSettings[profile].GetParam + " --fps " + vfi.fps + " " +
                                             " -o \"" + outdir + "\\" +
                                             settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                    else
                    {
                        if (!settings.use64bit)
                        {
                            this.Path      = settings.x264Path;
                            this.Parameter = string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o NUL";
                        }
                        else
                        {
                            this.Path      = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                             settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " --fps " + vfi.fps +
                                             " -o NUL" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                }
                else
                {
                    if (!settings.use64bit)
                    {
                        this.Path      = settings.x264Path;
                        this.Parameter = string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                         "\\" + settings.filePrefix + "_video.mkv\"";
                    }
                    else
                    {
                        this.Path      = "cmd.exe";
                        this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                         settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " --fps " + vfi.fps + " -o \"" + outdir + "\\" +
                                         settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 8
0
 public override void Process()
 {
     try
     {
         int index = -1;
         for (int i = 0; i < this.project.demuxedStreamList.streams.Count; i++)
         {
             if (project.demuxedStreamList.streams[i].streamType == StreamType.Video)
             {
                 index = i;
                 break;
             }
         }
         if (index > 0)
         {
             if (project.demuxedStreamList.streams[index].extraFileInfo != null && project.demuxedStreamList.streams[index].extraFileInfo.GetType() == typeof(VideoFileInfo))
             {
                 VideoFileInfo vfi = (VideoFileInfo)project.demuxedStreamList.streams[index].extraFileInfo;
                 if (vfi.cropInfo.resizeX == 1920)
                 {
                     if (vfi.cropInfo.resizeY > 864 && vfi.cropInfo.resizeY <= 1088)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 4;
                         }
                     }
                     else if (vfi.cropInfo.resizeY > 720 && vfi.cropInfo.resizeY <= 864)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 5;
                         }
                     }
                     else if (vfi.cropInfo.resizeY <= 720)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 6;
                         }
                     }
                 }
                 else if (vfi.cropInfo.resizeX == 1280)
                 {
                     if (vfi.cropInfo.resizeY > 648 && vfi.cropInfo.resizeY <= 720)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 9;
                         }
                     }
                     else if (vfi.cropInfo.resizeY > 588 && vfi.cropInfo.resizeY <= 648)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 10;
                         }
                     }
                     else if (vfi.cropInfo.resizeY > 540 && vfi.cropInfo.resizeY <= 588)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 11;
                         }
                     }
                     else if (vfi.cropInfo.resizeY <= 540)
                     {
                         if (project.settings.lastProfile >= 0 && project.settings.lastProfile < project.settings.encodingSettings.Count)
                         {
                             project.settings.encodingSettings[project.settings.lastProfile].refvalue = 12;
                         }
                     }
                 }
             }
         }
     }
     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)
     {
     }
 }
Esempio n. 10
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"));
            }
        }
Esempio n. 11
0
        public EncodeTool(UserSettings settings, TitleInfo titleInfo, int profile, bool secondPass, VideoFileInfo vfi)
            : base()
        {
            try
            {
                this.settings = settings;
                this.secondPass = secondPass;
                this.Priority = settings.x264Priority;
                this.vfi = vfi;
                this.titleInfo = titleInfo;
                this.profile = profile;

                bool is2pass = settings.encodingSettings[profile].pass2;
                
                if (settings.encodingSettings[profile].pass2)
                {
                    if (settings.encodingSettings[profile].sizeType == SizeType.Bitrate)
                    {
                        bitrate = (int)settings.encodingSettings[profile].sizeValue;
                    }
                    else if (settings.encodingSettings[profile].sizeType == SizeType.Size)
                    {
                        
                        try
                        {
                            length = Convert.ToInt32(vfi.length);
                            length = (int)(length / 1000);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            frames = Convert.ToInt32(vfi.frames);
                        }
                        catch (Exception)
                        {
                        }

                        // use frame count to calculate overhead
                        // to be done...

                        totalSize = GetSize();
                        targetSize = Convert.ToInt64(settings.encodingSettings[profile].sizeValue * 1024.0 * 1024.0);
                        bitrate = (int)((targetSize - totalSize) / 1024 / length); //kbyte/s
                        bitrate *= 8; //kbit/s

                        // no mkv overhead used yet
                    }
                }
                
                string outdir = settings.workingDir;
                if (settings.encodedMovieDir != "") outdir = settings.encodedMovieDir;

                string statsFile = outdir + "\\" + settings.filePrefix + "_stats";

                if (!secondPass)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        if (!settings.use64bit)
                        {
                            this.Path = settings.x264Path;
                            this.Parameter = settings.encodingSettings[profile].GetParam + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                    "\\" + settings.filePrefix + "_video.mkv\"";
                        }
                        else
                        {
                            this.Path = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                settings.x264x64Path + "\" " + settings.encodingSettings[profile].GetParam + " --fps " + vfi.fps + " " +
                                " -o \"" + outdir + "\\" +
                                settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                    else
                    {
                        if (!settings.use64bit)
                        {
                            this.Path = settings.x264Path;
                            this.Parameter = string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o NUL";
                        }
                        else
                        {
                            this.Path = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " --fps " + vfi.fps +
                                " -o NUL" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                }
                else
                {
                    if (!settings.use64bit)
                    {
                        this.Path = settings.x264Path;
                        this.Parameter = string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                            "\\" + settings.filePrefix + "_video.mkv\"";
                    }
                    else
                    {
                        this.Path = "cmd.exe";
                        this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                            settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " --fps " + vfi.fps + " -o \"" + outdir + "\\" +
                            settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                    }
                }
            }
            catch (Exception)
            {   
            }
        }