我怎样才能让所有的流媒体 jpeg 创建一个 avi?
Bitmap img = eventArgs.Frame;
for (int i = 0; i < 1000; i++)
{
//img.SetPixel(i, i, Color.Red);
writer.AddFrame(img);
}
writer.Close();
我从 AForge 那里得到了这个例子,http: //www.aforgenet.com/framework/docs/html/5fedbbbe-6d28-5f69-35a2-9d7119544a2d.htm 但是当我测试它时,它会创建一个具有 1 个相同帧的视频文件从视频开始到结尾。
我如何执行 writer.AddFrame(img); 每次都用新帧创建视频文件?
编辑:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Drawing;
using System.IO;
using AForge.Video;
using AForge.Video.VFW;
using AForge.Video.DirectShow;
namespace VidRec
{
public partial class LiveRecording : System.Web.UI.Page
{
AVIWriter writer = new AVIWriter("MSVC"); //video with compression
protected void Page_Load(object sender, EventArgs e)
{
//camera source
string streamingSource = "http://e888.example.com:81/snapshot.cgi";
// create new AVI file and open it
writer.Open("c:\\video.avi", 640, 480);
//IPcam streaming source to be recorded
JPEGStream JPEGSource = new JPEGStream(streamingSource);
//MJPEGStream JPEGSource = new MJPEGStream(streamingSource);
//login name and password
JPEGSource.Login = "login";
JPEGSource.Password = "password";
//set NewFrame event handler
JPEGSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
//start streaming the image files
JPEGSource.Start();
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) //event handler for NewFrame
{
//get frame
Bitmap image = eventArgs.Frame;
//add the image as a new frame of video file
writer.AddFrame(image);
}
protected void Button1_Click(object sender, EventArgs e)
{
writer.Close();
}
}
}