2

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"
user2427836
  • 85
  • 10
  • 1
    If you can use WSL or find a Windows version of the Unix `touch` command, you can use `touch -r ORIGINAL NEW` to copy forward the date from file `ORIGINAL` to file `NEW`. – Mark Setchell Feb 13 '22 at 12:32
  • Is there no way to do it in my batch script? – user2427836 Feb 13 '22 at 18:07
  • Mmmmm.... Windows batch scripting is not renowned for being intuitive, powerful or very useful. Most folks would probably describe it as arcane or unintuitive. There may be something in Powershell... – Mark Setchell Feb 13 '22 at 18:12
  • What is WSL and where can i find a good Windows version of the Unix touch command? – user2427836 Feb 13 '22 at 20:00
  • 1
    If you Google *"Windows WSL"* you'll find it is *"Windows Subsystem for Linux"*. It's kind of like attempting to make the arcane, unintuitive Windows batch into something more useful by adding Linux. If you Google *"GNU tools for Windows"* you'll find a package that contains `touch`. – Mark Setchell Feb 13 '22 at 20:13
  • Ok. I will try. Thanks. However if anybody knows a way to do this in my batch script I would apreciate it. – user2427836 Feb 13 '22 at 22:37
  • Powershell.... https://superuser.com/a/998291 – Mark Setchell Feb 13 '22 at 23:12

1 Answers1

2

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
)
Robert
  • 21
  • 2