Esempio n. 1
0
        private static EncoderResult Encoder(string inputFile, string outputPath,
                                             BasicMediaFormatInfo info, int videoIndex, int audioIndex)
        {
            EncoderResult encoderResult = new EncoderResult();

            encoderResult.VideoInfo = null;
            encoderResult.AudioInfo = null;
            if (videoIndex != -1 && info.MediaInfo[videoIndex].CodecType == "video" &&
                info.MediaInfo[videoIndex].CodecName != "mjpeg" &&
                info.MediaInfo[videoIndex].CodecName != "png")
            {
                encoderResult.VideoInfo = new BasicVideoInfo((BasicVideoInfo)info.MediaInfo[videoIndex]);
            }
            if (audioIndex != -1 && info.MediaInfo[audioIndex].CodecType == "audio")
            {
                encoderResult.AudioInfo = new BasicAudioInfo((BasicAudioInfo)info.MediaInfo[audioIndex]);
            }

            encoderResult.Extension = null;
            if (encoderResult.VideoInfo != null)
            {
                encoderResult.Extension = ".mp4";
            }
            else if (encoderResult.AudioInfo != null)
            {
                if (encoderResult.AudioInfo.CodecName == "vorbis" &&
                    encoderResult.AudioInfo.Channels <= 2)
                {
                    encoderResult.Extension = ".ogg";
                }
                else
                {
                    encoderResult.Extension = ".m4a";
                }
            }
            else
            {
                throw new Exception("\"" + inputFile + "\" does not have multimedia content.");
            }

            StringBuilder config = new StringBuilder();

            if (encoderResult.VideoInfo != null)
            {
                if (encoderResult.VideoInfo.Width * encoderResult.VideoInfo.Height > 1920 * 1080)
                {
                    double scale       = 1920.0 / encoderResult.VideoInfo.Width;
                    double heightScale = 1080.0 / encoderResult.VideoInfo.Height;
                    if (scale > heightScale)
                    {
                        scale = heightScale;
                    }
                    encoderResult.VideoInfo.Width  = (int)(encoderResult.VideoInfo.Width * scale);
                    encoderResult.VideoInfo.Height = (int)(encoderResult.VideoInfo.Height * scale);
                }

                if (encoderResult.VideoInfo.Width * encoderResult.VideoInfo.Height > 1280 * 720 && encoderResult.VideoInfo.FrameRate > 30.0)
                {
                    encoderResult.VideoInfo.FrameRate = 30.0;
                }

                if (encoderResult.VideoInfo.FrameRate > 60.0)
                {
                    encoderResult.VideoInfo.FrameRate = 60.0;
                }

                if (encoderResult.VideoInfo.CodecName == "h264" &&
                    encoderResult.VideoInfo.Width == ((BasicVideoInfo)info.MediaInfo[videoIndex]).Width &&
                    encoderResult.VideoInfo.Height == ((BasicVideoInfo)info.MediaInfo[videoIndex]).Height &&
                    encoderResult.VideoInfo.FrameRate == ((BasicVideoInfo)info.MediaInfo[videoIndex]).FrameRate &&
                    encoderResult.VideoInfo.Level <= 4.2)
                {
                    config.Append("-map 0:");
                    config.Append(videoIndex);
                    config.Append(" -c:v copy");
                }
                else
                {
                    config.Append("-map 0:");
                    config.Append(videoIndex);
                    config.Append(" -c:v libx264 -preset fast -crf 25 -s ");
                    config.Append(encoderResult.VideoInfo.Width);
                    config.Append("x");
                    config.Append(encoderResult.VideoInfo.Height);
                    config.Append(" -r ");
                    config.Append(encoderResult.VideoInfo.FrameRate);
                }
            }
            if (encoderResult.AudioInfo != null)
            {
                if (encoderResult.VideoInfo != null)
                {
                    config.Append(" ");
                }

                if ((encoderResult.AudioInfo.CodecName == "aac" ||
                     encoderResult.AudioInfo.CodecName == "vorbis") &&
                    encoderResult.AudioInfo.Channels <= 2)
                {
                    config.Append("-map 0:");
                    config.Append(audioIndex);
                    config.Append(" -c:a copy");
                }
                else
                {
                    config.Append("-map 0:");
                    config.Append(audioIndex);
                    config.Append(" -c:a aac -ac 2");
                }
            }

            if (info.Size > 4294967296)
            {
                int    bitrate       = 0;
                double totalDuration = 0;
                if (encoderResult.VideoInfo != null && encoderResult.AudioInfo == null)
                {
                    bitrate       = encoderResult.VideoInfo.Bitrate;
                    totalDuration = encoderResult.VideoInfo.Duration;
                }
                else if (encoderResult.VideoInfo == null && encoderResult.AudioInfo != null)
                {
                    bitrate       = encoderResult.AudioInfo.Bitrate;
                    totalDuration = encoderResult.AudioInfo.Duration;
                }
                else if (encoderResult.VideoInfo == null && encoderResult.AudioInfo == null)
                {
                    bitrate       = encoderResult.VideoInfo.Bitrate + encoderResult.AudioInfo.Bitrate;
                    totalDuration = encoderResult.VideoInfo.Duration;
                }

                if (bitrate == 0)
                {
                    bitrate = info.Bitrate;
                }
                if (totalDuration == 0)
                {
                    totalDuration = info.Duration;
                }

                double duration = 33822867456.0 / bitrate;
                double start    = 0.0;

                int parts = (int)(totalDuration / duration);
                if (totalDuration % duration != 0.0)
                {
                    parts++;
                }

                encoderResult.Name = new string[parts];

                for (int i = 0; i < parts; i++)
                {
                    encoderResult.Name[i] = Path.GetFileNameWithoutExtension(inputFile) + " part " + (i + 1).ToString();
                    string output    = Path.Combine(outputPath, MediaInjector.ValidFilename(encoderResult.Name[i]) + encoderResult.Extension);
                    string cut       = "-ss " + start.ToString() + " -noaccurate_seek -t " + duration.ToString();
                    string arguments = cut + " -i \"" + inputFile + "\" " + config.ToString() + " \"" + output + "\"";
                    FFmpeg(arguments);
                    start += duration;
                }
            }
            else
            {
                encoderResult.Name    = new string[1];
                encoderResult.Name[0] = Path.GetFileNameWithoutExtension(inputFile);
                string output    = Path.Combine(outputPath, MediaInjector.ValidFilename(encoderResult.Name[0]) + encoderResult.Extension);
                string arguments = "-i \"" + inputFile + "\" " + config.ToString() + " \"" + output + "\"";
                FFmpeg(arguments);
            }

            return(encoderResult);
        }
Esempio n. 2
0
        public WUMInjectorGUI()
        {
            Cll.Log.SaveIn("WUMInjector.log");
            Cll.Log.WriteLine("WUM Injector " + MediaInjector.Release);
            Cll.Log.WriteLine(DateTime.Now.ToString());

            InitializeComponent();

            BootTvImg   = new BootImage();
            BootDrcImg  = new BootImage();
            MenuIconImg = new MenuIconImage();

            this.Text = "WUM Injector " + MediaInjector.Release;

            ResourcesPath = Path.Combine(MediaInjector.DataPath, "resources");
            string imagesPath           = Path.Combine(ResourcesPath, "images");
            string NUSConverterDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NUSConverter");
            string packPath             = Path.Combine(NUSConverterDataPath, "pack");
            string unpackPath           = Path.Combine(NUSConverterDataPath, "unpack");
            string cnuspackerPath       = Path.Combine(packPath, "CNUSPacker.exe");
            string cdecryptPath         = Path.Combine(unpackPath, "CDecrypt.exe");

            if (!Directory.Exists(NUSConverterDataPath))
            {
                Directory.CreateDirectory(NUSConverterDataPath);
                Directory.CreateDirectory(packPath);
                Directory.CreateDirectory(unpackPath);
                FileStream fs = File.Create(cnuspackerPath);
                fs.Write(Resources.CNUSPacker, 0, Resources.CNUSPacker.Length);
                fs.Close();
                fs = File.Create(cdecryptPath);
                fs.Write(Resources.CDecrypt, 0, Resources.CDecrypt.Length);
                fs.Close();
                fs = File.Create(Path.Combine(unpackPath, "libeay32.dll"));
                fs.Write(Resources.libeay32, 0, Resources.libeay32.Length);
                fs.Close();
            }

            if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WUMMInjector")))
            {
                Directory.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WUMMInjector"), true);
            }

            if (!Directory.Exists(MediaInjector.DataPath))
            {
                Directory.CreateDirectory(MediaInjector.DataPath);
            }

            if (!Directory.Exists(ResourcesPath))
            {
                Directory.CreateDirectory(ResourcesPath);
                StreamWriter sw = File.CreateText(Path.Combine(ResourcesPath, "version"));
                sw.Write(MediaInjector.Release);
                sw.Close();
            }

            if (!Directory.Exists(imagesPath))
            {
                Directory.CreateDirectory(imagesPath);
                Resources.icon_multimedia.Save(Path.Combine(imagesPath, "icon.png"), ImageFormat.Png);
            }

            StringBuilder sb      = new StringBuilder();
            bool          warning = false;

            if (!File.Exists(cnuspackerPath))
            {
                sb.AppendLine("Warning! \"" + cnuspackerPath + "\" not found! NUSPacker allows you to encrypt NUS Content for WUP Installer.");
                sb.AppendLine("");
                warning = true;
            }
            if (!File.Exists(cdecryptPath))
            {
                sb.AppendLine("Warning! \"" + cdecryptPath + "\" not found! CDecrypt allows you to decrypt NUS Content for Loadiine.");
                warning = true;
            }
            if (warning)
            {
                MessageBox.Show(sb.ToString(), "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (NUSContent.CheckCommonKeyFiles())
            {
                textBoxCommonKey.Enabled       = false;
                panelCommonKey.BackgroundImage = Properties.Resources.checkmark_16;
            }
            else
            {
                textBoxCommonKey.Enabled       = true;
                panelCommonKey.BackgroundImage = Properties.Resources.x_mark_16;
            }

            Injector = new MediaInjector();
            if (Injector.BaseIsLoaded)
            {
                panelLoadedBase.BackgroundImage = Properties.Resources.checkmark_16;
                labelBase.Text         = Injector.LoadedBase;
                buttonLoadBase.Enabled = false;
            }
            else
            {
                panelLoadedBase.BackgroundImage = Properties.Resources.x_mark_16;
                labelBase.Text = "Base invalid!";
            }

            if (File.Exists(Path.Combine(imagesPath, "icon.png")))
            {
                MenuIconImg.Frame = new Bitmap(Path.Combine(imagesPath, "icon.png"));
            }
            else
            {
                MenuIconImg.Frame = null;
            }

            UpdateMenuIconPictureBox();
            UpdateBootTvPictureBox();
            UpdateBootDrcPictureBox();
        }