I try to copy the dates of the original file after converting them with ffmpeg, but it gives me following error: ".CreationTime was unexpected at this time".
Script:
set /A g=5
set /A crf=20
set encoding=x265
set targetFolder=.\converted
for %%f in (.\*.mp4) do (
echo "fullname: %%f"
echo "name: %%~nf"
ffmpeg -i "%%f" -vcodec "lib%encoding%" -crf %crf% -g %g% "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4"
$(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").CreationTime=(Get-Item "%%f").CreationTime
$(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").LastWriteTime=(Get-Item "%%f").LastWriteTime
$(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").LastAccessTime=(Get-Item "%%f").LastAccessTime
)
Note: outside the loop the command works:
$(Get-Item ".\converted\VID_20200712_103210.crf20.x265.mp4").CreationTime=(Get-Item ".\VID_20200712_103210.mp4").CreationTime
CodePudding user response:
I updated my script to a PowerShell script and it now works:
$g=5
$crf=20
$encoding="x265"
$targetFolder=".\converted"
foreach ($f in (Get-ChildItem -Path ".\*.mp4")) {
Write-Host "fullname: $f"
Write-Host "name: $($f.BaseName)"
ffmpeg -i "$f" -vcodec "lib$encoding" -crf $crf -g $g "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4"
(Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").CreationTime=(Get-Item $f).CreationTime
(Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").LastWriteTime=(Get-Item $f).LastWriteTime
(Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").LastAccessTime=(Get-Item $f).LastAccessTime
}