"""Video file module."""
import logging
import json
import ffmpeg
[docs]
class Video:
"""
Video class.
Aim to read a video file to extract technical information such as video
codec, resolution, etc…
"""
_log: logging.Logger = logging.getLogger(__file__)
def __init__(self, filename):
self.filename = filename
self.probe = ffmpeg.probe(self.filename)
self._log.debug(json.dumps(self.probe, indent=4))
@property
def audio(self):
"""Retrieve list of audio stream in file."""
return [
{
'codec': audio.get('codec_long_name', 'Unknown'),
'language': audio.get(
'tags', {'language': 'und'}
).get('language', 'und'),
'channels': audio.get('channels', 0)
}
for audio in self.probe['streams']
if audio.get('codec_type', '') == 'audio'
]
@property
def subtitle(self):
"""Retrieve list of subtitles."""
return [
{
'language': sub.get(
'tags', {'language': 'und'}
).get('language', 'und')
}
for sub in self.probe['streams']
if sub.get('codec_type', '') == 'subtitle'
]
@property
def video(self):
"""Retrieve list of video stream."""
return [
{
'codec': vid.get('codec_long_name', 'Unknown'),
'aspect': vid.get('display_aspect_ratio', '1:1'),
'width': vid.get('coded_width', vid.get('width', 0)),
'height': vid.get('coded_height', vid.get('height', 0)),
'durationinseconds': float(self.probe['format']['duration']),
}
for vid in self.probe['streams']
if vid.get('codec_type', '') == 'video'
]