Coverage for mymeco/files/video.py: 60%

18 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-05 22:06 +0000

1"""Video file module.""" 

2import logging 

3import json 

4import ffmpeg 

5 

6 

7class Video: 

8 """ 

9 Video class. 

10 

11 Aim to read a video file to extract technical information such as video 

12 codec, resolution, etc… 

13 """ 

14 

15 _log: logging.Logger = logging.getLogger(__file__) 

16 

17 def __init__(self, filename): 

18 self.filename = filename 

19 self.probe = ffmpeg.probe(self.filename) 

20 self._log.debug(json.dumps(self.probe, indent=4)) 

21 

22 @property 

23 def audio(self): 

24 """Retrieve list of audio stream in file.""" 

25 return [ 

26 { 

27 'codec': audio.get('codec_long_name', 'Unknown'), 

28 'language': audio.get( 

29 'tags', {'language': 'und'} 

30 ).get('language', 'und'), 

31 'channels': audio.get('channels', 0) 

32 } 

33 for audio in self.probe['streams'] 

34 if audio.get('codec_type', '') == 'audio' 

35 ] 

36 

37 @property 

38 def subtitle(self): 

39 """Retrieve list of subtitles.""" 

40 return [ 

41 { 

42 'language': sub.get( 

43 'tags', {'language': 'und'} 

44 ).get('language', 'und') 

45 } 

46 for sub in self.probe['streams'] 

47 if sub.get('codec_type', '') == 'subtitle' 

48 ] 

49 

50 @property 

51 def video(self): 

52 """Retrieve list of video stream.""" 

53 return [ 

54 { 

55 'codec': vid.get('codec_long_name', 'Unknown'), 

56 'aspect': vid.get('display_aspect_ratio', '1:1'), 

57 'width': vid.get('coded_width', vid.get('width', 0)), 

58 'height': vid.get('coded_height', vid.get('height', 0)), 

59 'durationinseconds': float(self.probe['format']['duration']), 

60 } 

61 for vid in self.probe['streams'] 

62 if vid.get('codec_type', '') == 'video' 

63 ]