In a shell, how to automatically set the modification (or creation) date and time of a Quicktime video file based on the metadata in the file with a single command (or a single command line)? For JPG files, we have exiv2 -T, but is there a similar command for .mov files?
To give an example, let's start with a file video.mov with the following metadata:
$ exiftool video.mov
ExifTool Version Number : 12.57
File Name : video.mov
Directory : .
File Size : 64 MB
File Modification Date/Time : 2023:07:04 02:53:05+02:00
File Access Date/Time : 2023:07:01 11:42:46+02:00
File Inode Change Date/Time : 2023:07:04 02:53:05+02:00
File Permissions : -rw-r--r--
File Type : MOV
File Type Extension : mov
MIME Type : video/quicktime
Major Brand : Apple QuickTime (.MOV/QT)
Minor Version : 0.0.0
Compatible Brands : qt
Media Data Size : 64215615
Media Data Offset : 36
Movie Header Version : 0
Create Date : 2023:07:01 11:42:00
Modify Date : 2023:07:01 11:42:46
Time Scale : 600
Duration : 0:00:45
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 6
Track Header Version : 0
Track Create Date : 2023:07:01 11:42:00
Track Modify Date : 2023:07:01 11:42:46
Track ID : 1
Track Duration : 0:00:45
Track Layer : 0
Track Volume : 0.00%
Image Width : 1920
Image Height : 1080
Clean Aperture Dimensions : 1920x1080
Production Aperture Dimensions : 1920x1080
Encoded Pixels Dimensions : 1920x1080
Graphics Mode : ditherCopy
Op Color : 32768 32768 32768
Compressor ID : hvc1
Source Image Width : 1920
Source Image Height : 1080
X Resolution : 72
Y Resolution : 72
Compressor Name : HEVC
Bit Depth : 24
Video Frame Rate : 29.997
Balance : 0
Audio Format : mp4a
Audio Channels : 2
Audio Bits Per Sample : 16
Audio Sample Rate : 44100
Purchase File Format : mp4a
Warning : [minor] The ExtractEmbedded option may find more tags in the media data
Matrix Structure : 1 0 0 0 1 0 0 0 1
Content Describes : Track 1
Media Header Version : 0
Media Create Date : 2023:07:01 11:42:00
Media Modify Date : 2023:07:01 11:42:46
Media Time Scale : 600
Media Duration : 0:00:45
Media Language Code : und
Gen Media Version : 0
Gen Flags : 0 0 0
Gen Graphics Mode : ditherCopy
Gen Op Color : 32768 32768 32768
Gen Balance : 0
Handler Class : Data Handler
Handler Vendor ID : Apple
Handler Description : Core Media Data Handler
Meta Format : mebx
Handler Type : Metadata Tags
Make : Apple
Model : iPhone SE (2nd generation)
Software : 16.5.1
Creation Date : 2023:07:01 13:42:00+02:00
Image Size : 1920x1080
Megapixels : 2.1
Avg Bitrate : 11.3 Mbps
Rotation : 90
The best approach (to set the modification date) I could come up myself with so far is reading the output of
$ exiftool video.mov | grep "Media Modify Date" | cut -f 19-20 -d ' '
, which is, in my example,
2023:07:01 11:42:46
(which is correct as normalized to UTC or GMT because in real life, the video was taken at around 13:42:… CEST), replacing : in the date in output with -, and finally issuing
$ touch -d "2023-07-01 11:42:46 UTC" video.mov
(my wild guess is that saying UTC is better than saying GMT above). This yields, as expected,
$ ls --full-time video.mov | cut -d ' ' -f 6-8
2023-07-01 13:42:46.000000000 +0200
(the machine is in the time zone CEST, hence +0200). The result is what we want (because the time zone in which the video itself was taken was also CEST), but the process of getting there was manual.
How to process the date from the first command sequence (exiftool … -d ' ') automatically, so that we can issue both the first command and the second command (touch …) in a single command line or in a script?
Alternatively, the modification (or creation) time of the .mov video file has to be read from the metadata in the video file and set on the operating system level in some other way. How? (An aside: as the meta-data field Media Modify Date may be all-zeros for some files, e.g., for a file created by ffmpeg, we might need some more programming logic and try to switch to the values of some other fields in such a case, e.g., adding Date/Time Original and Media Duration if they are properly filled.)
Has anyone already done this task, perhaps, and we just need to run an already available program with appropriate parameters?