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

发布于 2024-12-08 09:33:20 字数 1212 浏览 0 评论 0 原文

我想用图像制作视频,每个图像应该停留一秒钟。 AVIWriter 具有 25 帧速率,因此我必须添加一张图像 25 次才能使其停留一秒钟。

我尝试更改帧速率,但它不起作用。

谁能建议一个解决方法?

以下是将帧写入视频的代码:

    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();
    }

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.

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();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千柳 2024-12-15 09:33:20

您好,我遇到了同样的问题,看到这个主题已阅读全部内容,但没有评论
http://www.aforgenet.com/framework/docs/html/bc8345f8-8e09-c1a4-4834-8330e5e85605.htm
有一条注释类似“应在打开新文件之前设置该属性才能生效”。

Hello I had the same problem and saw this topic read it all and no comment for
http://www.aforgenet.com/framework/docs/html/bc8345f8-8e09-c1a4-4834-8330e5e85605.htm
There is a note like that "The property should be set befor opening new file to take effect."

空城旧梦 2024-12-15 09:33:20

如果您使用以下代码,哈坎的解决方案是有效的:

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();

每秒显示一个位图。
(只是为了给出一段直接工作的代码)。

The solution of Hakan is working, if you use this code:

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).

一曲琵琶半遮面シ 2024-12-15 09:33:20

AVIWriter 的默认帧速率是 25。由于您无法指定丢弃或跳过的帧,为什么不设置 AVIWriter::FrameRate 属性设置为 1?

The default frame rate for AVIWriter is 25. As you have no option to specify dropped or otherwise skipped frames, why wouldn't you set AVIWriter::FrameRate property to 1 before you start populating your writer with frames?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文