|
1
|
|
|
""" |
|
2
|
|
|
ffmpeg_streaming.media |
|
3
|
|
|
~~~~~~~~~~~~ |
|
4
|
|
|
|
|
5
|
|
|
Video and audio formats |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
:copyright: (c) 2020 by Amin Yazdanpanah. |
|
9
|
|
|
:website: https://www.aminyazdanpanah.com |
|
10
|
|
|
:email: [email protected] |
|
11
|
|
|
:license: MIT, see LICENSE for more details. |
|
12
|
|
|
""" |
|
13
|
|
|
import abc |
|
14
|
|
|
|
|
15
|
|
|
MULTIPLY_BY_ONE = 1 |
|
16
|
|
|
MULTIPLY_BY_TWO = 2 |
|
17
|
|
|
MULTIPLY_BY_FOUR = 4 |
|
18
|
|
|
MULTIPLY_BY_Eight = 8 |
|
19
|
|
|
MULTIPLY_BY_SIXTEEN = 16 |
|
20
|
|
|
MULTIPLY_BY_THIRTY_TWO = 32 |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def _verify_codecs(codec, codecs): |
|
24
|
|
|
if codec is None: |
|
25
|
|
|
return |
|
26
|
|
|
elif codec not in codecs: |
|
27
|
|
|
ValueError("The codec is not available!") |
|
28
|
|
|
else: |
|
29
|
|
|
return str(codec) |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class Format(abc.ABC): |
|
33
|
|
|
def __init__(self, video: str, audio: str): |
|
34
|
|
|
self.video = video |
|
35
|
|
|
self.audio = audio |
|
36
|
|
|
|
|
37
|
|
|
@abc.abstractmethod |
|
38
|
|
|
def multiply(self) -> int: |
|
39
|
|
|
pass |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
class H264(Format): |
|
43
|
|
|
def __init__(self, video: str = "libx264", audio: str = 'copy'): |
|
44
|
|
|
videos = ['libx264', 'h264', 'h264_afm'] |
|
45
|
|
|
audios = ['copy', 'aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'] |
|
46
|
|
|
|
|
47
|
|
|
super(H264, self).__init__(_verify_codecs(video, videos), _verify_codecs(audio, audios)) |
|
48
|
|
|
|
|
49
|
|
|
def multiply(self) -> int: |
|
50
|
|
|
return MULTIPLY_BY_TWO |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class HEVC(Format): |
|
54
|
|
|
def __init__(self, video: str = "libx265", audio: str = 'copy'): |
|
55
|
|
|
videos = ['libx265', 'h265'] |
|
56
|
|
|
audios = ['copy', 'aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'] |
|
57
|
|
|
|
|
58
|
|
|
super(HEVC, self).__init__(_verify_codecs(video, videos), _verify_codecs(audio, audios)) |
|
59
|
|
|
|
|
60
|
|
|
def multiply(self) -> int: |
|
61
|
|
|
return MULTIPLY_BY_TWO |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
class VP9(Format): |
|
65
|
|
|
def __init__(self, video: str = "libvpx-vp9", audio: str = 'copy'): |
|
66
|
|
|
videos = ['libvpx', 'libvpx-vp9'] |
|
67
|
|
|
audios = ['copy', 'aac', 'libvo_aacenc', 'libfaac', 'libmp3lame', 'libfdk_aac'] |
|
68
|
|
|
|
|
69
|
|
|
super(VP9, self).__init__(_verify_codecs(video, videos), _verify_codecs(audio, audios)) |
|
70
|
|
|
|
|
71
|
|
|
def multiply(self) -> int: |
|
72
|
|
|
return MULTIPLY_BY_TWO |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
class Formats: |
|
76
|
|
|
@staticmethod |
|
77
|
|
|
def h264(video: str = "libx264", audio: str = 'copy') -> Format: |
|
78
|
|
|
return H264(video, audio) |
|
79
|
|
|
|
|
80
|
|
|
@staticmethod |
|
81
|
|
|
def hevc(video: str = "libx265", audio: str = 'copy') -> Format: |
|
82
|
|
|
return HEVC(video, audio) |
|
83
|
|
|
|
|
84
|
|
|
@staticmethod |
|
85
|
|
|
def vp9(video: str = "libvpx-vp9", audio: str = 'copy') -> Format: |
|
86
|
|
|
return VP9(video, audio) |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
__all__ = [ |
|
90
|
|
|
'Format', |
|
91
|
|
|
'Formats' |
|
92
|
|
|
] |
|
93
|
|
|
|