C# 下寫入視頻的簡單實現


很多時候我們要讀寫視頻,C#讀視頻(對視頻解碼)網上的例子很多,然而寫視頻(對視頻編碼)的例子卻很少,也很少能搜索到有用的信息。下面是使用Aforge.Net寫視頻的簡單方案。

Aforge.Net 是一個 C# 版的圖像和計算機視覺庫,網站 http://www.aforgenet.com/ 。下載安裝。Aforge.Net 有一個子項目 AForge.Video.FFMPEG 對 ffmpeg 的視頻操作進行了封裝。

添加對 AForge.Video.FFMPEG.dll, AForge.Video.dll和 AForge.dll 三個 dll 的引用,Aforge.Net 的文檔中提供了個寫視頻的例子:

int width  = 320;
int height = 240;

// create instance of video writer
VideoFileWriter writer = new VideoFileWriter( );
// create new video file
writer.Open( "test.avi", width, height, 25, VideoCodec.MPEG4 );
// create a bitmap to save into the video file
Bitmap image = new Bitmap( width, height, PixelFormat.Format24bppRgb );
// write 1000 video frames
for ( int i = 0; i < 1000; i++ )
{
    image.SetPixel( i % width, i % height, Color.Red );
    writer.WriteVideoFrame( image );
}
writer.Close( );

由於 Aforge.Net 封裝的是 ffmpeg,因此需要將 ffmpeg 的幾個dll(AForge.NET\Framework\Externals\ffmpeg\bin路徑下的全部dll)放在執行路徑下。

如此簡單 …… </ p>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM