summaryrefslogtreecommitdiff
path: root/libmat2/video.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmat2/video.py')
-rw-r--r--libmat2/video.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/libmat2/video.py b/libmat2/video.py
new file mode 100644
index 0000000..b9f3687
--- /dev/null
+++ b/libmat2/video.py
@@ -0,0 +1,58 @@
1import os
2import subprocess
3
4from . import exiftool
5
6
7class AVIParser(exiftool.ExiftoolParser):
8 mimetypes = {'video/x-msvideo', }
9 meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', 'Directory',
10 'FileSize', 'FileModifyDate', 'FileAccessDate',
11 'FileInodeChangeDate', 'FilePermissions', 'FileType',
12 'FileTypeExtension', 'MIMEType', 'FrameRate', 'MaxDataRate',
13 'FrameCount', 'StreamCount', 'StreamType', 'VideoCodec',
14 'VideoFrameRate', 'VideoFrameCount', 'Quality',
15 'SampleSize', 'BMPVersion', 'ImageWidth', 'ImageHeight',
16 'Planes', 'BitDepth', 'Compression', 'ImageLength',
17 'PixelsPerMeterX', 'PixelsPerMeterY', 'NumColors',
18 'NumImportantColors', 'NumColors', 'NumImportantColors',
19 'RedMask', 'GreenMask', 'BlueMask', 'AlphaMask',
20 'ColorSpace', 'AudioCodec', 'AudioCodecRate',
21 'AudioSampleCount', 'AudioSampleCount',
22 'AudioSampleRate', 'Encoding', 'NumChannels',
23 'SampleRate', 'AvgBytesPerSec', 'BitsPerSample',
24 'Duration', 'ImageSize', 'Megapixels'}
25
26 def remove_all(self) -> bool:
27 """
28 TODO: handle problematic filenames starting with `-` and `--`,
29 check exiftool.py
30 """
31 cmd = [_get_ffmpeg_path(),
32 '-i', self.filename, # input file
33 '-y', # overwrite existing output file
34 '-loglevel', 'panic', # Don't show log
35 '-hide_banner', # hide the banner
36 '-codec', 'copy', # don't decode anything, just copy (speed!)
37 '-map_metadata', '-1', # remove supperficial metadata
38 '-map_chapters', '-1', # remove chapters
39 '-fflags', '+bitexact', # don't add any metadata
40 '-flags:v', '+bitexact', # don't add any metadata
41 '-flags:a', '+bitexact', # don't add any metadata
42 self.output_filename]
43
44 try:
45 subprocess.check_call(cmd)
46 except subprocess.CalledProcessError: # pragma: no cover
47 return False
48
49 return True
50
51
52def _get_ffmpeg_path() -> str: # pragma: no cover
53 ffmpeg_path = '/usr/bin/ffmpeg'
54 if os.path.isfile(ffmpeg_path):
55 if os.access(ffmpeg_path, os.X_OK):
56 return ffmpeg_path
57
58 raise RuntimeError("Unable to find ffmpeg")