5

I need an easy way to convert videos to h264 while keeping the original creation date.

Right now I'm doing it manually (encode, then edit the date), but it's a super boring task to do when I have 10+ videos.

Is there a way to do it automatically?

A conversion program with a "keep original file date" option, a batch, a script: i'm open to any solution on any OS.

2
  • Solutions for any os are OK, I have Windows 7, OS X 10.7.4 and Debian 6 Oct 3, 2012 at 17:17
  • I found this reviews.handbrake.fr/r/55/diff/1 , unfortunately, after many tries, I can't make it compile correctly (I can compile revision 3818, but I can't compile the diff...) Oct 3, 2012 at 22:08

6 Answers 6

3
+50

TESTING Copy your video directory to a new directory, then follow instruction below.

PowerShell Script

PowerShell come with Windows 7, no download needed. (Start->All Programs->Accessories->Windows PowerShell).

Start PowerShell as administrator.

You have to do following for the first time before you can run any script(you only have to do it once)

Set-ExecutionPolicy RemoteSigned

Answer "Y".

Put following 2 scripts in your video directory. Open PowerShell and cd to your video directory. .ps1 is PowerShell script extension.

SaveTime.ps1 (before video conversion)

Save following script as SaveTime.ps1 in your video directory. Run this script in PowerShell before your video conversion.

The script will create OldTime-record.ps1 in the same directory.

The script WILL NOT OVERWRITE OldTime-record.ps1. It will only append to the end if the file already exist.

So no worry if you run it by accident and losing your original time-stamp. Just use notepad to remove the extra lines. I added an example of this situation at the end.

# SaveTime.ps1 - Start 
$file = get-item *

write-output "`$file = New-Object string`[`] $($file.count)" >> OldTime-record.ps1
write-output "`$time = New-Object string`[`] $($file.count)" >> OldTime-record.ps1

$time = New-Object string[] $file.count

for ($i = 0; $i -lt $file.count; $i++) {
    write-output "`$file`[$i`]=`'$($file[$i].fullname)`'" >> OldTime-record.ps1
    write-output "`$time`[$i`]=`'$($file[$i].CreationTimeUTC.tostring('o'))`'" >> OldTime-record.ps1
}
# SaveTime.ps1 - End

OldTime.ps1 (after video conversion)

Save following script as OldTime.ps1 in your video directory. Run this script in PowerShell after video conversion. This script will read OldTime-record.ps1 and change file creation time accordingly.

# OldTime.ps1 - Start
. .\OldTime-record.ps1

for($i = 0; $i -lt $file.count; $i++) {
    write-output "$($file[$i])"
    write-output "$($time[$i])"
    Set-ItemProperty -Path $($file[$i]) -Name CreationTimeUTC -Value $($time[$i])
}
# OldTime.ps1 - End

Oldtime-record.ps1

This file hold file name and creation time records. Following shows what it look like if you open it in notepad.

$file = New-Object string[] 9
$time = New-Object string[] 9
$file[0]='E:\Downloads\test\New Folder'
$time[0]='2012-11-13T03:11:11.4504830Z'
$file[1]='E:\Downloads\test\file1'
$time[1]='2012-11-10T01:12:14.6126918Z'
$file[2]='E:\Downloads\test\file2'
$time[2]='2012-11-10T01:12:14.6646918Z'
$file[3]='E:\Downloads\test\file3'
$time[3]='2012-11-10T01:12:14.7276918Z'
$file[4]='E:\Downloads\test\cover.jpg'
$time[4]='2012-11-10T01:12:14.7886918Z'
$file[5]='E:\Downloads\test\OldTime.ps1'
$time[5]='2012-11-13T05:22:18.2124830Z'
$file[6]='E:\Downloads\test\SaveTime.ps1'
$time[6]='2012-11-13T05:44:22.8514830Z'
$file[7]='E:\Downloads\test\test.ps1'
$time[7]='2012-11-13T03:26:28.7084830Z'
$file[8]='E:\Downloads\test\test.time.ps1'
$time[8]='2012-11-13T05:32:51.8204830Z'

Following is what happen if you run SaveTime.ps1 by accident. It just append the new records at the end. To fix it, just delete all lines starting from the second occurrence of $file = New-Object string[].

$file = New-Object string[] 9
$time = New-Object string[] 9
$file[0]='E:\Downloads\test\New Folder'
$time[0]='2012-11-13T03:11:11.4504830Z'
$file[1]='E:\Downloads\test\file1'
$time[1]='2012-11-10T01:12:14.6126918Z'
$file[2]='E:\Downloads\test\file2'
$time[2]='2012-11-10T01:12:14.6646918Z'
$file[3]='E:\Downloads\test\file3'
$time[3]='2012-11-10T01:12:14.7276918Z'
$file[4]='E:\Downloads\test\cover.jpg'
$time[4]='2012-11-10T01:12:14.7886918Z'
$file[5]='E:\Downloads\test\OldTime.ps1'
$time[5]='2012-11-13T05:22:18.2124830Z'
$file[6]='E:\Downloads\test\SaveTime.ps1'
$time[6]='2012-11-13T05:44:22.8514830Z'
$file[7]='E:\Downloads\test\test.ps1'
$time[7]='2012-11-13T03:26:28.7084830Z'
$file[8]='E:\Downloads\test\test.time.ps1'
$time[8]='2012-11-13T05:32:51.8204830Z'
$file = New-Object string[] 11
$time = New-Object string[] 11
$file[0]='E:\Downloads\test\New Folder'
$time[0]='2012-11-13T03:11:11.4504830Z'
$file[1]='E:\Downloads\test\file1'
$time[1]='2012-11-10T01:12:14.6126918Z'
$file[2]='E:\Downloads\test\file2'
$time[2]='2012-11-10T01:12:14.6646918Z'
$file[3]='E:\Downloads\test\file3'
$time[3]='2012-11-10T01:12:14.7276918Z'
$file[4]='E:\Downloads\test\cover.jpg'
$time[4]='2012-11-10T01:12:14.7886918Z'
$file[5]='E:\Downloads\test\new  3.txt'
$time[5]='2012-11-13T06:47:05.4784830Z'
$file[6]='E:\Downloads\test\OldTime-record.ps1'
$time[6]='2012-11-13T05:50:11.7044830Z'
$file[7]='E:\Downloads\test\OldTime.ps1'
$time[7]='2012-11-13T05:22:18.2124830Z'
$file[8]='E:\Downloads\test\SaveTime.ps1'
$time[8]='2012-11-13T05:44:22.8514830Z'
$file[9]='E:\Downloads\test\test.ps1'
$time[9]='2012-11-13T03:26:28.7084830Z'
$file[10]='E:\Downloads\test\test.time.ps1'
$time[10]='2012-11-13T05:32:51.8204830Z'
4
  • Awesome! If I also want to change the modification date, I just add Set-ItemProperty -Path $($file[$i]) -Name LastWriteTime -Value $($time[$i]) in the FOR cycle, right? Nov 14, 2012 at 0:35
  • Yes, just make sure you use the UTC version of the time function. That will keep you away from any time zone issue.
    – John Siu
    Nov 14, 2012 at 1:18
  • With LastWriteTimeUTC Nov 14, 2012 at 9:22
  • Yes. That is correct :D
    – John Siu
    Nov 14, 2012 at 17:44
2

Another solution for Windows I just found for those who don't want to have to deal with a ton of scripting:

Convert and Date Preserve

Once you download it, the program itself is located in MultipleAviConvDatePreserve\bin\Release\MultipleAviConvDatePreserve.exe

And you can use it with any converter that allows command-line (such as handbrake). Not the easiest program to use, but easier than the posted solution.

Because I had some trouble getting the program to work myself, I thought some specific directions on how to use the program might be helpful.

Open Handbrake (or some command-line enabled video encoder) and setup a file for encode like you normally would (with all the preferences you want) and then add it to the queue. Then open the queue and click the "Queue" button and "Generate Batch Script" as shown in the screen shot below:
Generate Batch Script Then open the batch script in notepad and copy the contents (we will use it later). Next open up MultipleAviConvDatePreserve.exe And click the "Set SCRIPT" button Set SCRIPT
Then paste the contents of the batch script generated by Handbrake into the script text box but replace the source and destination in the script to %source and %dest: Enter script
I couldn't get the RunAsDate.exe to work, but you can try it out - it supposedly makes it so the system date doesn't need to be changed. After this, click OK and return to the main window. Then click the "Select DIR" and choose the directory with the video files you want to convert while preserving the original creation date. Then enter the EXACT (case-sensitive) file extension for the source under radio button "source Extension" after which you should see some files appear in the list (if you don't see any files, then the extension is wrong). Then select the files you want to convert (select them all by clicking the first one and then shift-clicking the last file). Then press "GO!" and everything should be self-explanatory from there.

3
  • It doesn't work for me - I think it can only work in Windows XP because it changes the system date before the conversion (not so safe) Dec 1, 2012 at 14:24
  • I'm using Windows 8 64-bit and it works...the program isn't exactly user friendly. Did you select the video files in the list before you tried to convert?
    – Nathan
    Dec 2, 2012 at 1:48
  • I added instructions in case that helps :)
    – Nathan
    Dec 2, 2012 at 7:30
1

On Windows with Powershell enabled, you can use this .BAT script to recursively convert all .AVI and .MP4 files in the current folder tree. Assuming you're encoding with ffmpeg from the FF Prompt with the same parameters; anyway feel free to edit the encoding command on the next to last line. Please note the use of %1 and %2 variables to hold the names of each original (e.g. "name.ext") and converted (e.g. "name_.ext") files.

FOR /r %%I in (*.avi, *.mp4) DO CALL :loopbody "%%~fI" "%%~dpnI_%%~xI" "%%~tI"
GOTO :EOF

:loopbody
   ffmpeg -i %1 -c:v libx264 -crf 18 -maxrate 4000k -bufsize 4000k -c:a libvo_aacenc -q:a 100 -map_metadata 0 -preset veryslow -tune film -movflags +faststart %2
   powershell Set-ItemProperty -LiteralPath '%2' -Name CreationTimeUtc -Value ('%3' -as [Datetime])
0
0

You said “creation date”.  If “modification date” is good enough for you, read on:

You didn’t say what OS you’re using.  If it’s *nix, use the touch command:

touch –r old_file new_file ...

sets new_file’s modification date/time to be the same as old_file’s.

This is available in some Unix emulation packages, like Subsystem for UNIX-based Applications (SUA).  ISTR this is a free download from Microsoft.

4
  • To add to that, to my knowledge there is no way to modify ctime, only mtime. Hope that helps. Oct 3, 2012 at 15:38
  • modification date is not ok, because almost all video editing software will sort by creation date :( Oct 3, 2012 at 16:44
  • In Linux, ctime is change time, which should always has the same value of mtime (modify time). Ext4 (filesystem) has crtime, which is creation time. However, using debugfs and stat on 2 different systems, I did not get expected result.
    – John Siu
    Nov 10, 2012 at 7:37
  • @John: It sounds like your Linux system might be non-standard. On most *nix systems, chmod’ing a file, or creating (or deleting) a hard link to it, will update ctime but not mtime. Nov 13, 2012 at 23:47
0

Which OS? There are touch utilities (both command-line and GUI-based) that will allow you to modify the creation, modification and access date of your files.

For example, here's one for Windows (BulkFileChanger):

NirSoft BFC

2
  • Yes, i use this to change manually the date. The problem is that when I have to change 10+ files, it's boring... Oct 3, 2012 at 17:16
  • Like I said above, plenty of other command-line touch utilities as well: Windows recursive touch commands. Plus of course if you want to set the same date/time for multiple files, the program above is not called BulkFileChanger for nothing. :)
    – Karan
    Oct 3, 2012 at 17:37
0

I finally found a simple-enough way! Tested on Windows XP, probably will work on any higher system.

  1. Convert files in any of your favourite Batch converter. I used Switch Audio File Converter Software. I don't understand why all these tools don't have the preserve timestamp feauture! It is so basic. And they will sometimes even stupidly argue why the option isn't necessary (see 1 and 2)
  2. Download touch utility for Windows. In my case, I have it within RTools and QGis, but you can also download it within e.g. the GNU utilities for Win32.
  3. Run cmd command in the directory, where are the original video files (*.MOV in my case) and the produced output files (in my case it was *.wav files). Enter the following command (modify the extensions appropriatelly):

    for %f in (*.wav) do (touch %f -r %~nf.MOV)

    here is the output:

enter image description here

HEUREKA! All output files have now timestamp corresponding to the original file!

3
  • This seems like a slightly polished version of my answer.  Which would be fine, if you said you were building on my answer.  But you said that my answer doesn’t work on Windows, and then you posted an answer saying to use touch-r on Windows.  P.S. Your command may work, but it’s traditional to put options before arguments.  P.P.S. The OP said in a comment on my answer “modification date is not ok, because almost all video editing software will sort by creation date”,  … (Cont’d) Sep 8, 2019 at 9:01
  • (Cont’d) …  and yet your answer doesn’t address the issue of what timestamp is set.  (If you’re going to show a screenshot of a cmd window, showing dir before and after would be more valuable than simply showing the machinery of the for loop.)  P.P.P.S. See also Difference between UnxUtils and GnuWin32? and Alternatives to unxutils and similar software. Sep 8, 2019 at 9:01
  • @Scott I am not building on your answer. I was using touch in Linux for +25 years. At the time I wrote my comment on your answer, I didn't know it exists for Windows and I didn't know it can be scripted in this way. I had to elaborate all this solution myself to solve that problem on my PC myself. Your answer didn't help me on the way. Fair enough, deleting my comment. Regarding the type of the timestamp, doesn't look like OP was concerned about the particular timestamp type, seems he just used different terminology, so no issue there. Regards.
    – Tomas
    Sep 8, 2019 at 16:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .