将传入的图像流保存到视频 [英] saving incoming image stream to video
问题描述
我需要将传入的图像流保存到视频中。目前我正在图像元素上显示一系列传入图像。这就是我所拥有的:
I need to save an incoming image stream into a video. Currently I am displaying a series of incoming images on an image element. This is what I have:
private void Received(ReceivedEventArgs e)
{
using (MemoryStream stream = new MemoryStream(
e.ReceivedBytes, e.StartIndex, e.BytesTransferred))
{
JpegBitmapDecoder decoder = new JpegBitmapDecoder(stream,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
Videoframe = decoder.Frames[0];
//anyway that I can save it to a video on local disk directly??
}
}
我想要知道的是,如果可以将图像流作为视频保存到硬盘上吗?如果是这样,我该怎么办呢?我用google搜索了很多,但他们都谈到了使用ffmpeg等将一系列预先存储的图像序列转换为视频;没有我觉得有帮助。任何指针/代码片段都会非常受欢迎,因为我不是编程专家。
谢谢!
What I want is to know is that if it is possible to save the image stream to the hard disk as a video? If so, how would I go about it? I have googled much but all of them talk about converting series of pre-stored image sequence to video using ffmpeg or such; none I found helpful. Any pointer/code snippet would be much appreciated since I am not an expert in programming.
Thank you!
推荐答案
这会对你有所帮助
AviFile库的简单C#包装器 [ ^ ]
This will help you
A Simple C# Wrapper for the AviFile Library[^]
我想解决它。这是代码:
Hi,
I manged to solve it. Here''s the code:
private Bitmap bmp;
private AviManager aviManager;
private VideoStream avistream;
private bool videocaptureactivated = false;
private Bitmap bitmap;
private void Savevideo()
{
string strpath = Environment.GetFolderPath (System.Environment.SpecialFolder.DesktopDirectory);
string filename = string.Format("Video Capture.avi");
string path = System.IO.Path.Combine(strpath, filename);
aviManager = new AviManager(path, false);
bmp = (Bitmap)System.Drawing.Image.FromFile(@"C:\samplescreen.bmp");
avistream = aviManager.AddVideoStream(false, framerate, bmp);
videocaptureactivated = true;
}
private void Received(ReceivedEventArgs e)
{
using (MemoryStream stream = new MemoryStream(
e.ReceivedBytes, e.StartIndex, e.BytesTransferred))
{
if (videocaptureactivated)
{
bitmap = (Bitmap)Bitmap.FromStream(stream);
avistream.AddFrame(bitmap);
}
}
}
private void stopsave()
{
videocaptureactivated = false;
bitmap.Dispose();
aviManager.Close();
}
由于视频编译为bmp''且未压缩,因此大小很大。我的下一步是做压缩写作。
感谢Ibrahim的建议!
Since the video is compiled bmp'' and uncompressed, the size is huge. Next step for me is to do the compressd writing.
Thanks for the suggestion Ibrahim!
这篇关于将传入的图像流保存到视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!