def __get_video_stream_attribute__(self, attr, stream = None): if stream is None: stream = self.__get_first_video_stream__() try: return stream[attr] except KeyError as e: util.logger.error("Video stream %s has no key %s\n", util.json_fmt(stream), e.args[0])
def get_file_specs(self): '''Reads file format specs''' self.format = self.specs['format']['format_name'] if self.format == 'mov,mp4,m4a,3gp,3g2,mj2': ext = util.get_file_extension(self.filename) if re.match('^(mp4|mov)', ext, re.IGNORECASE): self.format = ext.lower() self.format_long = self.specs['format']['format_long_name'] self.nb_streams = int(self.specs['format']['nb_streams']) self.size = int(self.specs['format']['size']) try: self.bitrate = int(self.specs['format']['bit_rate']) except KeyError as e: util.logger.error("JSON %s has no key %s\n", util.json_fmt(self.specs), e.args[0]) try: self.duration = float(self.specs['format']['duration']) except KeyError as e: util.logger.error("JSON %s has no key %s\n", util.json_fmt(self.specs), e.args[0])
def get_fps(self, stream=None): if self.video_fps is None: if stream is None: stream = self.__get_first_video_stream__() util.logger.debug('Video stream is %s', util.json_fmt(stream)) for tag in ['avg_frame_rate', 'r_frame_rate']: if tag in stream: self.video_fps = media.compute_fps(stream[tag]) break return self.video_fps
def get_video_bitrate(self): '''Returns video file video bitrate''' if self.video_bitrate is None: try: self.video_bitrate = int(self.specs['format']['bit_rate']) except KeyError as e: util.logger.error("Format %s has no key %s\n", util.json_fmt(self.specs['format']), e.args[0]) return self.video_bitrate
def probe(self): '''Returns media file general specs''' if self.specs is not None: return self.specs try: util.logger.info('Probing %s with %s', self.filename, util.get_ffprobe()) self.specs = ffmpeg.probe(self.filename, cmd=util.get_ffprobe()) except ffmpeg.Error as e: util.logger.error("%s error %s", util.get_ffprobe(), e.stderr) return None self.decode_specs() util.logger.debug(util.json_fmt(self.specs)) return self.specs
def get_video_codec(self, stream): '''Returns video file video codec''' util.logger.debug('Getting video codec') if self.video_codec is not None: return self.video_codec if stream is None: stream = self.__get_first_video_stream__() try: self.video_codec = stream['codec_name'] except KeyError as e: util.logger.error("Stream %s has no key %s\n", util.json_fmt(stream), e.args[0]) return self.video_codec
"File %s is not a supported file format" % file) if util.is_video_file(file): file_object = video.VideoFile(file) if nb_files == 1: props = VIDEO_PROPS elif util.is_audio_file(file): file_object = audio.AudioFile(file) if nb_files == 1: props = AUDIO_PROPS elif util.is_image_file(file): file_object = img.ImageFile(file) if nb_files == 1: props = IMAGE_PROPS specs = file_object.get_properties() util.logger.debug("Specs = %s", util.json_fmt(specs)) for prop in props: if args.format != "csv": try: if prop in UNITS: divider = UNITS[prop][0] unit = UNITS[prop][1] if unit == 'hms': print("%-20s : %s" % (prop, util.to_hms_str(specs[prop]))) else: print("%-20s : %.1f %s" % (prop, (int(specs[prop]) / divider), unit)) else: print("%-20s : %s" % (prop, str(specs[prop]) if specs[prop] is not None else ''))