public static void MergeSubtitle(Info info) { string output = info.videoTemp; System.Drawing.Point point = new Point(info.X, info.Y); FontFace fontface = info.fontFace; double fontscale = info.scale; MCvScalar color = new Bgr(info.B, info.G, info.R).MCvScalar; int thickness = info.thickness; LineType lineType = info.lineType; bool bottomLeftOrigin = false; VideoCapture cap = new VideoCapture(info.VideoPath); if (!cap.IsOpened) { MessageBox.Show("打开视频失败"); } int fps = (int)cap.GetCaptureProperty(CapProp.Fps); int width = (int)cap.GetCaptureProperty(CapProp.FrameWidth); int height = (int)cap.GetCaptureProperty(CapProp.FrameHeight); int frameNum = (int)cap.GetCaptureProperty(CapProp.FrameCount); VideoWriter writer = new VideoWriter(output, 0x7634706d, 24, new System.Drawing.Size(width, height), true); Mat mat = new Mat(); int i = 0; while (i < frameNum) { cap.SetCaptureProperty(CapProp.PosFrames, i); cap.Read(mat); if (mat.IsEmpty) { break; } string text; if ((text = SubtitleOption.GetFrameString(fps, i)) != "") { CvInvoke.PutText(mat, text, point, fontface, fontscale, color, thickness, lineType, bottomLeftOrigin); } writer.Write(mat); i++; progressdelegate(i * 100 / frameNum); } }
private void importSubtitleFileToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog.FileName = ""; openFileDialog.Filter = "srt文件|*.srt"; if (openFileDialog.ShowDialog() == DialogResult.OK) { info.SubtitlePath = openFileDialog.FileName; info.subtitles = SubtitleOption.ParseSubtitle(info.SubtitlePath); labelChooseSubtitle.Text = openFileDialog.SafeFileName; TTS.CreateSpeechFile(TTS.SubtitleToXml(info.subtitles), info.speechTemp); } if (modeVideoToolStripMenuItem.Checked) { info.AudioPath = info.bgmTemp; } else { if (info.AudioPath == null) { return; } } Merge.MixBgmAndSpeech(info); }