Make scripts parallel
This commit is contained in:
parent
870723509b
commit
e1debf99fd
26
hq2cd-ps1/convert-from-file.ps1
Normal file
26
hq2cd-ps1/convert-from-file.ps1
Normal file
@ -0,0 +1,26 @@
|
||||
# Output to a flat directory as I am going to use picard to rename the files after the fact
|
||||
|
||||
# Read each line in the file
|
||||
$filePaths = Get-Content -Path $args[0]
|
||||
$files = @()
|
||||
foreach ($filePath in $filePaths) {
|
||||
$files += Get-Item -Path $filePath
|
||||
}
|
||||
|
||||
# Save to output folder "Output"
|
||||
$destination = "Output"
|
||||
if (-not (Test-Path -Path $destination)) {
|
||||
New-Item -Path $destination -ItemType Directory
|
||||
}
|
||||
|
||||
# Now use ffmpeg to convert each file to 16-bit 44.1kHz
|
||||
<# This is the old way, use the new way below using -Parallel
|
||||
foreach ($file in $files) {
|
||||
$destinationPath = $destination + "\" + $file.Name
|
||||
ffmpeg -i $file.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath
|
||||
}
|
||||
#>
|
||||
$files | ForEach-Object -Parallel {
|
||||
$destinationPath = $destination + "\" + $_.Name
|
||||
ffmpeg -i $_.FullName -c:a flac -sample_fmt s16 -ar 44100 $destinationPath
|
||||
}
|
@ -3,16 +3,36 @@
|
||||
# Get all files with the .flac extension
|
||||
$files = Get-ChildItem -Path . -Filter *.flac -Recurse
|
||||
|
||||
Write-Host "Found" $files.Count "files"
|
||||
|
||||
# For each file, run ffprobe with json ouptut, and include it in a new list if it has a sample rate above 44100, and a bit depth above 16
|
||||
|
||||
$hq = @()
|
||||
|
||||
<# This is the old way, use the new way below using -Parallel
|
||||
foreach ($file in $files) {
|
||||
$ffprobe = ffprobe -v quiet -print_format json -show_format -show_streams $file.FullName
|
||||
$ffprobe = $ffprobe | ConvertFrom-Json
|
||||
$stream = $ffprobe.streams | Where-Object {$_.codec_name -eq "flac"}
|
||||
|
||||
if ($stream.sample_rate -gt 44100 -or $stream.bits_per_raw_sample -gt 16) {
|
||||
Write-Host $file.FullName
|
||||
$hq += $file
|
||||
}
|
||||
}
|
||||
#>
|
||||
$files | ForEach-Object -Parallel {
|
||||
$ffprobe = ffprobe -v quiet -print_format json -show_format -show_streams $_.FullName
|
||||
$ffprobe = $ffprobe | ConvertFrom-Json
|
||||
if ($ffprobe.format.sample_rate -gt 44100 -and $ffprobe.streams.bits_per_raw_sample -gt 16) {
|
||||
$stream = $ffprobe.streams | Where-Object {$_.codec_name -eq "flac"}
|
||||
|
||||
if ($stream.sample_rate -gt 44100 -or $stream.bits_per_raw_sample -gt 16) {
|
||||
Write-Host $_.FullName
|
||||
$hq += $_
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host $hq
|
||||
# Save each file in hq to a text file with its full path
|
||||
foreach ($file in $hq) {
|
||||
$file.FullName | Out-File -FilePath hq.txt -Append
|
||||
}
|
Loading…
Reference in New Issue
Block a user