Пример #1
0
 def selectTiers(self,tierSelection, canvasTier):
     file_opt = options =  {}
     options['filetypes'] = [('eaf files', '.eaf'), ('all files', '.*')]
     file = tkFileDialog.askopenfilename(**options)
     try:
         self.allTiers = pyelan.tierSet(file=file)
     except pyelan.noMediaError, e:
         #error if there are no tiers selected.
         tkMessageBox.showwarning(
             "No media found",
             "Could not find the media attached to the ELAN file (path:"+e.filename+"). Please open the ELAN file, find the media, and then save it again.")
Пример #2
0
 def selectTiers(self, tierSelection, canvasTier):
     file_opt = options = {}
     options['filetypes'] = [('eaf files', '.eaf'), ('all files', '.*')]
     file = tkFileDialog.askopenfilename(**options)
     try:
         self.allTiers = pyelan.tierSet(file=file)
     except pyelan.noMediaError, e:
         #error if there are no tiers selected.
         tkMessageBox.showwarning(
             "No media found",
             "Could not find the media attached to the ELAN file (path:" +
             e.filename +
             "). Please open the ELAN file, find the media, and then save it again."
         )
Пример #3
0
    raise Exception("The destination directory (" + str(destDir) +
                    ") does not exist. Please create it and try again.")

eafFiles = sys.argv[2:]
# eafFiles = ['../../elanFiles/GRI_016/GRI_016-SESSION_001-TRIAL_006.eaf']
for eafFile in eafFiles:
    eafPath = os.path.dirname(eafFile)
    basename = os.path.splitext(os.path.basename(eafFile))[0]

    print("Starting on file " + eafFile)

    # fix links, but supress warnings about those links for cleaner output
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")

        fl = pyelan.tierSet(file=eafFile)
        fl.fixLinks(
            searchDir=os.path.sep.join([destDir, "..", "Clipped Video"]))
        fl.fixLinks(searchDir=os.path.sep.join([destDir, "..", "AUDIO"]))
        fl.fixLinks(
            searchDir=os.path.sep.join([destDir, "..", "elanFilesCompleted"]))

    # find time series files that are linked to the eaf.
    tsconfs = filter(lambda s: re.match(".*tsconf.xml", s), fl.linkedFiles)
    if len(tsconfs) > 1:
        warnings.warn("There's more than one tsconf file")

    # setup a list to store warnings about tsconf files in. This will allow us to throw warnings about serious errors with tsconf files, but not for simply not finding files (which are being ignored)
    tsconfWarnings = []

    for tsconf in tsconfs:
Пример #4
0
    print("Staring to work on file: "+str(eafFile))
    # backup eaf file
    # is there a better way to backup old files? this will overwrite each other if used sequentially
    shutil.copyfile(eafFile, '.'.join([eafFile, "bak"]))
    eafPath = os.path.dirname(eafFile)

    # if  there is no path (just a filename was given), setup current directory as path.
    if eafPath == "":
        eafPath = "."

    # ignore errors issued by pyelan, the success of locating the files is checked later
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")

        # setup a pyelan tierSet object from the elan file
        fl = pyelan.tierSet(file = eafFile)

        # search for linked files in specific directories one after another. This works because the fixLinks function in pyelan does not try to search for a file if it's already reachable. In other words, each search finds a subset of the links, but the found links aren't overwriten by subsiquent searches.
        fl.fixLinks(searchDir = os.path.sep.join([eafPath,"../..","Clipped Video"]))
        fl.fixLinks(searchDir = os.path.sep.join([eafPath,"../..","AUDIO"]))
        fl.fixLinks(searchDir = os.path.sep.join([eafPath,"../..","mocapCSVs"]))
        fl.fixLinks(searchDir = os.path.sep.join([eafPath,]))

        # Iterate over the tsconf files that are linked, and find files linked there as well.
        for tsconf in filter(lambda s: re.match(".*tsconf.xml", s), fl.linkedFiles):
            print("Staring to work on tsconf file: "+os.path.basename(tsconf))
            # change TSCONFS to be in the EAF files' directory if they aren't here, this will be an issue.
            tsconf = os.path.sep.join([os.path.abspath(eafPath),os.path.basename(tsconf)])
            if os.path.isfile(tsconf):
                # if the file was found
                if verbose: print("The tsconf file "+tsconf+" was found.")
Пример #5
0
def processor(dataIn, outdir, slowDown=2, maskImage="masker/masks/green852x480.jpg"):
    for videoIn in dataIn:
        fps = 59.94

        # setup temp directories
        if os.path.exists("tmp"):
            shutil.rmtree("tmp")
        os.makedirs("tmp")

        if not os.path.exists(outdir):
            os.makedirs(outdir)
        #
        # extract frames of the video.
        # ffmpeg -i originalVideos/730.mp4 -q:v 1 -r 59.94 -f image2 testImg/image-%5d.png png is much bigger, but seems to be more faithful.
        output = subprocess.check_output(["ffmpeg", "-i", "originalVideos/"+videoIn, "-q:v", "1", "-r", str(fps), "-ss", str(dataIn[videoIn][4]/1000.), "-f", "image2", "-y", "tmp/image-%5d.png"])

        if not os.path.exists(os.path.join(outdir,'holdsOnly')):
            os.makedirs(os.path.join(outdir,'holdsOnly'))

        transMaskedfile = os.path.join(outdir,'holdsOnly','stim'+videoIn)
        transMasked = imgSplicer(videoIn, wordDur=dataIn[videoIn][0], masks=dataIn[videoIn][3], outpath=transMaskedfile, slowDown=slowDown, fpsin=fps, maskImage=maskImage)

        if not os.path.exists(os.path.join(outdir,'transOnly')):
            os.makedirs(os.path.join(outdir,'transOnly'))

        holdsMaskedfile = os.path.join(outdir,'transOnly','stim'+videoIn)
        holdsMasked = imgSplicer(videoIn, wordDur=dataIn[videoIn][0], masks=dataIn[videoIn][2], outpath=holdsMaskedfile, slowDown=slowDown, maskImage=maskImage)

        if not os.path.exists(os.path.join(outdir,'allClear')):
            os.makedirs(os.path.join(outdir,'allClear'))

        clearfile = os.path.join(outdir,'allClear','stim'+videoIn)
        imgSplicer(videoIn, wordDur=dataIn[videoIn][0], masks=None, outpath=clearfile, slowDown=slowDown, maskImage=maskImage)

        if not os.path.exists(os.path.join(outdir,'elanFiles')):
            os.makedirs(os.path.join(outdir,'elanFiles'))

        saveDir = os.path.join(outdir, "elanFiles")
        basename = os.path.splitext(videoIn)[0]
        media = [clearfile, holdsMaskedfile, transMaskedfile]

        if slowDown == 2:
            holdMasksTier = pyelan.tier("hold masks", [pyelan.annotation(begin=beg*slowDown, end=end*slowDown, value="") for beg, end in holdsMasked] )
            transMasksTier = pyelan.tier("trans masks", [pyelan.annotation(begin=beg*slowDown, end=end*slowDown, value="") for beg, end in transMasked])
            holdsAnnos = [pyelan.annotation(begin=beg*slowDown, end=end*slowDown, value="") for beg, end in dataIn[videoIn][2]]
        elif slowDown == 1:
            adjust = int(round((1000/59.94)*4))
            # add one frame('s worth of miliseconds) to each of the annotations to make up for adding one above.
            holdMasksTier = pyelan.tier("hold masks", [pyelan.annotation(begin=(beg+adjust)*slowDown, end=(end+adjust)*slowDown, value="") for beg, end in holdsMasked] )
            transMasksTier = pyelan.tier("trans masks", [pyelan.annotation(begin=(beg+adjust)*slowDown, end=(end+adjust)*slowDown, value="") for beg, end in transMasked])
            holdsAnnos = [pyelan.annotation(begin=(beg+adjust)*slowDown, end=(end+adjust)*slowDown, value="") for beg, end in dataIn[videoIn][2]]

        for n in range(0, len(holdsAnnos)):
            holdsAnnos[n].value = dataIn[videoIn][1][n]

        holdsTier = pyelan.tier("holds", holdsAnnos)

        tiers = [holdsTier, holdMasksTier, transMasksTier]

        allTiers = pyelan.tierSet(media=media, tiers=tiers)

        elanOut = os.path.join(saveDir,'.'.join([basename,"eaf"]))

        out = pyelan.tierSet.elanOut(allTiers, dest=elanOut)

        out.write(elanOut)

        shutil.rmtree("tmp")