码迷,mamicode.com
首页 > 其他好文 > 详细

c#生成AVI自动设置压缩格式,不调用AVISaveOptions

时间:2014-05-30 00:42:33      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:c   class   blog   code   a   int   

工作中遇到生成AVI视频的项目,代码中会调用AVISaveOptions来设置压缩格式,针对单个文件还好说,但是批量生成视频的时候,每一个都要设置格式,

体验不是很好,经过查询资料问题得到解决

最开始的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();
opts.fccType = _fccType;
opts.fccHandler = 0;
opts.dwKeyFrameEvery = 0;
opts.dwQuality = 0;
opts.dwFlags = 0;
opts.dwBytesPerSecond = 0;
opts.lpFormat = new IntPtr(0);
opts.cbFormat = 0;
opts.lpParms = new IntPtr(0);
opts.cbParms = 0;
opts.dwInterleaveEvery = 0;
AVICOMPRESSOPTIONS* p = &opts;
AVICOMPRESSOPTIONS** pp = &p;
IntPtr x = _ps;
IntPtr* ptr_ps = &x;
AVISaveOptions(0, 0, 1, ptr_ps, pp);
int hr = AVIMakeCompressedStream(out _psCompressed, _ps, ref opts, 0);

  修改后的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
opts.fccType = 0;
           opts.fccHandler = (int)0x6376736d;
           opts.dwKeyFrameEvery = 0;
           opts.dwQuality = 10000;
           opts.dwFlags = 8;
           opts.dwBytesPerSecond = 0;
           opts.lpFormat = new IntPtr(0);
           opts.cbFormat = 0;
           opts.lpParms = new IntPtr(0);
           opts.cbParms = 4;
           opts.dwInterleaveEvery = 0;
           AVICOMPRESSOPTIONS* p = &opts;
           AVICOMPRESSOPTIONS** pp = &p;
           IntPtr x = _ps;
           IntPtr* ptr_ps = &x;
           opts.lpParms = Marshal.AllocHGlobal(sizeof(int));
           //AVISaveOptions(0, 0, 1, ptr_ps, pp);
           int hr = AVIMakeCompressedStream(out _psCompressed, _ps, ref opts, 0);

  思路就是,Debug模式下,跟踪设置完压缩格式后

1
AVICOMPRESSOPTIONS结构体中各元素的值,其中lpParms需要利用
1
Marshal.AllocHGlobal(sizeof(int))来获取,其余根据监视的值设定即可

c#生成AVI自动设置压缩格式,不调用AVISaveOptions,布布扣,bubuko.com

c#生成AVI自动设置压缩格式,不调用AVISaveOptions

标签:c   class   blog   code   a   int   

原文地址:http://www.cnblogs.com/niuge/p/3758053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!