简体   繁体   English

AForge.NET-> AVIWriter将图像添加为框架

[英]AForge.NET -> AVIWriter Adding Images as Frames

I want to make a video from images, and each image should stay for one second. 我想用图像制作视频,每个图像应停留一秒钟。 The AVIWriter has 25 frames rate, so i have to add one image 25 times to make it stay for one second. AVIWriter具有25帧速率,因此我必须添加一张图像25次以使其停留一秒钟。

I tried changing the frame-rate, but it is not working. 我尝试更改帧速率,但无法正常工作。

Can anyone suggest a workaround? 谁能建议解决方法?

The following is the code for writing frames into video: 以下是将帧写入视频的代码:

    private void writeVideo()
    {
        // instantiate AVI writer, use WMV3 codec
        AVIWriter writer = new AVIWriter("wmv3");
        // create new AVI file and open it
        writer.Open(fileName, 320, 240);
        // create frame image
        Bitmap image = new Bitmap(320, 240);
        var cubit = new AForge.Imaging.Filters.ResizeBilinear(320, 240);
        string[] files = Directory.GetFiles(imagesFolder);
        writer.FrameRate = 25;
        int index = 0;
        int failed = 0;
        foreach (var item in files)
        {
            index++;
            try
            {
                image = Image.FromFile(item) as Bitmap;
                //image = cubit.Apply(image);

                for (int i = 0; i < 25; i++)
                {
                    writer.AddFrame(image); 
                }   
            }
            catch
            {
                failed++;
            }
            this.Text = index + " of " + files.Length + ". Failed: " + failed;
        }
        writer.Close();
    }

您好,我遇到了同样的问题,看到此主题已全部阅读,没有对http://www.aforgenet.com/framework/docs/html/bc8345f8-8e09-c1a4-4834-8330e5e85605.htm进行评论“应在打开新文件生效之前设置该属性。”

The solution of Hakan is working, if you use this code: 如果使用以下代码,则Hakan的解决方案将起作用:

AVIWriter videoWriter;
videoWriter = new AVIWriter("wmv3");
videoWriter.FrameRate = 1;
videoWriter.Open("test.avi", 320, 240);
videoWriter.AddFrame(bitmap1);
videoWriter.AddFrame(bitmap2);
videoWriter.AddFrame(bitmap3);
videoWriter.Close();

There is well one bitmap displayed per second. 每秒显示一个位图。 (just for giving a directly working piece of code). (仅用于给出直接起作用的代码)。

AVIWriter的默认帧速率为25。由于您没有选择指定丢弃或跳过帧的选项,为什么在开始使用帧填充写入器之前,为什么不将AVIWriter::FrameRate属性设置为1?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM