困扰很久的AsfWriter的声音问题. ( 积分: 300 )

S

sz_toto

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
// 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)',
));
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)',
));
Result := hr;
exit;
end;

hr := pProfile.SetName('Video1');
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.SetName (%x)',
));
Result := hr;
exit;
end;

hr := pProfile.SetDescription('LYSoft WMV ProFiles');
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.SetDescription (%x)',
));
Result := hr;
exit;
end;


hr := pProfile.CreateNewStream(WMMEDIATYPE_Video, pStream);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.CreatenewStream (%x)',
));
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)',
));
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)',
));
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)',
));
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)',
));
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)',
));
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)',
));
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)',
));
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)',
));
Result := hr;
exit;
end;

hr := ConfigAsfWriter.ConfigureFilterUsingProfile(pProfile);
if Failed(hr) then

begin

ShowMessage(format('Error on Call pWriter.ConfigureFilterUsingProfile (%x)',
));
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;
 
没见你写音频的代码 一般是因为, 音频解码器指定不对,或时间戳不对
 
没辙.建议你要用这个SetASFWriterProfile,还不如自己创建Profile,然后调用,要不修改系统Profile也行,在windows目录下WMSysPr9.prx..........
 
多人接受答案了。
 
顶部