[FFmpeg-user] How to keep the original creation date?

Dan Harkless ffmpeg at harkless.org
Thu Jun 22 23:57:24 EEST 2023

On 6/22/2023 10:35 AM, Kevin Willard via ffmpeg-user wrote:
> >> I've got 3000 family videos from 2009-2014 that played perfect back 
> >> then on Windows 7 but have the wrong aspect ratio today (all 
> >> stretched even though it says it is 1920X1080). The code belowfixes 
> >> the problem, but changes all the dates to current. It would be nice 
> >> to have the original time/date stamp for sorting and looking at the 
> >> family timeline.Google search brings me to Stackoverflow (ffmpeg keep 
> >> original file date?) They us PowerShell, I don't know how to use it 
> >> and I don't think it will work because in the example the PS 
> >> operation is done after the FFmpeg conversion is done. FFmpeg in the 
> >> copy sets the creation time, last modified, and last access to the 
> >> time/date the FFmpeg was run.

Since many tools (like ffmpeg, apparently) are missing the ability to 
preserve input file timestamps, I use a little Perl script I wrote 
called "timecopy" (AKA "timestamp"):


Install either the Windows-specific ActiveState version of Perl, or 
install the version that comes with Cygwin (see my comments below about 
installing it and adjusting your Windows %PATH%, but install "perl" 
instead of "gcc-core").

And then do something like this in your batch file:

     ffmpeg -i input.mp4 [other opts.] output.mp4
     timestamp -c input.mp4 output.mp4

A limitation of that script is that I originally wrote it for UNIX/Linux 
systems, and it doesn't preserve the creation time (which doesn't 
usually exist on UNIX), nor the access time.

Feel free to skip the rest of this, since you're using ffmpeg to produce 
separate output files with different paths than the input files, rather 
than using a command which modifies files in-place, but I also wrote a 
program called "timepreserve" which you can use to handle the latter 
case (and it also preserves access times, though not creation times):


The way it works is that you pass it a commandline to run, followed by 
one or more filenames you wish to preserve the timestamps of across that 
command-run.  Examples:

     timepreserve "touch *" *  # a no-op
     timepreserve "exifedit -b -t r *.jpg" *.jpg
     timepreserve "wrjpgcom -comment 'a cow' cow.jpg > X; mv X cow.jpg" 

It's a C source file which I haven't tried compiling it natively under 
MSVC, and I'm not sure whether it's possible to do so, but what I'd 
recommend is installing Cygwin (https://cygwin.com/). You'll get other 
useful UNIXey commands in the bargain.

After running Cygwin's setup-x86_64.exe, click through, selecting a 
mirror URL, and then on the Select Packages screen, change the "View" 
drop-down to "Full", and then scroll down to the "gcc-core" package and 
double-click on the drop-down that says "Skip" to select the latest 
version of that for install, and then click through the rest of the 

Run the "Cygwin64 Terminal" program that you'll find in your Start menu 
after this, 'cd' to the directory you downloaded my timepreserve.c file 
to, and then run 'gcc -O timepreserve.c -o timepreserve.exe'.

In your Windows Advanced System Settings, add "C:\cygwin64\bin" 
(assuming you use the default install path) to either your USER or 
SYSTEM %PATH%, along with whatever directory you produced the 
timepreserve.exe file in (or move it to C:\cygwin64\bin).  You'll then 
be ready to wrap timepreserve around ffmpeg, or other commandlines, 
including when called from Command Prompt / .BAT files.

Dan Harkless

More information about the ffmpeg-user mailing list