Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andrewp

macrumors member
Original poster
Oct 24, 2008
72
0
Heya,

I just converted 400+ of my videoes from MTS to mp4. However all the timestamps on the new files indicate that the videos were created today. So what I want is to copy the timestamps from the old files and apply them to the new ones.
I have read quite a few posts about this and it shouldn't be too difficult but I could not find a working mac solution so far.
 
or least does anybody know a video converter that preserver the original date of the videos?
 
or least does anybody know a video converter that preserver the original date of the videos?

Are you wanting to set the timestamp in some field WITHIN the video? Or just the timestamp you see in finder folder?

For the actual file, the touch command from the terminal app will work.
 
RE: touch, stat,...

Hi andrewp,

If you wish to use some bash commands, then the following commands will extract the date from one file and apply it to another file:

Code:
timestamp=`stat -t "%c%m%d%H%M.%S" testdate1 | cut -d : -f3- | cut -d " " -f2- | cut -d . -f1`
touch -t $timestamp testdate2

The "stat" command gets all of the various times associated with the file "testdate1". The three "cut" commands then extract one particular date in the format required for the "touch" command. If you wish to select a different date, then you would change the first "cut" to select whichever date you want. The "touch" command then uses the date from the "testdate1" file and resets the modification and access times of file "testdate2" to those of "testdate1".

Below is an example execution of these commands (the commands are on the lines beginning with a "pound sign" #, the output is on the following lines):

Code:
# stat testdate1
16777218 16291081 -rw-r--r-- 1 username staff 0 0 "Jan 14 05:52:02 2013" "Jan 14 05:52:02 2013" "Jan 19 08:14:29 2013" "Jan 14 05:52:02 2013" 4096 0 0 testdate1
# stat testdate2
16777218 16291082 -rw-r--r-- 1 username staff 0 0 "Jan 19 08:40:56 2013" "Jan 19 08:40:56 2013" "Jan 19 08:40:56 2013" "Jan 15 03:14:15 2010" 4096 0 0 testdate2
# timestamp=`stat -t "%c%m%d%H%M.%S" testdate1 | cut -d : -f3- | cut -d " " -f2- | cut -d . -f1`
# echo $timestamp
201301140552
# touch -t $timestamp testdate2
# stat testdate2
16777218 16291082 -rw-r--r-- 1 username staff 0 0 "Jan 14 05:52:00 2013" "Jan 14 05:52:00 2013" "Jan 19 08:42:23 2013" "Jan 15 03:14:15 2010" 4096 0 0 testdate2

As you see from the above output, the stat testdate1 returns a modification date of Jan 14 while the initial stat testdate2 returns Jan 19. The timestamp variable is set to 201301140552 (Jan 14, 2013 05:52) and the touch changes the modification and access times to this date. The final stat testdate2 shows that its modification time has been reset to the earlier date.


Regards,
Switon
 
Last edited:
Thanks for the replies guys!
-Switon, is that code for one file at the time or can it convert all the 400 files in one process?
 
Thanks for the replies guys!
-Switon, is that code for one file at the time or can it convert all the 400 files in one process?

The code as written is for 1 file. But a for loop can easily be written to support wildcards and do the command on each file individually, assuming of course the files have the same name other than extension.

If the names don't easily correlate, then it is harder.
 
RE: one file...

Thanks for the replies guys!
-Switon, is that code for one file at the time or can it convert all the 400 files in one process?


Hi andrewp,

Yes, the code I included runs on just one file, as I didn't know what your video filenames looked like. This code is meant as an executable example of what your actual code would look like. In other words, this is the "guts" of a shell script that would readjust the timestamps of your mp4 videos that you are interested in doing. This code, with a surrounding FOR statement whose variable is used for the filenames plus a little extra coding to generate the proper mp4 output filename, would perform the reset of the modification dates on all 400+ of your videos from a simple script with only about four lines of bash code.

I thank kevink2 for pointing this out before me, as I've been busy and haven't been able to reply as often as I should.

Regards,
Switon
 
Thanks a lot guys it makes good sense but I still struggle executing the command.
I created a .sh file with the lines Switon provided, but I am not sure how I should treat the "testdate" files. I renamed them to bear the same name as the video files, i.e 00216.MTS->00216.mp4, but this give me an error message:

touch: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]

I also tried to specify the location (/user/name/video/00216.MTS) but I still get the same error.

What am I missing?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.