private void LoadSourceThread()
        {
            _workEx = null;
            try {
                _aviMod = new AVIModifier(_sourcePath);
                _mp4Mod = new MPEG4FrameModifier();
                _aviMod.FrameModifier = _mp4Mod;
                _mp4Mod.VideoModifier = _aviMod;

                _aviMod.ProgressCallback = _waitForm.SetProgress;
                _aviMod.Preview();
            }
            catch (Exception ex) {
                _workEx = ex;
            }
            _waitForm.FinishedWork();
        }
        private void SetupForm(bool isVideoLoaded)
        {
            _updatingUI = true;

            grpAspectRatio.Enabled     = isVideoLoaded;
            grpPackedBitstream.Enabled = isVideoLoaded;
            grpUserData.Enabled        = isVideoLoaded;
            grpInterlacing.Enabled     = isVideoLoaded;
            btnSave.Enabled            = isVideoLoaded;
            btnVideoInfo.Enabled       = isVideoLoaded;

            if (!isVideoLoaded)
            {
                if (_aviMod != null)
                {
                    _aviMod.Close();
                    _aviMod = null;
                }
                _mp4Mod                  = null;
                _regUDList               = null;
                _autoUDList              = null;
                _showingAutoUD           = false;
                txtSourcePath.Text       = String.Empty;
                rbPAR_VGA_1_1.Checked    = true;
                txtPAR_Width.Text        = String.Empty;
                txtPAR_Height.Text       = String.Empty;
                txtDAR_Width.Text        = String.Empty;
                txtDAR_Height.Text       = String.Empty;
                lblIsPacked.Text         = "...";
                chkChangePacking.Text    = "Unpack";
                chkChangePacking.Checked = false;
                chkAutoUD.Checked        = true;
                chkAutoUD.Enabled        = false;
                lstUserData.Items.Clear();
                lblIsInterlaced.Text = "...";
                rbTFF.Checked        = true;
            }

            _updatingUI = false;
        }
示例#3
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);
        }