我有一个位图目录,它们都是相同的维度.我想将这些位图转换为视频文件.我不在乎视频文件(编解码器)是wmv还是avi.我唯一的要求是我指定帧率.这不需要跨平台,仅限Windows(Vista和XP).我已经阅读了一些关于使用Windows Media SDK或DirectShow的内容,但它们都没有明确提供代码示例.
任何人都可以提供一些见解,或者一些有价值的资源可以帮助我在C#中做到这一点吗?
如果被拒绝,我将提供一个可能的替代选项 - 缓冲的位图动画.
double framesPerSecond; Bitmap[] imagesToDisplay; // add the desired bitmaps to this array Timer playbackTimer; int currentImageIndex; PictureBox displayArea; (...) currentImageIndex = 0; playbackTimer.Interval = 1000 / framesPerSecond; playbackTimer.AutoReset = true; playbackTimer.Elapsed += new ElapsedEventHandler(playbackNextFrame); playbackTimer.Start(); (...) void playbackNextFrame(object sender, ElapsedEventArgs e) { if (currentImageIndex + 1 >= imagesToDisplay.Length) { playbackTimer.Stop(); return; } displayArea.Image = imagesToDisplay[currentImageIndex++]; }
如果观看用户可以访问图像,足够的资源将图像保存在存储器中,不想等待视频编码,并且可能存在对不同回放速度的需要,则诸如此类的方法工作良好.
......把它扔出去
您可以使用Splicer执行此操作.
请参阅http://www.codeplex.com/splicer/Wiki/View.aspx?title=News%20Feeds&referringTitle=Home上的示例3
编辑:
using (ITimeline timeline = new DefaultTimeline(25)) { IGroup group = timeline.AddVideoGroup(32, 160, 100); ITrack videoTrack = group.AddTrack(); IClip clip1 = videoTrack.AddImage("image1.jpg", 0, 2); IClip clip2 = videoTrack.AddImage("image2.jpg", 0, 2); IClip clip3 = videoTrack.AddImage("image3.jpg", 0, 2); IClip clip4 = videoTrack.AddImage("image4.jpg", 0, 2); double halfDuration = 0.5; group.AddTransition(clip2.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip2.Offset, halfDuration, StandardTransitions.CreateFade(), false); group.AddTransition(clip3.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip3.Offset, halfDuration, StandardTransitions.CreateFade(), false); group.AddTransition(clip4.Offset - halfDuration, halfDuration, StandardTransitions.CreateFade(), true); group.AddTransition(clip4.Offset, halfDuration, StandardTransitions.CreateFade(), false); ITrack audioTrack = timeline.AddAudioGroup().AddTrack(); IClip audio = audioTrack.AddAudio("soundtrack.wav", 0, videoTrack.Duration); audioTrack.AddEffect(0, audio.Duration, StandardEffects.CreateAudioEnvelope(1.0, 1.0, 1.0, audio.Duration)); using ( WindowsMediaRenderer renderer = new WindowsMediaRenderer(timeline, "output.wmv", WindowsMediaProfiles.HighQualityVideo)) { renderer.Render(); } }