News:

--

Main Menu

Preserve original file timestamp?

Started by User007, May 29, 2023, 09:18:33 AM

Previous topic - Next topic

User007

I have video files in .MTS extension, then i do batch conversion inside AviDemux to save them with .MP4 container.

Now i have lost original timestamp that my camera make (Date Modified) for .MTS files,

Is there way to preserve original timestamp when saving file or copy date modified to the .MP4 files, how can i do it?



eumagga0x2a

No, there is no way to accomplish this task in Avidemux. Stack Overflow may give some clues.

dosdan2

#2
Quote from: User007 on May 29, 2023, 09:18:33 AMIs there way to preserve original timestamp when saving file or copy date modified to the .MP4 files, how can i do it?

A small, free command-line utility, touch.exe, can do this.  Here is the version for Windows:
https://sourceforge.net/projects/touchforwindows/

A test file I made up with today's date/time and an older file I'll use as the reference date/time:
D:\>dir file*
 Directory of D:\

30/05/2023  06:44 PM                41 file
19/11/2021  08:37 AM                89 filelist.txt


The date/time copying operation:  touch -r filelist.txt file

file after touching:
Directory of D:\

19/11/2021  08:37 AM                41 file
19/11/2021  08:37 AM                89 filelist.txt


Just use the .MTS as the ref and the .MP4 as the target.



dosdan2

#3
Here's a batchfile that will touch all the MP4s in a directory based on matching MTS files. 



Assumptions: 
* touch.exe and Touch_all_MP4_from_MTS.bat need to be in a directory which is mentioned in your PATH list.
* Both the MTS and MP4 are in the same directory. The design could be changed to account for differing locations.
* You run the batchfile from within this directory.

Touch_all_MP4_from_MTS.bat
@ECHO off
FOR %%f IN (*.mts) DO (
IF EXIST %%~nf.mp4 (
touch -r "%%f" "%%~nf.mp4"
)
)

A test set of 3 MTS and 2 MP4 files. These are not actual video files, but for this purpose it doesn't matter. I've included some files with a space in their filename as well as a MTS file that does not have a matching MP4 (to test that no error occurs).

Before:
06/10/2018  11:25 AM            15,909 file1.mts
19/05/2019  11:04 AM           230,957 file 2.mts
19/05/2019  11:04 AM           230,957 file 3.mts
30/05/2023  06:57 PM                41 file1.mp4
30/05/2023  06:57 PM                41 file 2.mp4

After running the batchfile:
06/10/2018  11:25 AM            15,909 file1.mts
06/10/2018  11:25 AM                41 file1.mp4
19/05/2019  11:04 AM           230,957 file 2.mts
19/05/2019  11:04 AM                41 file 2.mp4
19/05/2019  11:04 AM           230,957 file 3.mts

eumagga0x2a

@dosdan2: You are most likely right in understanding the question by User007 as related to filesystem-level metadata, not to container-level one. But what has happened to dosdan no. 1?

User007

#5
I actually ended up using Touch from GNU Utilities for Win32, before i read your answer, but thanks for detail description.
Here's some alternative touch versions in answer here.

dosdan2

#6
Quote from: eumagga0x2a on May 30, 2023, 10:57:47 AM@dosdan2: You are most likely right in understanding the question by User007 as related to filesystem-level metadata, not to container-level one. But what has happened to dosdan no. 1?

I'm the same. I had a login issue to this site, so I created a 2nd login. (Ended up using a different browser to successfully log it.) This time, I just used what my saved logins suggested. Will switch back to my original username.

therube

(Like above) I have long used (my) SETTIME.BAT (essentially, touch -r) to re-date files.

SETTIME.bat
@ECHO OFF

ECHO  SETTIME  sets a file's date to the "same" file, named "abc"
ECHO  a sort of more current variation of my old ancient DOS settime program
ECHO.
ECHO  therube 02/20/2015
ECHO.
ECHO  File to change the date of:
ECHO    %1

FOR  %%i in (%1) do  SET  BASENAME=%%~dpiabc
ECHO  reference file (aka "abc"):
ECHO    "%BASENAME%"
ECHO.
ls -l %1
ls -l "%BASENAME%"
ECHO.

PAUSE

touch %1 --reference="%BASENAME%"
:: ls -l %1
c:\bin\dd.exe -1 %1

PAUSE
EXIT



More recently, I'm apt to use Everything 1.5 Alpha & its' [Edit | Advanced] Set File Time feature (with a Custom setting, #get-date-modified:<#clipboard:>.)
(You do a CNTRL+C, copy, of the source file, then set the new file using its' date modified [using Everything].)