Ticket #2667: mythburn-preview.patch

File mythburn-preview.patch, 31.0 KB (added by pholmes@…, 17 years ago)
  • mytharchive/mytharchive/archivesettings.cpp

     
    257257    return gc;
    258258};
    259259
     260static HostLineEdit *MythArchiveJpeg2yuvCmd()
     261{
     262    HostLineEdit *gc = new HostLineEdit("MythArchiveJpeg2yuvCmd");
     263    gc->setLabel(QObject::tr("jpeg2yuv command"));
     264    gc->setValue("jpeg2yuv");
     265    gc->setHelpText(QObject::tr("Command to run jpeg2yuv. Part of mjpegtools package"));
     266    return gc;
     267};
     268
     269static HostLineEdit *MythArchiveTranscodeCmd()
     270{
     271    HostLineEdit *gc = new HostLineEdit("MythArchiveTranscodeCmd");
     272    gc->setLabel(QObject::tr("transcode command"));
     273    gc->setValue("transcode");
     274    gc->setHelpText(QObject::tr("Command to run transcode. Part of mjpegtools package. This is used to convert MPEG2 video to png files"));
     275    return gc;
     276};
     277
     278
    260279ArchiveSettings::ArchiveSettings()
    261280{
    262281    VerticalConfigurationGroup* vcg1 = new VerticalConfigurationGroup(false);
     
    295314    vcg4->addChild(MythArchiveGrowisofsCmd());
    296315    vcg4->addChild(MythArchiveTcrequantCmd());
    297316    vcg4->addChild(MythArchivePng2yuvCmd());
     317    vcg4->addChild(MythArchiveJpeg2yuvCmd());
    298318    addChild(vcg4);
     319
     320    VerticalConfigurationGroup* vcg5 = new VerticalConfigurationGroup(false);
     321    vcg5->setLabel(QObject::tr("MythArchive External Commands (3)"));
     322    vcg5->addChild(MythArchiveTranscodeCmd());
     323    addChild(vcg5);
    299324}
  • mytharchive/mythburn/scripts/mythburn.py

     
    303303    checkCancelFlag()
    304304    return result
    305305
    306 def encodeMenu(background, tempvideo, music, musiclength, tempmovie, xmlfile, finaloutput, aspectratio):
     306def secondsToFrames(seconds):
     307    """Convert a time in seconds to a frame position"""
    307308    if videomode=="pal":
    308309        framespersecond=frameratePAL
    309310    else:
    310311        framespersecond=framerateNTSC
    311312
     313    frames=int(seconds * framespersecond)
     314    return frames
     315
     316def encodeMenu(background, tempvideo, music, musiclength, tempmovie, xmlfile, finaloutput, aspectratio, usejpeg):
     317    if videomode=="pal":
     318        framespersecond=frameratePAL
     319    else:
     320        framespersecond=framerateNTSC
     321
    312322    totalframes=int(musiclength * framespersecond)
    313323
    314     command = path_png2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \
    315                % (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)
     324    if usejpeg == True:
     325        command = path_jpeg2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \
     326                  % (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)
     327    else:
     328        command = path_png2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \
     329                  % (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)
    316330    result = runCommand(command)
    317331    if result<>0:
    318         fatalError("Failed while running png2yuv - %s" % command)
     332        fatalError("Failed while running png2yuv or jpeg2yuv - %s" % command)
    319333
    320     command = path_mplex[0] + " -f 8 -v 0 -o '%s' '%s' '%s'" % (tempmovie, tempvideo, music)
     334    command = path_mplex[0] + " -l %d -f 8 -v 0 -o '%s' '%s' '%s'" % (musiclength, tempmovie, tempvideo, music)
    321335    result = runCommand(command)
    322336    if result<>0:
    323337        fatalError("Failed while running mplex - %s" % command)
     
    533547                        'MythArchiveDateFormat',
    534548                        'MythArchiveTimeFormat',
    535549                        'ISO639Language0',
    536                         'ISO639Language1'
     550                        'ISO639Language1',
     551                        'MythArchiveJpeg2yuvCmd',
     552                        'MythArchiveTranscodeCmd'
    537553                        )) order by value"""
    538554
    539555    #write( sqlstatement)
     
    21672183    #Destroy the DOM and free memory
    21682184    dvddom.unlink()
    21692185
     2186def createEmptyPreviewFolder(videoitem):
     2187    previewfolder = os.path.join(getItemTempPath(videoitem), "preview")
     2188    if os.path.exists(previewfolder):
     2189        deleteAllFilesInFolder(previewfolder)
     2190        os.rmdir (previewfolder)
     2191    os.makedirs(previewfolder)
     2192    return previewfolder
     2193
     2194
     2195def generateVideoPreview(videoitem, itemonthispage, menuitem, starttime, menulength, previewfolder):
     2196    """generate thumnails for an preview in a menu"""
     2197
     2198    positionx = 9999
     2199    positiony = 9999
     2200    maskpicture = None
     2201
     2202    #run through the theme items and find any graphics that is using a movie identifier
     2203
     2204    for node in menuitem.childNodes:
     2205        if node.nodeName=="graphic":
     2206            if node.attributes["filename"].value == "%movie":
     2207
     2208                #This is an movie preview item so we need to generate the thumbnails
     2209
     2210                inputfile = os.path.join(getItemTempPath(videoitem),"stream.mv2")
     2211                outputfile = os.path.join(previewfolder, "preview-i%d-f" % itemonthispage)
     2212                previewsize = "%dx%d" %(getScaledAttribute(node, "w"), getScaledAttribute(node, "h"))
     2213                startframe=secondsToFrames(starttime)
     2214                endframe=int(secondsToFrames(int(starttime + menulength))-1)
     2215
     2216                splitcmd = path_transcode[0] + " -i %s -x auto,null -I 5 -Z %s -y im,null -F png -c %d-%d -o %s" %(inputfile, previewsize, startframe, endframe, outputfile)
     2217
     2218                result = runCommand(splitcmd)
     2219                if (result != 0):
     2220                    write( "split failed with code %d. Command = %s" % (result, splitcmd) )
     2221                positionx = getScaledAttribute(node, "x")
     2222                positiony = getScaledAttribute(node, "y")
     2223
     2224                #see if this graphics item has a mask
     2225
     2226                if node.hasAttribute("mask"):
     2227                    imagemaskfilename = getThemeFile(themeName, node.attributes["mask"].value)
     2228                    if node.attributes["mask"].value <> "" and doesFileExist(imagemaskfilename):
     2229                        maskpicture = Image.open(imagemaskfilename,"r").resize((getScaledAttribute(node, "w"), getScaledAttribute(node, "h")))
     2230                        maskpicture = maskpicture.convert("RGBA")
     2231
     2232    return (positionx, positiony, maskpicture)
     2233
     2234
    21702235def drawThemeItem(page, itemsonthispage, itemnum, menuitem, bgimage, draw,
    21712236                  bgimagemask, drawmask, highlightcolor, spumuxdom, spunode,
    21722237                  numberofitems, chapternumber, chapterlist):
     
    21872252        #Process each type of item to add it onto the background image
    21882253        if node.nodeName=="graphic":
    21892254            #Overlay graphic image onto background
    2190             imagefilename = expandItemText(infoDOM,node.attributes["filename"].value, itemnum, page, itemsonthispage, chapternumber, chapterlist)
    21912255
    2192             if doesFileExist(imagefilename):
    2193                 picture = Image.open(imagefilename,"r").resize((getScaledAttribute(node, "w"), getScaledAttribute(node, "h")))
    2194                 picture = picture.convert("RGBA")
    2195                 bgimage.paste(picture, (getScaledAttribute(node, "x"), getScaledAttribute(node, "y")), picture)
    2196                 del picture
    2197                 write( "Added image %s" % imagefilename)
     2256            #if this graphic item is a movie thumbnail then we dont process it here
     2257            if node.attributes["filename"].value == "%movie":
    21982258
     2259                #this is a movie item but we must still update the boundary box
     2260
    21992261                boundarybox=checkBoundaryBox(boundarybox, node)
    22002262            else:
    2201                 write( "Image file does not exist '%s'" % imagefilename)
     2263                imagefilename = expandItemText(infoDOM,node.attributes["filename"].value, itemnum, page, itemsonthispage, chapternumber, chapterlist)
    22022264
     2265                if doesFileExist(imagefilename) == False:
     2266                    if imagefilename == node.attributes["filename"].value:
     2267                        imagefilename = getThemeFile(themeName, node.attributes["filename"].value)
     2268                if doesFileExist(imagefilename):
     2269                    picture = Image.open(imagefilename,"r").resize((getScaledAttribute(node, "w"), getScaledAttribute(node, "h")))
     2270                    picture = picture.convert("RGBA")
     2271
     2272                    #see if an image mask exists
     2273                   
     2274                    imagemaskfilename = None
     2275                    if node.hasAttribute("mask"):
     2276                        if node.attribute["mask"].value <> "":
     2277                            imagemaskfilename = getThemeFile(themeName, node.attributes["mask"].value)
     2278                    if imagemaskfilename <> None and doesFileExist(imagemaskfilename):
     2279                        maskpicture = Image.open(imagemaskfilename,"r").resize((getScaledAttribute(node, "w"), getScaledAttribute(node, "h")))
     2280                        maskpicture = maskpicture.convert("RGBA")
     2281                        bgimage.paste(picture, (getScaledAttribute(node, "x"), getScaledAttribute(node, "y")), maskpicture)
     2282                        del maskpicture
     2283                    else:
     2284                        bgimage.paste(picture, (getScaledAttribute(node, "x"), getScaledAttribute(node, "y")), picture)
     2285                    del picture
     2286                    write( "Added image %s" % imagefilename)
     2287
     2288                    boundarybox=checkBoundaryBox(boundarybox, node)
     2289                else:
     2290                    write( "Image file does not exist '%s'" % imagefilename)
     2291
    22032292        elif node.nodeName=="text":
    22042293            #Apply some text to the background, including wordwrap if required.
    22052294            text=expandItemText(infoDOM,node.attributes["value"].value, itemnum, page, itemsonthispage,chapternumber,chapterlist)
     
    24692558    while itemnum <= numberofitems:
    24702559        write( "Menu page %s" % page)
    24712560
     2561        #need to check if any of the videos are flags as movies
     2562        #and if so generate the required preview
     2563
     2564        write( "Creating Preview Video")
     2565        previewitem = itemnum
     2566        itemsonthispage = 0
     2567        haspreview = False
     2568
     2569        previewx = []
     2570        previewy = []
     2571        previewmask = []
     2572        while previewitem <= numberofitems and itemsonthispage < itemsperpage:
     2573            menuitem=menuitems[ itemsonthispage ]
     2574            itemsonthispage+=1
     2575
     2576            #make sure the preview folder is empty and present
     2577
     2578            previewfolder = createEmptyPreviewFolder(previewitem)
     2579
     2580            #and then generate the preview if required (px=9999 means not required)
     2581
     2582            px, py, maskimage = generateVideoPreview(previewitem, itemsonthispage, menuitem, 0, menulength, previewfolder)
     2583            previewx.append(px)
     2584            previewy.append(py)
     2585            previewmask.append(maskimage)
     2586            if px != 9999:
     2587                haspreview = True
     2588
     2589            previewitem+=1
     2590
     2591        #previews generated but need to save where we started from
     2592        savedpreviewitem = itemnum
     2593
    24722594        #Default settings for this page
    24732595
    24742596        #Number of video items on this menu page
    24752597        itemsonthispage=0
    24762598
    24772599        #Load background image
    2478         bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    2479         draw=ImageDraw.Draw(bgimage)
     2600        #bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    24802601
     2602        #instead of loading the background image and drawing on it we now
     2603        #make a transparent image and draw all items on it. This overlay
     2604        #image is then added to the required background image when the
     2605        #preview items are added (the reason for this is it will assist
     2606        #if the background image is actually a video)
     2607
     2608        overlayimage=Image.new("RGBA",screensize)
     2609        draw=ImageDraw.Draw(overlayimage)
     2610
    24812611        #Create image to hold button masks (same size as background)
    2482         bgimagemask=Image.new("RGBA",bgimage.size)
     2612        bgimagemask=Image.new("RGBA",overlayimage.size)
    24832613        drawmask=ImageDraw.Draw(bgimagemask)
    24842614
    24852615        spumuxdom = xml.dom.minidom.parseString('<subpictures><stream><spu force="yes" start="00:00:00.0" highlight="" select="" ></spu></stream></subpictures>')
     
    24922622            itemsonthispage+=1
    24932623
    24942624            drawThemeItem(page, itemsonthispage,
    2495                         itemnum, menuitem, bgimage,
     2625                        itemnum, menuitem, overlayimage,
    24962626                        draw, bgimagemask, drawmask, highlightcolor,
    24972627                        spumuxdom, spunode, numberofitems, 0,"")
    24982628
     
    25002630            itemnum+=1
    25012631
    25022632        #Save this menu image and its mask
     2633        bgimage=Image.open(backgroundfilename,"r").resize(screensize)
     2634        bgimage.paste(overlayimage, (0,0), overlayimage)
     2635
    25032636        bgimage.save(os.path.join(getTempPath(),"background-%s.png" % page),"PNG",quality=99,optimize=0,dpi=screendpi)
    25042637        bgimagemask.save(os.path.join(getTempPath(),"backgroundmask-%s.png" % page),"PNG",quality=99,optimize=0,dpi=screendpi)
    25052638
     2639        #now that the base background has been made and all the previews generated
     2640        #we need to add the previews to the background
     2641        #Assumption: We assume that there is nothing in the location of where the items go (ie, no text on the images)
     2642
     2643        itemsonthispage = 0
     2644
     2645        numframes=secondsToFrames(menulength)
     2646
     2647        #numframes should be the number of preview images that have been created
     2648
     2649        if haspreview == True:
     2650            # only generate the preview video if required.
     2651
     2652            write( "Generation the chapter images" )
     2653            framenum = 0
     2654            while framenum < numframes:
     2655                previewitem = savedpreviewitem
     2656                itemsonthispage = 0
     2657                while previewitem <= numberofitems and itemsonthispage < itemsperpage:
     2658                    itemsonthispage+=1
     2659                    if previewx[itemsonthispage-1] != 9999:
     2660                        previewpath = os.path.join(getItemTempPath(previewitem), "preview")
     2661                        previewfile = "preview-i%d-f%06d.png" % (itemsonthispage, framenum)
     2662                        imagefile = os.path.join(previewpath, previewfile)
     2663
     2664                        if doesFileExist(imagefile):
     2665                            picture = Image.open(imagefile, "r")
     2666                            picture = picture.convert("RGBA")
     2667                            imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % itemsonthispage)
     2668                            if previewmask[itemsonthispage-1] != None:
     2669                                bgimage.paste(picture, (previewx[itemsonthispage-1], previewy[itemsonthispage-1]), previewmask[itemsonthispage-1])
     2670                            else:
     2671                                bgimage.paste(picture, (previewx[itemsonthispage-1], previewy[itemsonthispage-1]))
     2672                            del picture
     2673                    previewitem+=1
     2674                #-> slow bgimage.save(os.path.join(getTempPath(),"background-%s-f%06d.png" % (page, framenum)),"PNG",quality=100,optimize=0,dpi=screendpi)
     2675                bgimage.save(os.path.join(getTempPath(),"background-%s-f%06d.jpg" % (page, framenum)),"JPEG",dpi=screendpi)
     2676                framenum+=1
     2677
    25062678## Experimental!
    25072679##        for i in range(1,750):
    25082680##            bgimage.save(os.path.join(getTempPath(),"background-%s-%s.ppm" % (page,i)),"PPM",quality=99,optimize=0)
     
    25152687        del bgimage
    25162688        del drawmask
    25172689        del bgimagemask
     2690        del overlayimage
     2691        del previewx
     2692        del previewy
     2693        del previewmask
    25182694
    25192695        #write( spumuxdom.toprettyxml())
    25202696        WriteXMLToFile (spumuxdom,os.path.join(getTempPath(),"spumux-%s.xml" % page))
     
    25252701            aspect_ratio = 3
    25262702
    25272703        write("Encoding Menu Page %s using aspect ratio '%s'" % (page, mainmenuAspectRatio))
    2528         encodeMenu(os.path.join(getTempPath(),"background-%s.png" % page),
    2529                     os.path.join(getTempPath(),"temp.m2v"),
    2530                     getThemeFile(themeName,menumusic),
    2531                     menulength,
    2532                     os.path.join(getTempPath(),"temp.mpg"),
    2533                     os.path.join(getTempPath(),"spumux-%s.xml" % page),
    2534                     os.path.join(getTempPath(),"menu-%s.mpg" % page),
    2535                     aspect_ratio)
     2704        if haspreview == True:
     2705            encodeMenu(os.path.join(getTempPath(),"background-%s-f%%06d.jpg" % page),
     2706                        os.path.join(getTempPath(),"temp.m2v"),
     2707                        getThemeFile(themeName,menumusic),
     2708                        menulength,
     2709                        os.path.join(getTempPath(),"temp.mpg"),
     2710                        os.path.join(getTempPath(),"spumux-%s.xml" % page),
     2711                        os.path.join(getTempPath(),"menu-%s.mpg" % page),
     2712                        aspect_ratio,
     2713                        True)
     2714        else:
     2715            encodeMenu(os.path.join(getTempPath(),"background-%s.png" % page),
     2716                        os.path.join(getTempPath(),"temp.m2v"),
     2717                        getThemeFile(themeName,menumusic),
     2718                        menulength,
     2719                        os.path.join(getTempPath(),"temp.mpg"),
     2720                        os.path.join(getTempPath(),"spumux-%s.xml" % page),
     2721                        os.path.join(getTempPath(),"menu-%s.mpg" % page),
     2722                        aspect_ratio,
     2723                        False)
    25362724
    25372725        #Tidy up temporary files
    25382726####        os.remove(os.path.join(getTempPath(),"spumux-%s.xml" % page))
     
    25932781        #Default settings for this page
    25942782
    25952783        #Load background image
    2596         bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    2597         draw=ImageDraw.Draw(bgimage)
     2784        #bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    25982785
     2786        #instead of loading the background image and drawing on it we now
     2787        #make a transparent image and draw all items on it. This overlay
     2788        #image is then added to the required background image when the
     2789        #preview items are added (the reason for this is it will assist
     2790        #if the background image is actually a video)
     2791
     2792        overlayimage=Image.new("RGBA",screensize)
     2793        draw=ImageDraw.Draw(overlayimage)
     2794
    25992795        #Create image to hold button masks (same size as background)
    2600         bgimagemask=Image.new("RGBA",bgimage.size)
     2796        bgimagemask=Image.new("RGBA",overlayimage.size)
    26012797        drawmask=ImageDraw.Draw(bgimagemask)
    26022798
    26032799        spumuxdom = xml.dom.minidom.parseString('<subpictures><stream><spu force="yes" start="00:00:00.0" highlight="" select="" ></spu></stream></subpictures>')
     
    26052801
    26062802        #Extracting the thumbnails for the video takes an incredibly long time
    26072803        #need to look at a switch to disable this. or not use FFMPEG
     2804
    26082805        chapterlist=createVideoChapters(page,itemsperpage,getLengthOfVideo(page),True)
    26092806        chapterlist=string.split(chapterlist,",")
    26102807
     2808        #now need to preprocess the menu to see if any preview videos are required
     2809        #This must be done on an individual basis since we do the resize as the
     2810        #images are extracted.
     2811
     2812        #first make sure the preview folder is empty and present
     2813
     2814        previewfolder = createEmptyPreviewFolder(page)
     2815
     2816        haspreview = False
     2817
     2818        previewsegment=int(getLengthOfVideo(page) / itemsperpage)
     2819        previewtime = 0
     2820        previewchapter = 0
     2821        previewx = []
     2822        previewy = []
     2823        previewmask = []
     2824        while previewchapter < itemsperpage:
     2825            menuitem=menuitems[ previewchapter ]
     2826
     2827            #generate the preview if required (px=9999 means not required)
     2828
     2829            px, py, maskimage = generateVideoPreview(page, previewchapter, menuitem, previewtime, menulength, previewfolder)
     2830            previewx.append(px)
     2831            previewy.append(py)
     2832            previewmask.append(maskimage)
     2833            if px != 9999:
     2834                haspreview = True
     2835
     2836            previewchapter+=1
     2837            previewtime+=previewsegment
     2838
    26112839        #Loop through all the items on this menu page
    26122840        chapter=0
    26132841        while chapter < itemsperpage:  # and itemsonthispage < itemsperpage:
    26142842            menuitem=menuitems[ chapter ]
    26152843            chapter+=1
    26162844
    2617             drawThemeItem(page, itemsperpage, page, menuitem, 
    2618                         bgimage, draw,
     2845            drawThemeItem(page, itemsperpage, page, menuitem,
     2846                        overlayimage, draw,
    26192847                        bgimagemask, drawmask, highlightcolor,
    2620                         spumuxdom, spunode, 
     2848                        spumuxdom, spunode,
    26212849                        999, chapter, chapterlist)
    26222850
    26232851        #Save this menu image and its mask
     2852        bgimage=Image.open(backgroundfilename,"r").resize(screensize)
     2853        bgimage.paste(overlayimage, (0,0), overlayimage)
    26242854        bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s.png" % page),"PNG",quality=99,optimize=0,dpi=screendpi)
    26252855
    26262856        bgimagemask.save(os.path.join(getTempPath(),"chaptermenumask-%s.png" % page),"PNG",quality=99,optimize=0,dpi=screendpi)
    26272857
     2858        if haspreview == True:
     2859            numframes=secondsToFrames(menulength)
     2860
     2861            #numframes should be the number of preview images that have been created
     2862
     2863            write( "Generation the sub-menu images" )
     2864            framenum = 0
     2865            while framenum < numframes:
     2866                previewchapter = 0
     2867                while previewchapter < itemsperpage:
     2868                    if previewx[previewchapter] != 9999:
     2869                        previewpath = os.path.join(getItemTempPath(page), "preview")
     2870                        previewfile = "preview-i%d-f%06d.png" % (previewchapter, framenum)
     2871                        imagefile = os.path.join(previewpath, previewfile)
     2872
     2873                        if doesFileExist(imagefile):
     2874                            picture = Image.open(imagefile, "r")
     2875                            picture = picture.convert("RGBA")
     2876                            imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % previewchapter)
     2877                            if previewmask[previewchapter] != None:
     2878                                bgimage.paste(picture, (previewx[previewchapter], previewy[previewchapter]), previewmask[previewchapter])
     2879                            else:
     2880                                bgimage.paste(picture, (previewx[previewchapter], previewy[previewchapter]))
     2881                            del picture
     2882                    previewchapter+=1
     2883                bgimage.save(os.path.join(getTempPath(),"chaptermenu-%s-f%06d.jpg" % (page, framenum)),"JPEG",dpi=screendpi)
     2884                framenum+=1
     2885
    26282886        spumuxdom.documentElement.firstChild.firstChild.setAttribute("select",os.path.join(getTempPath(),"chaptermenumask-%s.png" % page))
    26292887        spumuxdom.documentElement.firstChild.firstChild.setAttribute("highlight",os.path.join(getTempPath(),"chaptermenumask-%s.png" % page))
    26302888
     
    26332891        del bgimage
    26342892        del drawmask
    26352893        del bgimagemask
     2894        del overlayimage
     2895        del previewx
     2896        del previewy
     2897        del previewmask
    26362898
    26372899        #write( spumuxdom.toprettyxml())
    26382900        WriteXMLToFile (spumuxdom,os.path.join(getTempPath(),"chapterspumux-%s.xml" % page))
     
    26482910                aspect_ratio = '2'
    26492911
    26502912        write("Encoding Chapter Menu Page %s using aspect ratio '%s'" % (page, chaptermenuAspectRatio))
    2651         encodeMenu(os.path.join(getTempPath(),"chaptermenu-%s.png" % page),
    2652                     os.path.join(getTempPath(),"temp.m2v"),
    2653                     getThemeFile(themeName,menumusic),
    2654                     menulength,
    2655                     os.path.join(getTempPath(),"temp.mpg"),
    2656                     os.path.join(getTempPath(),"chapterspumux-%s.xml" % page),
    2657                     os.path.join(getTempPath(),"chaptermenu-%s.mpg" % page),
    2658                     aspect_ratio)
    26592913
     2914        if haspreview == True:
     2915            encodeMenu(os.path.join(getTempPath(),"chaptermenu-%s-f%%06d.jpg" % page),
     2916                        os.path.join(getTempPath(),"temp.m2v"),
     2917                        getThemeFile(themeName,menumusic),
     2918                        menulength,
     2919                        os.path.join(getTempPath(),"temp.mpg"),
     2920                        os.path.join(getTempPath(),"chapterspumux-%s.xml" % page),
     2921                        os.path.join(getTempPath(),"chaptermenu-%s.mpg" % page),
     2922                        aspect_ratio,
     2923                        True)
     2924        else:
     2925            encodeMenu(os.path.join(getTempPath(),"chaptermenu-%s.png" % page),
     2926                        os.path.join(getTempPath(),"temp.m2v"),
     2927                        getThemeFile(themeName,menumusic),
     2928                        menulength,
     2929                        os.path.join(getTempPath(),"temp.mpg"),
     2930                        os.path.join(getTempPath(),"chapterspumux-%s.xml" % page),
     2931                        os.path.join(getTempPath(),"chaptermenu-%s.mpg" % page),
     2932                        aspect_ratio,
     2933                        False)
     2934
    26602935        #Tidy up
    26612936####        os.remove(os.path.join(getTempPath(),"chaptermenu-%s.png" % page))
    26622937####        os.remove(os.path.join(getTempPath(),"chaptermenumask-%s.png" % page))
     
    27032978    while itemnum <= numberofitems:
    27042979        write( "Creating details page for %s" % itemnum)
    27052980
     2981        #make sure the preview folder is empty and present
     2982
     2983        previewfolder = createEmptyPreviewFolder(itemnum)
     2984        haspreview = False
     2985
     2986        #and then generate the preview if required (px=9999 means not required)
     2987
     2988        previewx, previewy, previewmask = generateVideoPreview(itemnum, 1, detailnode, 0, menulength, previewfolder)
     2989        if previewx != 9999:
     2990            haspreview = True
     2991
    27062992        #Load background image
    2707         bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    2708         draw=ImageDraw.Draw(bgimage)
     2993        #bgimage=Image.open(backgroundfilename,"r").resize(screensize)
    27092994
     2995        #instead of loading the background image and drawing on it we now
     2996        #make a transparent image and draw all items on it. This overlay
     2997        #image is then added to the required background image when the
     2998        #preview items are added (the reason for this is it will assist
     2999        #if the background image is actually a video)
     3000
     3001        overlayimage=Image.new("RGBA",screensize)
     3002        draw=ImageDraw.Draw(overlayimage)
     3003
    27103004        spumuxdom = xml.dom.minidom.parseString('<subpictures><stream><spu force="yes" start="00:00:00.0" highlight="" select="" ></spu></stream></subpictures>')
    27113005        spunode = spumuxdom.documentElement.firstChild.firstChild
    27123006
    2713         drawThemeItem(0, 0, itemnum, detailnode, bgimage, draw, None, None,
     3007        drawThemeItem(0, 0, itemnum, detailnode, overlayimage, draw, None, None,
    27143008                      "", spumuxdom, spunode, numberofitems, 0, "")
    27153009
    27163010        #Save this details image
     3011        bgimage=Image.open(backgroundfilename,"r").resize(screensize)
     3012        bgimage.paste(overlayimage, (0,0), overlayimage)
    27173013        bgimage.save(os.path.join(getTempPath(),"details-%s.png" % itemnum),"PNG",quality=99,optimize=0,dpi=screendpi)
    27183014
     3015        if haspreview == True:
     3016            numframes=secondsToFrames(menulength)
     3017
     3018            #numframes should be the number of preview images that have been created
     3019
     3020            write( "Generation the detail images" )
     3021            framenum = 0
     3022            while framenum < numframes:
     3023                if previewx != 9999:
     3024                    previewpath = os.path.join(getItemTempPath(itemnum), "preview")
     3025                    previewfile = "preview-i%d-f%06d.png" % (1, framenum)
     3026                    imagefile = os.path.join(previewpath, previewfile)
     3027
     3028                    if doesFileExist(imagefile):
     3029                        picture = Image.open(imagefile, "r")
     3030                        picture = picture.convert("RGBA")
     3031                        imagemaskfile = os.path.join(previewpath, "mask-i%d.png" % 1)
     3032                        if previewmask != None:
     3033                            bgimage.paste(picture, (previewx, previewy), previewmask)
     3034                        else:
     3035                            bgimage.paste(picture, (previewx, previewy))
     3036                        del picture
     3037                bgimage.save(os.path.join(getTempPath(),"details-%s-f%06d.jpg" % (itemnum, framenum)),"JPEG",dpi=screendpi)
     3038                framenum+=1
     3039
     3040
    27193041        #Release large amounts of memory ASAP !
    27203042        del draw
    27213043        del bgimage
     
    27293051        WriteXMLToFile (spumuxdom,os.path.join(getTempPath(),"detailsspumux-%s.xml" % itemnum))
    27303052
    27313053        write("Encoding Details Page %s" % itemnum)
    2732         encodeMenu(os.path.join(getTempPath(),"details-%s.png" % itemnum),
    2733                     os.path.join(getTempPath(),"temp.m2v"),
    2734                     getThemeFile(themeName,menumusic),
    2735                     menulength,
    2736                     os.path.join(getTempPath(),"temp.mpg"),
    2737                     "",
    2738                     os.path.join(getTempPath(),"details-%s.mpg" % itemnum),
    2739                     aspect_ratio)
     3054        if haspreview == True:
     3055            encodeMenu(os.path.join(getTempPath(),"details-%s-f%%06d.jpg" % itemnum),
     3056                        os.path.join(getTempPath(),"temp.m2v"),
     3057                        getThemeFile(themeName,menumusic),
     3058                        menulength,
     3059                        os.path.join(getTempPath(),"temp.mpg"),
     3060                        "",
     3061                        os.path.join(getTempPath(),"details-%s.mpg" % itemnum),
     3062                        aspect_ratio,
     3063                        True)
     3064        else:
     3065            encodeMenu(os.path.join(getTempPath(),"details-%s.png" % itemnum),
     3066                        os.path.join(getTempPath(),"temp.m2v"),
     3067                        getThemeFile(themeName,menumusic),
     3068                        menulength,
     3069                        os.path.join(getTempPath(),"temp.mpg"),
     3070                        "",
     3071                        os.path.join(getTempPath(),"details-%s.mpg" % itemnum),
     3072                        aspect_ratio,
     3073                        False)
    27403074
    27413075        #On to the next item
    27423076        itemnum+=1
     
    33713705                    if os.path.exists(folder):
    33723706                        #Remove all the files first
    33733707                        deleteAllFilesInFolder(folder)
     3708                        previewfolder = os.path.join(folder, "preview")
     3709                        if os.path.exists(previewfolder):
     3710                            deleteAllFilesInFolder(previewfolder)
     3711                            os.rmdir(previewfolder)
    33743712                        #Remove the folder
    33753713                        os.rmdir (folder)
    33763714                    os.makedirs(folder)
     
    35663904path_png2yuv = [defaultsettings["MythArchivePng2yuvCmd"], os.path.split(defaultsettings["MythArchivePng2yuvCmd"])[1]]
    35673905path_spumux = [defaultsettings["MythArchiveSpumuxCmd"], os.path.split(defaultsettings["MythArchiveSpumuxCmd"])[1]]
    35683906path_mpeg2enc = [defaultsettings["MythArchiveMpeg2encCmd"], os.path.split(defaultsettings["MythArchiveMpeg2encCmd"])[1]]
     3907path_jpeg2yuv = [defaultsettings["MythArchiveJpeg2yuvCmd"], os.path.split(defaultsettings["MythArchiveJpeg2yuvCmd"])[1]]
     3908path_transcode = [defaultsettings["MythArchiveTranscodeCmd"], os.path.split(defaultsettings["MythArchiveTranscodeCmd"])[1]]
    35693909
    35703910try:
    35713911    try: