特定フォルダ以下のmp4のサムネイルを指定秒数で取得したくなった。取得をするたびに新しいタブページを追加する。ダブルクリックすると、explorerで開く。
実行ファイルと同じ場所にffmpeg.exeが必要。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace themenail { public partial class Form1 : Form { public Form1() { InitializeComponent(); toolStripProgressBar1.Visible = false; } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") return; toolStripProgressBar1.Visible = true; string path = textBox2.Text; string[] files; TabPage tp = new TabPage(); ListView lv = new ListView(); ImageList il = new ImageList(); il.ImageSize = new Size(255, 255); il.ColorDepth = ColorDepth.Depth32Bit; lv.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; lv.Size = new Size(tp.Size.Width-2,tp.Height-3); lv.Top = 2; lv.LargeImageList = il; lv.MouseDoubleClick += new MouseEventHandler(DbClick); tp.Controls.Add(lv); tabControl1.Controls.Add(tp); tabControl1.SelectedTab = tp; try { files = System.IO.Directory.GetFiles(path, "*.mp4",System.IO.SearchOption.AllDirectories); toolStripProgressBar1.Minimum = 0; toolStripProgressBar1.Maximum = files.Length; for (int i = 0; i < files.Length; i++) { Application.DoEvents(); toolStripProgressBar1.Value = i; System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo( Application.StartupPath + @"\ffmpeg.exe", "-ss " + textBox1.Text + " -i \"" + files[i] + "\" -vframes 1 -f image2 pipe:1"); ps.RedirectStandardOutput = true; ps.CreateNoWindow = true; ps.UseShellExecute = false; System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = ps; p.Start(); Image img = Image.FromStream(p.StandardOutput.BaseStream); Image theme = img.GetThumbnailImage(255, 255, null, IntPtr.Zero); il.Images.Add(theme); lv.Items.Add(files[i], i); } } catch (Exception ex) { MessageBox.Show(ex.Message); } toolStripProgressBar1.Visible = false; MessageBox.Show("完了"); } private void DbClick(object sender, MouseEventArgs e) { string path = ((ListView)sender).SelectedItems[0].Text; System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "explorer"; p.StartInfo.Arguments = "/select," + path; p.Start(); } } } |