465
495
totalframes=int(musiclength * framespersecond)
467
command = path_jpeg2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \
468
% (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)
497
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" \
498
% (totalframes, framespersecond, quoteCmdArg(background), quoteCmdArg(path_mpeg2enc[0]), aspectratio, quoteCmdArg(tempvideo))
469
499
result = runCommand(command)
471
501
fatalError("Failed while running jpeg2yuv - %s" % command)
473
command = path_mplex[0] + " -f 8 -v 0 -o '%s' '%s' '%s'" % (tempmovie, tempvideo, music)
503
command = quoteCmdArg(path_mplex[0]) + " -f 8 -v 0 -o %s %s %s" % (quoteCmdArg(tempmovie), quoteCmdArg(tempvideo), quoteCmdArg(music))
474
504
result = runCommand(command)
476
506
fatalError("Failed while running mplex - %s" % command)
478
508
if xmlfile != "":
479
command = path_spumux[0] + " -m dvd -s 0 '%s' < '%s' > '%s'" % (xmlfile, tempmovie, finaloutput)
509
command = quoteCmdArg(path_spumux[0]) + " -m dvd -s 0 %s < %s > %s" % (quoteCmdArg(xmlfile), quoteCmdArg(tempmovie), quoteCmdArg(finaloutput))
480
510
result = runCommand(command)
482
512
fatalError("Failed while running spumux - %s" % command)
1767
1792
# workout which files we need and rename them
1768
renameProjectXFiles(folder, pxbasename)
1793
video, audio1, audio2 = selectStreams(folder)
1795
subtitles = selectSubtitleStream(folder)
1797
videoID_hex = "0x%x" % video[VIDEO_ID]
1798
if audio1[AUDIO_ID] != -1:
1799
audio1ID_hex = "0x%x" % audio1[AUDIO_ID]
1802
if audio2[AUDIO_ID] != -1:
1803
audio2ID_hex = "0x%x" % audio2[AUDIO_ID]
1806
if addSubtitles and subtitles[SUBTITLE_ID] != -1:
1807
subtitlesID_hex = "0x%x" % subtitles[SUBTITLE_ID]
1809
subtitlesID_hex = ""
1812
files = os.listdir(folder)
1814
if file[0:9] == "stream{0x": # don't rename files that have already been renamed
1817
if PID == videoID_hex or SubID == videoID_hex:
1818
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2"))
1819
elif PID == audio1ID_hex or SubID == audio1ID_hex:
1820
os.rename(os.path.join(folder, file), os.path.join(folder, "stream0." + file[-3:]))
1821
elif PID == audio2ID_hex or SubID == audio2ID_hex:
1822
os.rename(os.path.join(folder, file), os.path.join(folder, "stream1." + file[-3:]))
1823
elif PID == subtitlesID_hex or SubID == subtitlesID_hex:
1824
if file[-3:] == "sup":
1825
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup"))
1827
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO"))
1830
# Fallback if assignment and renaming by ID failed
1832
files = os.listdir(folder)
1834
if file[0:9] == "stream{0x": # don't rename files that have already been renamed
1835
if not os.path.exists(os.path.join(folder, "stream.mv2")) and file[-3:] == "m2v":
1836
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2"))
1837
elif not (os.path.exists(os.path.join(folder, "stream0.ac3")) or os.path.exists(os.path.join(folder, "stream0.mp2"))) and file[-3:] == "ac3":
1838
os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.ac3"))
1839
elif not (os.path.exists(os.path.join(folder, "stream0.ac3")) or os.path.exists(os.path.join(folder, "stream0.mp2"))) and file[-3:] == "mp2":
1840
os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.mp2"))
1841
elif not (os.path.exists(os.path.join(folder, "stream1.ac3")) or os.path.exists(os.path.join(folder, "stream1.mp2"))) and file[-3:] == "ac3":
1842
os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.ac3"))
1843
elif not (os.path.exists(os.path.join(folder, "stream1.ac3")) or os.path.exists(os.path.join(folder, "stream1.mp2"))) and file[-3:] == "mp2":
1844
os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.mp2"))
1845
elif not os.path.exists(os.path.join(folder, "stream.sup")) and file[-3:] == "sup":
1846
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup"))
1847
elif not os.path.exists(os.path.join(folder, "stream.sup.IFO")) and file[-3:] == "IFO":
1848
os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO"))
1770
1851
# if we have some dvb subtitles and the user wants to add them to the DVD
1771
1852
# convert them to pngs and create the spumux xml file
1791
1872
#############################################################
1792
# find the required stream files and rename them
1794
def renameProjectXFiles(folder, pxbasename):
1796
write("renameProjectXFiles start -----------------------------------------", False)
1797
logf = open(os.path.join(folder, pxbasename + "_log.txt"))
1798
logdata = logf.readlines()
1801
# find stream PIDs and Files
1804
for line in logdata:
1805
tokens = line.split()
1807
if tokens[0] == "++>":
1808
# From ProjectX/resources/pjxresources_en.properties:
1809
if tokens[1] == "Mpg":
1810
if tokens[2] == "Video:":
1811
write("found MPEG video stream %s" % tokens[4], False)
1812
streamIds.append(int(tokens[4], 16))
1813
if tokens[2] == "Audio:":
1814
write("found MPEG audio stream %s" % tokens[4], False)
1815
streamIds.append(int(tokens[4], 16))
1816
if tokens[1] == "AC3/DTS":
1817
write("found AC3/DTS audio stream %s" % tokens[4], False)
1818
streamIds.append(int(tokens[4], 16))
1819
if tokens[1] == "LPCM":
1820
write("found LPCM audio stream %s" % tokens[4], False)
1821
streamIds.append(int(tokens[4], 16))
1822
if tokens[1] == "Teletext:":
1823
write("found Teletext stream %s" % tokens[3], False)
1824
streamIds.append(int(tokens[3], 16))
1825
if tokens[1] == "Subpicture:":
1826
write("found Subpicture stream %s" % tokens[3], False)
1827
streamIds.append(int(tokens[3], 16))
1828
if tokens[1] == "Generic_VBI:":
1829
write("found Generic_VBI stream %s" % tokens[3], False)
1830
streamIds.append(int(tokens[3], 16))
1831
if tokens[0] == "--->":
1832
if tokens[1] == "new":
1833
if tokens[2] == "File:":
1834
write("found file for stream 0x%x, %s" % (streamIds[len(streamIds)-1], tokens[3]), False)
1835
streamFiles.append(tokens[3].replace("'","")) # let's hope the path never has a space in it
1836
if tokens[0] == "-->":
1837
if tokens[1] == "stream":
1838
if tokens[2] == "omitted":
1839
write("stream 0x%x omitted" % streamIds[len(streamIds)-1], False)
1840
streamFiles.append("")
1842
write("streadmIds=%s" % streamIds)
1843
write("streamFiles=%s" % streamFiles)
1845
# choose which streams we need
1846
video, audio1, audio2 = selectStreams(folder)
1848
if getFileType(folder) == "mpeg":
1849
videoID = video[VIDEO_ID] & 255
1850
audio1ID = audio1[AUDIO_ID] & 255
1851
audio2ID = audio2[AUDIO_ID] & 255
1853
videoID = video[VIDEO_ID]
1854
audio1ID = audio1[AUDIO_ID]
1855
audio2ID = audio2[AUDIO_ID]
1857
# sanity check - we should have a file for each ID
1858
if len(streamIds) == len(streamFiles):
1859
# loop thought the available streams looking for the ones we want
1860
for stream in streamIds:
1861
write("got stream: %d" % stream, False)
1862
if stream == videoID:
1863
write("found video streamID", False)
1864
if os.path.exists(streamFiles[streamIds.index(stream)]):
1865
write("found video stream file", False)
1866
os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream.mv2"))
1868
if stream == audio1ID:
1869
write("found audio1 streamID", False)
1870
if os.path.exists(streamFiles[streamIds.index(stream)]):
1871
write("found audio1 stream file", False)
1872
if audio1[AUDIO_CODEC] == "AC3":
1873
os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.ac3"))
1875
os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.mp2"))
1877
if stream == audio2ID:
1878
write("found audio2 streamID", False)
1879
if os.path.exists(streamFiles[streamIds.index(stream)]):
1880
write("found audio2 stream file", False)
1881
if audio2[AUDIO_CODEC] == "AC3":
1882
os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.ac3"))
1884
os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.mp2"))
1886
# final chance to find the correct stream files
1887
if not os.path.exists(os.path.join(folder, "stream.mv2")):
1888
if os.path.exists(os.path.join(folder, pxbasename + ".m2v")):
1889
os.rename(os.path.join(folder, pxbasename + ".m2v"), os.path.join(folder, "stream.mv2"))
1891
if not os.path.exists(os.path.join(folder, "stream0.mp2")) or not os.path.exists(os.path.join(folder, "stream0.ac3")):
1892
if os.path.exists(os.path.join(folder, pxbasename + ".mp2")):
1893
os.rename(os.path.join(folder, pxbasename + ".mp2"), os.path.join(folder, "stream0.mp2"))
1894
if os.path.exists(os.path.join(folder, pxbasename + ".ac3")):
1895
os.rename(os.path.join(folder, pxbasename + ".ac3"), os.path.join(folder, "stream0.ac3"))
1897
if not os.path.exists(os.path.join(folder, "stream1.mp2")) or not os.path.exists(os.path.join(folder, "stream1.ac3")):
1898
if os.path.exists(os.path.join(folder, pxbasename + "[1].mp2")):
1899
os.rename(os.path.join(folder, pxbasename + "[1].mp2"), os.path.join(folder, "stream1.mp2"))
1900
if os.path.exists(os.path.join(folder, pxbasename + "[1].ac3")):
1901
os.rename(os.path.join(folder, pxbasename + "[1].ac3"), os.path.join(folder, "stream1.ac3"))
1903
# do we have any subtitle files
1904
if os.path.exists(os.path.join(folder, pxbasename + ".sup")):
1905
os.rename(os.path.join(folder, pxbasename + ".sup"), os.path.join(folder, "stream.sup"))
1907
if os.path.exists(os.path.join(folder, pxbasename + ".sup.IFO")):
1908
os.rename(os.path.join(folder, pxbasename + ".sup.IFO"), os.path.join(folder, "stream.sup.IFO"))
1910
write("renameProjectXFiles end -----------------------------------------", False)
1912
#############################################################
1913
1873
# convert time stamp to pts
1915
1875
def ts2pts(time):
2280
2237
def BurnDVDISO(title):
2281
2238
write( "Burning ISO image to %s" % dvddrivepath)
2286
while not finished and tries < 10:
2240
#######################
2241
# some helper functions
2287
2243
f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
2288
drivestatus = ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0)
2291
if drivestatus == CDROM.CDS_DISC_OK or drivestatus == CDROM.CDS_NO_INFO:
2244
status = ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0)
2247
def displayneededdisktype():
2248
if mediatype == DVD_SL:
2249
write("Please insert an empty single-layer disc (DVD+R or DVD-R).")
2250
if mediatype == DVD_DL:
2251
write("Please insert an empty double-layer disc (DVD+R DL or DVD-R DL).")
2252
if mediatype == DVD_RW:
2253
write("Please insert a rewritable disc (DVD+RW or DVD-RW).")
2255
runCommand("pumount " + quoteCmdArg(dvddrivepath));
2258
f = os.open(drivepath, os.O_RDONLY | os.O_NONBLOCK)
2259
r = ioctl(f,action, 0)
2263
write("Failed to eject the disc!")
2269
while drivestatus() == CDROM.CDS_DRIVE_NOT_READY:
2271
write("Waiting for drive")
2275
# Try a hard reset if the device is still not ready
2276
write("Try a hard-reset of the device")
2277
tray(CDROM.CDROMRESET)
2281
####################
2282
# start working here
2287
# Maybe the user has no appropriate medium or something alike. Give her the chance to cancel.
2290
# If drive needs some time (for example to close the tray) give it to it
2293
if drivestatus() == CDROM.CDS_DISC_OK or drivestatus() == CDROM.CDS_NO_INFO:
2293
2295
# If the frontend has a previously burnt DVD+RW mounted,
2294
2296
# growisofs will fail to burn it, so try to pumount it first...
2295
runCommand("pumount " + dvddrivepath);
2297
runCommand("pumount " + quoteCmdArg(dvddrivepath));
2300
command = quoteCmdArg(path_growisofs[0]) + " -dvd-compat"
2302
command += " -speed=%d" % drivespeed
2297
2303
if mediatype == DVD_RW and erasedvdrw == True:
2298
command = path_growisofs[0] + " -dvd-compat "
2300
command += "-speed=%d " % drivespeed
2301
command += " -use-the-force-luke -Z " + dvddrivepath
2302
command += " -dvd-video -V '" + title.replace("'", "'\\''") + "' "
2303
command += os.path.join(getTempPath(),'dvd')
2305
command = path_growisofs[0] + " -dvd-compat "
2307
command += "-speed=%d " % drivespeed
2308
command += " -Z " + dvddrivepath + " -dvd-video -V '" + title.replace("'", "'\\''") + "' "
2309
command += os.path.join(getTempPath(),'dvd')
2304
command += " -use-the-force-luke"
2305
command += " -Z " + quoteCmdArg(dvddrivepath) + " -dvd-video -V " + quoteCmdArg(title) + " " + quoteCmdArg(os.path.join(getTempPath(),'dvd'))
2312
2307
write("Running growisofs to burn DVD")
2314
2309
result = runCommand(command)
2317
write("ERROR: Failed while running growisofs.")
2318
write("Result %d, Command was: %s" % (result, command))
2319
write("Please check the troubleshooting section of the README for ways to fix this error")
2326
# eject the burned disc
2327
f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
2328
r = ioctl(f,CDROM.CDROMEJECT, 0)
2331
write("Failed to eject the disc! "
2332
"Maybe the media monitor has mounted it")
2334
elif drivestatus == CDROM.CDS_TRAY_OPEN:
2335
# Give the user 10secs to close the Tray
2315
write("You probably inserted a medium of wrong type.")
2316
elif (result == 156):
2318
write("You probably inserted a non-empty, corrupt or too small medium.")
2319
elif (result == 144):
2321
write("You inserted a non-empty medium.")
2324
write("ERROR: Failed while running growisofs.")
2325
write("Result %d, Command was: %s" % (result, command))
2326
write("Please check mythburn.log for further information")
2329
write("Going to try it again until canceled by user:")
2332
displayneededdisktype()
2335
tray(CDROM.CDROMEJECT)
2338
elif drivestatus() == CDROM.CDS_TRAY_OPEN:
2339
displayneededdisktype()
2336
2340
write("Waiting for tray to close.")
2338
elif drivestatus == CDROM.CDS_NO_DISC:
2339
# Open the Tray, if there is one.
2340
write("Opening tray to get it fed with a DVD.")
2341
f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
2342
ioctl(f,CDROM.CDROMEJECT, 0)
2344
elif drivestatus == CDROM.CDS_DRIVE_NOT_READY:
2346
write("Trying a hard-reset of the device")
2347
f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
2348
ioctl(f,CDROM.CDROMEJECT, 0)
2355
fatalError("Tried 10 times to get a good status from DVD drive - Giving up!")
2341
# Wait until user closes tray or cancels
2342
while drivestatus() == CDROM.CDS_TRAY_OPEN:
2345
elif drivestatus() == CDROM.CDS_NO_DISC:
2346
tray(CDROM.CDROMEJECT)
2347
displayneededdisktype()
2357
2349
write("Finished burning ISO image")
2420
2412
M2Vsize0 = os.path.getsize(source)
2421
2413
write("Initial M2Vsize is %.2f Mb , target is %.2f Mb" % ( (float(M2Vsize0)/mega), (float(M2Vsize0)/(factor*mega)) ))
2423
command = path_M2VRequantiser[0]
2415
command = quoteCmdArg(path_M2VRequantiser[0])
2424
2416
command += " %.5f " % factor
2425
2417
command += " %s " % M2Vsize0
2426
command += " < %s " % source
2427
command += " > %s " % destination
2418
command += " < %s " % quoteCmdArg(source)
2419
command += " > %s " % quoteCmdArg(destination)
2429
2421
write("Running: " + command)
2430
2422
result = runCommand(command)
2424
fatalError("Failed while running M2VRequantiser. Command was %s" % command)
2432
2426
M2Vsize1 = os.path.getsize(destination)
2434
2428
write("M2Vsize after requant is %.2f Mb " % (float(M2Vsize1)/mega))
2435
2429
fac1=float(M2Vsize0) / float(M2Vsize1)
2436
2430
write("Factor demanded %.5f, achieved %.5f, ratio %.5f " % ( factor, fac1, fac1/factor))
2439
fatalError("Failed while running M2VRequantiser. Command was %s" % command)
2441
2432
#############################################################
2442
2433
# Calculates the total size of all the video, audio and menu files