Jump to content

Lame Convertor


Recommended Posts

I looked everywhere for this and couldn't find it, so I'm posting here. This is a Lame conversion with progress (You need to download lame.exe and lame_enc.dll). Percentage tracker could be improved -- suggestions welcome:

Local $fileIn="something.wav,$fileOut="something.mp3",$artist="test",$title="test",

ProgressOn("Mp3 Conversion", $fileIn)
Local $enc = Run('lame.exe --nohist -b 128 --cbr --noreplaygain -s 44.1 --ta "'&$artist&'" --tt "'&$title&'" --id3v1-only "'&$fileIn&'" "'&@ScriptDir&'\Temp\'&$fileOut&'"',"",@SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
Local $line = ""
while(ProcessExists($enc))
   Sleep(200)
   $line = StderrRead($enc)
   If StringLen($line) > 0 Then
      if StringInStr($line,"25%") <> 0 Then
         ProgressSet(25," 25 percent")
      Sleep(750)
      EndIf
      if StringInStr($line,"50%") <> 0 Then
         ProgressSet(50," 50 percent")
         Sleep(750)
      EndIf
      if StringInStr($line,"75%") <> 0 Then
         ProgressSet(75," 75 percent")
         Sleep(750)
      EndIf
      if StringInStr($line,"100%") <> 0 Then
         ProgressSet(100, " 100 percent")
         Sleep(750)
      EndIf
   EndIf
WEnd
ProcessWaitClose($enc)
ProgressOff()

 

Edited by Melba23
Link to comment
Share on other sites

  • Moderators

mannworks00,

Welcome to the AutoIt forums.

But in future please do not hijack 9-year old threads - just a start a new one as I have now done for you.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 years later...

Here is what I came up with

 

;Lame Encoder mannworks00
#include <Misc.au3>
#include <File.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
OnAutoItExitRegister("_Exit")

Global $g_bStop = False
Global Const $g_sWavDir = "C:\Audio_Wav"
Global $g_hUser32 = DllOpen("user32.dll")

Local $aFileList = _FileListToArray($g_sWavDir, "*.wav")
If IsArray($aFileList) Then
    ProgressOn("Mp3 Conversion ", "", "", 0, 0, BitOr($DLG_NOTONTOP, $DLG_MOVEABLE))
    For $i = 1 To $aFileList[0]
        ConsoleWrite($aFileList[$i] & @CRLF)
        Mp3Encode($i, $aFileList[0], $aFileList[$i], False, "", "", 160)
        If $g_bStop OR _IsPressed("1B", $g_hUser32) Then
            Exit
        EndIf
    Next

EndIf

Func Mp3Encode($iCur, $iCt, $sFileIn, $bDeleteSource, $sArtist = "", $sTitle = "", $iBitrate = 120)

    Local $sFileName = $sFileIn
    Local $sFileOut = $g_sWavDir & "\" & StringReplace($sFileIn, ".wav", ".mp3", -1)
    $sFileIn = $g_sWavDir & "\" & $sFileIn
    Local $aTrackTag

    if $sArtist = "" and $sTitle = "" Then
        $aTrackTag = StringRegExp($sFileName, "\\?(.*)\s-\s(.*).wav", 1)
        If IsArray($aTrackTag) Then
            $sArtist = $aTrackTag[0]
            $sTitle = $aTrackTag[1]
            ConsoleWrite("Artist: " & $sArtist & " Title: " & $sTitle & @CRLF)
        Else
            Return
        EndIf
    Endif

    ProgressSet(0, " " & $iCur & "\" & $iCt, $sFileName)
    Local $hEnc = Run('lame.exe --nohist -b '& $iBitrate & ' --cbr --noreplaygain -q 0 -s 44.1 --priority 3 ' & _
                     '--ta "' & $sArtist & '" --tt "' & $sTitle & '" --id3v1-only "' & $sFileIn & '" "' & $sFileOut & '"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    Local $aProgress, $iProgress
    While (ProcessExists($hEnc))
        If _IsPressed("1B", $g_hUser32) Then
            $g_bStop = True
        EndIf
        Sleep(500)
        $aProgress = StringRegExp(StderrRead($hEnc), ".*\(\D?(\d*)%\)", 1)
        If IsArray($aProgress) Then ProgressSet($aProgress[0])
    WEnd
    ProcessWaitClose($hEnc)

    If $bDeleteSource And FileExists($sFileOut) And FileGetSize($sFileOut) > 0 Then
        FileDelete($sFileIn)
    EndIf
EndFunc   ;==>Mp3Encode

Func _Exit()
    ProgressOff()
    DllClose($g_hUser32)
EndFunc   ;==>_Exit

 

Link to comment
Share on other sites

And one more that can run multiple instances to speed up the conversion

;Lame Encoder mannworks00
#include <Misc.au3>
#include <File.au3>
#include <WinAPISys.au3>
#include <WinAPIProc.au3>
#include <AutoItConstants.au3>
#include <ProcessConstants.au3>
#include <Array.au3>

OnAutoItExitRegister("_Exit")

Global $g_bStop = False
Global Const $g_sWavDir = "C:\Audio_WAV"
Global $g_hUser32 = DllOpen("user32.dll")

Local $aFileList = _FileListToArray($g_sWavDir, "*.wav")
If IsArray($aFileList) Then
    ProgressOn("Mp3 Conversion ", "", "", 0, 0, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE))
    For $i = 1 To $aFileList[0]
        ConsoleWrite($aFileList[$i] & @CRLF)
        Mp3Encode($i, $aFileList[0], $aFileList[$i], False, "", "", 160)
        If $g_bStop Or _IsPressed("1B", $g_hUser32) Then
            Exit
        EndIf
    Next

EndIf

Func Mp3Encode($iCur, $iCt, $sFileIn, $bDeleteSource, $sArtist = "", $sTitle = "", $iBitrate = 120)

    Local $sFileName = $sFileIn
    Local $sFileOut = $g_sWavDir & "\" & StringReplace($sFileIn, ".wav", ".mp3", -1)
    $sFileIn = $g_sWavDir & "\" & $sFileIn
    If (Not FileExists($sFileIn)) or FileExists($sFileOut) Then Return
    Local $aTrackTag

    If $sArtist = "" And $sTitle = "" Then
        $aTrackTag = StringRegExp($sFileName, "\\?(.*)\s-\s(.*).wav", 1)
        If IsArray($aTrackTag) Then
            $sArtist = $aTrackTag[0]
            $sTitle = $aTrackTag[1]
            ConsoleWrite("Artist: " & $sArtist & " Title: " & $sTitle & @CRLF)
        Else
            Return
        EndIf
    EndIf

    ProgressSet(0, " " & $iCur & "\" & $iCt, $sFileName)
    Local $hEnc = Run('lame.exe --nohist -b ' & $iBitrate & ' --cbr --noreplaygain -q 0 -s 44.1 --priority 3 ' & _
            '--ta "' & $sArtist & '" --tt "' & $sTitle & '" --id3v1-only "' & $sFileIn & '" "' & $sFileOut & '"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ConsoleWrite(SetProcessAffinity(0, $hEnc) & @crlf)
    Local $aProgress, $iProgress
    While (ProcessExists($hEnc))
        If _IsPressed("1B", $g_hUser32) Then
            $g_bStop = True
        EndIf
        Sleep(500)
        $aProgress = StringRegExp(StderrRead($hEnc), ".*\(\D?(\d*)%\)", 1)
        If IsArray($aProgress) Then ProgressSet($aProgress[0])
    WEnd
    ProcessWaitClose($hEnc)

    If $bDeleteSource And FileExists($sFileOut) And FileGetSize($sFileOut) > 0 Then
        FileDelete($sFileIn)
    EndIf
EndFunc   ;==>Mp3Encode

Func _Exit()
    ProgressOff()
    DllClose($g_hUser32)
EndFunc   ;==>_Exit

Func SetProcessAffinity($iAffinityMask = 0, $iPID = @AutoItPID)
    Local $sRetn = "Skipping Affinity" & @CRLF
    Local $hProcess
    If _WinAPI_GetVersion() >= 6.0 Then
        $hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_SET_INFORMATION, $PROCESS_QUERY_LIMITED_INFORMATION), 0, $iPID)
    Else
        $hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_SET_INFORMATION, $PROCESS_QUERY_INFORMATION), 0, $iPID)
    EndIf
    If Not $hProcess Then Return "Couldn't Get Handle " & _WinAPI_GetLastErrorMessage() & @CRLF
    If $iAffinityMask = 0 Then
        Local $aAffinity = _WinAPI_GetProcessAffinityMask($hProcess)
        If @error Then
            $sRetn = "Couldn't Get Affinity " & _WinAPI_GetLastErrorMessage() & @CRLF
            $iAffinityMask = -1
        EndIf

        $iAffinityMask = BitXOR($aAffinity[2], 1)
    EndIf
    If $iAffinityMask > 1 Then
        If Not _WinAPI_SetProcessAffinityMask($hProcess, $iAffinityMask) Then
            $sRetn = "Couldn't Set Affinity " & _WinAPI_GetLastErrorMessage() & @CRLF
        Else
            $sRetn = "Set Affinity Mask " & $iAffinityMask & @CRLF
        EndIf
    Else
        $sRetn &= " " & $iAffinityMask
    EndIf

    _WinAPI_CloseHandle($hProcess)
    Return $sRetn
EndFunc   ;==>SetProcessAffinity

 

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...