Beispiel #1
0
        private void ConvertVideo()
        {
            string strFilePath = this.txtFile.Text;
            string saveFolder  = this.txtSaveFolder.Text;

            if (string.IsNullOrEmpty(strFilePath))
            {
                MessageBox.Show("Please choose the file for converting!");
                return;
            }

            string[] filePaths = strFilePath.Split('|');

            foreach (string filePath in filePaths)
            {
                FileInfo file         = new FileInfo(filePath);
                string   strStartTime = DateTime.Now.ToString("HH:mm:ss");
                string   strTime      = "00:00:00";

                VideoInfo videoInfo = VideoHelper.GetVideoInfo(filePath);
                if (!this.lvMessage.Items.ContainsKey(file.Name))
                {
                    ListViewItem li = new ListViewItem();
                    li.Tag  = videoInfo;
                    li.Name = file.Name;
                    li.Text = file.Name;
                    li.SubItems.Add("Ready");                  //Message
                    li.SubItems.Add(videoInfo.DurationString); //Duration
                    li.SubItems.Add("");                       //Current Time
                    li.SubItems.Add("");                       //Start Time
                    li.SubItems.Add("0%");                     //Progress

                    this.lvMessage.Items.Add(li);
                }
                else
                {
                    ListViewItem li = this.lvMessage.Items[file.Name];
                    li.Tag = videoInfo;
                    li.SubItems[1].Text = "Ready";                  //Message
                    li.SubItems[2].Text = videoInfo.DurationString; //Duration
                    li.SubItems[3].Text = strTime;                  //Current Time
                    li.SubItems[4].Text = "";                       //Start Time
                    li.SubItems[4].Tag  = null;
                    li.SubItems[5].Text = "0%";                     //Progress
                    li.BackColor        = Color.White;
                }
            }

            this.btnExecute.Enabled = false;

            this.convertHandler.FilePaths = filePaths.ToList();

            switch (this.cboVideoType.Text)
            {
            case nameof(VideoType.Original):
                this.convertHandler.Option.FileType = "";
                break;

            case nameof(VideoType.Custom):
                this.convertHandler.Option.FileType = this.txtFileType.Text;
                break;

            default:
                this.convertHandler.Option.FileType = this.cboVideoType.Text;
                break;
            }

            int?width  = default(int?);
            int?height = default(int?);

            switch (this.cboResolution.Text)
            {
            case nameof(VideoResolution.P1080):
                width = 1920; height = 1080;
                break;

            case nameof(VideoResolution.P720):
                width = 1280; height = 720;
                break;

            case nameof(VideoResolution.P480):
                width = 720; height = 480;
                break;

            case nameof(VideoResolution.P360):
                width = 480; height = 360;
                break;

            case nameof(VideoResolution.Custom):
                if (this.nudWidth.Value > 0)
                {
                    width = (int)this.nudWidth.Value;
                }
                if (this.nudHeight.Value > 0)
                {
                    height = (int)this.nudHeight.Value;
                }
                break;
            }

            this.convertHandler.Option.SaveFolder       = this.txtSaveFolder.Text;
            this.convertHandler.Option.ResolutionWidth  = width;
            this.convertHandler.Option.ResolutionHeight = height;

            if (this.cboQuality.Text == VideoQuality.Custom.ToString())
            {
                this.convertHandler.Option.Quality = (int)this.nudQuality.Value;
            }
            else
            {
                this.convertHandler.Option.Quality = (int)Enum.Parse(typeof(VideoQuality), this.cboQuality.Text);
            }

            this.convertHandler.Subscribe(this);

            ConvertSetting setting = SettingManager.GetSetting();

            this.convertHandler.Setting = setting;

            LogHelper.EnableDebug    = setting.EnableDebug;
            FeedbackHelper.EnableLog = setting.EnableLog;

            this.convertHandler.Convert();
        }