Recent

Author Topic: How to convert WAV to MP3 with acs  (Read 1808 times)

myisjwj

  • Full Member
  • ***
  • Posts: 101
How to convert WAV to MP3 with acs
« on: September 08, 2023, 04:38:17 pm »
How to convert WAV to MP3 with acs

toby

  • Sr. Member
  • ****
  • Posts: 275
Re: How to convert WAV to MP3 with acs
« Reply #1 on: September 08, 2023, 06:00:48 pm »
is acs the online converter?

you can use ffmpeg directly with

tprocess.execute(

or

sysutils.executeprocess(


cdbc

  • Hero Member
  • *****
  • Posts: 2727
    • http://www.cdbc.dk
Re: How to convert WAV to MP3 with acs
« Reply #2 on: September 08, 2023, 06:52:07 pm »
Hi
Google for LAME library, "lame mp3 encoder download" preferably with pascal/fpc/delphi bindings...
If your mention of acs concerns this: https://wiki.freepascal.org/ACS, then I think the bindings are already there, you just have to figure out how to call them exactly, maybe this: https://lame.sourceforge.io/ has the info you need  ;)
Regards Benny

If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: How to convert WAV to MP3 with acs
« Reply #3 on: September 08, 2023, 07:16:31 pm »
How to convert WAV to MP3 with acs
There seem to be a fileconvert example that convert files based on extension. Have you tried it ? (I am not sure it supports mp3 out of the box or that you need to include the correct units and/or install the correct dependencies (if any) first).
Today is tomorrow's yesterday.

myisjwj

  • Full Member
  • ***
  • Posts: 101
Re: How to convert WAV to MP3 with acs
« Reply #4 on: September 10, 2023, 05:35:46 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button4Click(Sender: TObject);
  2. var
  3.   FileIn: TACSFileIn;
  4.   FileOut: TACSFileOut;
  5. begin
  6.   FileIn:=TAcsFileIn.Create(Nil);
  7.   FileIn.FileName:='C:\11.wav' ;
  8.   FileIn.StartSample:=0;
  9.   FileIn.EndSample:=-1;
  10.   FileIn.Loop:=False;
  11.   FileIn.Open();
  12.   FileOut:=TAcsFileOut.Create(Nil);
  13.   FileOut.FileName:='C:\11.mp3';
  14.   FileOut.Input:=FileIn;
  15.   FileOut.PrefetchMode:=pmAuto;
  16.   FileOut.FileMode:=foRewrite;
  17.   FileOut.Run();
  18.   //FileOut.Free;
  19.   //FileIn.Free;
  20. end;
  21.  
  22. procedure TForm1.Button5Click(Sender: TObject);
  23. var
  24.   i:Integer;
  25. begin
  26.   ComboBox1.Clear;
  27.    for i := 0 to FileFormats.Count-1 do
  28.     if TACSFileFormat(Fileformats[i]).FileClass.InheritsFrom(TACSCustomFileOut) then
  29.       ComboBox1.Items.Add(TACSFileFormat(Fileformats[i]).Extension);//The supported extensions are mp3 and wav
  30. end;


If you add the following code
FileOut.Free;
FileIn.Free;
It can't be documented.

If you add the following code
//FileOut.Free;
//FileIn.Free;
Generate an aa.mp3 file, size 648. But it can't be played.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: How to convert WAV to MP3 with acs
« Reply #5 on: September 11, 2023, 01:52:29 am »
@myisjwj
Your code looks fine to me (but I am not really familiar with ACS components).

Your result is even better than mine because my MP3 output stays at zero bytes (instead converting wav to og results in an ogg output file of 56 bytes for me). I have no idea what might be the issue there. Trying to loop through the (output) status or (input) progress does not yield any better results for me.

Oh, and ofc you should free both instances when you are done (even if that results in a wrong result).

If you can't get a better answer from the author here on the forums (he is active though not very much recently) then consider asking for help on the github page here.

BTW on what platform are you trying this because I tried on Linux and had to manually edit the ACS sources to change the library path (of libmp3lame) to something sane.
« Last Edit: September 11, 2023, 01:56:35 am by TRon »
Today is tomorrow's yesterday.

myisjwj

  • Full Member
  • ***
  • Posts: 101
Re: How to convert WAV to MP3 with acs
« Reply #6 on: September 11, 2023, 03:37:47 am »
system:windows7

jamie

  • Hero Member
  • *****
  • Posts: 7662
Re: How to convert WAV to MP3 with acs
« Reply #7 on: September 11, 2023, 04:52:30 am »
I don't think that is going to create a mp3. I really think there is more to it.

The only true wisdom is knowing you know nothing

cdbc

  • Hero Member
  • *****
  • Posts: 2727
    • http://www.cdbc.dk
Re: How to convert WAV to MP3 with acs
« Reply #8 on: September 11, 2023, 10:26:52 pm »
Hi
I've spent the last couple of hours, trying to get acs to compile on linux, I find it's generally flawed! I'll play with it some more... No wonder, you couldn't get a result, right off the bat  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: How to convert WAV to MP3 with acs
« Reply #9 on: September 12, 2023, 04:09:56 am »
@cdbc:
I got the components from OPM (manually downloaded) then copied out the src folder of the package zip file to a subdirectory of my testproject then compiled a FPC console application with fpc -Fu"./acs/*" -Fu"./acs/formats/*" -Mdelphi -B testproject.pas

As said, I needed to change the library names in some of the unit source-files as they included the full path (using a wrong path for my debian machine) and ofc acs has some dependencies that need to be met based on what it is you are trying to accomplish with your code.

I haven't had a in depth look as of how the components are suppose to work. Seeing the documentation mentioning that it started out as normal classes have led me to assume that they should work without the need for a GUI and/or use of GUI components.

@jamie:
The example is telling us that that is the way it is suppose to work, provided that you include the right units that register additional classes/extension so that the different fileformats are (actually) supported. A bit like how TFPImage works with supporting different fileformats or compiling in support for SSL in web classes automatically when you include the correct unit(s).
« Last Edit: September 12, 2023, 04:19:34 am by TRon »
Today is tomorrow's yesterday.

myisjwj

  • Full Member
  • ***
  • Posts: 101
Re: How to convert WAV to MP3 with acs
« Reply #10 on: September 12, 2023, 07:16:54 am »
It's ready to use.
First copy unit Lame_Enc under https://blog.csdn.net/y281252548/article/details/127314378 Lazarus is going to change that.
Program segment as follows
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Tin,Tout:TMemoryStream;
  4.   rc:Integer;
  5. begin
  6.   FMp3BlockAlign:=1;
  7.   vConfig.Format.dwConfig:=0;
  8.   vConfig.Format.MP3.byMode:=3;//BE_MP3_MODE_MONO = 3
  9.   vConfig.Format.MP3.dwSampleRate:=11025;//This value is the same as the SampleRate of the wav file
  10.   vConfig.Format.MP3.wBitrate:=16;//n-16
  11.  
  12.   rc:=beInit;
  13.   Tin:=TMemoryStream.Create;
  14.   Tin.LoadFromFile('c:\1116.wav');
  15.   Tout:=TMemoryStream.Create;
  16.   rc:=beEnc(Tin,Tout);
  17.   Tout.SaveToFile('c:\temp.mp3');
  18.   ShowMessage(IntToStr(rc));
  19. end;

 

TinyPortal © 2005-2018