图像序列的视频流? [英] Image sequence to video stream?
问题描述
许多人一样似乎已经有(有多个线程对这个问题在这里)我在想办法从图像序列创建的视频。
Like many people already seem to have (there are several threads on this subject here) I am looking for ways to create video from a sequence of images.
我想要实现在C#我的功能!
I want to implement my functionality in C#!
下面是我wan't做的:
Here is what I wan't to do:
/*Pseudo code*/
void CreateVideo(List<Image> imageSequence, long durationOfEachImageMs, string outputVideoFileName, string outputFormat)
{
// Info: imageSequence.Count will be > 30 000 images
// Info: durationOfEachImageMs will be < 300 ms
if (outputFormat = "mpeg")
{
}
else if (outputFormat = "avi")
{
}
else
{
}
//Save video file do disk
}
我知道有一个叫做项目的熔接机( HTTP://splicer.$c$cplex.com / ),但我无法找到合适的文档或明显的例子,我可以按照(<一个href=\"http://www.$c$cplex.com/Splicer/Wiki/View.aspx?title=News%20Feeds&referringTitle=Home\">these是我找到的例子)。
I know there's a project called Splicer (http://splicer.codeplex.com/) but I can't find suitable documentation or clear examples that I can follow (these are the examples that I found).
最近我想做的事情,我觉得在这里codePLEX是这样的:
<一href=\"http://stackoverflow.com/questions/251467/how-can-i-create-a-video-from-a-directory-of-images-in-c\">How我可以在C#中图像的目录中创建一个视频?
The closest I want to do, which I find here on CodePlex is this: How can I create a video from a directory of images in C#?
我也看到有关的的ffmpeg (例如这几个主题:<一href=\"http://stackoverflow.com/questions/1707516/c-sharp-and-ffmpeg-$p$pferably-without-shell-commands\">C# ?和FFmpeg的preferably没有shell命令以及这样的:使用的ffmpeg转换图像序列),但我觉得没有人帮助我与我的问题,我不认为的ffmpeg -command线风格对我来说是最好的解决方案(因为图像的量)
I have also read a few threads about ffmpeg (for example this: C# and FFmpeg preferably without shell commands? and this: convert image sequence using ffmpeg) but I find no one to help me with my problem and I don't think ffmpeg-command-line-style is the best solution for me (because of the amount of images).
我相信,我可以使用拼接器以某种方式 - 项目(?)。
I believe that I can use the Splicer-project in some way (?).
在我的情况下,约约> 30 000的图像,每个图像应显示为约200毫秒(在视频流,我想创建)。
In my case, it is about about > 30 000 images where each image should be displayed for about 200 ms (in the videostream that I want to create).
(视频是什么?越来越多的植物...)
(What the video is about? Plants growing ...)
谁能帮我完成我的功能?
Can anyone help me complete my function?
推荐答案
那么,这个答案来得有点晚了,但因为我已经注意到与我原来的问题最近的一些活动(以及有没有提供一个可行的解决方案的事实)我想给你什么终于为我工作。
Well, this answer comes a bit late, but since I have noticed some activity with my original question lately (and the fact that there was not provided a working solution) I would like to give you what finally worked for me.
我要我的答案分为三部分:
I'll split my answer into three parts:
- 背景
- 问题
- 解决方案
(此部分是不重要的溶液)
(this section is not important for the solution)
我原来的问题是,我有很多的图像(即一个巨大的量),这是单独存储在数据库中的字节数组图像。的我要拍一个视频序列与所有这些图像。的
My original problem was that I had a lot of images (i.e. a huge amount), images that were individually stored in a database as byte arrays. I wanted to make a video sequence with all these images.
我的设备安装了这样的事情总图:
My equipment setup was something like this general drawing:
图像描绘在不同状态下成长的番茄植株。所有的图像是在白天每隔1分钟。
The images depicted growing tomato plants in different states. All images were taken every 1 minute under daytime.
/*pseudo code for taking and storing images*/
while (true)
{
if (daylight)
{
//get an image from the camera
//store the image as byte array to db
}
//wait 1 min
}
我有一个非常简单的数据库存储图像,有它只有一个表(该表ImageSet):
I had a very simple db for storing images, there were only one table (the table ImageSet) in it:
我读到的ffmpeg(请参阅我原来的问题)的文章很多,但我找不到任何关于如何从图像的采集到的视频。
I had read many articles about ffmpeg (please see my original question) but I couldn't find any on how to go from a collection of images to a video.
最后,我得到了一个工作的解决方案!
它的主要部分来自于开源项目 AForge.NET 。总之,你可以说, AForge.NET是在C#计算机视觉和人工智能库。
(如果你想在框架的一个副本,只要抓住它 http://www.aforgenet.com/ )
Finally, I got a working solution! The main part of it comes from the open source project AForge.NET. In short, you could say that AForge.NET is a computer vision and artificial intelligence library in C#. (If you want a copy of the framework, just grab it from http://www.aforgenet.com/)
在AForge.NET,有这种VideoFileWriter类(与ffmpeg的帮助编写videofiles一类)。这几乎做了所有的工作。 (还有一个很好的例子<一个href=\"http://www.aforgenet.com/framework/docs/html/4ee1742c-44d3-b250-d6aa-90cd2d606611.htm\">here)
In AForge.NET, there is this VideoFileWriter class (a class for writing videofiles with help of ffmpeg). This did almost all of the work. (There is also a very good example here)
这是我用来获取和图像数据从我的图像数据库转换成影片的最后类(减少):
This is the final class (reduced) which I used to fetch and convert image data into a video from my image database:
public class MovieMaker
{
public void Start()
{
var startDate = DateTime.Parse("12 Mar 2012");
var endDate = DateTime.Parse("13 Aug 2012");
CreateMovie(startDate, endDate);
}
/*THIS CODE BLOCK IS COPIED*/
public Bitmap ToBitmap(byte[] byteArrayIn)
{
var ms = new System.IO.MemoryStream(byteArrayIn);
var returnImage = System.Drawing.Image.FromStream(ms);
var bitmap = new System.Drawing.Bitmap(returnImage);
return bitmap;
}
public Bitmap ReduceBitmap(Bitmap original, int reducedWidth, int reducedHeight)
{
var reduced = new Bitmap(reducedWidth, reducedHeight);
using (var dc = Graphics.FromImage(reduced))
{
// you might want to change properties like
dc.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
dc.DrawImage(original, new Rectangle(0, 0, reducedWidth, reducedHeight), new Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel);
}
return reduced;
}
/*END OF COPIED CODE BLOCK*/
private void CreateMovie(DateTime startDate, DateTime endDate)
{
int width = 320;
int height = 240;
var framRate = 200;
using (var container = new ImageEntitiesContainer())
{
//a LINQ-query for getting the desired images
var query = from d in container.ImageSet
where d.Date >= startDate && d.Date <= endDate
select d;
// create instance of video writer
using (var vFWriter = new VideoFileWriter())
{
// create new video file
vFWriter.Open("nameOfMyVideoFile.avi", width, height, framRate, VideoCodec.Raw);
var imageEntities = query.ToList();
//loop throught all images in the collection
foreach (var imageEntity in imageEntities)
{
//what's the current image data?
var imageByteArray = imageEntity.Data;
var bmp = ToBitmap(imageByteArray);
var bmpReduced = ReduceBitmap(bmp, width, height);
vFWriter.WriteVideoFrame(bmpReduced);
}
vFWriter.Close();
}
}
}
}
更新2013年11月29日(如何)(希望这是你问什么@Kiquenet?)
Update 2013-11-29 (how to) (Hope this is what you asked for @Kiquenet?)
- 从下载页面下载AForge.NET框架(下载文件ZIP压缩文件,你会发现很多有趣的视觉与项目,如视频工作室解决方案,在
AForge.NET框架-2.2.5 \\ Samples文件夹
...) - 命名空间:
AForge.Video.FFMPEG
(从<一个href=\"http://www.aforgenet.com/framework/docs/html/4ee1742c-44d3-b250-d6aa-90cd2d606611.htm\">documentation) - 大会:
AForge.Video.FFMPEG
(在AForge.Video.FFMPEG.dll
)(从<一个href=\"http://www.aforgenet.com/framework/docs/html/4ee1742c-44d3-b250-d6aa-90cd2d606611.htm\">documentation) (你可以找到这个AForge.Video.FFMPEG.dll
在AForge.NET框架-2.2.5 \\发布
文件夹)
- Download AForge.NET Framework from the downloads page (Download full ZIP archive and you will find many interesting Visual Studio solutions with projects, like Video, in the
AForge.NET Framework-2.2.5\Samples folder
...) - Namespace:
AForge.Video.FFMPEG
(from the documentation) - Assembly:
AForge.Video.FFMPEG
(inAForge.Video.FFMPEG.dll
) (from the documentation) (you can find thisAForge.Video.FFMPEG.dll
in theAForge.NET Framework-2.2.5\Release
folder)
如果你想创建您的自己的解决方案的,请确保你在你的项目中引用 AForge.Video.FFMPEG.dll
。然后,它应该很容易使用VideoFileWriter类。如果按照<一个href=\"http://www.aforgenet.com/framework/docs/html/4ee1742c-44d3-b250-d6aa-90cd2d606611.htm\">link对类,你会发现一个很不错的(和简单的例子)。在code,他们喂养与位图
在为
-loop
If you want to create your own solution, make sure you have a reference to AForge.Video.FFMPEG.dll
in your project. Then it should be easy to use the VideoFileWriter class. If you follow the link to the class you will find a very good (and simple example). In the code, they are feeding the VideoFileWriter with Bitmap image
in a for
-loop
这篇关于图像序列的视频流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!