Marty001 0 Posted December 31, 2023 I am wanting to execute a CLI command to convert all FLAC files to MP3, after looking on google and the usual places I have come up with procedure TForm1.act_MUSIC_CONVERSION_FLACStoMP3Execute(Sender: TObject); begin ShellExecute(0, nil, 'cmd.exe',PWideCHar( 'find '+PwideChar(form1.FileListBox1.Directory)+'. -name "*.flac" -exec ffmpeg -i {} -ab 320k -map_metadata 0 -id3v2_version 3 {}.mp3 \;'), nil, SW_HIDE); end; however the command window opens but nothing is executed :( Share this post Link to post
Brian Evans 105 Posted December 31, 2023 (edited) In Windows command line Find searches for text in files. In BASH it does look more like your find command, it would need to be run with WSL.EXE not CMD.EXE if you are using Windows Subsystem for Linux. The path probably needs to be put in double quotes in case it contains spaces and be fixed up to be what it would be looking for the Linux side. Edited December 31, 2023 by Brian Evans Share this post Link to post
FPiette 383 Posted December 31, 2023 Maybe look at http://www.DelphiFFmpeg.com Share this post Link to post
Remy Lebeau 1394 Posted January 1 (edited) On 12/30/2023 at 7:54 PM, Marty001 said: I am wanting to execute a CLI command to convert all FLAC files to MP3, after looking on google and the usual places I have come up with ... however the command window opens but nothing is executed 😞 I would not suggest putting it all on the OS to run that entire command in one go. You should break it up into steps and then use appropriate APIs to run each step directly in your code, eg: uses ..., System.SysUtils; procedure TForm1.act_MUSIC_CONVERSION_FLACStoMP3Execute(Sender: TObject); var dir: string; sr: TSearchRec; begin dir := IncludeTrailingPathDelimiter(FileListBox1.Directory); if FindFirst(dir + '*.flac', faAnyFile, sr) <> 0 then try repeat if (sr.Attr and faDirectory) = 0 then begin ShellExecute(0, nil, 'ffmpeg.exe', PChar('-i "' + sr.Name + '" -ab 320k -map_metadata 0 -id3v2_version 3 "' + sr.Name + '.mp3"'), PChar(dir), SW_HIDE); end; until FindNext(sr) <> 0; finally FindClose(sr); end; end; Alternatively: uses ..., System.SysUtils, System.IOUtils; procedure TForm1.act_MUSIC_CONVERSION_FLACStoMP3Execute(Sender: TObject); var dir, fileName: string; begin dir := IncludeTrailingPathDelimiter(FileListBox1.Directory); for fileName in TDirectory.GetFiles(dir, '*.flac') do ShellExecute(0, nil, 'ffmpeg.exe', PChar('-i "' + fileName + '" -ab 320k -map_metadata 0 -id3v2_version 3 "' + fileName + '.mp3"'), PChar(dir), SW_HIDE); end; Yes, its' more work, but it gives you much more control. Edited January 1 by Remy Lebeau Share this post Link to post