English 中文(简体)
Create a Video Stream (AVI) from a Series of Images
原标题:

There is an IP web camera that I wrote a .NET class for sometime ago. It s basically a Timer implementation that pings a snapshot CGI script from the camera every five seconds. The camera itself is very rudamentary; it does not have any sort of API for me to work with, the only thing I can do programmatically (remotely) is invoke this script. The script returns a 640x480 JPEG image. Simple.

Now what I need to be able to do is take a days worth of these images, and create a "time lapse" AVI video stream out of it that will eventually be embedded into a web page. How can I do this with VB.NET?

最佳回答

.net doesn t directly support video formats. Your best option would be to use a 3rd party tool to generate the .avi.

ffmpeg is one option. You could access it directly via a command line like this:

ffmpeg -f image2 -i img%d.jpg /output/a.mpg

You would need to name your images img1.jpg, img2.jpg etc. For more details see the ffmpeg faq. You should also find details in the faq for how to output different video formats.

You can start a process from vb using Process.Start(). Something like this:

Process.Start("ffmpeg.exe", "-f image2 -i img%d.jpg /output/a.mpg")

You could also take a look at ffmpeg-sharp or Tao.FFmpeg, they are .net wrappers for the ffmpeg libraries. I haven t tried either personally, but it looks like it might help you out.

Another alternative would be to take a look at MEncoder, which has similar functionality. You should be able to look up a similar command line for this tool.

[Related SO question: 271003]

问题回答

FFMpeg has windows binaries and is very popular.

Making movies from image files using ffmpeg/mencoder

You ll have to check whether the available output formats suit you.

This is a C# wrapper by someone at Codeproject:

http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx

That wrapper should provide you with what you need.

There are several command-line tools that can take a series of images and output an AVI file. I would suggest you call one of them from your app.

I would provide links to suggestions, but it has been years since I ve used one.

Edit: apparently you can do this using ffmpeg: http://ffmpeg.org/ffmpeg-doc.html

For creating a video from many images:

ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi

The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签