2018-10-18 19:19:56 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
2018-10-22 16:45:30 +02:00
|
|
|
import logging
|
2018-10-18 19:19:56 +02:00
|
|
|
|
|
|
|
from . import exiftool
|
|
|
|
|
|
|
|
|
|
|
|
class AVIParser(exiftool.ExiftoolParser):
|
|
|
|
mimetypes = {'video/x-msvideo', }
|
|
|
|
meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', 'Directory',
|
|
|
|
'FileSize', 'FileModifyDate', 'FileAccessDate',
|
|
|
|
'FileInodeChangeDate', 'FilePermissions', 'FileType',
|
|
|
|
'FileTypeExtension', 'MIMEType', 'FrameRate', 'MaxDataRate',
|
|
|
|
'FrameCount', 'StreamCount', 'StreamType', 'VideoCodec',
|
|
|
|
'VideoFrameRate', 'VideoFrameCount', 'Quality',
|
|
|
|
'SampleSize', 'BMPVersion', 'ImageWidth', 'ImageHeight',
|
|
|
|
'Planes', 'BitDepth', 'Compression', 'ImageLength',
|
|
|
|
'PixelsPerMeterX', 'PixelsPerMeterY', 'NumColors',
|
|
|
|
'NumImportantColors', 'NumColors', 'NumImportantColors',
|
|
|
|
'RedMask', 'GreenMask', 'BlueMask', 'AlphaMask',
|
|
|
|
'ColorSpace', 'AudioCodec', 'AudioCodecRate',
|
|
|
|
'AudioSampleCount', 'AudioSampleCount',
|
|
|
|
'AudioSampleRate', 'Encoding', 'NumChannels',
|
|
|
|
'SampleRate', 'AvgBytesPerSec', 'BitsPerSample',
|
|
|
|
'Duration', 'ImageSize', 'Megapixels'}
|
|
|
|
|
2018-10-23 16:32:28 +02:00
|
|
|
def remove_all(self) -> bool:
|
2018-10-18 19:19:56 +02:00
|
|
|
cmd = [_get_ffmpeg_path(),
|
2018-10-23 16:14:21 +02:00
|
|
|
'-i', self.filename, # input file
|
2018-10-18 19:19:56 +02:00
|
|
|
'-y', # overwrite existing output file
|
|
|
|
'-loglevel', 'panic', # Don't show log
|
|
|
|
'-hide_banner', # hide the banner
|
|
|
|
'-codec', 'copy', # don't decode anything, just copy (speed!)
|
|
|
|
'-map_metadata', '-1', # remove supperficial metadata
|
|
|
|
'-map_chapters', '-1', # remove chapters
|
|
|
|
'-fflags', '+bitexact', # don't add any metadata
|
|
|
|
'-flags:v', '+bitexact', # don't add any metadata
|
|
|
|
'-flags:a', '+bitexact', # don't add any metadata
|
|
|
|
self.output_filename]
|
|
|
|
try:
|
2018-10-22 19:12:39 +02:00
|
|
|
subprocess.check_call(cmd)
|
2018-10-22 16:45:30 +02:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
logging.error("Something went wrong during the processing of %s: %s", self.filename, e)
|
2018-10-18 19:19:56 +02:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def _get_ffmpeg_path() -> str: # pragma: no cover
|
|
|
|
ffmpeg_path = '/usr/bin/ffmpeg'
|
|
|
|
if os.path.isfile(ffmpeg_path):
|
|
|
|
if os.access(ffmpeg_path, os.X_OK):
|
|
|
|
return ffmpeg_path
|
|
|
|
|
|
|
|
raise RuntimeError("Unable to find ffmpeg")
|