在C#中将图像转换为视频时,如何增加视频的长度(运行时)?

在C#中将图像转换为视频时,如何增加视频的长度(运行时)?,c#,windows,image,video,converters,C#,Windows,Image,Video,Converters,我正在使用Accord.Extensions.Imaging库。下面的代码成功地转换了放置在bin>Debug>Images文件夹中具有指定尺寸(729674)的png文件,并将转换后的视频文件放置在bin>Debug文件夹中,但视频长度为0秒。我知道这是有效的,因为在播放视频文件时,我会在瞬间看到图像 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste

我正在使用
Accord.Extensions.Imaging
库。下面的代码成功地转换了放置在
bin>Debug>Images
文件夹中具有指定尺寸(729674)的png文件,并将转换后的视频文件放置在
bin>Debug
文件夹中,但视频长度为0秒。我知道这是有效的,因为在播放视频文件时,我会在瞬间看到图像

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Accord.Extensions.Imaging;

namespace Image_To_Video_2
{
    class Program
    {
        static void Main(string[] args)
        {
            makeAvi("images", "video.avi");

        }

        public static void makeAvi(string imageInputfolderName, string outVideoFileName, float fps = 12.0f, string imgSearchPattern = "*.png")
        {   // reads all images in folder 
            VideoWriter w = new VideoWriter(outVideoFileName,
                new Accord.Extensions.Size(729, 674), fps, true, VideoCodec.MotionJpeg);
            Accord.Extensions.Imaging.ImageDirectoryReader ir =
                new ImageDirectoryReader(imageInputfolderName, imgSearchPattern);            

            while (ir.Position < ir.Length)
            {
                IImage i = ir.Read();
                w.Write(i);
            }
            w.Close();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Accord.Extensions.Imaging;
命名空间图像\u到\u视频\u 2
{
班级计划
{
静态void Main(字符串[]参数)
{
makeAvi(“images”、“video.avi”);
}
公共静态void makeAvi(字符串imageInputfolderName,字符串outVideoFileName,浮点fps=12.0f,字符串imgSearchPattern=“*.png”)
{//读取文件夹中的所有图像
VideoWriter w=新的VideoWriter(outVideoFileName,
新雅阁。扩展。大小(729674),fps,真,视频编解码器。运动JPEG);
Accord.Extensions.Imaging.ImageDirectoryReader ir=
新的ImageDirectoryReader(imageInputfolderName,imgSearchPattern);
而(红外位置<红外长度)
{
IImage i=ir.Read();
w、 编写(i);
}
w、 Close();
}
}
}

每个图像占用一帧。因此,可以降低(每秒帧数)fps的值。例如,当前代码中的12比1。在这种情况下,您的图像将每秒钟显示一次。

谢谢!我只想使用一个图像并将其转换为2分钟的视频,因为在代码中不可能使用少于1 fps的速度。我刚刚在文件夹中多次复制了图像,效果很好,这不是最好的解决方法,但效果很好。您知道如何通过代码正确地执行它吗?您可以使用文件夹中的一个图像,而不是在文件夹中重复多次,只需使用w.write(i)将其写入多次即可;要获得2分钟的视频,您需要以1倍的帧速率将其写入120次,非常感谢!