【问题标题】:AForge.NET -> AVIWriter Adding Images as FramesAForge.NET -> AVIWriter 添加图像作为框架
【发布时间】:2011-10-03 05:08:26
【问题描述】:

我想用图片制作视频,每张图片都应该停留一秒钟。 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();
    }

【问题讨论】:

  • 将相同的帧添加 25 次后,您会得到什么?
  • AVI 作为容器格式既适用于 1 fps 帧速率,也适用于空帧/丢失帧。如果您能找到一种方法来为您的帧(例如帧#0,然后是帧#25)加上时间戳并将其推送到这个库中,AVI API 会自动将丢失的帧添加为空帧,并且生成的文件将以 1 fps 的速度播放。
  • @box86rowh 当我添加相同的帧 25 次并且速率为 20 帧时,该帧会停留一秒钟。当我将帧速率降低到 20 并添加 20 帧时,每个帧停留的时间不到一秒。
  • @Inuyasha 我贴了视频加帧的相关代码......

标签: c# image video photo video-encoding


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您使用此代码,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();
    

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

    【讨论】:

      【解决方案3】:

      AVIWriter 的默认帧速率为 25。由于您无法指定丢弃或跳过的帧,为什么不将 AVIWriter::FrameRate 属性设置为 1,然后再开始使用帧填充写入器?

      【讨论】:

      • 我已经试过 writer.FrameRate = 1;但它仍然无法正常工作。默认值为 25,根据我的“糟糕”经验,无法更新。
      • 底层 AVI 编写器的工作方式如下:您不仅提供新帧,而且还带有时间戳。如果您推送帧#0、#1、#2 和#9,AVI 编写器层将考虑到这一点并处理跳过帧#3 到#8。所以它似乎是 AForge.NET 库的限制,因为它忽略了帧时间。也许您想查看 AForge.NET 代码并对其进行更新以解决问题。
      猜你喜欢
      • 2017-08-15
      • 1970-01-01
      • 2020-05-19
      • 2013-02-02
      • 2019-05-15
      • 2013-01-22
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      相关资源
      最近更新 更多