我想把WAV格式文件转成MP3,哪位兄弟有代码或函数啊(50)

  • 主题发起人 主题发起人 tsedlinux
  • 开始时间 开始时间
T

tsedlinux

Unregistered / Unconfirmed
GUEST, unregistred user!
我想把WAV格式文件转成MP3,哪位兄弟有代码或函数啊
 
http://lame.sourceforge.net/index.phpProgram demo;{$APPTYPE CONSOLE}Uses Windows, SysUtils, Lame_Enc_ In '../Lame_Enc_.pas', libmp3lame In '../libmp3lame.pas';Const Wav = '1.wav';
mp3 = '2.mp3';Var F1, F2: THandle;
Path: String;
beConfig: TBE_Config;
dwSamples, dwSamplesMP3: LongWord;
hbeStream: THBE_STREAM;
error: BE_ERR;
pBuffer: PSmallInt;
pMP3Buffer: PByte;
do
ne: LongWord;
dwWrite: LongWord;
ToRead: LongWord;
ToWrite: LongWord;
TotalSize: Int64;
iTime: Dword;
begin
Path := ExtractFilePath(ParamStr(0));
If Not FileExists(Path + Wav) then
Exit;
FillChar(beConfig, SizeOf(beConfig), 0);
beConfig.dwConfig := BE_CONFIG_LAME;
If beConfig.dwConfig = BE_CONFIG_MP3 then
begin
beConfig.Format.mp3.dwSampleRate := 44100;
beConfig.Format.mp3.byMode := BE_MP3_MODE_STEREO;
beConfig.Format.mp3.wBitrate := 128;
beConfig.Format.mp3.bCopyright := false;
beConfig.Format.mp3.bCRC := $00000000;
beConfig.Format.mp3.bOriginal := false;
beConfig.Format.mp3.bPrivate := false;
End else
begin
//Structure information beConfig.Format.lhv1.dwStructVersion := CURRENT_STRUCT_VERSION;
beConfig.Format.lhv1.dwStructSize := SizeOf(beConfig);
//Basic encoder setting beConfig.Format.lhv1.dwSampleRate := 44100;
beConfig.Format.lhv1.dwReSampleRate := 44100;
beConfig.Format.lhv1.nMode := BE_MP3_MODE_STEREO;
beConfig.Format.lhv1.dwBitrate := 128;
beConfig.Format.lhv1.dwMaxBitrate := 128;
beConfig.Format.lhv1.nQuality := 2;
beConfig.Format.lhv1.dwMPegVersion := MPEG1;
beConfig.Format.lhv1.dwPsyModel := 0;
beConfig.Format.lhv1.dwEmphasis := 0;
//Bit Stream Settings beConfig.Format.lhv1.bPrivate := false;
beConfig.Format.lhv1.bCRC := false;
beConfig.Format.lhv1.bCopyright := True;
beConfig.Format.lhv1.bOriginal := True;
//VBR Stuff beConfig.Format.lhv1.bWriteVBRHeader := false;
beConfig.Format.lhv1.bEnableVBR := false;
beConfig.Format.lhv1.nVBRQuality := 0;
beConfig.Format.lhv1.bNoRes := True;
end;

F1 := FileOpen(Path + Wav, fmOpenRead);
F2 := FileCreate(Path + mp3);
error := beInitStream(@beConfig, @dwSamples, @dwSamplesMP3, @hbeStream);
If error = BE_ERR_SUCCESSFUL then
begin
pBuffer := AllocMem(dwSamples * 2);
pMP3Buffer := AllocMem(dwSamplesMP3);
Try do
ne := 0;
iTime := GetTickCount;
FileSeek(F1, 0, 0);
TotalSize := GetFileSize(F1, Nil);
While (done < TotalSize)do
begin
If (done + dwSamples * 2 < TotalSize) then
ToRead := dwSamples * 2 else
begin
ToRead := TotalSize -do
ne;
FillChar(pBuffer^, dwSamples, 0);
end;

If FileRead(F1, pBuffer^, ToRead) = -1 then
Raise Exception.Create('Erreur de lecture');
error := beEncodeChunk(hbeStream, ToRead Div 2, pBuffer, pMP3Buffer, @ToWrite);
If error <> BE_ERR_SUCCESSFUL then
begin
beCloseStream(hbeStream);
Raise Exception.Create('Echec de l''encodage');
end;

If FileWrite(F2, pMP3Buffer^, ToWrite) = -1 then
Raise Exception.Create('Erreur driture');
Inc(done, ToRead);
{inc(i);
If i Mod 64 = 0 then
begin
Form1.ProgressBar.Position := Round(100 *do
ne / TotalSize);
Application.ProcessMessages;
end;
} end;

error := beDeInitStream(hbeStream, pMP3Buffer, @dwWrite);
If error <> BE_ERR_SUCCESSFUL then
begin
beCloseStream(hbeStream);
Raise Exception.Create('Echec ?la sortie');
end;

If dwWrite <> 0 then
begin
If FileWrite(F2, pMP3Buffer^, dwWrite) = -1 then
Raise Exception.Create('Erreur ?la derniriture');
end;

beCloseStream(hbeStream);
iTime := GetTickCount - iTime;
Writeln(Format('用时:%d', [iTime]));
Finally FreeMem(pBuffer);
FreeMem(pMP3Buffer);
end;

end;

FileClose(F2);
FileClose(F1);
end.
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部