Сохранение нескольких картинок(3000-4000 штук) в видеофайл(.mov или .avi) - C#
Формулировка задачи:
Здравствуйте! Я тут решил некое количество картинок(без звука) сохранить в видеофайл! Мысль в том, чтобы получать картинку и сразу-же дописывать её в файл! Желательно без использования сторонних библиотек!
Заранее спасибо, о Великие)
Решение задачи: «Сохранение нескольких картинок(3000-4000 штук) в видеофайл(.mov или .avi)»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Video.VFW;
using AForge.Video;
using AForge.Video.DirectShow;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
private bool DeviceExist = false;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource = null;
public AVIWriter writer;
private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
comboBox1.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
comboBox1.Items.Add(device.Name);
}
comboBox1.SelectedIndex = 0; //make dafault to first cam
}
catch (ApplicationException)
{
DeviceExist = false;
comboBox1.Items.Add("No capture device on your system");
}
}
private void button1_Click(object sender, EventArgs e) //рефреш списка подключенных веб камер
{
getCamList();
}
private void button2_Click(object sender, EventArgs e) //непостредственно запись
{
writer = new AVIWriter("DIB ");
// writer.Codec = "DivX";
// create new AVI file and open it
writer.Open("video.avi", 160, 120);
// create frame image
Bitmap image = new Bitmap(160, 120);
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.DesiredFrameSize = new Size(160, 120);
//videoSource.DesiredFrameRate = 10;
videoSource.Start();
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) //обработчик события NewFrame
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
//do processing here
writer.AddFrame(img);
}
private void CloseVideoSource() //отключить камеру
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource = null;
}
}
private void button3_Click(object sender, EventArgs e) //остановить запись
{
CloseVideoSource();
writer.Close();
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}