I'm trying to create a Powershell script that watches a folder for new MP3 files and converts them to M4A format using FFMPEG and FDK AAC encoder.
Since fdkaac.exe won't take MP3 files as input, I use this command, which pipes from ffmpeg:
ffmpeg -i $path -f caf - | fdkaac -p5 -b64 - -o $outfolder\$outname.m4a
This works just fine if I enter it into a command prompt and the resulting M4A file that's generated has no problems.
However if I run this from Powershell, the M4A file is created but contains nothing but unpleasant white noise (and very faint traces of music).
An ideas why that is so?
Here's the Powershell script if it helps:
### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "E:\test"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$watcher.NotifyFilter = [IO.NotifyFilters]'FileName, Size'
### DEFINE ACTIONS AFTER A EVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs.FullPath
$filename = $Event.SourceEventArgs.Name
$outname = [io.path]::GetFileNameWithoutExtension($path)
$outfolder = "C:\Users\Public\Music\"
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "E:\log.txt" -value $logline
If ($path -match '.mp3|.m4a') {
$command = "ffmpeg -i `"$path`" -f caf - | fdkaac -p5 -b64 - -o `"$outfolder\$outname.m4a`""
Add-content "E:\log.txt" -value "[Transcode] $filename"
& command
}
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY
$created = Register-ObjectEvent $watcher "Created" -Action $action
while ($true) {sleep 5}
ffmpeg -i $path -f caf - | fdkaac -p5 -b64 - -o $outfolder\$outname.m4ausing static files, paths, etc. rather than the dynamic variables from PS to see if the results are fine in case it's the dynamic logic that only causes this at least this would be an easy way to confirm it you've not already done this. – Vomit IT - Chunky Mess Style Aug 18 '16 at 04:51fdkaacbugs out with aERROR: unsupported sample rateon Powershell. I had Task Manager open and I noticed that when I ran the command on CMD, bothffmpeg.exeandfdkaac.exewere being executed simultaneously while Powershell seemed to be running the programs sequentially. – Vinayak Aug 18 '16 at 10:50$commandto"ffmpeg -i \"$path`" -f caf - | fdkaac -p5 -b64 - -o `"$outfolder$name.m4a`""and called it withcmd /c $command` to let CMD run the command instead and it works fine now. – Vinayak Aug 18 '16 at 10:54