Python을 사용하여 비디오 파일에서 Exif 속성 " DateEncoded " 를 가져 오는 방법을 찾을 수 없습니다 .
여러 가지 exif 도구를 사용해 보았지만 이 특정 mp4 파일 (Android 앱 FilmicPro를 사용하여 녹음)은 특별한 경우 인 것 같습니다.
Windows 탐색기는 실제로 QuickTime exif 키 " Media_DateEncoded "인 "Create Date"속성 (이미지 참조) 아래에 올바른 날짜를 표시합니다 .
Adobe Media Encoder도 올바른 날짜를 검색하는 것 같습니다.
그러나 내가 시도한 다섯 가지 방법 중 어느 것도 프로그래밍 방식으로 올바른 날짜 (2019 년 1 월 6 일)를 검색 할 수 없습니다. 항상 1 월 7 일을 반환합니다!
왜 / 어떻게 설명 할 수있는 사람이 있습니까?
다음은 코드입니다.
import os
import re
import struct
import subprocess as sub
from datetime import datetime
from hachoir.parser import createParser
from hachoir.metadata import extractMetadata
from win32com.propsys import propsys, pscon
# Download ExifTool from https://exiftool.org/
EXIF_TOOL = "exiftool.exe"
def method_1(fpath):
# On Windows ctime means "Creation time", on Linux "Changed time"
ctime = os.path.getctime(fpath)
dtime = datetime.fromtimestamp(ctime)
return dtime.strftime("%Y:%m:%d %H:%M:%S")
def method_2(fpath):
'''
This requires Hachoir installed. For Python3 run:
>> pip3 install hachoir==3.1.1
>> pip3 install hachoir-parser
The property key 'Creation date' is a filesystem metadata, but
it was the only one returned by Hachoir. What I really need is
the Quicktime key 'Media_DateEncoded', which Windows Explorer
calls "Media Created"
'''
parser = createParser(fpath)
with parser:
metadata = extractMetadata(parser)
exif_dict = metadata.exportDictionary()['Metadata']
return exif_dict['Creation date']
def method_3(fpath):
'''
This executes this shell comand:
>> exiftool.exe -h VID_20190106_162804.mp4
...which returns an HTML like string from stdout.
So using regular expression, we look for this section:
"Media Create Date</td><td>2019:01:07 00:28:08</td></tr>"
'''
p = sub.Popen(
[EXIF_TOOL, '-h',fpath],
stdout=sub.PIPE,
encoding='utf8')
res, err = p.communicate()
pattern = re.compile(
r'Media Create Date\</td\>\<td\>(\d{4}:\d{2}:\d{2}\s\d{2}:\d{2}:\d{2})'
)
match = re.findall(pattern, res)
if match:
return match[0]
def method_4(fpath):
'''
Here we look for the Quicktime property key: Media_DateEncoded, which
Windows Explorer calls "Media Created"
'''
fpath = fpath.replace('/', '\\') # Windows api does not work with posix paths
properties = propsys.SHGetPropertyStoreFromParsingName(fpath)
dtime = properties.GetValue(pscon.PKEY_Media_DateEncoded).GetValue()
return dtime.strftime("%Y:%m:%d %H:%M:%S")
def method_5(fpath):
ATOM_HEADER_SIZE = 8
# Difference between Unix epoch and QuickTime epoch, in seconds
EPOCH_ADJUSTER = 2082844800
# open file and search for moov item
f = open(fpath, "rb")
while 1:
atom_header = f.read(ATOM_HEADER_SIZE)
if atom_header[4:8] == b'moov':
break
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 Exception("moov atom is compressed")
elif atom_header[4:8] != b'mvhd':
raise Exception("expected to find 'mvhd' header")
else:
f.seek(4, 1)
creation_date = struct.unpack(">I", f.read(4))[0]
dtime = datetime.utcfromtimestamp(creation_date - EPOCH_ADJUSTER)
return dtime.strftime("%Y:%m:%d %H:%M:%S")
win32의 Python 3.7.3 (v3.7.3 : ef4ec6ed12) [MSC v.1916 64 비트 (AMD64)]
운영체제 : Windows 10 버전 10.0.18362 Build 18362
고려하지 않은 점은 Quicktime 메타 데이터 타임 스탬프가 현지 시간이 아닌 UTC로 저장된다는 사실입니다. 시간대별로 저장 시간을 조정해야합니다. 모든 프로그램이 그렇지는 않지만 Windows는이를 이해하고 그에 따라 수정 된 시간을 표시합니다.
exiftool을 사용하여 타임 스탬프를 추출 할 때 -api QuickTimeUTC
옵션을 추가하면 exiftool이 컴퓨터의 현재 시간대를 자동으로 조정합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다