1# -*- coding: utf-8 -*- 2# 3# PhotoFilmStrip - Creates movies out of your pictures. 4# 5# Copyright (C) 2010 Jens Goepfert 6# 7 8from photofilmstrip.core.Aspect import Aspect 9 10 11class FrameRate: 12 13 def __init__(self, numValue, strValue): 14 self.num = numValue 15 self.str = strValue 16 17 def __str__(self, *args, **kwargs): 18 return u"%.2f fps" % self.num 19 20 def AsFloat(self): 21 return self.num 22 23 def AsStr(self): 24 return self.str 25 26 27class OutputProfile: 28 29 PAL = 1 30 NTSC = 2 31 32 def __init__(self, name, resolution, frameRate, bitrate, videoNorm=None): 33 self.__name = name 34 self.__resolution = resolution 35 self.__frameRate = frameRate 36 self.__bitrate = bitrate 37 self.__videoNorm = videoNorm 38 self.__friendlyName = None 39 40 def GetName(self, withRes=False): 41 if self.__videoNorm: 42 simple = self.__name 43 else: 44 simple = "{0}@{1}".format(self.__name, self.__frameRate) 45 if withRes: 46 return "%s (%dx%d)" % (simple, self.GetResolution()[0], self.GetResolution()[1]) 47 else: 48 return simple 49 50 def GetBitrate(self): 51 return self.__bitrate 52 53 def GetResolution(self): 54 return self.__resolution 55 56 def GetFrameRate(self): 57 return self.__frameRate 58 59 def GetVideoNorm(self): 60 return self.__videoNorm 61 62 def IsMPEGProfile(self): 63 for mpegProf in ("VCD", "SVCD", "DVD"): 64 if self.__name.startswith(mpegProf): 65 return True 66 return False 67 68 def SetFriendlyName(self, value): 69 self.__friendlyName = value 70 71 def GetFriendlyName(self): 72 return self.__friendlyName 73 74 75FPS15 = FrameRate(15.0, "15/1") 76FPS23996 = FrameRate(24000.0 / 1001.0, "24000/1001") 77FPS24 = FrameRate(24.0, "24/1") 78FPS25 = FrameRate(25.0, "25/1") 79FPS29997 = FrameRate(30000.0 / 1001.0, "30000/1001") 80FPS30 = FrameRate(30.0, "30/1") 81FPS50 = FrameRate(50.0, "50/1") 82FPS59994 = FrameRate(60000.0 / 1001.0, "60000/1001") 83FPS60 = FrameRate(60.0, "60/1") 84 85 86def __CreateMPEGProfiles(): 87 vcd_pal = OutputProfile("VCD-PAL", (352, 288), FPS25, 1150, 88 OutputProfile.PAL) 89 vcd_ntsc = OutputProfile("VCD-NTSC", (352, 240), FPS29997, 1150, 90 OutputProfile.NTSC) 91 92 svcd_pal = OutputProfile("SVCD-PAL", (480, 576), FPS25, 2500, 93 OutputProfile.PAL) 94 svcd_ntsc = OutputProfile("SVCD-NTSC", (480, 576), FPS29997, 2500, 95 OutputProfile.NTSC) 96 97 dvd_pal = OutputProfile("DVD-PAL", (720, 576), FPS25, 8000, 98 OutputProfile.PAL) 99 dvd_ntsc = OutputProfile("DVD-NTSC", (720, 480), FPS29997, 8000, 100 OutputProfile.NTSC) 101 result = [vcd_pal, vcd_ntsc, svcd_pal, svcd_ntsc, dvd_pal, dvd_ntsc] 102 for prof in result: 103 prof.SetFriendlyName(prof.GetName()) 104 return result 105 106 107def __Create16_9Profiles(): 108 profs = [] 109 110 # 360p 111 for fps in [FPS23996, FPS25]: 112 prof = OutputProfile("360p", (640, 360), fps, 1000) 113 if fps is FPS25: 114 prof.SetFriendlyName("Medium") 115 profs.append(prof) 116 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 117 prof = OutputProfile("360p", (640, 360), fps, 1500) 118 profs.append(prof) 119 120 # 480p 121 for fps in [FPS24, FPS30]: 122 prof = OutputProfile("480p", (854, 480), fps, 2500) 123 profs.append(prof) 124 for fps in [FPS50, FPS60]: 125 prof = OutputProfile("480p", (854, 480), fps, 4000) 126 profs.append(prof) 127 128 # 720p 129 for fps in [FPS23996, FPS24, FPS25]: 130 prof = OutputProfile("HD 720p", (1280, 720), fps, 5000) 131 if fps is FPS25: 132 prof.SetFriendlyName("HD") 133 profs.append(prof) 134 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 135 prof = OutputProfile("HD 720p", (1280, 720), fps, 7500) 136 profs.append(prof) 137 138 # 1080p 139 for fps in [FPS23996, FPS24, FPS25]: 140 prof = OutputProfile("HD 1080p", (1920, 1080), fps, 8000) 141 if fps is FPS25: 142 prof.SetFriendlyName("FULL-HD") 143 profs.append(prof) 144 for fps in [FPS29997, FPS30, FPS50, FPS60]: 145 prof = OutputProfile("HD 1080p", (1920, 1080), fps, 12000) 146 profs.append(prof) 147 148 # 2160p 149 for fps in [FPS23996, FPS24, FPS25]: 150 prof = OutputProfile("UHD-1 2160p", (3840, 2160), fps, 25000) 151 if fps is FPS25: 152 prof.SetFriendlyName("UHD") 153 profs.append(prof) 154 for fps in [FPS29997, FPS30, FPS50, FPS60]: 155 prof = OutputProfile("UHD-1 2160p", (3840, 2160), fps, 50000) 156 profs.append(prof) 157 158 # 4320p 159 for fps in [FPS25, FPS30, FPS50, FPS60]: 160 prof = OutputProfile("UHD-2 4320p", (7680, 4320), fps, 60000) 161 profs.append(prof) 162 163 return profs 164 165 166def __Create4_3Profiles(): 167 profs = [] 168 169 # 360p 170 for fps in [FPS23996, FPS25]: 171 prof = OutputProfile("360p", (480, 360), fps, 1000) 172 if fps is FPS25: 173 prof.SetFriendlyName("Medium") 174 profs.append(prof) 175 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 176 prof = OutputProfile("360p", (480, 360), fps, 1500) 177 profs.append(prof) 178 179 # 480p 180 for fps in [FPS24, FPS30]: 181 prof = OutputProfile("480p", (640, 480), fps, 2500) 182 profs.append(prof) 183 for fps in [FPS50, FPS60]: 184 prof = OutputProfile("480p", (640, 480), fps, 4000) 185 profs.append(prof) 186 187 # 720p 188 for fps in [FPS23996, FPS24, FPS25]: 189 prof = OutputProfile("HD 720p", (960, 720), fps, 5000) 190 if fps is FPS25: 191 prof.SetFriendlyName("HD") 192 profs.append(prof) 193 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 194 prof = OutputProfile("HD 720p", (960, 720), fps, 7500) 195 profs.append(prof) 196 197 # 1080p 198 for fps in [FPS23996, FPS24, FPS25]: 199 prof = OutputProfile("HD 1080p", (1440, 1080), fps, 8000) 200 if fps is FPS25: 201 prof.SetFriendlyName("FULL-HD") 202 profs.append(prof) 203 for fps in [FPS29997, FPS30, FPS50, FPS60]: 204 prof = OutputProfile("HD 1080p", (1440, 1080), fps, 12000) 205 profs.append(prof) 206 207 # 2160p 208 for fps in [FPS23996, FPS24, FPS25]: 209 prof = OutputProfile("UHD-1 2160p", (2880, 2160), fps, 25000) 210 if fps is FPS25: 211 prof.SetFriendlyName("UHD") 212 profs.append(prof) 213 for fps in [FPS29997, FPS30, FPS50, FPS60]: 214 prof = OutputProfile("UHD-1 2160p", (2880, 2160), fps, 50000) 215 profs.append(prof) 216 217 # 4320p 218 for fps in [FPS25, FPS30, FPS50, FPS60]: 219 prof = OutputProfile("UHD-2 4320p", (5760, 4320), fps, 60000) 220 profs.append(prof) 221 return profs 222 223 224def __Create3_2Profiles(): 225 profs = [] 226 227 # 360p 228 for fps in [FPS23996, FPS25]: 229 prof = OutputProfile("360p", (540, 360), fps, 1000) 230 if fps is FPS25: 231 prof.SetFriendlyName("Medium") 232 profs.append(prof) 233 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 234 prof = OutputProfile("360p", (540, 360), fps, 1500) 235 profs.append(prof) 236 237 # 480p 238 for fps in [FPS24, FPS30]: 239 prof = OutputProfile("480p", (720, 480), fps, 2500) 240 profs.append(prof) 241 for fps in [FPS50, FPS60]: 242 prof = OutputProfile("480p", (720, 480), fps, 4000) 243 profs.append(prof) 244 245 # 720p 246 for fps in [FPS23996, FPS24, FPS25]: 247 prof = OutputProfile("HD 720p", (1080, 720), fps, 5000) 248 if fps is FPS25: 249 prof.SetFriendlyName("HD") 250 profs.append(prof) 251 for fps in [FPS29997, FPS30, FPS50, FPS59994, FPS60]: 252 prof = OutputProfile("HD 720p", (1080, 720), fps, 7500) 253 profs.append(prof) 254 255 # 1080p 256 for fps in [FPS23996, FPS24, FPS25]: 257 prof = OutputProfile("HD 1080p", (1620, 1080), fps, 8000) 258 if fps is FPS25: 259 prof.SetFriendlyName("FULL-HD") 260 profs.append(prof) 261 for fps in [FPS29997, FPS30, FPS50, FPS60]: 262 prof = OutputProfile("HD 1080p", (1620, 1080), fps, 12000) 263 profs.append(prof) 264 265 # 2160p 266 for fps in [FPS23996, FPS24, FPS25]: 267 prof = OutputProfile("UHD-1 2160p", (3240, 2160), fps, 25000) 268 if fps is FPS25: 269 prof.SetFriendlyName("UHD") 270 profs.append(prof) 271 for fps in [FPS29997, FPS30, FPS50, FPS60]: 272 prof = OutputProfile("UHD-1 2160p", (3240, 2160), fps, 50000) 273 profs.append(prof) 274 275 # 4320p 276 for fps in [FPS25, FPS30, FPS50, FPS60]: 277 prof = OutputProfile("UHD-2 4320p", (6480, 4320), fps, 60000) 278 profs.append(prof) 279 280 return profs 281 282 283def GetOutputProfiles(aspect=Aspect.ASPECT_16_9): 284 if aspect == Aspect.ASPECT_4_3: 285 return __Create4_3Profiles() 286 elif aspect == Aspect.ASPECT_3_2: 287 return __Create3_2Profiles() 288 else: 289 return __Create16_9Profiles() 290 291 292def GetMPEGProfiles(): 293 return __CreateMPEGProfiles() 294