0

我怎样才能让所有的流媒体 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();
    }
}

}

4

3 回答 3

0

如果您查看您的示例,您会看到它们在每个循环中都修改了图像。你没有,所以你从头到尾都有相同的框架。

于 2012-10-01T09:34:04.160 回答
0

要测试一个示例,只需稍作更改并取消注释第 4 行,例如:

Bitmap img = eventArgs.Frame;
for (int i = 0; i < 1000; i++)
{
    JPEGStream JPEGSource = new JPEGStream(streamingSource);
    img = (bitmap)JPEGSource;
    // if JPEGSource is stream not image then use below like instead of above line
    // img = Image.FromStream(JPEGSource);
    writer.AddFrame(img);
}
writer.Close();

如果上述方法不起作用并且您将此流保存到名称为 timestamp.jpeg 的任何文件夹中,那么您可以使用以下代码:

using System.IO;

现在:

Bitmap img = eventArgs.Frame;
for (int i = 0; i < 1000; i++)
{
    // JPEGStream JPEGSource = new JPEGStream(streamingSource);
    // save it to folder like d:\images\
    // if you are saving images to folder using any other program 
    // then this might not be needed
    string[] filePaths = Directory.GetFiles(@"d:\images\");
    foreach(string f in filePaths)
    {
        img = Image.FromFile(f);
        writer.AddFrame(img);
    }
}
writer.Close();
于 2012-10-01T11:43:48.150 回答
0

对于循环的每次迭代,您都需要将下一张图像放入您的 img 中。

你将它们冷加载到一个数组中,然后在你的 for 循环中循环。


评论后编辑

假设您有 10 个图像名称 1.jpg 到 10.jpg

你冷做一个这样的数组。

        Image[] imageAry = new Image[10];

        for (int i = 0; i < 10; i++)
        {
            imageAry[i] = Image.FromFile(string.Format("{0}.jpg", i + 1))
        }

然后你会在你的 for 循环中使用你的 imageAry 数组并遍历每张图片。

于 2012-10-01T09:37:01.523 回答