使用aforge的AVIWriter打开或创建文件异常Failed creating compressed stream的解决办法

参考http://www.aforgenet.com/framework/features/avi_files.html

Reading/writing AVI files

AForge.NET framework provides simple API to read and write AVI video files throughVideo for Windows interface. Although the interface is quite old and marked as obsolete by Microsoft, it is still supported and gives fairly simple API for accessing AVI video files.

AVIReader class
The class provides access to AVI video files and allows getting each video frame individually, as well as navigate through a video file specifying index of the next frame to receive:

// instantiate AVI reader
AVIReader reader = new AVIReader( );
// open video file
reader.Open( "test.avi" );
// read the video file
while ( reader.Position - reader.Start < reader.Length )
{
    // get next frame
    Bitmap image = reader.GetNextFrame( );
    // .. process the frame somehow or display it
}
reader.Close( );

AVIWriter class
The class provides simple API for writing AVI video files. All you need to do is to specify codec to use, video size and frame rate and then start adding frames: 

// instantiate AVI writer, use WMV3 codec
AVIWriter writer = new AVIWriter( "wmv3" );
// create new AVI file and open it
writer.Open( "test.avi", 320, 240 );
// create frame image
Bitmap image = new Bitmap( 320, 240 );

for ( int i = 0; i < 240; i++ )
{
    // update image
    image.SetPixel( i, i, Color.Red );
    // add the image as a new frame of video file
    writer.AddFrame( image );
}
writer.Close( );

使用writer.Open( "test.avi", 320, 240 );的时候,抛出异常Failed creating compressed stream

原因是:(1)wmv3编码不能在64bit下运行(2)windows7没有相应的codec

解决方法:(1)将所有的项目,改为x86 (2)安装wmv9VCMsetup (下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=6191) 本人由于是32位的win7系统,只安装了Winndows Media Video 9 VCM就解决了问题。


感谢 Aforge开发摄像头监控的一些情况说明 http://www.cnblogs.com/ddlzq/archive/2010/10/21/1857385.html




  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Easiest way to install: Load the program group AviDemo.bpg, install the package AviPack.dpk(bpl), try the demos. Read the source of AviWriter_2.pas (in AviPack) to get help on what the procedures and properties do. **Current version: AviWriter_2 ver 1.0.0.4 Changes: Finally got On-the-fly compression working with still being able to add an audio-stream. Use property OnTheFlyCompression (default is true) Also, now more than one audio file can be added. For each wav-file a delay (ms) can be specified, which says when it'll start playing. Use method AddWaveFile. In 1.0.0.3 the delay got too short. Now it seems to work, due to really adding "silence" from the end of the previous audio file. Note: Some Codecs don't support On-the-fly compression. If OnTheFlyCompression is false, only one wave file can be added. **A list of codec-gotchas: (still unclear about the exact range of occurrance) IV50 Indeo Video 5: Both frame dimensions must be a factor of 4. DIVX DivX codec: Both frame dimensions must be a factor of 4. Gives a floating point error under certain circumstances. More and more likely that this occurs if the frames are too "different". If this happens, then there's an AV in Avifil32.dll, don't know how to prevent this. The codec compresses real movies nicely at frametimes <=60 ms, when changing the settings in its dialog box as follows: Bitrate (1st page): to >=1300 Max Keyframe interval (2nd page): to <=20. MRLE MS-RLE Use that one if you want to make avis which play transparently in a TAnimate. (Thanks Eddie Shipman) But it does not support on-the-fly compression. Whenever a codec fails to work, there's this dreaded error "A call to an operating system function failed" while writing a compressed file, or an unhandled exception. The only way to prevent it, that I see, is, to collect more peculiarities about the codecs and stop execution in case of certain combinations of settings. When queried about their capabilities, some of these guys seem to lie. Renate Schaaf [email protected]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值