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, "操作提示"); } } } }
/// <summary> /// 立即提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmit_Click(object sender, EventArgs e) { string phone = txtPhone.Text; string date = txtDate.Text; if (string.IsNullOrEmpty(phone)) { MessageBox.Show(TextKit.failMsg, "操作提示"); return; } if (!ValidateKit.isMobile(phone)) { MessageBox.Show(TextKit.failMobileMsg, "操作提示"); return; } DataGridViewRow row = new DataGridViewRow(); //排序 DataGridViewTextBoxCell sort = new DataGridViewTextBoxCell(); sort.Value = Convert.ToInt32(dataGridView.Rows.Count + 1); row.Cells.Add(sort); //手机号 DataGridViewTextBoxCell phoneCell = new DataGridViewTextBoxCell(); phoneCell.Value = phone; row.Cells.Add(phoneCell); DataGridViewTextBoxCell starttime = new DataGridViewTextBoxCell(); starttime.Value = date; row.Cells.Add(starttime); DataGridViewTextBoxCell transcodeCell = new DataGridViewTextBoxCell(); transcodeCell.Value = "等待转码"; row.Cells.Add(transcodeCell); DataGridViewTextBoxCell upCell = new DataGridViewTextBoxCell(); upCell.Value = "等待资源"; row.Cells.Add(upCell); DataGridViewTextBoxCell inPathCell = new DataGridViewTextBoxCell(); inPathCell.Value = this.pbInPath; row.Cells.Add(inPathCell); DataGridViewTextBoxCell outPathCell = new DataGridViewTextBoxCell(); outPathCell.Value = this.pbOutPath; row.Cells.Add(outPathCell); dataGridView.Rows.Add(row); DataModel data = new DataModel(); data.phone = phone; data.starttime = date; data.op = phone + " " + pbInPath + " " + pbOutPath;; data.sort = dataGridView.Rows.Count - 1; //获取个人摆拍 if (!string.IsNullOrEmpty(this.pbPhotoPath)) { data.photo = this.pbPhotoPath; //copy个性摆拍 System.IO.File.Copy(data.photo, System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + data.phone + ".jpg"); } UploadDataModel m = new UploadDataModel(); m.phone = data.phone; m.starttime = data.starttime; m.mac = MacKit.GetMacString(); FileKit.createFile(JsonConvert.SerializeObject(m), System.IO.Directory.GetCurrentDirectory() + @"\ffmpeg\output\" + data.phone + ".json"); txtPhone.Text = ""; txtDate.Text = ""; pbIn.Image = global::VideoApplication.Properties.Resources._in; pbOut.Image = global::VideoApplication.Properties.Resources._out; pbPhoto.Image = global::VideoApplication.Properties.Resources.image; this.pbInPath = ""; this.pbOutPath = ""; this.pbPhotoPath = ""; wirteGridData(); QueueKit.q.Enqueue(data); }
/// <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, "操作提示"); } }