Ejemplo n.º 1
0
        private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (string.IsNullOrEmpty(this.pbVideoInPath))
            {
                MessageBox.Show("请选择车内视频", "操作提示");
                return;
            }
            if (string.IsNullOrEmpty(this.pbVideoOutPath))
            {
                MessageBox.Show("请选择车外视频", "操作提示");
                return;
            }
            if (e.ColumnIndex == 4)
            {
                string stime    = Convert.ToString(dataGridView.Rows[e.RowIndex].Cells[2].Value);
                string duration = Convert.ToString(dataGridView.Rows[e.RowIndex].Cells[3].Value);
                string playPath = "";
                int    code     = 0;
                if (!ValidateKit.IsTime(stime))
                {
                    code = 1;
                }
                if (!ValidateKit.isNumber(duration))
                {
                    code = 2;
                }
                if (code == 0)
                {
                    string videoType = Convert.ToString(dataGridView.Rows[e.RowIndex].Cells[1].Value);
                    //播放车外视频
                    if (videoType == TextKit.videoOutValue)
                    {
                        playPath = this.pbVideoOutPath;
                    }
                    if (videoType == TextKit.videoInValue)
                    {
                        playPath = this.pbVideoInPath;
                    }

                    //播放器
                    string paramter = string.Format("-ss {0} -t {1} -threads 1 -x 640 -y 480 -autoexit -i {2}", stime, duration, playPath);

                    //VideoHandleKit.execute(VideoHandleKit.ffplayfile, paramter);
                    //axWindowsMediaPlayer1.URL = playPath;
                    //axWindowsMediaPlayer1.Ctlcontrols.play();//播放文件
                    PlayForm play = new PlayForm(stime, duration, playPath);
                    play.ShowDialog();
                }
                else
                {
                    if (code == 1)
                    {
                        MessageBox.Show(TextKit.failTimeMsg, "操作提示");
                    }
                    if (code == 2)
                    {
                        MessageBox.Show(TextKit.failDurationMsg, "操作提示");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetting_Click(object sender, EventArgs e)
        {
            List <SettingModel> data = new List <SettingModel>();
            int           code       = 0;
            StringBuilder sb         = new StringBuilder(@"@echo off");

            sb.Append("\r\n");
            sb.Append(VideoHandleKit.ffmpegfile);
            sb.Append("\r\n");

            string filelist      = string.Empty;
            int    totalDuration = 0;

            foreach (DataGridViewRow m in dataGridView.Rows)
            {
                SettingModel model    = new SettingModel();
                string       sort     = Convert.ToString(m.Cells["sort"].Value);
                string       type     = Convert.ToString(m.Cells["videotype"].Value);
                string       stime    = Convert.ToString(m.Cells["stime"].Value);
                string       duration = Convert.ToString(m.Cells["duration"].Value);
                if (!ValidateKit.IsTime(stime))
                {
                    code = 1;
                    break;
                }
                if (!ValidateKit.isNumber(duration))
                {
                    code = 2;
                    break;
                }
                model.sort     = sort;
                model.type     = type;
                model.stime    = stime;
                model.duration = duration;
                totalDuration += Convert.ToInt32(model.duration);
                string paramter = "%2";
                //判断车内车外
                if (model.type == TextKit.videoOutValue)
                {
                    paramter = "%3";
                }
                string filename = "tmp/" + model.sort + ".ts";
                sb.Append("ffmpeg -y -ss " + model.stime + " -i " + paramter + " -t " + model.duration + " -vcodec copy -an tmp/t.mp4 -loglevel 16");
                sb.Append("\r\n");
                sb.Append("ffmpeg -y -i tmp/t.mp4 -b:v 1024k -s 1080x640 -f mpegts " + filename + " -loglevel 16");
                sb.Append("\r\n");
                if (!string.IsNullOrEmpty(filelist))
                {
                    filelist += "|";
                }
                filelist += filename;
                data.Add(model);
            }
            if (code == 0)
            {
                //保存文件
                FileKit.setData(data);

                //ffmpeg -y -ss 0 -i bg.mp3 -t 52 -acodec copy tmp/1.mp3 -loglevel 16
                sb.AppendFormat("ffmpeg -y -ss 0 -i bg.mp3 -t {0} -acodec copy tmp/b.mp3 -loglevel 16", totalDuration);
                sb.Append("\r\n");
                sb.Append("ffmpeg -y -i \"concat:" + filelist + "\" -i tmp/b.mp3 -c copy tmp/body.ts -loglevel 16");
                sb.Append("\r\n");
                sb.Append("ffmpeg -y -i \"concat:header.ts|tmp/body.ts|footer.ts\" -vcodec h264 tmp/finish.mp4 -loglevel 16");
                sb.Append("\r\n");
                sb.Append(@"move %CD%\tmp\finish.mp4  %CD%\output\%1.mp4");
                FileKit.setData(sb.ToString(), "ffmpeg/e.bat");

                MessageBox.Show(TextKit.successMsg, "操作提示");
                this.Hide();
            }
            else
            {
                MessageBox.Show(TextKit.failMsg, "操作提示");
            }
        }