如何创建图像序列文件的视频文件? [英] How to create video file from Images sequence file?

查看:502
本文介绍了如何创建图像序列文件的视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有400序列图像。
我想从他们创造的视频文件(夹.. MPEG)

I have 400 sequence images. I want to create from them video file ( clip .. mpeg )

我下载AForge.NET',我试图寻找到它,看看如果可能的 - 但我不精没有办法做到这一点。

I download the 'AForge.NET' and i try to look into it to see if it possible - but i don't fine any way to do it.

我该怎么办呢?

推荐答案

查找文档,找到的 VideoFileWriter类,看它的成员中,看到的 WriteVideoFrame方法(S),阅读的的:写新的视频帧到当前打开的视频文件。答对了。走了一半。

Look up the documentation, find the VideoFileWriter Class, look at it's members, see the WriteVideoFrame method(s), read the line: "Write new video frame into currently opened video file.". Bingo. Half way there.

如果阅读了这些方法的签名(当您无法连接点的 WriteVideoFrame(位图) )或不理解如何使用 打开()重载或的 关闭()方法(你为什么不,最后两个是相当常见的文件I / O),你可以随时的谷歌VideoFileWriter WriteVideoFrame例如,的找到代码,从那里去。该函数的肉有:

If you can't connect the dots when reading the methods' signature (WriteVideoFrame(Bitmap)) or don't understand how to use the Open() overloads or Close() method (why wouldn't you, the last two are pretty common for File I/O) you can always Google "VideoFileWriter WriteVideoFrame example", find code, go from there. The meat of the function there is:

VideoFileWriter writer = new VideoFileWriter();
writer.Open("myfile.avi", width, height, 25, VideoCodec.MPEG4, 1000000);
    // ... here you'll need to load your bitmaps
    writer.WriteVideoFrame(image);
}
writer.Close();



所以,这样的事情或许应该工作:

So something like this should probably work:

using (VideoFileWriter writer = new VideoFileWriter()) 
{
    writer.Open(@"d:\myfile.avi", 640, 480, 25, VideoCodec.MPEG4);
    foreach (var file in Directory.GetFiles(@"d:\foo\bar", "*.jpg"))
    {
        writer.WriteVideoFrame(Bitmap.FromFile(file) as Bitmap);
    }
    writer.Close();
}



其中,有摆弄周围的几分钟,给了我这样的:

Which, with a few minutes of fiddling around, gave me something like this:

var size = new Size(1600, 1200);                    // The desired size of the video
var fps = 25;                                       // The desired frames-per-second
var codec = VideoCodec.MPEG4;                       // Which codec to use
var destinationfile = @"d:\myfile.avi";             // Output file
var srcdirectory = @"d:\foo\bar";                   // Directory to scan for images
var pattern = "*.jpg";                              // Files to look for in srcdirectory
var searchoption = SearchOption.TopDirectoryOnly;   // Search Top Directory Only or all subdirectories (recursively)?

using (var writer = new VideoFileWriter())          // Initialize a VideoFileWriter
{
    writer.Open(destinationfile, size.Width, size.Height, fps, codec);              // Start output of video
    foreach (var file in Directory.GetFiles(srcdirectory, pattern, searchoption))   // Iterate files
    {
        using (var original = (Bitmap)Image.FromFile(file))     // Read bitmap
        using (var resized = new Bitmap(original, size))        // Resize if necessary
            writer.WriteVideoFrame(resized);                    // Write frame
    }
    writer.Close();                                 // Close VideoFileWriter
}                                                   // Dispose VideoFileWriter

这调整大小的图像;不应在序列中的所有图像是相同的。如果他们的的你可以简单地通过改变

This resizes images; should not all images in the sequence be the same. If they are you can skip that step simply by changing

using (var original = (Bitmap)Image.FromFile(file))     // Read bitmap
using (var resized = new Bitmap(original, size))        // Resize if necessary
    writer.WriteVideoFrame(resized);                    // Write frame



to:

using (var mybitmap = (Bitmap)Image.FromFile(file))     // Read bitmap
    writer.WriteVideoFrame(mybitmap);                   // Write frame



另外,还要确保你添加正确的使用报表;你会在最低限度,需要上面的例子如下:

Also make sure you add the correct using statements; you will, at a minimum, need the following for above examples:

using AForge.Video.FFMPEG;
using System.Drawing;
using System.IO;



此外,你需要引用的DLL的描述的这里

...您应该已经创建了一个项目,加入到AForge.Video.FFMPEG库的引用,设置目标平台,x86和目标框架版本3.5或更低了。如果是的话,就可以继续下去。

... you should have created a project, added a reference to the AForge.Video.FFMPEG library, set the target platform to x86 and the target framework version to 3.5 or lower now. If so, it can go on.

...我们需要从AForge存档几个dll文件。您可以在AForge存档文件夹里面的Externals\ffmpeg中找到这些。在此文件夹中的所有文件都复制到您的Visual Studio项目的输出文件夹。 (之后我们改变了目标架构现在应该是YourProjectFolder\bin\x86\Debug。)

... we need a few more dlls from the AForge archive. You can find these in the folder "Externals\ffmpeg" inside the AForge archive. All files in this folder have to be copied to the output folder of your Visual Studio project. (After we changed the target architecture this now should be "YourProjectFolder\bin\x86\Debug".)

如果它依然的的工作,然后告诉我们发生了什么,的确切的错误信息等。

If it still doesn't work then tell us what happens, exact error messages etc.

这篇关于如何创建图像序列文件的视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆