| | from distutils.log import fatal |
| | import json |
| |
|
| | from ..common.Common import * |
| | from ..common.Execute import * |
| | from ..media.Timecodes import * |
| |
|
| | class AudioInfo: |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | def __init__(self, file_path): |
| | |
| | self.file_path = file_path |
| | self.file_size = GetFileSize(file_path) |
| |
|
| | command = "ffprobe -v error -select_streams a:0 " + " -show_entries stream=codec_name,sample_rate,channels,start_time,duration,,bit_rate,nb_frames -v quiet -of csv=\"p=0\" " + file_path |
| | stdout, _, errorCode = ExecuteCommand(command) |
| |
|
| | stdout = stdout.split("\n")[0] |
| | stdout = stdout.strip() |
| |
|
| | info = stdout.split(",") |
| |
|
| | index = 0 |
| |
|
| | self.audio_codec = info[index] |
| | index = index + 1 |
| |
|
| | self.sample_rate = int(info[index]) |
| | index = index + 1 |
| |
|
| | self.channels = int(info[index]) |
| | index = index + 1 |
| |
|
| | if info[index] != "N/A": |
| | self.start_timestamp = float(info[index]) |
| | index = index + 1 |
| |
|
| | if info[index] != "N/A": |
| | self.duration = float(info[index]) |
| | index = index + 1 |
| |
|
| | if info[index] != "N/A": |
| | self.bitrate_kbps = float(info[index]) / 1000 |
| | index = index + 1 |
| |
|
| | if info[index] != "N/A": |
| | self.frame_count = float(info[index]) |
| | index = index + 1 |
| |
|
| | def String(self): |
| | return json.dumps(self, default=lambda o: o.__dict__, |
| | sort_keys=True, indent=4) |
| |
|
| | def Print(self, stream): |
| | stream.write(self.String()) |
| |
|
| | def IsDolbyVision(self): |
| | return self.color_space == "bt2020nc" |
| |
|
| | |
| | def DurationAsMin(self): |
| | return self.duration / 60 |
| |
|
| | def DurationAsSec(self): |
| | return self.duration |
| |
|
| | def DurationAsMillisec(self): |
| | return (self.duration * 1000) |
| |
|
| | def DurationAsTimecode(self): |
| | return MillisecToTimeCode(self.DurationAsMillisec()) |