困扰很久的AsfWriter的声音问题

donexie 2007-05-06 12:37:57
代码:
// now render streams
CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
CheckDSError(RenderStream(nil, nil, AudioSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
//设置视频格式
SetASFWriterProfile(AsfWriter,640, 480,15);
CaptureGraph.Play;

然后录下来的录像只有图像没有声音!!

附SetASFWriterProfile函数.

function TMainForm.SetASFWriterProfile(pWriter: TASFWriter; lWidth, lHeight, bitRate: Integer): HRESULT;
var
hr: HRESULT;
pvi: PVideoInfoHeader;
pProfile: IWMProfile;
pProfileMgr: IWMProfileManager;
pStream: IWMStreamConfig;
pMediaProps: IWMVideoMediaProps;
pMediaType: PWMMediaType;
cbMediaType: Cardinal;
ConfigAsfWriter: IConfigAsfWriter;
begin
{ hr = m_pWMVEncoder->QueryInterface(IID_IConfigAsfWriter, (void**)&pConfig);
hr=LoadCustomProfile("D1.prx",&pProfile );
hr=pProfile->GetStream(1,&pStreamConfig);
hr=pStreamConfig->QueryInterface(IID_IWMMediaProps,(void**)&pProps);
hr=pProps->GetMediaType(pType,&size);
BITMAPINFOHEADER* pBitmap=(BITMAPINFOHEADER*)&pHeader->bmiHeader;
pBitmap->biWidth=720;
pBitmap->biHeight=576;
hr=pProps->SetMediaType(pType);
hr=pProfile->ReconfigStream(pStreamConfig);
hr=pConfig->ConfigureFilterUsingProfile(pProfile); }

hr := WMCreateProfileManager(pProfileMgr);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call WMCreateProfileManager (%x)', [hr]));
Result := hr;
exit;
end;
hr := pProfileMgr.CreateEmptyProfile(WMT_VER_7_0, pProfile);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pProfileMgr.CreateEmptyProfile (%x)', [hr]));
Result := hr;
exit;
end;
hr := pProfile.SetName('Video1');
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pProfile.SetName (%x)', [hr]));
Result := hr;
exit;
end;
hr := pProfile.SetDescription('LYSoft WMV ProFiles');
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pProfile.SetDescription (%x)', [hr]));
Result := hr;
exit;
end;

hr := pProfile.CreateNewStream(WMMEDIATYPE_Video, pStream);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pProfile.CreatenewStream (%x)', [hr]));
Result := hr;
exit;
end;

// Get the media properties interface for the new stream.
hr := pStream.QueryInterface(IID_IWMVideoMediaProps, pMediaProps);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pStream.QueryInterface (%x)', [hr]));
Result := hr;
exit;
end;

// Get the media-type structure.
// First, get the size of the media-type structure.
hr := pMediaProps.GetMediaType(nil, cbMediaType);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pMediaProps.GetMediaType (%x)', [hr]));
Result := hr;
exit;
end;

// Allocate memory for the structure based on the retrieved size.
pMediaType := AllocMem(cbMediatype);
// Retrieve the media-type structure.
hr := pMediaProps.GetMediaType(pMediaType, cbMediaType);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pMediaProps.GetMediaType (1) (%x)', [hr]));
Result := hr;
exit;
end;

// Change the video size
pvi := PVideoInfoHeader(pMediaType.pbFormat);
// ShowMessage(format('%d,%d,%d,%d',[pvi.bmiHeader.biWidth,pvi.bmiheader.biHeight,pvi.bmiHeader.biBitCount,pvi.bmiHeader.biSizeImage]));
pvi.bmiHeader.biWidth := lWidth;
pvi.bmiHeader.biHeight := lHeight;
pvi.bmiHeader.biSizeImage := pvi.bmiHeader.biWidth * pvi.bmiHeader.biHeight * pvi.bmiHeader.biBitCount div 8;
pvi.rcSource := RECT(0, 0, lWidth, lHeight);
pvi.rcTarget := RECT(0, 0, lWidth, lHeight);
pvi.dwBitRate := bitRate;
pvi.AvgTimePerFrame := Round(10000000 / 15); // PFS = 15
pvi.bmiHeader.biCompression := WMMEDIASUBTYPE_WMV1.D1;
pMediaType.subtype := WMMEDIASUBTYPE_WMV1;
pMediaProps.SetMaxKeyFrameSpacing(30000000);
pMediaProps.SetQuality(100);
hr := pMediaProps.SetMediaType(pMediaType);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pMediaProps.SetMediaType (%x)', [hr]));
Result := hr;
exit;
end;

// Release the media properties interface and delete the structure.
pMediaProps := nil;
FreeMem(pMediaType);
pMediaType := nil;

hr := pStream.SetBitrate(bitRate);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pStream.SetBitrate (%x)', [hr]));
Result := hr;
exit;
end;

pStream.SetBufferWindow($FFFFFFFF);
// Set the stream number.
hr := pStream.SetStreamNumber(1);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pStream.SetStreamNumber (%x)', [hr]));
Result := hr;
exit;
end;

// Include the new stream in the profile.
hr := pProfile.AddStream(pStream);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call pProfile.AddStream (%x)', [hr]));
Result := hr;
exit;
end;

pProfile.ReconfigStream(pStream);
pStream := nil;

hr := pWriter.QueryInterface(IID_IConfigAsfWriter, ConfigAsfWriter);
if FAILED(hr) then
begin
ShowMessage(format('Error on Call WMCreateProfileManager (%x)', [hr]));
Result := hr;
exit;
end;
hr := ConfigAsfWriter.ConfigureFilterUsingProfile(pProfile);
if Failed(hr) then
begin
ShowMessage(format('Error on Call pWriter.ConfigureFilterUsingProfile (%x)', [hr]));
Result := hr;
exit;
end;
ConfigAsfWriter := nil;

// TODO: Save the custom profile to a string, and save the string to a file.

// Release remaining interfaces.
pProfile := nil;
pProfileMgr := nil;
Result := S_OK;
end;
...全文
646 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
donexie 2007-05-08
  • 打赏
  • 举报
回复
系统的profile,ASFWriter用的是哪个啊,该怎么改呢?改成640X480就成.

<PRX>

<profile version="458752"
name="Video for dial-up modems or single channel ISDN (28.8 to 56 Kbps)"
guid="{5B16E74B-4068-45B5-B80E-7BF8C80D2C2F}"
description="Use this multiple bit rate profile for target audiences with a dial-up modem or single channel ISDN connection (bandwidth is

between 28.8 Kbps and 56 Kbps).">
<streamconfig majortype="{73647561-0000-0010-8000-00AA00389B71}"
streamnumber="1"
streamname="Audio Stream"
inputname="Audio"
bitrate="8000"
bufferwindow="-1">
<wmmediatype subtype="{00000161-0000-0010-8000-00AA00389B71}"
bfixedsizesamples="1"
btemporalcompression="0"
lsamplesize="64">
<waveformatex wFormatTag="353"
nChannels="1"
nSamplesPerSec="8000"
nAvgBytesPerSec="1000"
nBlockAlign="64"
</profile>

</PRX>
蒋晟 2007-05-08
  • 打赏
  • 举报
回复
看半天没看见哪里加音频流了
donexie 2007-05-08
  • 打赏
  • 举报
回复
SetASFWriterProfile函数本身没有带音频的,是这个原因么,如果如此,该如何该这个函数呢?

2,552

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧