質問編集履歴

1

ソースを記載

2016/05/15 12:51

投稿

ariel200
ariel200

スコア33

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,201 @@
27
27
  タイムシフト再生のご経験がありましたら方法論だけでも結構ですのでご教示頂きたく、
28
28
 
29
29
  よろしくお願い致します。
30
+
31
+
32
+
33
+ 現在のソースを記載致します。撮影〜ファイル保存処理です。最終的にはタイムシフトの
34
+
35
+ プレビューをpictureBoxに表示したいです。
36
+
37
+ videoSource_Newframeメソッド内でフレーム毎のBitmapが取得できるので、そのBitmapデータを
38
+
39
+ 使って実現できそうな気もします。
40
+
41
+
42
+
43
+ ```C#
44
+
45
+ using System;
46
+
47
+ using System.IO;
48
+
49
+ using System.Collections.Generic;
50
+
51
+ using System.ComponentModel;
52
+
53
+ using System.Data;
54
+
55
+ using System.Drawing;
56
+
57
+ using System.Drawing.Imaging;
58
+
59
+ using System.Diagnostics;
60
+
61
+ using System.Linq;
62
+
63
+ using System.Text;
64
+
65
+ using System.Threading.Tasks;
66
+
67
+ using System.Windows.Forms;
68
+
69
+ using AForge.Video;
70
+
71
+ using AForge.Video.DirectShow;
72
+
73
+ using AForge.Video.FFMPEG;
74
+
75
+
76
+
77
+ namespace WindowsFormsApplication1
78
+
79
+ {
80
+
81
+ public partial class Form1 : Form
82
+
83
+ {
84
+
85
+ private FilterInfoCollection videoDevices;
86
+
87
+ private VideoCaptureDevice videoSource;
88
+
89
+ private VideoFileWriter writer;
90
+
91
+ private string fileName = string.Empty;
92
+
93
+
94
+
95
+ public Form1()
96
+
97
+ {
98
+
99
+ InitializeComponent();
100
+
101
+ }
102
+
103
+
104
+
105
+ private void Form1_Load(object sender, EventArgs e)
106
+
107
+ {
108
+
109
+ videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
110
+
111
+ writer = new VideoFileWriter();
112
+
113
+
114
+
115
+ foreach (FilterInfo device in videoDevices)
116
+
117
+ {
118
+
119
+ comboBox1.Items.Add(device.Name);
120
+
121
+ }
122
+
123
+
124
+
125
+ videoSource = new VideoCaptureDevice();
126
+
127
+ }
128
+
129
+
130
+
131
+ // 撮影開始/停止
132
+
133
+ private void button1_Click(object sender, EventArgs e)
134
+
135
+ {
136
+
137
+ if (videoSource.IsRunning)
138
+
139
+ {
140
+
141
+ terminate();
142
+
143
+ }
144
+
145
+ else
146
+
147
+ {
148
+
149
+ videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
150
+
151
+ VideoCapabilities cap = videoSource.VideoCapabilities[0];
152
+
153
+
154
+
155
+ videoSource.NewFrame += new NewFrameEventHandler(videoSource_Newframe);
156
+
157
+ videoSource.Start();
158
+
159
+
160
+
161
+ DateTime dt = DateTime.Now;
162
+
163
+ fileName = dt.ToString("yyyyMMdd_HHmmss") + ".avi";
164
+
165
+ writer.Open(fileName, cap.FrameSize.Width, cap.FrameSize.Height, cap.AverageFrameRate, VideoCodec.MPEG4);
166
+
167
+
168
+
169
+ }
170
+
171
+ }
172
+
173
+
174
+
175
+ public void videoSource_Newframe(object sender, NewFrameEventArgs eventArgs)
176
+
177
+ {
178
+
179
+ Bitmap image = (Bitmap)eventArgs.Frame.Clone();
180
+
181
+
182
+
183
+ ///////////////////////////////
184
+
185
+ // このBitmapを使って実現できる?
186
+
187
+ ///////////////////////////////
188
+
189
+
190
+
191
+ writer.WriteVideoFrame(image);
192
+
193
+ }
194
+
195
+
196
+
197
+ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
198
+
199
+ {
200
+
201
+ if (videoSource.IsRunning)
202
+
203
+ {
204
+
205
+ terminate();
206
+
207
+ }
208
+
209
+ }
210
+
211
+
212
+
213
+ private void terminate()
214
+
215
+ {
216
+
217
+ videoSource.Stop();
218
+
219
+ writer.Close();
220
+
221
+ }
222
+
223
+ }
224
+
225
+ }
226
+
227
+ ```