Get Updates by Email

Thursday, 19 September 2013

Sorting MTS and JPG files according to Date and Time

I recently had a problem with sorting MTS files (Sony TX10 camera, video format) in bulk according to date and time.

My solution is a bash script as follows:

for i in *.MTS
hash=$(exiftool $i|grep Original)
hash2=${hash//[:+ DateTimOrgnl]}
 mv $i ${hash2:1:8}-${hash2:9:6}.MTS

All the MTS files will usually be of the filename 00051.MTS, 00052.MTS, etc.

After running this file, all the MTS files will be sorted according to the EXIF data in the header.
The result will be a list of MTS files of the filename 20130913-102033.MTS, etc. where 20130913 stands for 13th of September 2013, and 102033 stands for the time (10.20:33am) the video was made.

I also picked up from StackOverflow a nifty command to sort out the JPG files according to EXIF data (date and time). The solution is:

for i in *.JPG
jhead -n%Y%m%d-%H%M%S $i 

The result will be that all the *.JPG files will be sorted according to names like 20130913-102033.jpg, etc.

That means that the MTS and JPG files will be named in similar fashion.

That's just what I need! :)