def handle_attr_capture(filename, attr_name): handler = MediaInfo() handler.Open(filename) info = handler.Inform() value = 'unable to retrieve data' if info: value = get_attr_value(info, attr_name) handler.Close() return value
import os import subprocess from pathlib import Path os.chdir(os.environ["PROGRAMFILES"] + "\\mediainfo") from MediaInfoDLL3 import MediaInfo, Stream MI = MediaInfo() def get_length(path, recursive=False, mode=1): sum = 0 for thing in os.listdir(path): # if its a file if os.path.isfile(path + thing): MI.Open(path + thing) if mode is 1: duration = MI.Get(Stream.Video, 0, "Duration") if mode is 2: duration = MI.Get(Stream.Audio, 0, "Duration") try: sum += int(duration) print("added duration {0} from file: {1}".format(int(duration), path + thing)) except ValueError: print("Skipping a file: " + path + thing) MI.Close() # if its a dir elif os.path.isdir(path + thing): if recursive: print("diving into: " + thing)
def __init__(self): self.MI = MediaInfo()
class Parser: def __init__(self): self.MI = MediaInfo() def scan_file(self, file_num): # print(get_filesDict(file_num)) self.MI.Open(config.rootDir + '/' + filesDict[int(file_num)]) self.get_info() # return filesDict[int(file_num)] def get_info(self): finalInfo = '' self.MI.Option_Static("Inform", "General;%FileName%.%FileExtension%") outDict['File name'] = self.MI.Inform() self.MI.Option_Static("Inform", "General;%FileSize/String2%") outDict['File size'] = self.MI.Inform() self.MI.Option_Static("Inform", "General;%Format%") outDict['File format'] = self.MI.Inform() self.MI.Option_Static("Inform", "General;%Duration/String4%") outDict['Duration'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%CodecID%") outDict['Codec'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%BitRate_Mode/String%, %BitRate/String%") outDict['Bit rate'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%FrameRate/String%") outDict['Frame rate'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%ScanOrder/String%") outDict['Field order'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%Width%x%Height%") outDict['Resolution'] = self.MI.Inform() self.MI.Option_Static("Inform", "Video;%PixelAspectRatio%") outDict['Aspect'] = self.MI.Inform() self.MI.Option_Static("Inform", "Audio;%Format%") outDict['Audio codec'] = self.MI.Inform() self.MI.Option_Static("Inform", "Audio;%BitRate/String%") outDict['Audio bit rate'] = self.MI.Inform() self.MI.Option_Static("Inform", "Audio;%SamplingRate/String%") outDict['Sample rate'] = self.MI.Inform() self.MI.Option_Static("Inform", "Audio;%BitDepth_Detected%") outDict['Sample size'] = self.MI.Inform() self.MI.Option_Static("Inform", "Audio;%Channel(s)/String%, %ChannelLayout%") outDict['Channels layout'] = self.MI.Inform() return outDict # def getFInfo(self): # finalInfo = '' # for key in outDict: # finalInfo = (key + ': ' + outDict[key] + '\n') # return finalInfo
def read_video_height(self, video_file): MI = MediaInfo() MI.Open(video_file) height = MI.Get(Stream.Video, 0, "Height") MI.Close() return height