我有一个电话通讯应用程序发送的 .MOV 视频。我可以检索文件和作者的真实创建数据吗?我尝试使用 ffprobe、mediainfo 和类似工具,但只给我下载日期。
问问题
19430 次
4 回答
11
我编写了一个快速的 Python 2 脚本,它可以获取创建和修改时间戳,因为它们很容易找到。找到作者有点困难,因为它可以以几种不同的方式存储。示例用法:
$ ./mov-timestamps.py file.mov
creation date: 2013-03-29 16:14:01
modification date: 2013-03-29 16:14:13
有时您可能会看到 1904 年 1 月 1 日的日期。这意味着时间戳为 0。如果您看到 1970 年 1 月 1 日的日期,则该文件可能是由 FFmpeg 生成的,出于安全原因,它不存储此元数据。
#!/usr/bin/python
import datetime
import struct
import sys
ATOM_HEADER_SIZE = 8
# difference between Unix epoch and QuickTime epoch, in seconds
EPOCH_ADJUSTER = 2082844800
if len(sys.argv) < 2:
print "USAGE: mov-length.py <file.mov>"
sys.exit(1)
# open file and search for moov item
f = open(sys.argv[1], "rb")
while 1:
atom_header = f.read(ATOM_HEADER_SIZE)
if atom_header[4:8] == 'moov':
break
else:
atom_size = struct.unpack(">I", atom_header[0:4])[0]
f.seek(atom_size - 8, 1)
# found 'moov', look for 'mvhd' and timestamps
atom_header = f.read(ATOM_HEADER_SIZE)
if atom_header[4:8] == 'cmov':
print "moov atom is compressed"
elif atom_header[4:8] != 'mvhd':
print "expected to find 'mvhd' header"
else:
f.seek(4, 1)
creation_date = struct.unpack(">I", f.read(4))[0]
modification_date = struct.unpack(">I", f.read(4))[0]
print "creation date:",
print datetime.datetime.utcfromtimestamp(creation_date - EPOCH_ADJUSTER)
print "modification date:",
print datetime.datetime.utcfromtimestamp(modification_date - EPOCH_ADJUSTER)
于 2014-01-28T02:35:53.180 回答
11
因此,我将MMM 的代码更新为 Python3 并改进了一些东西。
def get_mov_timestamps(filename):
''' Get the creation and modification date-time from .mov metadata.
Returns None if a value is not available.
'''
from datetime import datetime as DateTime
import struct
ATOM_HEADER_SIZE = 8
# difference between Unix epoch and QuickTime epoch, in seconds
EPOCH_ADJUSTER = 2082844800
creation_time = modification_time = None
# search for moov item
with open(filename, "rb") as f:
while True:
atom_header = f.read(ATOM_HEADER_SIZE)
#~ print('atom header:', atom_header) # debug purposes
if atom_header[4:8] == b'moov':
break # found
else:
atom_size = struct.unpack('>I', atom_header[0:4])[0]
f.seek(atom_size - 8, 1)
# found 'moov', look for 'mvhd' and timestamps
atom_header = f.read(ATOM_HEADER_SIZE)
if atom_header[4:8] == b'cmov':
raise RuntimeError('moov atom is compressed')
elif atom_header[4:8] != b'mvhd':
raise RuntimeError('expected to find "mvhd" header.')
else:
f.seek(4, 1)
creation_time = struct.unpack('>I', f.read(4))[0] - EPOCH_ADJUSTER
creation_time = DateTime.fromtimestamp(creation_time)
if creation_time.year < 1990: # invalid or censored data
creation_time = None
modification_time = struct.unpack('>I', f.read(4))[0] - EPOCH_ADJUSTER
modification_time = DateTime.fromtimestamp(modification_time)
if modification_time.year < 1990: # invalid or censored data
modification_time = None
return creation_time, modification_time
和...
你不知道吗,就在我完成时,我发现了如何使用 exiftool 来完成它,我用它来处理 .jpg 文件的类似任务。:-/
⏵ exiftool -time:all img_3904.mov
于 2019-02-14T04:36:54.643 回答
4
你试过hachoir吗?pip install hachoir
使用, 然后在命令行安装它:
$ hachoir-metadata IMG_9395.MOV
返回例如
Metadata:
- Duration: 2 sec 220 ms
- Image width: 1440 pixels
- Image height: 1080 pixels
- Creation date: 2020-04-15 20:22:57
- Last modification: 2020-04-15 20:22:58
- Comment: Play speed: 100.0%
- Comment: User volume: 100.0%
- MIME type: video/quicktime
- Endianness: Big endian
如果您愿意,也可以在 Python 中使用它:
from hachoir.parser import createParser
from hachoir.metadata import extractMetadata
def creation_date(filename):
parser = createParser(filename)
metadata = extractMetadata(parser)
return metadata.get('creation_date')
于 2020-05-11T20:35:09.007 回答
2
这是一个不是纯 python 的版本,而是需要作为 mediainfo 工具一部分的 libmediainfo。
import pymediainfo
import sys
media_info = pymediainfo.MediaInfo.parse(sys.argv[1])
#For the first track - otherwise iterate over each track
print(' Encoded date {}'.format(track[0].encoded_date))
print(' Tagged date {}'.format(track[0].tagged_date))
于 2020-04-26T16:33:59.257 回答