/// <summary> /// だいたい0.3秒おきの動画サムネイルを取得する /// </summary> /// <param name="videoPath">ビデオファイルパス</param> /// <returns></returns> public static IEnumerable <Bitmap> GetThumbnails(string videoPath) { // メタ情報で再生時間取得 var ffprob = new NReco.VideoInfo.FFProbe(); var info = ffprob.GetMediaInfo(videoPath); var duration = info.Duration; var videoConv = new NReco.VideoConverter.FFMpegConverter(); // 最短0.3秒おき、最大100分割 var skipSec = duration.TotalSeconds < 30 ? 0.3f : (float)(duration.TotalSeconds / 100); var frameSec = 0f; while ((float)duration.TotalSeconds > frameSec) { // Bitmapリソースは受信側で開放する。 var jpegStream = new MemoryStream(); videoConv.GetVideoThumbnail(videoPath, jpegStream, frameSec); yield return((Bitmap)Image.FromStream(jpegStream)); frameSec += skipSec; } }
private void BtnConvert_Click(object sender, EventArgs e) { this.btnBrowse.Enabled = false; this.btnConvert.Enabled = false; this.btnDestination.Enabled = false; this.listAudio.Items.Clear(); int i = 0; this.lblCurrentFile.Visible = true; this.pbProgress.Visible = true; this.listVideo.Visible = true; this.listAudio.Visible = true; this.pbTotalProgress.Visible = true; this.pbProgress.Maximum = 100; this.pbTotalProgress.Maximum = 100; this.totalItem = this.listVideo.Items.Count; this.pbTotalProgress.Value = 0; this.processedItem = 0; foreach (string file in this.input) { try { this.pbProgress.Value = 0; this.processedItem = i + 1; //var item = this.listVideo.Items[i]; //string outputFile = item.ToString(); var outputFile = Path.GetFileNameWithoutExtension(file); //outputFile.Substring(0, outputFile.LastIndexOf('.')); this.lblCurrentFile.Text = "Converting: " + file; var ConvertToAudio = new NReco.VideoConverter.FFMpegConverter(); var ffprobe = new NReco.VideoInfo.FFProbe(); MediaInfo videoInfo = ffprobe.GetMediaInfo(file); this.totalSeconds = videoInfo.Duration.Milliseconds; ConvertToAudio.ConvertProgress += new EventHandler <ConvertProgressEventArgs>(this.UpdateProgress); ConvertToAudio.ConvertMedia(file, this.txtAudio.Text + "\\" + outputFile + ".mp3", "mp3"); this.listAudio.Items.Add(this.txtAudio.Text + "\\" + outputFile + ".mp3"); i++; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); i++; } } this.lblCurrentFile.Text = "Completed"; this.btnBrowse.Enabled = true; this.btnConvert.Enabled = true; this.btnDestination.Enabled = true; }