'ffmpeg keep file creation and modification dates when encoding/resizing multiple videos

I have the following batch code (I'm on Windows 10) that resize all the videos in a folder. It keeps the origin media created date but it doesn't keep the File attributes Date created and Date modified dates after encoding. How do I add this to the code below?

for %%a in ("*.mp4") do ffmpeg -i "%%a" -map_metadata 0 -vf "scale=iw/4:ih/4" -c:v libx264 -c:a copy "..\%%~na.mp4"


Solution 1:[1]

I originally got the answer to your question from this post, which can also serve as a template because it worked for me last year: ffmpeg keep original file date?

Moreover, I created this for you below:

for %%a in ("*.mp4") do (
    "C:\Program Files\FFmpeg (LATEST)\ffmpeg.exe" -i "%%a" -map_metadata 0 -vf "scale=iw/4:ih/4" -c:v libx264 -c:a copy "..\%%~na.mp4"
    "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"  ^(ls '..\%%~na.mp4'^).CreationTime = ^(ls '%%a'^).CreationTime
    "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"  ^(ls '..\%%~na.mp4'^).LastWriteTime = ^(ls '%%a'^).LastWriteTime
    "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"  ^(ls '..\%%~na.mp4'^).LastAccessTime = ^(ls '%%a'^).LastAccessTime
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1