diff options
| author | jvoisin | 2019-02-02 18:44:02 +0100 |
|---|---|---|
| committer | jvoisin | 2019-02-02 19:19:36 +0100 |
| commit | 8e84ba547abbc3e2bed91f3bd508317d16bbb4c3 (patch) | |
| tree | 526293fd1e02e97c9b120e6d0e0a3d805f33e5e0 /libmat2 | |
| parent | 812bf2553bfe9b77e1d47af08269edb2d430e48f (diff) | |
Add support for wmv
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/video.py | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/libmat2/video.py b/libmat2/video.py index a5029c0..825df92 100644 --- a/libmat2/video.py +++ b/libmat2/video.py | |||
| @@ -9,7 +9,14 @@ from . import exiftool | |||
| 9 | 9 | ||
| 10 | class AbstractFFmpegParser(exiftool.ExiftoolParser): | 10 | class AbstractFFmpegParser(exiftool.ExiftoolParser): |
| 11 | """ Abstract parser for all FFmpeg-based ones, mainly for video. """ | 11 | """ Abstract parser for all FFmpeg-based ones, mainly for video. """ |
| 12 | # Some fileformats have mandatory metadata fields | ||
| 13 | meta_key_value_whitelist = {} # type: Dict[str, Union[str, int]] | ||
| 14 | |||
| 12 | def remove_all(self) -> bool: | 15 | def remove_all(self) -> bool: |
| 16 | if self.meta_key_value_whitelist: | ||
| 17 | logging.warning('The format of "%s" (video/mp4) has some mandatory ' | ||
| 18 | 'metadata fields; mat2 filled them with standard ' | ||
| 19 | 'data.', self.filename) | ||
| 13 | cmd = [_get_ffmpeg_path(), | 20 | cmd = [_get_ffmpeg_path(), |
| 14 | '-i', self.filename, # input file | 21 | '-i', self.filename, # input file |
| 15 | '-y', # overwrite existing output file | 22 | '-y', # overwrite existing output file |
| @@ -31,6 +38,41 @@ class AbstractFFmpegParser(exiftool.ExiftoolParser): | |||
| 31 | return False | 38 | return False |
| 32 | return True | 39 | return True |
| 33 | 40 | ||
| 41 | def get_meta(self) -> Dict[str, Union[str, dict]]: | ||
| 42 | meta = super().get_meta() | ||
| 43 | |||
| 44 | ret = dict() # type: Dict[str, Union[str, dict]] | ||
| 45 | for key, value in meta.items(): | ||
| 46 | if key in self.meta_key_value_whitelist.keys(): | ||
| 47 | if value == self.meta_key_value_whitelist[key]: | ||
| 48 | continue | ||
| 49 | ret[key] = value | ||
| 50 | return ret | ||
| 51 | |||
| 52 | |||
| 53 | class WMVParser(AbstractFFmpegParser): | ||
| 54 | mimetypes = {'video/x-ms-wmv', } | ||
| 55 | meta_whitelist = {'AudioChannels', 'AudioCodecID', 'AudioCodecName', | ||
| 56 | 'ErrorCorrectionType', 'AudioSampleRate', 'DataPackets', | ||
| 57 | 'Directory', 'Duration', 'ExifToolVersion', | ||
| 58 | 'FileAccessDate', 'FileInodeChangeDate', 'FileLength', | ||
| 59 | 'FileModifyDate', 'FileName', 'FilePermissions', | ||
| 60 | 'FileSize', 'FileType', 'FileTypeExtension', | ||
| 61 | 'FrameCount', 'FrameRate', 'ImageHeight', 'ImageSize', | ||
| 62 | 'ImageWidth', 'MIMEType', 'MaxBitrate', 'MaxPacketSize', | ||
| 63 | 'Megapixels', 'MinPacketSize', 'Preroll', 'SendDuration', | ||
| 64 | 'SourceFile', 'StreamNumber', 'VideoCodecName', } | ||
| 65 | meta_key_value_whitelist = { # some metadata are mandatory :/ | ||
| 66 | 'AudioCodecDescription': '', | ||
| 67 | 'CreationDate': '0000:00:00 00:00:00Z', | ||
| 68 | 'FileID': '00000000-0000-0000-0000-000000000000', | ||
| 69 | 'Flags': 2, # FIXME: What is this? Why 2? | ||
| 70 | 'ModifyDate': '0000:00:00 00:00:00', | ||
| 71 | 'TimeOffset': '0 s', | ||
| 72 | 'VideoCodecDescription': '', | ||
| 73 | 'StreamType': 'Audio', | ||
| 74 | } | ||
| 75 | |||
| 34 | 76 | ||
| 35 | class AVIParser(AbstractFFmpegParser): | 77 | class AVIParser(AbstractFFmpegParser): |
| 36 | mimetypes = {'video/x-msvideo', } | 78 | mimetypes = {'video/x-msvideo', } |
| @@ -51,6 +93,7 @@ class AVIParser(AbstractFFmpegParser): | |||
| 51 | 'SampleRate', 'AvgBytesPerSec', 'BitsPerSample', | 93 | 'SampleRate', 'AvgBytesPerSec', 'BitsPerSample', |
| 52 | 'Duration', 'ImageSize', 'Megapixels'} | 94 | 'Duration', 'ImageSize', 'Megapixels'} |
| 53 | 95 | ||
| 96 | |||
| 54 | class MP4Parser(AbstractFFmpegParser): | 97 | class MP4Parser(AbstractFFmpegParser): |
| 55 | mimetypes = {'video/mp4', } | 98 | mimetypes = {'video/mp4', } |
| 56 | meta_whitelist = {'AudioFormat', 'AvgBitrate', 'Balance', 'TrackDuration', | 99 | meta_whitelist = {'AudioFormat', 'AvgBitrate', 'Balance', 'TrackDuration', |
| @@ -84,23 +127,6 @@ class MP4Parser(AbstractFFmpegParser): | |||
| 84 | 'TrackVolume': '0.00%', | 127 | 'TrackVolume': '0.00%', |
| 85 | } | 128 | } |
| 86 | 129 | ||
| 87 | def remove_all(self) -> bool: | ||
| 88 | logging.warning('The format of "%s" (video/mp4) has some mandatory ' | ||
| 89 | 'metadata fields; mat2 filled them with standard data.', | ||
| 90 | self.filename) | ||
| 91 | return super().remove_all() | ||
| 92 | |||
| 93 | def get_meta(self) -> Dict[str, Union[str, dict]]: | ||
| 94 | meta = super().get_meta() | ||
| 95 | |||
| 96 | ret = dict() # type: Dict[str, Union[str, dict]] | ||
| 97 | for key, value in meta.items(): | ||
| 98 | if key in self.meta_key_value_whitelist.keys(): | ||
| 99 | if value == self.meta_key_value_whitelist[key]: | ||
| 100 | continue | ||
| 101 | ret[key] = value | ||
| 102 | return ret | ||
| 103 | |||
| 104 | 130 | ||
| 105 | def _get_ffmpeg_path() -> str: # pragma: no cover | 131 | def _get_ffmpeg_path() -> str: # pragma: no cover |
| 106 | ffmpeg_path = '/usr/bin/ffmpeg' | 132 | ffmpeg_path = '/usr/bin/ffmpeg' |
