|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 from collections import OrderedDict |
|
18 |
|
19 # import interfaces |
|
20 |
|
21 # import packages |
|
22 from zope.interface import Interface, Attribute |
|
23 from zope.schema import List, Choice, Int |
|
24 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
25 |
|
26 from pyams_media import _ |
|
27 |
|
28 |
|
29 # |
|
30 # Medias interfaces |
|
31 # |
|
32 |
|
33 CONVERTER_NAME = 'Medias converter' |
|
34 CONVERTER_HANDLER_KEY = 'pyams_media.tcp_handler' |
|
35 |
|
36 CUSTOM_AUDIO_TYPES = (b'application/ogg',) |
|
37 CUSTOM_VIDEO_TYPES = () |
|
38 |
|
39 |
|
40 class IMediaInfo(Interface): |
|
41 """Media file info interface""" |
|
42 |
|
43 infos = Attribute("Complete media info dictionary") |
|
44 |
|
45 |
|
46 # |
|
47 # Media converter utility interfaces |
|
48 # |
|
49 |
|
50 class IMediaConverter(Interface): |
|
51 """Media converter interface""" |
|
52 |
|
53 label = Attribute("Media converter label") |
|
54 |
|
55 format = Attribute("Media converter target format") |
|
56 |
|
57 def convert(self, media): |
|
58 """Convert media to format handled by given converter""" |
|
59 |
|
60 |
|
61 class IMediaVideoConverter(IMediaConverter): |
|
62 """Media video converter""" |
|
63 |
|
64 |
|
65 class IMediaAudioConverter(IMediaConverter): |
|
66 """Media audio converter""" |
|
67 |
|
68 |
|
69 # |
|
70 # Media conversions adapter interfaces |
|
71 # |
|
72 |
|
73 class IMediaConversions(Interface): |
|
74 """Media conversions interface""" |
|
75 |
|
76 def add_conversion(self, conversion, format, extension=None, width=None): |
|
77 """Add given conversion to media""" |
|
78 |
|
79 def has_conversion(self, formats): |
|
80 """Check if one of given formats is available in conversions""" |
|
81 |
|
82 def get_conversion(self, format): |
|
83 """Get converted media for given format and width""" |
|
84 |
|
85 def get_conversions(self): |
|
86 """Get current list of media conversions""" |
|
87 |
|
88 |
|
89 class IMediaConversion(Interface): |
|
90 """Marker interface for already converted media files""" |
|
91 |
|
92 |
|
93 # |
|
94 # Media conversion utility configuration interface |
|
95 # |
|
96 |
|
97 VIDEO_FRAME_SIZE = {'sqcif': (128, 96), |
|
98 'qqvga': (160, 120), |
|
99 'qcif': (176, 144), |
|
100 'cga': (320, 200), |
|
101 'qvga': (320, 240), |
|
102 'cif': (352, 288), |
|
103 'vga': (640, 480), |
|
104 '4cif': (704, 576), |
|
105 'svga': (800, 600), |
|
106 'wvga': (852, 480), |
|
107 'hd480': (852, 480), |
|
108 'hd720': (1280, 720), |
|
109 'xga': (1024, 768), |
|
110 'sxga': (1280, 1024), |
|
111 'wxga': (1366, 768), |
|
112 'uxga': (1600, 1200), |
|
113 'wsxga': (1600, 1024), |
|
114 'hd1080': (1920, 1080), |
|
115 'wuxga': (1920, 1200), |
|
116 'qxga': (2048, 1536), |
|
117 'wqxga': (2560, 1600), |
|
118 'qsxga': (2560, 2048), |
|
119 'wqsxga': (3200, 2048), |
|
120 'wquxga': (3840, 2400), |
|
121 'hsxga': (5120, 4096), |
|
122 'whsxga': (6400, 4096), |
|
123 'whuxga': (7680, 4800)} |
|
124 |
|
125 |
|
126 VIDEO_FRAME_SIZE_NAMES = OrderedDict((('sqcif', "sqcif (128x96)"), |
|
127 ('qqvga', "qqvga (160x120)"), |
|
128 ('qcif', "qcif (176x144)"), |
|
129 ('cga', "cga (320x200)"), |
|
130 ('qvga', "qvga (320x240)"), |
|
131 ('cif', "cif (352x288)"), |
|
132 ('vga', "vga (640x480)"), |
|
133 ('4cif', "4cif (704x576)"), |
|
134 ('svga', "svga (800x600)"), |
|
135 ('wvga', "wvga (852x480)"), |
|
136 ('hd480', "hd480 (852x480)"), |
|
137 ('hd720', "hd720 (1280x720)"), |
|
138 ('xga', "xga (1024x768)"), |
|
139 ('sxga', "sxga (1280x1024)"), |
|
140 ('wxga', "wxga (1366x768)"), |
|
141 ('uxga', "uxga (1600x1200)"), |
|
142 ('wsxga', "wsxga (1600x1024)"), |
|
143 ('hd1080', "hd1080 (1920x1080)"), |
|
144 ('wuxga', "wuxga (1920x1200)"), |
|
145 ('qxga', "qxga (2048x1536)"), |
|
146 ('wqxga', "wqxga (2560x1600)"), |
|
147 ('qsxga', "qsxga (2560x2048)"), |
|
148 ('wqsxga', "wqsxga (3200x2048)"), |
|
149 ('wquxga', "wquxga (3840x2400)"), |
|
150 ('hsxga', "hsxga (5120x4096)"), |
|
151 ('whsxga', "whsxga (6400x4096)"), |
|
152 ('whuxga', "whuxga (7680x4800)"))) |
|
153 |
|
154 |
|
155 VIDEO_FRAME_SIZE_VOCABULARY = SimpleVocabulary([SimpleTerm(v, title=t) for v, t in VIDEO_FRAME_SIZE_NAMES.items()]) |
|
156 |
|
157 |
|
158 class IMediaConversionUtility(Interface): |
|
159 """Media conversion client interface""" |
|
160 |
|
161 zeo_connection = Choice(title=_("ZEO connection name"), |
|
162 description=_("Name of ZEO connection utility defining converter connection"), |
|
163 required=False, |
|
164 vocabulary="PyAMS ZEO connections") |
|
165 |
|
166 video_formats = List(title=_("Video formats conversions"), |
|
167 description=_("Published video files will be automatically converted to this format"), |
|
168 value_type=Choice(vocabulary="PyAMS media video converters"), |
|
169 required=False) |
|
170 |
|
171 video_frame_size = List(title=_("Video frames size"), |
|
172 description=_("Leave empty to keep original frame size..."), |
|
173 required=True, |
|
174 value_type=Choice(vocabulary=VIDEO_FRAME_SIZE_VOCABULARY)) |
|
175 |
|
176 video_audio_sampling = Int(title=_("Video audio frequency"), |
|
177 description=_("A common value is 22050. Leave empty to keep original value."), |
|
178 required=False) |
|
179 |
|
180 video_audio_bitrate = Int(title=_("Video audio bitrate"), |
|
181 description=_("In kilo-bytes per second. Leave empty to keep original value."), |
|
182 required=False) |
|
183 |
|
184 video_quantisation = Int(title=_("Video quantisation scale"), |
|
185 description=_("Lower value indicates higher quality"), |
|
186 required=False, |
|
187 default=1) |
|
188 |
|
189 audio_formats = List(title=_("Audio formats conversions"), |
|
190 description=_("Published audio files will be automatically converted to this format"), |
|
191 value_type=Choice(vocabulary="PyAMS media audio converters"), |
|
192 required=False) |
|
193 |
|
194 def check_media_conversion(self, media): |
|
195 """Check if conversion is needed for given media""" |
|
196 |
|
197 def convert(self, media, format): |
|
198 """Convert given media to requested format""" |