Exemplo n.º 1
0
        private static int Run()
        {
            if (!File.Exists(_pathSrc))
            {
                throw new Exception("Source file doesn't exist.");
            }
            if ((_pathDst != null) && File.Exists(_pathDst))
            {
                throw new Exception("Destination file already exists.");
            }

            bool modifying = false;

            _loading = true;
            AVIModifier        aviMod = new AVIModifier(_pathSrc);
            MPEG4FrameModifier mp4Mod = new MPEG4FrameModifier();

            aviMod.FrameModifier    = mp4Mod;
            mp4Mod.VideoModifier    = aviMod;
            aviMod.ProgressCallback = new ProgressCallback(Progress);
            aviMod.Preview();
            Progress(1.0);
            Console.WriteLine();

            if (_showInfo)
            {
                Console.WriteLine("---------- Video Info ----------");
                Console.Write(mp4Mod.GenerateStats());
                Console.WriteLine("--------------------------------");
            }

            if (_writeFrameList)
            {
                Console.Write("Writing frame list...");
                try {
                    FileStream fs = new FileStream(_frameListPath, FileMode.CreateNew, FileAccess.Write);
                    using (StreamWriter sw = new StreamWriter(fs)) {
                        mp4Mod.DumpFrameList(sw);
                    }
                }
                catch {
                    Console.WriteLine();
                    throw new Exception("Cannot write frame list, make sure the file doesn't already exist.");
                }
                Console.WriteLine(" Done.");
            }

            if (_pathDst == null)
            {
                return(0);
            }

            if (_unpack && mp4Mod.IsPacked)
            {
                modifying           = true;
                mp4Mod.NewIsPacked  = false;
                mp4Mod.UserDataList = mp4Mod.SuggestedUserData();
            }
            if (_pack && !mp4Mod.IsPacked && mp4Mod.ContainsBVOPs)
            {
                modifying           = true;
                mp4Mod.NewIsPacked  = true;
                mp4Mod.UserDataList = mp4Mod.SuggestedUserData();
            }
            if (_changePAR || _changeDAR)
            {
                MPEG4PAR pold = mp4Mod.PARInfo;
                MPEG4PAR pnew = new MPEG4PAR();

                if (_changePAR)
                {
                    if (_parType != PARType.Custom)
                    {
                        pnew.Type = _parType;
                    }
                    else
                    {
                        pnew.SetCustomPAR(_customPAR);
                    }
                }
                else if (_changeDAR)
                {
                    double rar = (double)mp4Mod.FrameWidth / (double)mp4Mod.FrameHeight;
                    pnew.SetCustomPAR(_customDAR / rar);
                }

                if ((pold.Type != pnew.Type) ||
                    ((pnew.Type == PARType.Custom) &&
                     ((pnew.Width != pold.Width) || (pnew.Height != pold.Height))))
                {
                    modifying      = true;
                    mp4Mod.PARInfo = pnew;
                }
            }
            if (_changeFieldOrder && mp4Mod.IsInterlaced && (mp4Mod.TopFieldFirst != _isTFF))
            {
                modifying            = true;
                mp4Mod.TopFieldFirst = _isTFF;
            }

            if (!modifying && !_alwaysWrite)
            {
                Console.WriteLine("Aborting: Video already has the desired format.");
                return(2);
            }

            _loading = false;
            aviMod.Write(_pathDst);
            Progress(1.0);
            Console.WriteLine();

            Console.WriteLine("Video was written successfully.");
            return(0);
        }
Exemplo n.º 2
0
        private void LoadSource(string path)
        {
            SetupForm(false);
            _sourcePath        = path;
            txtSourcePath.Text = path;

            // Load video
            _waitForm = new frmWait("Loading", "Loading video, please wait...",
                                    new Thread(LoadSourceThread));
            _waitForm.ShowDialog(this);
            _waitForm.Dispose();
            _waitForm = null;

            if (_workEx != null)
            {
                SetupForm(false);
                MessageBox.Show(this, _workEx.Message, "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            else if (_aviMod.WasStopped)
            {
                SetupForm(false);
                return;
            }

            SetupForm(true);

            _updatingUI = true;

            // Aspect Ratio
            switch (_mp4Mod.PARInfo.Type)
            {
            case PARType.VGA_1_1:
                rbPAR_VGA_1_1.Checked = true;
                break;

            case PARType.PAL_4_3:
                rbPAR_PAL_4_3.Checked = true;
                break;

            case PARType.NTSC_4_3:
                rbPAR_NTSC_4_3.Checked = true;
                break;

            case PARType.PAL_16_9:
                rbPAR_PAL_16_9.Checked = true;
                break;

            case PARType.NTSC_16_9:
                rbPAR_NTSC_16_9.Checked = true;
                break;

            case PARType.Custom: {
                double par = (double)_mp4Mod.PARInfo.Width / (double)_mp4Mod.PARInfo.Height;
                double rar = (double)_mp4Mod.FrameWidth / (double)_mp4Mod.FrameHeight;
                double dar = par * rar;

                rbPAR_Custom.Checked = true;
                txtPAR_Width.Text    = _mp4Mod.PARInfo.Width.ToString();
                txtPAR_Height.Text   = _mp4Mod.PARInfo.Height.ToString();

                txtDAR_Width.Text  = dar.ToString("0.###");
                txtDAR_Height.Text = "1";

                break;
            }
            }

            // Packed Bitstream
            lblIsPacked.Text         = _mp4Mod.IsPacked ? "Yes" : "No";
            chkChangePacking.Text    = _mp4Mod.IsPacked ? "Unpack" : "Pack";
            chkChangePacking.Enabled = _mp4Mod.IsPacked || _mp4Mod.ContainsBVOPs;

            // User Data
            _regUDList     = _mp4Mod.UserDataList;
            _autoUDList    = _mp4Mod.SuggestedUserData();
            UDListBoxItems = _regUDList;

            // Interlacing
            bool isInt = _mp4Mod.IsInterlaced;

            lblIsInterlaced.Text = isInt ? "Yes" : "No";
            rbTFF.Enabled        = isInt;
            rbBFF.Enabled        = isInt;
            if (isInt)
            {
                (_mp4Mod.TopFieldFirst ? rbTFF : rbBFF).Checked = true;
            }

            _updatingUI = false;
        }