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

When converting image to video in C# how can I increase the length (runtime) of the video?

我正在使用 Accord.Extensions.Imaging 库。下面的代码成功转换了 bin > Debug > Images 文件夹中指定尺寸 (729, 674) 的 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();
        }
    }
}

每张图片占用一帧。因此,您可以降低 (Frame Per Second) fps 的值。例如,当前代码中的 12 为 1。在这种情况下,您的图像将每张显示 1 秒。