So I want to start with that ffmpeg and powershell isn't really my strength but I have been using the following powershell command to convert every .flac file in a certain directory to a 320K file.
dir *.flac | foreach {ffmpeg -i $_.FullName -c:v copy -b:a 320k $_.FullName.Replace('flac', 'mp3')}
This works exactly how I want to without any album art being transcoded but I want to incorporate a way so that the new .mp3 files that are created have the SAME DATE MODIFICATION value of the .flac files. Is something like this even possible?
audio_ex.flac = Date Modification: 1/1/2010
audio_ex.mp3 = Date Modification: 9/8/2021
should be instead
audio_ex.flac = Date Modification: 1/1/2010
audio_ex.mp3 = Date Modification: 1/1/2010
I have a folder of 6K files and want each original date modified to match the newly created files so if I can do the above command and also have the date mod time match within one execution, that would be ideal.
I thought of manually changing each files mod time using 3rd party tools but it will be too time consuming.
CodePudding user response:
Try the following (note that aliases were expanded to their underlying cmdlet names):
Get-ChildItem -Filter *.flac | ForEach-Object {
$outFile = $_.FullName -replace '\.flac$', '.mp3'
ffmpeg -i $_.FullName -c:v copy -b:a 320k $outFile
(Get-Item -LiteralPath $outFile).LastWriteTime = $_.LastWriteTime
}