Created
May 19, 2025 01:08
-
-
Save leo-tavares/45f25d5ae8cc5ee36a26cc8e14a3bb42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Requer PowerShell 5.1+ | |
| # Caminho para a pasta com os arquivos .mp4 | |
| $inputFolder = "F:\Downloads\musicas" | |
| $outputFolder = "F:\Downloads\musicas\M4A" | |
| $maxParallelJobs = 5 # Número máximo de conversões simultâneas | |
| # Criar pasta de saída se necessário | |
| if (-not (Test-Path -Path $outputFolder)) { | |
| New-Item -ItemType Directory -Path $outputFolder | |
| } | |
| # Obter arquivos MP4 | |
| $mp4Files = Get-ChildItem -Path $inputFolder -Filter *.mp4 | |
| $jobs = @() | |
| foreach ($file in $mp4Files) { | |
| # Verificar se já atingimos o limite de jobs paralelos | |
| while (($jobs | Where-Object { $_.State -eq "Running" }).Count -ge $maxParallelJobs) { | |
| Start-Sleep -Seconds 1 | |
| } | |
| $inputPath = $file.FullName | |
| $outputPath = Join-Path $outputFolder ($file.BaseName + ".m4a") | |
| Write-Host "Iniciando conversão: $($file.Name)" | |
| $job = Start-Job -ScriptBlock { | |
| param($in, $out) | |
| Start-Process -FilePath "ffmpeg" -ArgumentList "-i `"$in`" -vn -c:a aac -b:a 192k `"$out`"" -NoNewWindow -Wait | |
| } -ArgumentList $inputPath, $outputPath | |
| $jobs += $job | |
| } | |
| # Esperar todos os jobs finalizarem | |
| Write-Host "Aguardando todas as conversões terminarem..." | |
| $jobs | ForEach-Object { Wait-Job $_ } | |
| # Verificar e limpar jobs | |
| foreach ($job in $jobs) { | |
| if ($job.State -eq "Failed") { | |
| Write-Warning "Erro na conversão (job ID $($job.Id))" | |
| Receive-Job $job -Keep | |
| } else { | |
| Receive-Job $job | Out-Null | |
| } | |
| Remove-Job $job | |
| } | |
| Write-Host "✅ Todas as conversões foram concluídas." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment