スポーツのフォームチェック用に、ノートPCについているWebカメラで撮影して、任意の秒数
(1〜30秒くらいまで)を遅らせてからプレビュー画面に再生表示するソフトを開発したいです。
現状はVS Community 2015でC#フォームアプリケーション + AForge.NET 2.2.5を使っています。
まずはAForge.NETの勉強がてらWebカメラで撮影した動画をaviファイルとして保存、
再生する処理を実装する事はできました。
肝心のタイムシフト再生部分で実装方法が分からず困っています。そもそもどのような
考え方でタイムシフト再生が実現できるのか分からないというレベルです。
試した事は、保存しながら数秒後に再生させてみたのですが再生できませんでした。
(開始フレームから進まない)
タイムシフト再生のご経験がありましたら方法論だけでも結構ですのでご教示頂きたく、
よろしくお願い致します。
現在のソースを記載致します。撮影〜ファイル保存処理です。最終的にはタイムシフトの
プレビューをpictureBoxに表示したいです。
videoSource_Newframeメソッド内でフレーム毎のBitmapが取得できるので、そのBitmapデータを
使って実現できそうな気もします。
C#
1using System; 2using System.IO; 3using System.Collections.Generic; 4using System.ComponentModel; 5using System.Data; 6using System.Drawing; 7using System.Drawing.Imaging; 8using System.Diagnostics; 9using System.Linq; 10using System.Text; 11using System.Threading.Tasks; 12using System.Windows.Forms; 13using AForge.Video; 14using AForge.Video.DirectShow; 15using AForge.Video.FFMPEG; 16 17namespace WindowsFormsApplication1 18{ 19 public partial class Form1 : Form 20 { 21 private FilterInfoCollection videoDevices; 22 private VideoCaptureDevice videoSource; 23 private VideoFileWriter writer; 24 private string fileName = string.Empty; 25 26 public Form1() 27 { 28 InitializeComponent(); 29 } 30 31 private void Form1_Load(object sender, EventArgs e) 32 { 33 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); 34 writer = new VideoFileWriter(); 35 36 foreach (FilterInfo device in videoDevices) 37 { 38 comboBox1.Items.Add(device.Name); 39 } 40 41 videoSource = new VideoCaptureDevice(); 42 } 43 44 // 撮影開始/停止 45 private void button1_Click(object sender, EventArgs e) 46 { 47 if (videoSource.IsRunning) 48 { 49 terminate(); 50 } 51 else 52 { 53 videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString); 54 VideoCapabilities cap = videoSource.VideoCapabilities[0]; 55 56 videoSource.NewFrame += new NewFrameEventHandler(videoSource_Newframe); 57 videoSource.Start(); 58 59 DateTime dt = DateTime.Now; 60 fileName = dt.ToString("yyyyMMdd_HHmmss") + ".avi"; 61 writer.Open(fileName, cap.FrameSize.Width, cap.FrameSize.Height, cap.AverageFrameRate, VideoCodec.MPEG4); 62 63 } 64 } 65 66 public void videoSource_Newframe(object sender, NewFrameEventArgs eventArgs) 67 { 68 Bitmap image = (Bitmap)eventArgs.Frame.Clone(); 69 70 /////////////////////////////// 71 // このBitmapを使って実現できる? 72 /////////////////////////////// 73 74 writer.WriteVideoFrame(image); 75 } 76 77 private void Form1_FormClosing(object sender, FormClosingEventArgs e) 78 { 79 if (videoSource.IsRunning) 80 { 81 terminate(); 82 } 83 } 84 85 private void terminate() 86 { 87 videoSource.Stop(); 88 writer.Close(); 89 } 90 } 91}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/15 12:55