Jump to content

"Multithreaded" Flac to mp3 converter


archrival
 Share

Recommended Posts

Here is a quick and dirty "multithreaded" flac to mp3 converter. It uses lame and flac. Let me know what you think. I use it for my own purposes but I thought others might find it useful. The "multithreaded" portion will spawn as many or as little flac to mp3 conversions as you like. I personally use 2 on my dual core. The program will just convert all .flac files in a given folder to .mp3, no tagging or renaming is done, I have other programs to do that.

CODE
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_UseAnsi=y

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>

Dim $file_array[1]

$threads = InputBox('Thread Selection', 'Enter number of encoding threads:', "2", "", 225, 100)

If @error Then Exit

$threads = Number($threads)

If Not IsInt($threads) Then

MsgBox(0, 'Error', 'Please enter an integer')

Exit

EndIf

Dim $encode_pid[$threads + 1]

$flac_folder = FileSelectFolder("Select Folder", "")

If @error Then Exit

$lame_exe = 'lame.exe'

$flac_exe = 'flac.exe'

$flac_options = '-d -c'

$lame_options = InputBox('Encoder Options', 'Enter LAME encoding options:', '-V0 --preset extreme --verbose -', "", 225, 100)

If @error Then Exit

$search = FileFindFirstFile($flac_folder & "\*.flac")

If $search = -1 Then

MsgBox(0, "Error", "No files matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

_ArrayAdd($file_array, $file)

WEnd

FileClose($search)

$file_array[0] = UBound($file_array) - 1

For $i = 1 To $threads

$encode_pid[$i] = Run(@ComSpec & ' /c ' & $flac_exe & ' ' & $flac_options & ' "' & $flac_folder & "\" & $file_array[$i] & '" | ' & $lame_exe & ' ' & $lame_options & ' "' & StringTrimRight($flac_folder & "\" & $file_array[$i], 4) & 'mp3"')

Next

$k = $threads

While $k < $file_array[0]

For $j = 1 To $threads

If ProcessExists($encode_pid[$j]) = 0 Then

$k = $k + 1

$encode_pid[$j] = Run(@ComSpec & ' /c ' & $flac_exe & ' ' & $flac_options & ' "' & $flac_folder & "\" & $file_array[$k] & '" | ' & $lame_exe & ' ' & $lame_options & ' "' & StringTrimRight($flac_folder & "\" & $file_array[$k], 4) & 'mp3"')

EndIf

Sleep(250)

Next

Sleep(250)

WEnd

Edited by archrival
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...