我们如何通过MSAPI从所有格式的视频中提取音频? [英] how we extract audio from video through MSAPI for all formats?

查看:134
本文介绍了我们如何通过MSAPI从所有格式的视频中提取音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Aoa ...实际上我正在开发一个应用程序,我需要从视频中获取音频和基于语音识别的应用程序,所以我在这个项目中最初使用MSAPI ..现在我想用相同的API提取音频..i不想使用任何其他API,如DirectShow或MediaFoundation或ffmpeg等可能导致项目依赖..现在我有一段时间后我使用MSAPI编写代码从视频中提取音频,但仅在.wmv的特定域中我想从所有格式中提取音频,如.avi .mp4等,并在提取存储音频后以mp3或波形格式播放..plz引导我并根据我的需要做出可能对我有用的变化...确实我总是有这个论坛上的明确和有用的指南..亲切地帮助我...



代码我有:

使用系统;

使用System.IO;

使用Yeti.MMedia;

使用Yeti.WMFSdk;

使用WaveLib;

...

使用(WmaStream str = new WmaStream(Somefile.wma))

{

byte [] buffer = new byte [str.SampleSize * 2];

AudioWriter writer = new WaveWriter(new FileStream(Somefile.wav,

FileMode.Create),

str.Format);

试试

{

int read;

while((read = str.Read(buffer,0,buffer.Length))> 0)

{

writer.Write (缓冲区,0,读取);

}

}

终于

{

writer.Close();

}

} //str.Close()由Dispose自动调用。

Aoa...Actually i m developing an application where i need to extact audio from video and this application based on speech recognition so initally in this project i use MSAPI ..now i want to extract audio with the same API ..i dont want to use any other API like DirectShow or MediaFoundation or ffmpeg etc which may lead project to be dependant..now after a time i have code using MSAPI that is written to extract audio from video but in a specific domain only from .wmv while i want to extract audio from all formats like .avi .mp4 etc and after extracting store that audio in mp3 or wave format..plz guide me and make possible changes which may work for me according to my need...Indeed i always got clear and helpful guide on this forum..kindly help me...

code i have:
using System;
using System.IO;
using Yeti.MMedia;
using Yeti.WMFSdk;
using WaveLib;
...
using (WmaStream str = new WmaStream("Somefile.wma"))
{
byte[] buffer = new byte[str.SampleSize*2];
AudioWriter writer = new WaveWriter(new FileStream("Somefile.wav",
FileMode.Create),
str.Format);
try
{
int read;
while ( (read = str.Read(buffer, 0, buffer.Length)) > 0)
{
writer.Write(buffer, 0, read);
}
}
finally
{
writer.Close();
}
} //str.Close() is automatically called by Dispose.

推荐答案

这篇关于我们如何通过MSAPI从所有格式的视频中提取音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆