diff --git a/mythplugins/mytharchive/mytharchive/mythburn.cpp b/mythplugins/mytharchive/mytharchive/mythburn.cpp
index 5ef8122904..fadbb2db94 100644
|
a
|
b
|
|
| 29 | 29 | #include <mythsystemlegacy.h> |
| 30 | 30 | #include <mythmiscutil.h> |
| 31 | 31 | #include <exitcodes.h> |
| | 32 | #include <mythconfig.h> |
| 32 | 33 | |
| 33 | 34 | // mytharchive |
| 34 | 35 | #include "archiveutil.h" |
| … |
… |
void MythBurn::runScript()
|
| 909 | 910 | QFile::remove(logDir + "/mythburncancel.lck"); |
| 910 | 911 | |
| 911 | 912 | createConfigFile(configDir + "/mydata.xml"); |
| 912 | | commandline = "python " + GetShareDir() + "mytharchive/scripts/mythburn.py"; |
| | 913 | commandline = PYTHON_EXE; |
| | 914 | commandline += " " + GetShareDir() + "mytharchive/scripts/mythburn.py"; |
| 913 | 915 | commandline += " -j " + configDir + "/mydata.xml"; // job file |
| 914 | 916 | commandline += " -l " + logDir + "/progress.log"; // progress log |
| 915 | 917 | commandline += " > " + logDir + "/mythburn.log 2>&1 &"; // Logs |
diff --git a/mythplugins/mytharchive/mythburn/scripts/mythburn.py b/mythplugins/mytharchive/mythburn/scripts/mythburn.py
index 4f5a96d7ab..90a12d0b41 100755
|
a
|
b
|
|
| 2 | 2 | # -*- coding: utf-8 -*- |
| 3 | 3 | from __future__ import unicode_literals |
| 4 | 4 | |
| | 5 | # python 3 doesn't have a unicode type |
| | 6 | try: |
| | 7 | unicode |
| | 8 | except: |
| | 9 | unicode = str |
| | 10 | |
| | 11 | # python 3 doesn't have a long type |
| | 12 | try: |
| | 13 | long |
| | 14 | except: |
| | 15 | long = int |
| | 16 | |
| | 17 | |
| 5 | 18 | # mythburn.py |
| 6 | 19 | # The ported MythBurn scripts which feature: |
| 7 | 20 | |
| … |
… |
from __future__ import unicode_literals
|
| 49 | 62 | |
| 50 | 63 | |
| 51 | 64 | # version of script - change after each update |
| 52 | | VERSION="0.1.20131119-1" |
| | 65 | VERSION="0.2.20200122-1" |
| 53 | 66 | |
| 54 | 67 | # keep all temporary files for debugging purposes |
| 55 | 68 | # set this to True before a first run through when testing |
| … |
… |
import unicodedata
|
| 96 | 109 | import time |
| 97 | 110 | import tempfile |
| 98 | 111 | from fcntl import ioctl |
| 99 | | import CDROM |
| | 112 | |
| | 113 | try: |
| | 114 | import CDROM |
| | 115 | except: |
| | 116 | # Some hardcoded values for ioctl calls, |
| | 117 | # not available on python > 3.5, see include/linux/cdrom.h |
| | 118 | class CDROM(object): |
| | 119 | CDS_NO_INFO = 0 |
| | 120 | CDS_NO_DISC = 1 |
| | 121 | CDS_TRAY_OPEN = 2 |
| | 122 | CDS_DRIVE_NOT_READY = 3 |
| | 123 | CDS_DISC_OK = 4 |
| | 124 | CDROMEJECT = 0x5309 |
| | 125 | CDROMRESET = 0x5312 |
| | 126 | CDROM_DRIVE_STATUS = 0x5326 |
| | 127 | CDROM_LOCKDOOR = 0x5329 |
| | 128 | |
| 100 | 129 | from shutil import copy |
| 101 | 130 | |
| 102 | 131 | import MythTV |
| … |
… |
drivespeed = 0;
|
| 155 | 184 | #main menu aspect ratio (4:3 or 16:9) |
| 156 | 185 | mainmenuAspectRatio = "16:9" |
| 157 | 186 | |
| 158 | | #chapter menu aspect ratio (4:3, 16:9 or Video) |
| | 187 | #chapter menu aspect ratio (4:3, 16:9 or Video) |
| 159 | 188 | #video means same aspect ratio as the video title |
| 160 | 189 | chaptermenuAspectRatio = "Video" |
| 161 | 190 | |
| … |
… |
class FontDef(object):
|
| 279 | 308 | def write(text, progress=True): |
| 280 | 309 | """Simple place to channel all text output through""" |
| 281 | 310 | |
| 282 | | sys.stdout.write((text + "\n").encode("utf-8", "replace")) |
| | 311 | if sys.version_info == 2: |
| | 312 | sys.stdout.write((text + "\n").encode("utf-8", "replace")) |
| | 313 | else: |
| | 314 | sys.stdout.write(text + "\n") |
| 283 | 315 | sys.stdout.flush() |
| 284 | 316 | |
| 285 | 317 | if progress == True and progresslog != "": |
| … |
… |
def encodeMenu(background, tempvideo, music, musiclength, tempmovie, xmlfile, fi
|
| 505 | 537 | command = quoteCmdArg(path_jpeg2yuv[0]) + " -n %s -v0 -I p -f %s -j %s | %s -b 5000 -a %s -v 1 -f 8 -o %s" \ |
| 506 | 538 | % (totalframes, framespersecond, quoteCmdArg(background), quoteCmdArg(path_mpeg2enc[0]), aspectratio, quoteCmdArg(tempvideo)) |
| 507 | 539 | result = runCommand(command) |
| 508 | | if result<>0: |
| | 540 | if result!=0: |
| 509 | 541 | fatalError("Failed while running jpeg2yuv - %s" % command) |
| 510 | 542 | |
| 511 | 543 | command = quoteCmdArg(path_mplex[0]) + " -f 8 -v 0 -o %s %s %s" % (quoteCmdArg(tempmovie), quoteCmdArg(tempvideo), quoteCmdArg(music)) |
| 512 | 544 | result = runCommand(command) |
| 513 | | if result<>0: |
| | 545 | if result!=0: |
| 514 | 546 | fatalError("Failed while running mplex - %s" % command) |
| 515 | 547 | |
| 516 | 548 | if xmlfile != "": |
| 517 | 549 | command = quoteCmdArg(path_spumux[0]) + " -m dvd -s 0 %s < %s > %s" % (quoteCmdArg(xmlfile), quoteCmdArg(tempmovie), quoteCmdArg(finaloutput)) |
| 518 | 550 | result = runCommand(command) |
| 519 | | if result<>0: |
| | 551 | if result!=0: |
| 520 | 552 | fatalError("Failed while running spumux - %s" % command) |
| 521 | 553 | else: |
| 522 | 554 | os.rename(tempmovie, finaloutput) |
| … |
… |
def encodeMenu(background, tempvideo, music, musiclength, tempmovie, xmlfile, fi
|
| 527 | 559 | os.remove(tempmovie) |
| 528 | 560 | |
| 529 | 561 | ############################################################# |
| 530 | | # Return an xml node from a re-encoding profile xml file for |
| | 562 | # Return an xml node from a re-encoding profile xml file for |
| 531 | 563 | # a given profile name |
| 532 | 564 | |
| 533 | 565 | def findEncodingProfile(profile): |
| … |
… |
def getLengthOfVideo(index):
|
| 606 | 638 | return duration |
| 607 | 639 | |
| 608 | 640 | ############################################################# |
| 609 | | # Gets the audio sample rate and number of channels of a video file |
| | 641 | # Gets the audio sample rate and number of channels of a video file |
| 610 | 642 | # from its stream info file |
| 611 | 643 | |
| 612 | 644 | def getAudioParams(folder): |
| … |
… |
def getVideoParams(folder):
|
| 643 | 675 | if video.attributes["aspectratio"].value != 'N/A': |
| 644 | 676 | aspect_ratio = video.attributes["aspectratio"].value |
| 645 | 677 | else: |
| 646 | | aspect_ratio = "1.77778" |
| | 678 | aspect_ratio = "1.77778" |
| 647 | 679 | |
| 648 | 680 | videores = video.attributes["width"].value + 'x' + video.attributes["height"].value |
| 649 | 681 | fps = video.attributes["fps"].value |
| … |
… |
def getFormatedLengthOfVideo(index):
|
| 729 | 761 | def frameToTime(frame, fps): |
| 730 | 762 | sec = int(frame / fps) |
| 731 | 763 | frame = frame - int(sec * fps) |
| 732 | | mins = sec / 60 |
| | 764 | mins = sec // 60 |
| 733 | 765 | sec %= 60 |
| 734 | | hour = mins / 60 |
| | 766 | hour = mins // 60 |
| 735 | 767 | mins %= 60 |
| 736 | 768 | |
| 737 | 769 | return '%02d:%02d:%02d' % (hour, mins, sec) |
| … |
… |
def frameToTime(frame, fps):
|
| 740 | 772 | # Convert a time string of format 00:00:00 to number of seconds |
| 741 | 773 | |
| 742 | 774 | def timeStringToSeconds(formatedtime): |
| 743 | | parts = string.split(formatedtime, ':') |
| | 775 | parts = formatedtime.split(':') |
| 744 | 776 | if len(parts) != 3: |
| 745 | 777 | return 0 |
| 746 | 778 | |
| … |
… |
def createVideoChapters(itemnum, numofchapters, lengthofvideo, getthumbnails):
|
| 801 | 833 | ############################################################# |
| 802 | 834 | # Creates some fixed length chapter marks |
| 803 | 835 | |
| 804 | | def createVideoChaptersFixedLength(itemnum, segment, lengthofvideo): |
| 805 | | """Returns chapter marks at cut list ends, |
| | 836 | def createVideoChaptersFixedLength(itemnum, segment, lengthofvideo): |
| | 837 | """Returns chapter marks at cut list ends, |
| 806 | 838 | or evenly spaced chapters 'segment' seconds through the file""" |
| 807 | 839 | |
| 808 | 840 | |
| … |
… |
def createVideoChaptersFixedLength(itemnum, segment, lengthofvideo):
|
| 820 | 852 | if lengthofvideo < segment: |
| 821 | 853 | return "00:00:00" |
| 822 | 854 | |
| 823 | | numofchapters = lengthofvideo / segment + 1; |
| | 855 | numofchapters = lengthofvideo // segment + 1; |
| 824 | 856 | chapters = "00:00:00" |
| 825 | 857 | starttime = 0 |
| 826 | 858 | count = 2 |
| … |
… |
def getDefaultParametersFromMythTVDB():
|
| 845 | 877 | sqlstatement="""SELECT value, data FROM settings WHERE value IN( |
| 846 | 878 | 'DBSchemaVer', |
| 847 | 879 | 'ISO639Language0', |
| 848 | | 'ISO639Language1') |
| | 880 | 'ISO639Language1') |
| 849 | 881 | OR (hostname=%s AND value IN( |
| 850 | 882 | 'VideoStartupDir', |
| 851 | 883 | 'GalleryDir', |
| … |
… |
def getOptions(options):
|
| 939 | 971 | |
| 940 | 972 | def expandItemText(infoDOM, text, itemnumber, pagenumber, keynumber,chapternumber, chapterlist ): |
| 941 | 973 | """Replaces keywords in a string with variables from the XML and filesystem""" |
| 942 | | text=string.replace(text,"%page","%s" % pagenumber) |
| | 974 | text=text.replace("%page","%s" % pagenumber) |
| 943 | 975 | |
| 944 | 976 | #See if we can use the thumbnail/cover file for videos if there is one. |
| 945 | 977 | if getText( infoDOM.getElementsByTagName("coverfile")[0]) =="": |
| 946 | | text=string.replace(text,"%thumbnail", os.path.join( getItemTempPath(itemnumber), "title.jpg")) |
| | 978 | text=text.replace("%thumbnail", os.path.join( getItemTempPath(itemnumber), "title.jpg")) |
| 947 | 979 | else: |
| 948 | | text=string.replace(text,"%thumbnail", getText( infoDOM.getElementsByTagName("coverfile")[0]) ) |
| | 980 | text=text.replace("%thumbnail", getText( infoDOM.getElementsByTagName("coverfile")[0]) ) |
| 949 | 981 | |
| 950 | | text=string.replace(text,"%itemnumber","%s" % itemnumber ) |
| 951 | | text=string.replace(text,"%keynumber","%s" % keynumber ) |
| | 982 | text=text.replace("%itemnumber","%s" % itemnumber ) |
| | 983 | text=text.replace("%keynumber","%s" % keynumber ) |
| 952 | 984 | |
| 953 | | text=string.replace(text,"%title",getText( infoDOM.getElementsByTagName("title")[0]) ) |
| 954 | | text=string.replace(text,"%subtitle",getText( infoDOM.getElementsByTagName("subtitle")[0]) ) |
| 955 | | text=string.replace(text,"%description",getText( infoDOM.getElementsByTagName("description")[0]) ) |
| 956 | | text=string.replace(text,"%type",getText( infoDOM.getElementsByTagName("type")[0]) ) |
| | 985 | text=text.replace("%title",getText( infoDOM.getElementsByTagName("title")[0]) ) |
| | 986 | text=text.replace("%subtitle",getText( infoDOM.getElementsByTagName("subtitle")[0]) ) |
| | 987 | text=text.replace("%description",getText( infoDOM.getElementsByTagName("description")[0]) ) |
| | 988 | text=text.replace("%type",getText( infoDOM.getElementsByTagName("type")[0]) ) |
| 957 | 989 | |
| 958 | | text=string.replace(text,"%recordingdate",getText( infoDOM.getElementsByTagName("recordingdate")[0]) ) |
| 959 | | text=string.replace(text,"%recordingtime",getText( infoDOM.getElementsByTagName("recordingtime")[0]) ) |
| | 990 | text=text.replace("%recordingdate",getText( infoDOM.getElementsByTagName("recordingdate")[0]) ) |
| | 991 | text=text.replace("%recordingtime",getText( infoDOM.getElementsByTagName("recordingtime")[0]) ) |
| 960 | 992 | |
| 961 | | text=string.replace(text,"%duration", getFormatedLengthOfVideo(itemnumber)) |
| | 993 | text=text.replace("%duration", getFormatedLengthOfVideo(itemnumber)) |
| 962 | 994 | |
| 963 | | text=string.replace(text,"%myfolder",getThemeFile(themeName,"")) |
| | 995 | text=text.replace("%myfolder",getThemeFile(themeName,"")) |
| 964 | 996 | |
| 965 | 997 | if chapternumber>0: |
| 966 | | text=string.replace(text,"%chapternumber","%s" % chapternumber ) |
| 967 | | text=string.replace(text,"%chaptertime","%s" % chapterlist[chapternumber - 1] ) |
| 968 | | text=string.replace(text,"%chapterthumbnail", os.path.join( getItemTempPath(itemnumber), "chapter-%s.jpg" % chapternumber)) |
| | 998 | text=text.replace("%chapternumber","%s" % chapternumber ) |
| | 999 | text=text.replace("%chaptertime","%s" % chapterlist[chapternumber - 1] ) |
| | 1000 | text=text.replace("%chapterthumbnail", os.path.join( getItemTempPath(itemnumber), "chapter-%s.jpg" % chapternumber)) |
| 969 | 1001 | |
| 970 | 1002 | return text |
| 971 | 1003 | |
| … |
… |
def intelliDraw(drawer, text, font, containerWidth):
|
| 994 | 1026 | #write("containerWidth: %s" % containerWidth) |
| 995 | 1027 | words = text.split() |
| 996 | 1028 | lines = [] # prepare a return argument |
| 997 | | lines.append(words) |
| | 1029 | lines.append(words) |
| 998 | 1030 | finished = False |
| 999 | 1031 | line = 0 |
| 1000 | 1032 | while not finished: |
| … |
… |
def intelliDraw(drawer, text, font, containerWidth):
|
| 1008 | 1040 | if drawer.textsize(' '.join(thistext),font.getFont())[0] > containerWidth: |
| 1009 | 1041 | # this is the heart of the algorithm: we pop words off the current |
| 1010 | 1042 | # sentence until the width is ok, then in the next outer loop |
| 1011 | | # we move on to the next sentence. |
| | 1043 | # we move on to the next sentence. |
| 1012 | 1044 | if str(thistext).find(' ') != -1: |
| 1013 | 1045 | newline.insert(0,thistext.pop(-1)) |
| 1014 | 1046 | else: |
| … |
… |
def paintButton(draw, bgimage, bgimagemask, node, infoDOM, itemnum, page,
|
| 1133 | 1165 | ############################################################# |
| 1134 | 1166 | # Paint some theme text on to an image |
| 1135 | 1167 | |
| 1136 | | def paintText(draw, image, text, node, color = None, |
| | 1168 | def paintText(draw, image, text, node, color = None, |
| 1137 | 1169 | x = None, y = None, width = None, height = None): |
| 1138 | 1170 | """Takes a piece of text and draws it onto an image inside a bounding box.""" |
| 1139 | 1171 | #The text is wider than the width of the bounding box |
| 1140 | 1172 | |
| 1141 | 1173 | if x == None: |
| 1142 | | x = getScaledAttribute(node, "x") |
| | 1174 | x = getScaledAttribute(node, "x") |
| 1143 | 1175 | y = getScaledAttribute(node, "y") |
| 1144 | 1176 | width = getScaledAttribute(node, "w") |
| 1145 | 1177 | height = getScaledAttribute(node, "h") |
| … |
… |
def paintText(draw, image, text, node, color = None,
|
| 1186 | 1218 | for i in lines: |
| 1187 | 1219 | if (j * h) < (height - (vindent * 2) - h): |
| 1188 | 1220 | textImage = font.drawText(i, color) |
| 1189 | | write( "Wrapped text = " + i.encode("ascii", "replace"), False) |
| | 1221 | write( "Wrapped text = " + i ) # encoding is done within 'write' |
| 1190 | 1222 | |
| 1191 | 1223 | if halign == "left": |
| 1192 | 1224 | xoffset = hindent |
| 1193 | 1225 | elif halign == "center" or halign == "centre": |
| 1194 | | xoffset = (width / 2) - (textImage.size[0] / 2) |
| | 1226 | xoffset = (width // 2) - (textImage.size[0] // 2) |
| 1195 | 1227 | elif halign == "right": |
| 1196 | 1228 | xoffset = width - textImage.size[0] - hindent |
| 1197 | 1229 | else: |
| … |
… |
def paintText(draw, image, text, node, color = None,
|
| 1200 | 1232 | if valign == "top": |
| 1201 | 1233 | yoffset = vindent |
| 1202 | 1234 | elif valign == "center" or halign == "centre": |
| 1203 | | yoffset = (height / 2) - (textImage.size[1] / 2) |
| | 1235 | yoffset = (height // 2) - (textImage.size[1] // 2) |
| 1204 | 1236 | elif valign == "bottom": |
| 1205 | 1237 | yoffset = height - textImage.size[1] - vindent |
| 1206 | 1238 | else: |
| … |
… |
def paintText(draw, image, text, node, color = None,
|
| 1208 | 1240 | |
| 1209 | 1241 | image.paste(textImage, (x + xoffset,y + yoffset + j * h), textImage) |
| 1210 | 1242 | else: |
| 1211 | | write( "Truncated text = " + i.encode("ascii", "replace"), False) |
| | 1243 | write( "Wrapped text = " + i ) # encoding is done within 'write' |
| 1212 | 1244 | #Move to next line |
| 1213 | 1245 | j = j + 1 |
| 1214 | 1246 | |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1230 | 1262 | (imgw, imgh) = picture.size |
| 1231 | 1263 | write("Image (%s, %s) into space of (%s, %s) at (%s, %s)" % (imgw, imgh, w, h, xpos, ypos), False) |
| 1232 | 1264 | |
| 1233 | | # the theme can override the default stretch behaviour |
| 1234 | | if imageDom.hasAttribute("stretch"): |
| | 1265 | # the theme can override the default stretch behaviour |
| | 1266 | if imageDom.hasAttribute("stretch"): |
| 1235 | 1267 | if imageDom.attributes["stretch"].value == "True": |
| 1236 | 1268 | stretch = True |
| 1237 | 1269 | else: |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1243 | 1275 | else: |
| 1244 | 1276 | if float(w)/imgw < float(h)/imgh: |
| 1245 | 1277 | # Width is the constraining dimension |
| 1246 | | imgh = imgh*w/imgw |
| | 1278 | imgh = imgh*w//imgw |
| 1247 | 1279 | imgw = w |
| 1248 | 1280 | if imageDom.hasAttribute("valign"): |
| 1249 | 1281 | valign = imageDom.attributes["valign"].value |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1253 | 1285 | if valign == "bottom": |
| 1254 | 1286 | ypos += h - imgh |
| 1255 | 1287 | if valign == "center": |
| 1256 | | ypos += (h - imgh)/2 |
| | 1288 | ypos += (h - imgh)//2 |
| 1257 | 1289 | else: |
| 1258 | 1290 | # Height is the constraining dimension |
| 1259 | | imgw = imgw*h/imgh |
| | 1291 | imgw = imgw*h//imgh |
| 1260 | 1292 | imgh = h |
| 1261 | 1293 | if imageDom.hasAttribute("halign"): |
| 1262 | 1294 | halign = imageDom.attributes["halign"].value |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1266 | 1298 | if halign == "right": |
| 1267 | 1299 | xpos += w - imgw |
| 1268 | 1300 | if halign == "center": |
| 1269 | | xpos += (w - imgw)/2 |
| | 1301 | xpos += (w - imgw)//2 |
| 1270 | 1302 | |
| 1271 | 1303 | write("Image resized to (%s, %s) at (%s, %s)" % (imgw, imgh, xpos, ypos), False) |
| 1272 | 1304 | picture = picture.resize((imgw, imgh)) |
| 1273 | 1305 | picture = picture.convert("RGBA") |
| 1274 | 1306 | |
| 1275 | | if maskfilename <> None and doesFileExist(maskfilename): |
| | 1307 | if maskfilename != None and doesFileExist(maskfilename): |
| 1276 | 1308 | maskpicture = Image.open(maskfilename, "r").resize((imgw, imgh)) |
| 1277 | 1309 | maskpicture = maskpicture.convert("RGBA") |
| 1278 | 1310 | else: |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1280 | 1312 | |
| 1281 | 1313 | destimage.paste(picture, (xpos, ypos), maskpicture) |
| 1282 | 1314 | del picture |
| 1283 | | if maskfilename <> None and doesFileExist(maskfilename): |
| | 1315 | if maskfilename != None and doesFileExist(maskfilename): |
| 1284 | 1316 | del maskpicture |
| 1285 | 1317 | |
| 1286 | 1318 | write ("Added image %s" % filename) |
| … |
… |
def paintImage(filename, maskfilename, imageDom, destimage, stretch=True):
|
| 1294 | 1326 | def checkBoundaryBox(boundarybox, node): |
| 1295 | 1327 | # We work out how much space all of our graphics and text are taking up |
| 1296 | 1328 | # in a bounding rectangle so that we can use this as an automatic highlight |
| 1297 | | # on the DVD menu |
| | 1329 | # on the DVD menu |
| 1298 | 1330 | if getText(node.attributes["static"]) == "False": |
| 1299 | 1331 | if getScaledAttribute(node, "x") < boundarybox[0]: |
| 1300 | 1332 | boundarybox = getScaledAttribute(node, "x"), boundarybox[1], boundarybox[2], boundarybox[3] |
| … |
… |
def getFileInformation(file, folder):
|
| 1389 | 1421 | if file.attributes["type"].value=="recording": |
| 1390 | 1422 | filename = file.attributes["filename"].value |
| 1391 | 1423 | try: |
| 1392 | | rec = DB.searchRecorded(basename=os.path.basename(filename)).next() |
| | 1424 | rec = next(DB.searchRecorded(basename=os.path.basename(filename))) |
| 1393 | 1425 | except StopIteration: |
| 1394 | 1426 | fatalError("Failed to get recording details from the DB for %s" % filename) |
| 1395 | 1427 | |
| … |
… |
def getFileInformation(file, folder):
|
| 1412 | 1444 | elif file.attributes["type"].value=="recording": |
| 1413 | 1445 | filename = file.attributes["filename"].value |
| 1414 | 1446 | try: |
| 1415 | | rec = DB.searchRecorded(basename=os.path.basename(filename)).next() |
| | 1447 | rec = next(DB.searchRecorded(basename=os.path.basename(filename))) |
| 1416 | 1448 | except StopIteration: |
| 1417 | 1449 | fatalError("Failed to get recording details from the DB for %s" % filename) |
| 1418 | 1450 | |
| … |
… |
def getFileInformation(file, folder):
|
| 1443 | 1475 | elif file.attributes["type"].value=="video": |
| 1444 | 1476 | filename = file.attributes["filename"].value |
| 1445 | 1477 | try: |
| 1446 | | vid = MVID.searchVideos(file=filename).next() |
| | 1478 | vid = next(MVID.searchVideos(file=filename)) |
| 1447 | 1479 | except StopIteration: |
| 1448 | 1480 | vid = Video.fromFilename(filename) |
| 1449 | 1481 | |
| … |
… |
def getFileInformation(file, folder):
|
| 1489 | 1521 | |
| 1490 | 1522 | data.thumblist = ','.join(thumblist) |
| 1491 | 1523 | |
| 1492 | | for k,v in data.items(): |
| | 1524 | for k,v in list(data.items()): |
| 1493 | 1525 | write( "Node = %s, Data = %s" % (k, v)) |
| 1494 | 1526 | node = infoDOM.createElement(k) |
| 1495 | 1527 | # v may be either an integer. Therefore we have to |
| … |
… |
def getFileInformation(file, folder):
|
| 1507 | 1539 | # Write an xml file to disc |
| 1508 | 1540 | |
| 1509 | 1541 | def WriteXMLToFile(myDOM, filename): |
| | 1542 | |
| 1510 | 1543 | #Save the XML file to disk for use later on |
| 1511 | 1544 | f=open(filename, 'w') |
| 1512 | 1545 | |
| 1513 | | if sys.hexversion >= 0x020703F0: |
| | 1546 | if sys.hexversion >= 0x03000000: |
| | 1547 | f.write(myDOM.toprettyxml(indent=" ", encoding="UTF-8").decode()) |
| | 1548 | elif sys.hexversion >= 0x020703F0: |
| 1514 | 1549 | f.write(myDOM.toprettyxml(indent=" ", encoding="UTF-8")) |
| 1515 | 1550 | else: |
| 1516 | 1551 | f.write(myDOM.toxml(encoding="UTF-8")) |
| … |
… |
def multiplexMPEGStream(video, audio1, audio2, destination, syncOffset):
|
| 1588 | 1623 | |
| 1589 | 1624 | write("Multiplexing MPEG stream to %s" % destination) |
| 1590 | 1625 | |
| 1591 | | # no need to use a sync offset if projectx was used to demux the streams |
| | 1626 | # no need to use a sync offset if projectx was used to demux the streams |
| 1592 | 1627 | if useprojectx: |
| 1593 | 1628 | syncOffset = 0 |
| 1594 | 1629 | else: |
| … |
… |
def multiplexMPEGStream(video, audio1, audio2, destination, syncOffset):
|
| 1631 | 1666 | |
| 1632 | 1667 | if not doesFileExist(audio2): |
| 1633 | 1668 | write("Available streams - video and one audio stream") |
| | 1669 | write("running %s -M -f 8 -v 0 --sync-offset %sms -o %s %s %s" %(path_mplex[0], syncOffset, destination, video, audio1)) |
| 1634 | 1670 | result=os.spawnlp(mode, path_mplex[0], path_mplex[1], |
| 1635 | 1671 | '-M', |
| 1636 | 1672 | '-f', '8', |
| … |
… |
def multiplexMPEGStream(video, audio1, audio2, destination, syncOffset):
|
| 1663 | 1699 | write("Checking integrity of subtitle pngs") |
| 1664 | 1700 | command = quoteCmdArg(os.path.join(scriptpath, "testsubtitlepngs.sh")) + " " + quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml") |
| 1665 | 1701 | result = runCommand(command) |
| 1666 | | if result<>0: |
| | 1702 | if result!=0: |
| 1667 | 1703 | fatalError("Failed while running testsubtitlepngs.sh - %s" % command) |
| 1668 | 1704 | |
| 1669 | 1705 | write("Running spumux to add subtitles") |
| 1670 | 1706 | command = quoteCmdArg(path_spumux[0]) + " -P %s <%s >%s" % (quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml"), quoteCmdArg(destination), quoteCmdArg(os.path.splitext(destination)[0] + "-sub.mpg")) |
| 1671 | 1707 | result = runCommand(command) |
| 1672 | | if result<>0: |
| | 1708 | if result!=0: |
| 1673 | 1709 | nonfatalError("Failed while running spumux.\n" |
| 1674 | 1710 | "Command was - %s.\n" |
| 1675 | 1711 | "Look in the full log to see why it failed" % command) |
| … |
… |
def getStreamInformation(filename, xmlFilename, lenMethod):
|
| 1691 | 1727 | |
| 1692 | 1728 | result = runCommand(command) |
| 1693 | 1729 | |
| 1694 | | if result <> 0: |
| | 1730 | if result != 0: |
| 1695 | 1731 | fatalError("Failed while running mytharchivehelper to get stream information.\n" |
| 1696 | 1732 | "Result: %d, Command was %s" % (result, command)) |
| 1697 | 1733 | |
| … |
… |
def runMythtranscode(chanid, starttime, destination, usecutlist, localfile):
|
| 1730 | 1766 | """Use mythtranscode to cut commercials and/or clean up an mpeg2 file""" |
| 1731 | 1767 | |
| 1732 | 1768 | try: |
| 1733 | | rec = DB.searchRecorded(chanid=chanid, starttime=starttime).next() |
| | 1769 | rec = next(DB.searchRecorded(chanid=chanid, starttime=starttime)) |
| 1734 | 1770 | cutlist = rec.markup.getcutlist() |
| 1735 | 1771 | except StopIteration: |
| 1736 | 1772 | cutlist = [] |
| … |
… |
def runMythtranscode(chanid, starttime, destination, usecutlist, localfile):
|
| 1770 | 1806 | def generateProjectXCutlist(chanid, starttime, folder): |
| 1771 | 1807 | """generate cutlist_x.txt for ProjectX""" |
| 1772 | 1808 | |
| 1773 | | rec = DB.searchRecorded(chanid=chanid, starttime=starttime).next() |
| | 1809 | rec = next(DB.searchRecorded(chanid=chanid, starttime=starttime)) |
| 1774 | 1810 | starttime = rec.starttime.utcisoformat() |
| 1775 | 1811 | cutlist = rec.markup.getcutlist() |
| 1776 | 1812 | |
| … |
… |
def generateProjectXCutlist(chanid, starttime, folder):
|
| 1781 | 1817 | for cut in cutlist: |
| 1782 | 1818 | # we need to reverse the cutlist because ProjectX wants to know |
| 1783 | 1819 | # the bits to keep not what to cut |
| 1784 | | |
| | 1820 | |
| 1785 | 1821 | if i == 0: |
| 1786 | 1822 | if cut[0] != 0: |
| 1787 | 1823 | cutlist_f.write('0\n%d\n' % cut[0]) |
| … |
… |
def extractVideoFrame(source, destination, seconds):
|
| 1979 | 2015 | |
| 1980 | 2016 | command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), seconds, quoteCmdArg(destination)) |
| 1981 | 2017 | result = runCommand(command) |
| 1982 | | if result <> 0: |
| | 2018 | if result != 0: |
| 1983 | 2019 | fatalError("Failed while running mytharchivehelper to get thumbnails.\n" |
| 1984 | 2020 | "Result: %d, Command was %s" % (result, command)) |
| 1985 | 2021 | try: |
| 1986 | 2022 | myimage=Image.open(destination,"r") |
| 1987 | 2023 | |
| 1988 | | if myimage.format <> "JPEG": |
| | 2024 | if myimage.format != "JPEG": |
| 1989 | 2025 | write( "Something went wrong with thumbnail capture - " + myimage.format) |
| 1990 | | return (0L,0L) |
| | 2026 | return (long(0),long(0)) |
| 1991 | 2027 | else: |
| 1992 | 2028 | return myimage.size |
| 1993 | 2029 | except IOError: |
| 1994 | | return (0L, 0L) |
| | 2030 | return (long(0),long(0)) |
| 1995 | 2031 | |
| 1996 | 2032 | ############################################################# |
| 1997 | 2033 | # Grabs a list of single frames from a file |
| … |
… |
def extractVideoFrames(source, destination, thumbList):
|
| 2003 | 2039 | command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), thumbList, quoteCmdArg(destination)) |
| 2004 | 2040 | write(command) |
| 2005 | 2041 | result = runCommand(command) |
| 2006 | | if result <> 0: |
| | 2042 | if result != 0: |
| 2007 | 2043 | fatalError("Failed while running mytharchivehelper to get thumbnails.\n" |
| 2008 | 2044 | "Result: %d, Command was %s" % (result, command)) |
| 2009 | 2045 | |
| … |
… |
def encodeVideoToMPEG2(source, destvideofile, video, audio1, audio2, aspectratio
|
| 2083 | 2119 | else: |
| 2084 | 2120 | passLog = os.path.join(getTempPath(), 'pass') |
| 2085 | 2121 | |
| 2086 | | pass1 = string.replace(command, "%passno","1") |
| 2087 | | pass1 = string.replace(pass1, "%passlogfile", quoteCmdArg(passLog)) |
| | 2122 | pass1 = command.replace("%passno","1") |
| | 2123 | pass1 = pass1.replace("%passlogfile", quoteCmdArg(passLog)) |
| 2088 | 2124 | write("Pass 1 - " + pass1) |
| 2089 | 2125 | result = runCommand(pass1) |
| 2090 | 2126 | |
| … |
… |
def encodeVideoToMPEG2(source, destvideofile, video, audio1, audio2, aspectratio
|
| 2095 | 2131 | if os.path.exists(destvideofile): |
| 2096 | 2132 | os.remove(destvideofile) |
| 2097 | 2133 | |
| 2098 | | pass2 = string.replace(command, "%passno","2") |
| 2099 | | pass2 = string.replace(pass2, "%passlogfile", passLog) |
| | 2134 | pass2 = command.replace("%passno","2") |
| | 2135 | pass2 = pass2.replace("%passlogfile", passLog) |
| 2100 | 2136 | write("Pass 2 - " + pass2) |
| 2101 | 2137 | result = runCommand(pass2) |
| 2102 | 2138 | |
| … |
… |
def encodeNuvToMPEG2(chanid, starttime, mediafile, destvideofile, folder, profil
|
| 2117 | 2153 | profileNode = findEncodingProfile(profile) |
| 2118 | 2154 | parameters = profileNode.getElementsByTagName("parameter") |
| 2119 | 2155 | |
| 2120 | | # default values - will be overriden by values from the profile |
| | 2156 | # default values - will be overriden by values from the profile |
| 2121 | 2157 | outvideobitrate = "5000k" |
| 2122 | 2158 | if videomode == "ntsc": |
| 2123 | 2159 | outvideores = "720x480" |
| … |
… |
def encodeNuvToMPEG2(chanid, starttime, mediafile, destvideofile, folder, profil
|
| 2198 | 2234 | if cpuCount > 1: |
| 2199 | 2235 | command += "-threads %d " % cpuCount |
| 2200 | 2236 | |
| 2201 | | command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout"))) |
| | 2237 | command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout"))) |
| 2202 | 2238 | command += "-f rawvideo -pix_fmt yuv420p -s %s -aspect %s -r %s " % (videores, aspectratio, fps) |
| 2203 | 2239 | command += "-i %s " % quoteCmdArg(os.path.join(folder, "vidout")) |
| 2204 | 2240 | command += "-aspect %s -r %s " % (aspectratio, fps) |
| … |
… |
def runDVDAuthor():
|
| 2235 | 2271 | write( "Starting dvdauthor") |
| 2236 | 2272 | checkCancelFlag() |
| 2237 | 2273 | result=os.spawnlp(os.P_WAIT, path_dvdauthor[0],path_dvdauthor[1],'-x',os.path.join(getTempPath(),'dvdauthor.xml')) |
| 2238 | | if result<>0: |
| | 2274 | if result!=0: |
| 2239 | 2275 | fatalError("Failed while running dvdauthor. Result: %d" % result) |
| 2240 | 2276 | write( "Finished dvdauthor") |
| 2241 | 2277 | |
| … |
… |
def CreateDVDISO(title):
|
| 2252 | 2288 | |
| 2253 | 2289 | result = runCommand(command) |
| 2254 | 2290 | |
| 2255 | | if result<>0: |
| | 2291 | if result!=0: |
| 2256 | 2292 | fatalError("Failed while running mkisofs.\n" |
| 2257 | 2293 | "Command was %s" % command) |
| 2258 | 2294 | |
| 2259 | 2295 | write("Finished creating ISO image") |
| 2260 | 2296 | |
| 2261 | 2297 | ############################################################# |
| 2262 | | # Burns the contents of a directory to create a DVD |
| | 2298 | # Burns the contents of a directory to create a DVD |
| 2263 | 2299 | |
| 2264 | 2300 | |
| 2265 | 2301 | def BurnDVDISO(title): |
| … |
… |
def BurnDVDISO(title):
|
| 2293 | 2329 | try: |
| 2294 | 2330 | ioctl(f,action, value) |
| 2295 | 2331 | except: |
| 2296 | | write("Sending command ", action, " to drive failed", False) |
| | 2332 | write("Sending command '0x%x' to drive failed" %action, False) |
| 2297 | 2333 | os.close(f) |
| 2298 | 2334 | else: # try eject-command |
| 2299 | 2335 | if runCommand("eject " + quoteCmdArg(dvddrivepath)) == 32512: |
| … |
… |
def BurnDVDISO(title):
|
| 2312 | 2348 | ioctl(f,action, value) |
| 2313 | 2349 | res = True |
| 2314 | 2350 | except: |
| 2315 | | write("Sending command ", action, " to drive failed", False) |
| | 2351 | write("Sending command '0x%x' to drive failed" %action, False) |
| 2316 | 2352 | res = False |
| 2317 | | os.close(f) |
| 2318 | | return res |
| | 2353 | os.close(f) |
| | 2354 | return res |
| 2319 | 2355 | def waitForDrive(): |
| 2320 | 2356 | tries = 0 |
| 2321 | 2357 | while drivestatus() == CDROM.CDS_DRIVE_NOT_READY: |
| … |
… |
def BurnDVDISO(title):
|
| 2363 | 2399 | result = runCommand(command) |
| 2364 | 2400 | if result == 0: |
| 2365 | 2401 | finished = True |
| 2366 | | |
| | 2402 | |
| 2367 | 2403 | # Wait till the drive is not busy any longer |
| 2368 | 2404 | f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) |
| 2369 | 2405 | busy = True |
| … |
… |
def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2):
|
| 2427 | 2463 | command = "mythreplex --demux --fix_sync -t TS -o %s " % quoteCmdArg(folder + "/stream") |
| 2428 | 2464 | command += "-v %d " % (video[VIDEO_ID]) |
| 2429 | 2465 | |
| 2430 | | if audio1[AUDIO_ID] != -1: |
| | 2466 | if audio1[AUDIO_ID] != -1: |
| 2431 | 2467 | if audio1[AUDIO_CODEC] == 'MP2': |
| 2432 | 2468 | command += "-a %d " % (audio1[AUDIO_ID]) |
| 2433 | 2469 | elif audio1[AUDIO_CODEC] == 'AC3': |
| … |
… |
def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2):
|
| 2435 | 2471 | elif audio1[AUDIO_CODEC] == 'EAC3': |
| 2436 | 2472 | command += "-c %d " % (audio1[AUDIO_ID]) |
| 2437 | 2473 | |
| 2438 | | if audio2[AUDIO_ID] != -1: |
| | 2474 | if audio2[AUDIO_ID] != -1: |
| 2439 | 2475 | if audio2[AUDIO_CODEC] == 'MP2': |
| 2440 | 2476 | command += "-a %d " % (audio2[AUDIO_ID]) |
| 2441 | 2477 | elif audio2[AUDIO_CODEC] == 'AC3': |
| … |
… |
def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2):
|
| 2447 | 2483 | command = "mythreplex --demux --fix_sync -o %s " % quoteCmdArg(folder + "/stream") |
| 2448 | 2484 | command += "-v %d " % (video[VIDEO_ID] & 255) |
| 2449 | 2485 | |
| 2450 | | if audio1[AUDIO_ID] != -1: |
| | 2486 | if audio1[AUDIO_ID] != -1: |
| 2451 | 2487 | if audio1[AUDIO_CODEC] == 'MP2': |
| 2452 | 2488 | command += "-a %d " % (audio1[AUDIO_ID] & 255) |
| 2453 | 2489 | elif audio1[AUDIO_CODEC] == 'AC3': |
| … |
… |
def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2):
|
| 2456 | 2492 | command += "-c %d " % (audio1[AUDIO_ID] & 255) |
| 2457 | 2493 | |
| 2458 | 2494 | |
| 2459 | | if audio2[AUDIO_ID] != -1: |
| | 2495 | if audio2[AUDIO_ID] != -1: |
| 2460 | 2496 | if audio2[AUDIO_CODEC] == 'MP2': |
| 2461 | 2497 | command += "-a %d " % (audio2[AUDIO_ID] & 255) |
| 2462 | 2498 | elif audio2[AUDIO_CODEC] == 'AC3': |
| … |
… |
def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2):
|
| 2470 | 2506 | |
| 2471 | 2507 | result = runCommand(command) |
| 2472 | 2508 | |
| 2473 | | if result<>0: |
| | 2509 | if result!=0: |
| 2474 | 2510 | fatalError("Failed while running mythreplex. Command was %s" % command) |
| 2475 | 2511 | |
| 2476 | 2512 | ############################################################# |
| … |
… |
def runM2VRequantiser(source,destination,factor):
|
| 2486 | 2522 | command += " %s " % M2Vsize0 |
| 2487 | 2523 | command += " < %s " % quoteCmdArg(source) |
| 2488 | 2524 | command += " > %s " % quoteCmdArg(destination) |
| 2489 | | |
| | 2525 | |
| 2490 | 2526 | write("Running: " + command) |
| 2491 | 2527 | result = runCommand(command) |
| 2492 | | if result<>0: |
| | 2528 | if result!=0: |
| 2493 | 2529 | fatalError("Failed while running M2VRequantiser. Command was %s" % command) |
| 2494 | 2530 | |
| 2495 | 2531 | M2Vsize1 = os.path.getsize(destination) |
| 2496 | | |
| | 2532 | |
| 2497 | 2533 | write("M2Vsize after requant is %.2f Mb " % (float(M2Vsize1)/mega)) |
| 2498 | 2534 | fac1=float(M2Vsize0) / float(M2Vsize1) |
| 2499 | 2535 | write("Factor demanded %.5f, achieved %.5f, ratio %.5f " % ( factor, fac1, fac1/factor)) |
| 2500 | 2536 | |
| 2501 | 2537 | ############################################################# |
| 2502 | | # Calculates the total size of all the video, audio and menu files |
| | 2538 | # Calculates the total size of all the video, audio and menu files |
| 2503 | 2539 | |
| 2504 | 2540 | def calculateFileSizes(files): |
| 2505 | 2541 | """ Returns the sizes of all video, audio and menu files""" |
| … |
… |
def calculateFileSizes(files):
|
| 2515 | 2551 | #Process this file |
| 2516 | 2552 | file=os.path.join(folder,"stream.mv2") |
| 2517 | 2553 | #Get size of vobfile in MBytes |
| 2518 | | totalvideosize+=os.path.getsize(file) |
| | 2554 | totalvideosize+=os.path.getsize(file) |
| 2519 | 2555 | |
| 2520 | 2556 | #Get size of audio track 1 |
| 2521 | 2557 | if doesFileExist(os.path.join(folder,"stream0.ac3")): |
| 2522 | | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream0.ac3")) |
| | 2558 | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream0.ac3")) |
| 2523 | 2559 | if doesFileExist(os.path.join(folder,"stream0.mp2")): |
| 2524 | | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream0.mp2")) |
| | 2560 | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream0.mp2")) |
| 2525 | 2561 | |
| 2526 | | #Get size of audio track 2 if available |
| | 2562 | #Get size of audio track 2 if available |
| 2527 | 2563 | if doesFileExist(os.path.join(folder,"stream1.ac3")): |
| 2528 | | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream1.ac3")) |
| | 2564 | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream1.ac3")) |
| 2529 | 2565 | if doesFileExist(os.path.join(folder,"stream1.mp2")): |
| 2530 | | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream1.mp2")) |
| | 2566 | totalaudiosize+=os.path.getsize(os.path.join(folder,"stream1.mp2")) |
| 2531 | 2567 | |
| 2532 | 2568 | # add chapter menu if available |
| 2533 | 2569 | if doesFileExist(os.path.join(getTempPath(),"chaptermenu-%s.mpg" % filecount)): |
| 2534 | | totalmenusize+=os.path.getsize(os.path.join(getTempPath(),"chaptermenu-%s.mpg" % filecount)) |
| | 2570 | totalmenusize+=os.path.getsize(os.path.join(getTempPath(),"chaptermenu-%s.mpg" % filecount)) |
| 2535 | 2571 | |
| 2536 | 2572 | # add details page if available |
| 2537 | 2573 | if doesFileExist(os.path.join(getTempPath(),"details-%s.mpg" % filecount)): |
| … |
… |
def calculateFileSizes(files):
|
| 2547 | 2583 | ######################################## |
| 2548 | 2584 | #returns total size of bitrate-limited m2v files |
| 2549 | 2585 | |
| 2550 | | def total_mv2_brl(files,rate): |
| 2551 | | tvsize=0 |
| | 2586 | def total_mv2_brl(files,rate): |
| | 2587 | tvsize=0 |
| 2552 | 2588 | filecount=0 |
| 2553 | 2589 | for node in files: |
| 2554 | 2590 | filecount+=1 |
| … |
… |
def total_mv2_brl(files,rate):
|
| 2557 | 2593 | file=os.path.join(folder,"stream.mv2") |
| 2558 | 2594 | progvsize=os.path.getsize(file) |
| 2559 | 2595 | progvbitrate=progvsize/progduration |
| 2560 | | if progvbitrate>rate : |
| | 2596 | if progvbitrate>rate : |
| 2561 | 2597 | tvsize+=progduration*rate |
| 2562 | 2598 | else: |
| 2563 | 2599 | tvsize+=progvsize |
| 2564 | 2600 | |
| 2565 | | return tvsize |
| | 2601 | return tvsize |
| 2566 | 2602 | |
| 2567 | 2603 | ######################################### |
| 2568 | | # Uses requantiser if available to shrink the video streams so |
| | 2604 | # Uses requantiser if available to shrink the video streams so |
| 2569 | 2605 | # they will fit on a DVD |
| 2570 | 2606 | |
| 2571 | 2607 | def performMPEG2Shrink(files,dvdrsize): |
| … |
… |
def performMPEG2Shrink(files,dvdrsize):
|
| 2582 | 2618 | |
| 2583 | 2619 | #Subtract the audio, menus and packaging overhead from the size of the disk (we cannot shrink this further) |
| 2584 | 2620 | mv2space=((dvdrsize*mega-totalmenusize)/fudge_pack)-totalaudiosize |
| 2585 | | |
| | 2621 | |
| 2586 | 2622 | if mv2space<0: |
| 2587 | 2623 | fatalError("Audio and menu files are too big. No room for video. Giving up!") |
| 2588 | 2624 | |
| … |
… |
def performMPEG2Shrink(files,dvdrsize):
|
| 2602 | 2638 | vsize+=os.path.getsize(file) |
| 2603 | 2639 | duration+=getLengthOfVideo(filecount) |
| 2604 | 2640 | |
| 2605 | | #We need to shrink the video files to fit into the space available. It seems sensible |
| 2606 | | #to do this by imposing a common upper limit on the mean video bit-rate of each recording; |
| | 2641 | #We need to shrink the video files to fit into the space available. It seems sensible |
| | 2642 | #to do this by imposing a common upper limit on the mean video bit-rate of each recording; |
| 2607 | 2643 | #this will not further reduce the visual quality of any that were transmitted at lower bit-rates. |
| 2608 | 2644 | |
| 2609 | | #Now find the bit-rate limit by iteration between initially defined upper and lower bounds. |
| | 2645 | #Now find the bit-rate limit by iteration between initially defined upper and lower bounds. |
| 2610 | 2646 | #The code is based on 'rtbis' from Numerical Recipes by W H Press et al., CUP. |
| 2611 | | |
| | 2647 | |
| 2612 | 2648 | #A small multiple of the average input bit-rate should be ok as the initial upper bound, |
| 2613 | 2649 | #(although a fixed value or one related to the max value could be used), and zero as the lower bound. |
| 2614 | 2650 | #The function relating bit-rate upper limit to total file size is smooth and monotonic, |
| 2615 | | #so there should be no convergence problem. |
| 2616 | | |
| | 2651 | #so there should be no convergence problem. |
| | 2652 | |
| 2617 | 2653 | vrLo=0.0 |
| 2618 | 2654 | vrHi=3.0*float(vsize)/duration |
| 2619 | | |
| | 2655 | |
| 2620 | 2656 | vrate=vrLo |
| 2621 | 2657 | vrinc=vrHi-vrLo |
| 2622 | 2658 | count=0 |
| … |
… |
def performMPEG2Shrink(files,dvdrsize):
|
| 2628 | 2664 | testsize=total_mv2_brl(files,vrtest) |
| 2629 | 2665 | if (testsize<mv2space): |
| 2630 | 2666 | vrate=vrtest |
| 2631 | | |
| | 2667 | |
| 2632 | 2668 | write("vrate %.3f kb/s, testsize %.4f , mv2space %.4f Mb " % ((vrate)/1000.0, (testsize)/mega, (mv2space)/mega) ) |
| 2633 | 2669 | filecount=0 |
| 2634 | 2670 | for node in files: |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2665 | 2701 | #Total number of video items on a single menu page (no less than 1!) |
| 2666 | 2702 | itemsperpage = menuitems.length |
| 2667 | 2703 | write( "Menu items per page %s" % itemsperpage) |
| 2668 | | autoplaymenu = 2 + ((numberofitems + itemsperpage - 1)/itemsperpage) |
| | 2704 | autoplaymenu = 2 + ((numberofitems + itemsperpage - 1)//itemsperpage) |
| 2669 | 2705 | |
| 2670 | 2706 | if wantChapterMenu: |
| 2671 | 2707 | #Get the chapter menu node (we must only have 1) |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2775 | 2811 | #g4 holds the menu page last displayed |
| 2776 | 2812 | pre = dvddom.createElement("pre") |
| 2777 | 2813 | pre.appendChild(dvddom.createTextNode("{button=g2*1024;g4=%s;}" % page)) |
| 2778 | | menupgc.appendChild(pre) |
| | 2814 | menupgc.appendChild(pre) |
| 2779 | 2815 | |
| 2780 | 2816 | vob = dvddom.createElement("vob") |
| 2781 | 2817 | vob.setAttribute("file",os.path.join(getTempPath(),"menu-%s.mpg" % page)) |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2833 | 2869 | elif chaptermenuAspectRatio == "16:9": |
| 2834 | 2870 | video.setAttribute("aspect", "16:9") |
| 2835 | 2871 | video.setAttribute("widescreen", "nopanscan") |
| 2836 | | else: |
| | 2872 | else: |
| 2837 | 2873 | # use same aspect ratio as the video |
| 2838 | 2874 | if getAspectRatioOfVideo(itemnum) > aspectRatioThreshold: |
| 2839 | 2875 | video.setAttribute("aspect", "16:9") |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2849 | 2885 | |
| 2850 | 2886 | pre = dvddom.createElement("pre") |
| 2851 | 2887 | mymenupgc.appendChild(pre) |
| 2852 | | if wantDetailsPage: |
| | 2888 | if wantDetailsPage: |
| 2853 | 2889 | pre.appendChild(dvddom.createTextNode("{button=s7 - 1 * 1024;}")) |
| 2854 | 2890 | else: |
| 2855 | 2891 | pre.appendChild(dvddom.createTextNode("{button=s7 * 1024;}")) |
| 2856 | 2892 | |
| 2857 | 2893 | vob = dvddom.createElement("vob") |
| 2858 | 2894 | vob.setAttribute("file",os.path.join(getTempPath(),"chaptermenu-%s.mpg" % itemnum)) |
| 2859 | | mymenupgc.appendChild(vob) |
| | 2895 | mymenupgc.appendChild(vob) |
| 2860 | 2896 | |
| 2861 | 2897 | #Loop menu forever |
| 2862 | 2898 | post = dvddom.createElement("post") |
| 2863 | 2899 | post.appendChild(dvddom.createTextNode("jump cell 1;")) |
| 2864 | 2900 | mymenupgc.appendChild(post) |
| 2865 | 2901 | |
| 2866 | | # the first chapter MUST be 00:00:00 if its not dvdauthor adds it which |
| | 2902 | # the first chapter MUST be 00:00:00 if its not dvdauthor adds it which |
| 2867 | 2903 | # throws of the chapter selection - so make sure we add it if needed so we |
| 2868 | | # can compensate for it in the chapter selection menu |
| | 2904 | # can compensate for it in the chapter selection menu |
| 2869 | 2905 | firstChapter = 0 |
| 2870 | 2906 | thumblist = createVideoChapters(itemnum, chapters, getLengthOfVideo(itemnum), False) |
| 2871 | | chapterlist = string.split(thumblist, ",") |
| | 2907 | chapterlist = thumblist.split(",") |
| 2872 | 2908 | if chapterlist[0] != '00:00:00': |
| 2873 | 2909 | firstChapter = 1 |
| 2874 | 2910 | x = 1 |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2876 | 2912 | #Add this recording to this page's menu... |
| 2877 | 2913 | button = dvddom.createElement("button") |
| 2878 | 2914 | button.setAttribute("name","%s" % x) |
| 2879 | | if wantDetailsPage: |
| | 2915 | if wantDetailsPage: |
| 2880 | 2916 | button.appendChild(dvddom.createTextNode("jump title %s chapter %s;" % (1, firstChapter + x + 1))) |
| 2881 | 2917 | else: |
| 2882 | 2918 | button.appendChild(dvddom.createTextNode("jump title %s chapter %s;" % (1, firstChapter + x))) |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 2933 | 2969 | vob = dvddom.createElement("vob") |
| 2934 | 2970 | if wantChapterMenu: |
| 2935 | 2971 | thumblist = createVideoChapters(itemnum, chapters, getLengthOfVideo(itemnum), False) |
| 2936 | | chapterlist = string.split(thumblist, ",") |
| | 2972 | chapterlist = thumblist.split(",") |
| 2937 | 2973 | if chapterlist[0] != '00:00:00': |
| 2938 | 2974 | thumblist = '00:00:00,' + thumblist |
| 2939 | 2975 | vob.setAttribute("chapters", thumblist) |
| 2940 | 2976 | else: |
| 2941 | | vob.setAttribute("chapters", |
| | 2977 | vob.setAttribute("chapters", |
| 2942 | 2978 | createVideoChaptersFixedLength(itemnum, |
| 2943 | | chapterLength, |
| | 2979 | chapterLength, |
| 2944 | 2980 | getLengthOfVideo(itemnum))) |
| 2945 | 2981 | |
| 2946 | 2982 | vob.setAttribute("file",os.path.join(getItemTempPath(itemnum),"final.vob")) |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 3006 | 3042 | |
| 3007 | 3043 | pre = dvddom.createElement("pre") |
| 3008 | 3044 | pre.appendChild(dvddom.createTextNode(dvdcode)) |
| 3009 | | menupgc.appendChild(pre) |
| | 3045 | menupgc.appendChild(pre) |
| 3010 | 3046 | |
| 3011 | 3047 | if wantIntro: |
| 3012 | 3048 | #Menu creation is finished so we know how many pages were created |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 3018 | 3054 | dvdcode+="jump menu %s;" % (page + 1) |
| 3019 | 3055 | if (page>1): |
| 3020 | 3056 | dvdcode+=" else " |
| 3021 | | dvdcode+="}" |
| | 3057 | dvdcode+="}" |
| 3022 | 3058 | vmgm_pre_node.appendChild(dvddom.createTextNode(dvdcode)) |
| 3023 | 3059 | |
| 3024 | 3060 | #write(dvddom.toprettyxml()) |
| … |
… |
def createDVDAuthorXML(screensize, numberofitems):
|
| 3026 | 3062 | WriteXMLToFile (dvddom,os.path.join(getTempPath(),"dvdauthor.xml")) |
| 3027 | 3063 | |
| 3028 | 3064 | #Destroy the DOM and free memory |
| 3029 | | dvddom.unlink() |
| | 3065 | dvddom.unlink() |
| 3030 | 3066 | |
| 3031 | 3067 | ############################################################# |
| 3032 | 3068 | # Creates the DVDAuthor xml file used to create a DVD with no main menu |
| … |
… |
def createDVDAuthorXMLNoMenus(screensize, numberofitems):
|
| 3220 | 3256 | dvddom.unlink() |
| 3221 | 3257 | |
| 3222 | 3258 | ############################################################# |
| 3223 | | # Creates the directory to hold the preview images for an animated menu |
| | 3259 | # Creates the directory to hold the preview images for an animated menu |
| 3224 | 3260 | |
| 3225 | 3261 | def createEmptyPreviewFolder(videoitem): |
| 3226 | 3262 | previewfolder = os.path.join(getItemTempPath(videoitem), "preview") |
| … |
… |
def generateVideoPreview(videoitem, itemonthispage, menuitem, starttime, menulen
|
| 3264 | 3300 | #see if this graphics item has a mask |
| 3265 | 3301 | if node.hasAttribute("mask"): |
| 3266 | 3302 | imagemaskfilename = getThemeFile(themeName, node.attributes["mask"].value) |
| 3267 | | if node.attributes["mask"].value <> "" and doesFileExist(imagemaskfilename): |
| | 3303 | if node.attributes["mask"].value != "" and doesFileExist(imagemaskfilename): |
| 3268 | 3304 | maskpicture = Image.open(imagemaskfilename,"r").resize((width, height)) |
| 3269 | 3305 | maskpicture = maskpicture.convert("RGBA") |
| 3270 | 3306 | |
| … |
… |
def generateVideoPreview(videoitem, itemonthispage, menuitem, starttime, menulen
|
| 3276 | 3312 | def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw, |
| 3277 | 3313 | bgimagemask, drawmask, highlightcolor, spumuxdom, spunode, |
| 3278 | 3314 | numberofitems, chapternumber, chapterlist): |
| 3279 | | """Draws text and graphics onto a dvd menu, called by |
| | 3315 | """Draws text and graphics onto a dvd menu, called by |
| 3280 | 3316 | createMenu and createChapterMenu""" |
| 3281 | 3317 | |
| 3282 | 3318 | #Get the XML containing information about this item |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3287 | 3323 | fatalError("The info.xml file (%s) doesn't look right" % |
| 3288 | 3324 | os.path.join(getItemTempPath(itemnum),"info.xml")) |
| 3289 | 3325 | |
| 3290 | | #boundarybox holds the max and min dimensions for this item |
| | 3326 | #boundarybox holds the max and min dimensions for this item |
| 3291 | 3327 | #so we can auto build a menu highlight box |
| 3292 | 3328 | boundarybox = 9999,9999,0,0 |
| 3293 | 3329 | wantHighlightBox = True |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3319 | 3355 | |
| 3320 | 3356 | # see if an image mask exists |
| 3321 | 3357 | maskfilename = None |
| 3322 | | if node.hasAttribute("mask") and node.attributes["mask"].value <> "": |
| | 3358 | if node.hasAttribute("mask") and node.attributes["mask"].value != "": |
| 3323 | 3359 | maskfilename = getThemeFile(themeName, node.attributes["mask"].value) |
| 3324 | 3360 | |
| 3325 | | # if this is a thumb image and is a MythVideo coverart image then preserve |
| | 3361 | # if this is a thumb image and is a MythVideo coverart image then preserve |
| 3326 | 3362 | # its aspect ratio unless overriden later by the theme |
| 3327 | 3363 | if (node.attributes["filename"].value == "%thumbnail" |
| 3328 | 3364 | and getText(infoDOM.getElementsByTagName("coverfile")[0]) !=""): |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3366 | 3402 | button.setAttribute("name","previous") |
| 3367 | 3403 | button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) |
| 3368 | 3404 | button.setAttribute("y0","%s" % getScaledAttribute(node, "y")) |
| 3369 | | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| | 3405 | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| 3370 | 3406 | getScaledAttribute(node, "w"))) |
| 3371 | 3407 | button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") + |
| 3372 | 3408 | getScaledAttribute(node, "h"))) |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3390 | 3426 | button.setAttribute("name","next") |
| 3391 | 3427 | button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) |
| 3392 | 3428 | button.setAttribute("y0","%s" % getScaledAttribute(node, "y")) |
| 3393 | | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| | 3429 | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| 3394 | 3430 | getScaledAttribute(node, "w"))) |
| 3395 | | button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") + |
| | 3431 | button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") + |
| 3396 | 3432 | getScaledAttribute(node, "h"))) |
| 3397 | 3433 | spunode.appendChild(button) |
| 3398 | 3434 | |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3411 | 3447 | button.setAttribute("name","playall") |
| 3412 | 3448 | button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) |
| 3413 | 3449 | button.setAttribute("y0","%s" % getScaledAttribute(node, "y")) |
| 3414 | | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| | 3450 | button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + |
| 3415 | 3451 | getScaledAttribute(node, "w"))) |
| 3416 | 3452 | button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") + |
| 3417 | 3453 | getScaledAttribute(node, "h"))) |
| … |
… |
def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
|
| 3426 | 3462 | # draw background if required |
| 3427 | 3463 | paintBackground(bgimage, node) |
| 3428 | 3464 | |
| 3429 | | paintButton(draw, bgimage, bgimagemask, node, infoDOM, |
| 3430 | | itemnum, page, itemsonthispage, chapternumber, |
| | 3465 | paintButton(draw, bgimage, bgimagemask, node, infoDOM, |
| | 3466 | itemnum, page, itemsonthispage, chapternumber, |
| 3431 | 3467 | chapterlist) |
| 3432 | 3468 | |
| 3433 | 3469 | button = spumuxdom.createElement("button") |
| … |
… |
def createMenu(screensize, screendpi, numberofitems):
|
| 3616 | 3652 | bgimage.paste(overlayimage, (0,0), overlayimage) |
| 3617 | 3653 | |
| 3618 | 3654 | #Save this menu image and its mask |
| 3619 | | bgimage.save(os.path.join(getTempPath(),"background-%s.jpg" % page),"JPEG", quality=99) |
| | 3655 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 3656 | rgb_bgimage.save(os.path.join(getTempPath(),"background-%s.jpg" % page),"JPEG", quality=99) |
| | 3657 | del rgb_bgimage |
| 3620 | 3658 | bgimagemask.save(os.path.join(getTempPath(),"backgroundmask-%s.png" % page),"PNG",quality=99,optimize=0,dpi=screendpi) |
| 3621 | 3659 | |
| 3622 | 3660 | #now that the base background has been made and all the previews generated |
| 3623 | 3661 | #we need to add the previews to the background |
| 3624 | | #Assumption: We assume that there is nothing in the location of where the items go |
| | 3662 | #Assumption: We assume that there is nothing in the location of where the items go |
| 3625 | 3663 | #(ie, no text on the images) |
| 3626 | 3664 | |
| 3627 | 3665 | itemsonthispage = 0 |
| … |
… |
def createMenu(screensize, screendpi, numberofitems):
|
| 3654 | 3692 | del picture |
| 3655 | 3693 | previewitem+=1 |
| 3656 | 3694 | #bgimage.save(os.path.join(getTempPath(),"background-%s-f%06d.png" % (page, framenum)),"PNG",quality=100,optimize=0,dpi=screendpi) |
| 3657 | | bgimage.save(os.path.join(getTempPath(),"background-%s-f%06d.jpg" % (page, framenum)),"JPEG",quality=99) |
| | 3695 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 3696 | rgb_bgimage.save(os.path.join(getTempPath(),"background-%s-f%06d.jpg" % (page, framenum)),"JPEG",quality=99) |
| | 3697 | del rgb_bgimage |
| 3658 | 3698 | framenum+=1 |
| 3659 | 3699 | |
| 3660 | 3700 | spumuxdom.documentElement.firstChild.firstChild.setAttribute("select",os.path.join(getTempPath(),"backgroundmask-%s.png" % page)) |
| … |
… |
def createChapterMenu(screensize, screendpi, numberofitems):
|
| 3769 | 3809 | |
| 3770 | 3810 | #Extract the thumbnails |
| 3771 | 3811 | chapterlist=createVideoChapters(page,itemsperpage,getLengthOfVideo(page),True) |
| 3772 | | chapterlist=string.split(chapterlist,",") |
| | 3812 | chapterlist=chapterlist.split(",") |
| 3773 | 3813 | |
| 3774 | 3814 | #now need to preprocess the menu to see if any preview videos are required |
| 3775 | 3815 | #This must be done on an individual basis since we do the resize as the |
| … |
… |
def createChapterMenu(screensize, screendpi, numberofitems):
|
| 3813 | 3853 | chapter+=1 |
| 3814 | 3854 | |
| 3815 | 3855 | drawThemeItem(page, itemsperpage, page, menuitem, |
| 3816 | | overlayimage, draw, |
| | 3856 | overlayimage, draw, |
| 3817 | 3857 | bgimagemask, drawmask, highlightcolor, |
| 3818 | 3858 | spumuxdom, spunode, |
| 3819 | 3859 | 999, chapter, chapterlist) |
| … |
… |
def createChapterMenu(screensize, screendpi, numberofitems):
|
| 3821 | 3861 | #Save this menu image and its mask |
| 3822 | 3862 | bgimage=Image.open(backgroundfilename,"r").resize(screensize) |
| 3823 | 3863 | bgimage.paste(overlayimage, (0,0), overlayimage) |
| 3824 | | bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s.jpg" % page),"JPEG", quality=99) |
| | 3864 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 3865 | rgb_bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s.jpg" % page),"JPEG", quality=99) |
| | 3866 | del rgb_bgimage |
| 3825 | 3867 | |
| 3826 | 3868 | bgimagemask.save(os.path.join(getTempPath(),"chaptermenumask-%s.png" % page),"PNG",quality=90,optimize=0) |
| 3827 | 3869 | |
| … |
… |
def createChapterMenu(screensize, screendpi, numberofitems):
|
| 3850 | 3892 | bgimage.paste(picture, (previewx[previewchapter], previewy[previewchapter])) |
| 3851 | 3893 | del picture |
| 3852 | 3894 | previewchapter+=1 |
| 3853 | | bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s-f%06d.jpg" % (page, framenum)),"JPEG",quality=99) |
| | 3895 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 3896 | rgb_bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s-f%06d.jpg" % (page, framenum)),"JPEG",quality=99) |
| | 3897 | del rgb_bgimage |
| 3854 | 3898 | framenum+=1 |
| 3855 | 3899 | |
| 3856 | 3900 | spumuxdom.documentElement.firstChild.firstChild.setAttribute("select",os.path.join(getTempPath(),"chaptermenumask-%s.png" % page)) |
| … |
… |
def createChapterMenu(screensize, screendpi, numberofitems):
|
| 3873 | 3917 | aspect_ratio = '2' |
| 3874 | 3918 | elif chaptermenuAspectRatio == "16:9": |
| 3875 | 3919 | aspect_ratio = '3' |
| 3876 | | else: |
| | 3920 | else: |
| 3877 | 3921 | if getAspectRatioOfVideo(page) > aspectRatioThreshold: |
| 3878 | 3922 | aspect_ratio = '3' |
| 3879 | 3923 | else: |
| … |
… |
def createDetailsPage(screensize, screendpi, numberofitems):
|
| 3971 | 4015 | #Save this details image |
| 3972 | 4016 | bgimage=Image.open(backgroundfilename,"r").resize(screensize) |
| 3973 | 4017 | bgimage.paste(overlayimage, (0,0), overlayimage) |
| 3974 | | bgimage.save(os.path.join(getTempPath(),"details-%s.jpg" % itemnum),"JPEG", quality=99) |
| | 4018 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 4019 | rgb_bgimage.save(os.path.join(getTempPath(),"details-%s.jpg" % itemnum),"JPEG", quality=99) |
| | 4020 | del rgb_bgimage |
| 3975 | 4021 | |
| 3976 | 4022 | if haspreview == True: |
| 3977 | 4023 | numframes=secondsToFrames(menulength) |
| … |
… |
def createDetailsPage(screensize, screendpi, numberofitems):
|
| 3994 | 4040 | else: |
| 3995 | 4041 | bgimage.paste(picture, (previewx, previewy)) |
| 3996 | 4042 | del picture |
| 3997 | | bgimage.save(os.path.join(getTempPath(),"details-%s-f%06d.jpg" % (itemnum, framenum)),"JPEG",quality=99) |
| | 4043 | rgb_bgimage=bgimage.convert('RGB') ### ticket #13306 |
| | 4044 | rgb_bgimage.save(os.path.join(getTempPath(),"details-%s-f%06d.jpg" % (itemnum, framenum)),"JPEG",quality=99) |
| | 4045 | del rgb_bgimage |
| 3998 | 4046 | framenum+=1 |
| 3999 | 4047 | |
| 4000 | 4048 | |
| … |
… |
def isMediaAVIFile(file):
|
| 4043 | 4091 | return Magic=="RIFF" |
| 4044 | 4092 | |
| 4045 | 4093 | ############################################################# |
| 4046 | | # checks to see if an audio stream need to be converted to ac3 |
| | 4094 | # checks to see if an audio stream need to be converted to ac3 |
| 4047 | 4095 | |
| 4048 | 4096 | def processAudio(folder): |
| 4049 | 4097 | """encode audio to ac3 for better compression and compatability with NTSC players""" |
| … |
… |
def selectStreams(folder):
|
| 4135 | 4183 | for node in nodes: |
| 4136 | 4184 | index = int(node.attributes["ffmpegindex"].value) |
| 4137 | 4185 | lang = node.attributes["language"].value |
| 4138 | | format = string.upper(node.attributes["codec"].value) |
| | 4186 | format = node.attributes["codec"].value.upper() |
| 4139 | 4187 | pid = int(node.attributes["id"].value) |
| 4140 | 4188 | if lang == preferredlang1 and format == "AC3": |
| 4141 | 4189 | if found: |
| … |
… |
def selectStreams(folder):
|
| 4150 | 4198 | for node in nodes: |
| 4151 | 4199 | index = int(node.attributes["ffmpegindex"].value) |
| 4152 | 4200 | lang = node.attributes["language"].value |
| 4153 | | format = string.upper(node.attributes["codec"].value) |
| | 4201 | format = node.attributes["codec"].value.upper() |
| 4154 | 4202 | pid = int(node.attributes["id"].value) |
| 4155 | 4203 | if lang == preferredlang1 and format == "MP2": |
| 4156 | 4204 | if found: |
| … |
… |
def selectStreams(folder):
|
| 4164 | 4212 | if not found: |
| 4165 | 4213 | for node in nodes: |
| 4166 | 4214 | index = int(node.attributes["ffmpegindex"].value) |
| 4167 | | format = string.upper(node.attributes["codec"].value) |
| | 4215 | format = node.attributes["codec"].value.upper() |
| 4168 | 4216 | pid = int(node.attributes["id"].value) |
| 4169 | 4217 | if not found: |
| 4170 | 4218 | audio1 = (index, format, pid, lang) |
| … |
… |
def selectStreams(folder):
|
| 4183 | 4231 | for node in nodes: |
| 4184 | 4232 | index = int(node.attributes["ffmpegindex"].value) |
| 4185 | 4233 | lang = node.attributes["language"].value |
| 4186 | | format = string.upper(node.attributes["codec"].value) |
| | 4234 | format = node.attributes["codec"].value.upper() |
| 4187 | 4235 | pid = int(node.attributes["id"].value) |
| 4188 | 4236 | if lang == preferredlang2 and format == "AC3": |
| 4189 | 4237 | if found: |
| … |
… |
def selectStreams(folder):
|
| 4198 | 4246 | for node in nodes: |
| 4199 | 4247 | index = int(node.attributes["ffmpegindex"].value) |
| 4200 | 4248 | lang = node.attributes["language"].value |
| 4201 | | format = string.upper(node.attributes["codec"].value) |
| | 4249 | format = node.attributes["codec"].value.upper() |
| 4202 | 4250 | pid = int(node.attributes["id"].value) |
| 4203 | 4251 | if lang == preferredlang2 and format == "MP2": |
| 4204 | 4252 | if found: |
| … |
… |
def selectStreams(folder):
|
| 4212 | 4260 | if not found: |
| 4213 | 4261 | for node in nodes: |
| 4214 | 4262 | index = int(node.attributes["ffmpegindex"].value) |
| 4215 | | format = string.upper(node.attributes["codec"].value) |
| | 4263 | format = node.attributes["codec"].value.upper() |
| 4216 | 4264 | pid = int(node.attributes["id"].value) |
| 4217 | 4265 | if not found: |
| 4218 | 4266 | # make sure we don't choose the same stream as audio1 |
| … |
… |
def selectSubtitleStream(folder):
|
| 4266 | 4314 | for node in nodes: |
| 4267 | 4315 | index = int(node.attributes["ffmpegindex"].value) |
| 4268 | 4316 | lang = node.attributes["language"].value |
| 4269 | | format = string.upper(node.attributes["codec"].value) |
| | 4317 | format = node.attributes["codec"].value.upper() |
| 4270 | 4318 | pid = int(node.attributes["id"].value) |
| 4271 | 4319 | if not found and lang == preferredlang1 and format == "dvbsub": |
| 4272 | 4320 | subtitle = (index, format, pid, lang) |
| … |
… |
def selectSubtitleStream(folder):
|
| 4277 | 4325 | for node in nodes: |
| 4278 | 4326 | index = int(node.attributes["ffmpegindex"].value) |
| 4279 | 4327 | lang = node.attributes["language"].value |
| 4280 | | format = string.upper(node.attributes["codec"].value) |
| | 4328 | format = node.attributes["codec"].value.upper() |
| 4281 | 4329 | pid = int(node.attributes["id"].value) |
| 4282 | 4330 | if not found and lang == preferredlang2 and format == "dvbsub": |
| 4283 | 4331 | subtitle = (index, format, pid, lang) |
| … |
… |
def selectSubtitleStream(folder):
|
| 4287 | 4335 | if not found: |
| 4288 | 4336 | for node in nodes: |
| 4289 | 4337 | index = int(node.attributes["ffmpegindex"].value) |
| 4290 | | format = string.upper(node.attributes["codec"].value) |
| | 4338 | format = node.attributes["codec"].value.upper() |
| 4291 | 4339 | pid = int(node.attributes["id"].value) |
| 4292 | 4340 | if not found: |
| 4293 | 4341 | subtitle = (index, format, pid, lang) |
| … |
… |
def getStreamList(folder):
|
| 4414 | 4462 | def isFileOkayForDVD(file, folder): |
| 4415 | 4463 | """return true if the file is dvd compliant""" |
| 4416 | 4464 | |
| 4417 | | if not string.lower(getVideoCodec(folder)).startswith("mpeg2video"): |
| | 4465 | if not getVideoCodec(folder).lower().startswith("mpeg2video"): |
| 4418 | 4466 | return False |
| 4419 | 4467 | |
| 4420 | | # if string.lower(getAudioCodec(folder)) != "ac3" and encodeToAC3: |
| | 4468 | |
| | 4469 | # if (getAudioCodec(folder)).lower() != "ac3" and encodeToAC3: |
| 4421 | 4470 | # return False |
| 4422 | 4471 | |
| 4423 | 4472 | videosize = getVideoSize(os.path.join(folder, "streaminfo.xml")) |
| … |
… |
def processFile(file, folder, count):
|
| 4454 | 4503 | |
| 4455 | 4504 | ############################################################# |
| 4456 | 4505 | # process a single file ready for burning using mythtranscode/mythreplex |
| 4457 | | # to cut and demux |
| | 4506 | # to cut and demux |
| 4458 | 4507 | |
| 4459 | 4508 | def doProcessFile(file, folder, count): |
| 4460 | 4509 | """Process a single video/recording file ready for burning.""" |
| … |
… |
def doProcessFile(file, folder, count):
|
| 4494 | 4543 | #can only use mythtranscode to cut commercials on mpeg2 files |
| 4495 | 4544 | write("File type is '%s'" % getFileType(folder)) |
| 4496 | 4545 | write("Video codec is '%s'" % getVideoCodec(folder)) |
| 4497 | | if string.lower(getVideoCodec(folder)).startswith("mpeg2video"): |
| | 4546 | if (getVideoCodec(folder)).lower().startswith("mpeg2video"): |
| 4498 | 4547 | if file.attributes["usecutlist"].value == "1" and getText(infoDOM.getElementsByTagName("hascutlist")[0]) == "yes": |
| 4499 | 4548 | # Run from local file? |
| 4500 | 4549 | if file.hasAttribute("localfilename"): |
| … |
… |
def doProcessFile(file, folder, count):
|
| 4510 | 4559 | write("Failed to run mythtranscode to remove unwanted segments") |
| 4511 | 4560 | else: |
| 4512 | 4561 | #does the user always want to run recordings through mythtranscode? |
| 4513 | | #may help to fix any errors in the file |
| 4514 | | if (alwaysRunMythtranscode == True or |
| | 4562 | #may help to fix any errors in the file |
| | 4563 | if (alwaysRunMythtranscode == True or |
| 4515 | 4564 | (getFileType(folder) == "mpegts" and isFileOkayForDVD(file, folder))): |
| 4516 | 4565 | # Run from local file? |
| 4517 | 4566 | if file.hasAttribute("localfilename"): |
| … |
… |
def doProcessFile(file, folder, count):
|
| 4527 | 4576 | write("Failed to run mythtranscode to fix any errors") |
| 4528 | 4577 | else: |
| 4529 | 4578 | #does the user always want to run mpeg2 files through mythtranscode? |
| 4530 | | #may help to fix any errors in the file |
| | 4579 | #may help to fix any errors in the file |
| 4531 | 4580 | write("File type is '%s'" % getFileType(folder)) |
| 4532 | 4581 | write("Video codec is '%s'" % getVideoCodec(folder)) |
| 4533 | 4582 | |
| 4534 | 4583 | if (alwaysRunMythtranscode == True and |
| 4535 | | string.lower(getVideoCodec(folder)).startswith("mpeg2video") and |
| | 4584 | getVideoCodec(folder).lower().startswith("mpeg2video") and |
| 4536 | 4585 | isFileOkayForDVD(file, folder)): |
| 4537 | 4586 | if file.hasAttribute("localfilename"): |
| 4538 | 4587 | localfile = file.attributes["localfilename"].value |
| … |
… |
def doProcessFile(file, folder, count):
|
| 4579 | 4628 | mediafile = -1 |
| 4580 | 4629 | chanid = getText(infoDOM.getElementsByTagName("chanid")[0]) |
| 4581 | 4630 | starttime = getText(infoDOM.getElementsByTagName("starttime")[0]) |
| 4582 | | usecutlist = (file.attributes["usecutlist"].value == "1" and |
| | 4631 | usecutlist = (file.attributes["usecutlist"].value == "1" and |
| 4583 | 4632 | getText(infoDOM.getElementsByTagName("hascutlist")[0]) == "yes") |
| 4584 | 4633 | else: |
| 4585 | 4634 | chanid = -1 |
| … |
… |
def doProcessFile(file, folder, count):
|
| 4612 | 4661 | else: |
| 4613 | 4662 | profile = defaultEncodingProfile |
| 4614 | 4663 | |
| 4615 | | #do the re-encode |
| | 4664 | #do the re-encode |
| 4616 | 4665 | encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video, |
| 4617 | 4666 | audio1, audio2, aspectratio, profile) |
| 4618 | 4667 | mediafile = os.path.join(folder, 'newfile2.mpg') |
| … |
… |
def doProcessFileProjectX(file, folder, count):
|
| 4677 | 4726 | |
| 4678 | 4727 | #As part of this routine we need to pre-process the video this MAY mean: |
| 4679 | 4728 | #1. encoding to mpeg2 (if its an avi for instance or isn't DVD compatible) |
| 4680 | | #2. removing commercials/cleaning up mpeg2 stream |
| | 4729 | #2. removing commercials/cleaning up mpeg2 stream |
| 4681 | 4730 | #3. selecting audio track(s) to use and encoding audio from mp2 into ac3 |
| 4682 | 4731 | #4. de-multiplexing into video and audio steams |
| 4683 | 4732 | |
| … |
… |
def doProcessFileProjectX(file, folder, count):
|
| 4733 | 4782 | mediafile = -1 |
| 4734 | 4783 | chanid = getText(infoDOM.getElementsByTagName("chanid")[0]) |
| 4735 | 4784 | starttime = getText(infoDOM.getElementsByTagName("starttime")[0]) |
| 4736 | | usecutlist = (file.attributes["usecutlist"].value == "1" and |
| | 4785 | usecutlist = (file.attributes["usecutlist"].value == "1" and |
| 4737 | 4786 | getText(infoDOM.getElementsByTagName("hascutlist")[0]) == "yes") |
| 4738 | 4787 | else: |
| 4739 | 4788 | chanid = -1 |
| … |
… |
def doProcessFileProjectX(file, folder, count):
|
| 4766 | 4815 | else: |
| 4767 | 4816 | profile = defaultEncodingProfile |
| 4768 | 4817 | |
| 4769 | | #do the re-encode |
| | 4818 | #do the re-encode |
| 4770 | 4819 | encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video, |
| 4771 | 4820 | audio1, audio2, aspectratio, profile) |
| 4772 | 4821 | mediafile = os.path.join(folder, 'newfile2.mpg') |
| … |
… |
def doProcessFileProjectX(file, folder, count):
|
| 4787 | 4836 | # now attempt to split the source file into video and audio parts |
| 4788 | 4837 | # using projectX |
| 4789 | 4838 | |
| 4790 | | # If this is an mpeg2 myth recording and there is a cut list available and the |
| | 4839 | # If this is an mpeg2 myth recording and there is a cut list available and the |
| 4791 | 4840 | # user wants to use it run projectx to cut out commercials etc |
| 4792 | 4841 | if file.attributes["type"].value == "recording": |
| 4793 | 4842 | if file.attributes["usecutlist"].value == "1" and getText(infoDOM.getElementsByTagName("hascutlist")[0]) == "yes": |
| … |
… |
def processJob(job):
|
| 4995 | 5044 | filecount+=1 |
| 4996 | 5045 | folder=getItemTempPath(filecount) |
| 4997 | 5046 | #Multiplex this file |
| 4998 | | #(This also removes non-required audio feeds inside mpeg streams |
| | 5047 | #(This also removes non-required audio feeds inside mpeg streams |
| 4999 | 5048 | #(through re-multiplexing) we only take 1 video and 1 or 2 audio streams) |
| 5000 | 5049 | pid=multiplexMPEGStream(os.path.join(folder,'stream.mv2'), |
| 5001 | 5050 | os.path.join(folder,'stream0'), |
| … |
… |
def main():
|
| 5166 | 5215 | videopath = defaultsettings.get("VideoStartupDir", None) |
| 5167 | 5216 | gallerypath = defaultsettings.get("GalleryDir", None) |
| 5168 | 5217 | musicpath = defaultsettings.get("MusicLocation", None) |
| 5169 | | videomode = string.lower(defaultsettings["MythArchiveVideoFormat"]) |
| | 5218 | videomode = defaultsettings["MythArchiveVideoFormat"].lower() |
| 5170 | 5219 | temppath = os.path.join(defaultsettings["MythArchiveTempDir"], "work") |
| 5171 | 5220 | logpath = os.path.join(defaultsettings["MythArchiveTempDir"], "logs") |
| 5172 | 5221 | write("temppath: " + temppath) |
| … |
… |
def main():
|
| 5233 | 5282 | try: |
| 5234 | 5283 | fd = os.open(lckpath, os.O_WRONLY | os.O_CREAT | os.O_EXCL) |
| 5235 | 5284 | try: |
| 5236 | | os.write(fd, "%d\n" % os.getpid()) |
| | 5285 | os.write(fd, b"%d\n" % os.getpid()) |
| 5237 | 5286 | os.close(fd) |
| 5238 | 5287 | except: |
| 5239 | 5288 | os.remove(lckpath) |
| 5240 | 5289 | raise |
| 5241 | | except OSError, e: |
| | 5290 | except OSError as e: |
| 5242 | 5291 | if e.errno == errno.EEXIST: |
| 5243 | 5292 | write("Lock file exists -- already running???") |
| 5244 | 5293 | sys.exit(1) |
| … |
… |
def main():
|
| 5281 | 5330 | # remove our lock file |
| 5282 | 5331 | os.remove(lckpath) |
| 5283 | 5332 | |
| 5284 | | # make sure the files we created are read/writable by all |
| | 5333 | # make sure the files we created are read/writable by all |
| 5285 | 5334 | os.system("chmod -R a+rw-x+X %s" % defaultsettings["MythArchiveTempDir"]) |
| 5286 | 5335 | except SystemExit: |
| 5287 | 5336 | write("Terminated") |