def extractfragment(inputs,outputs,options={},callbacks=[]):
    try:
	mfileid=inputs[0]
	videopath=_get_mfile(mfileid)

	tempout=tempfile.NamedTemporaryFile(suffix=".mp4")
	logging.info("temp file: %s" % tempout.name)

	intime=options["intime"]
	fragmentlength=options["fragmentlength"]

	# extract 'fragmentlength' video fragment starting at 'intime' (seconds)
	# ffmpeg -ss 00:00:30.0 -t 00:00:10.0 -i input.wmv -acodec copy -vcodec copy -async 1 output.wmv
	args = ["ffmpeg -y -ss",intime,"-t",fragmentlength,"-i",videopath,"-acodec copy -vcodec copy -async 1",tempout.name]
	cmd = " ".join(args)
	logging.info(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
	(stdout,stderr) = p.communicate()
	logging.info(stdout)

	if p.returncode != 0:
		raise Exception("Command %s exited with code %d. Stderr: %s" % (cmd, p.returncode, stderr))

        # make job outputs available
        _save_joboutput(outputs[0], tempout)

        for callback in callbacks:
            subtask(callback).delay()

        return {"success":True, "message":"extractfragment successful"}
    except Exception as e:
        logging.info("Error with extractfragment %s." % e)
        raise e
def ffmbc(inputs,outputs,options={},callbacks=[]):
    try:
	mfileid=inputs[0]
	videopath=_get_mfile(mfileid)

	tempout=tempfile.NamedTemporaryFile()
	logging.info("temp file: %s" % tempout.name)

	ffmpeg_args=options["args"]

	# extract all I frames that are no closer than 5 seconds apart
	args = ["ffmbc -y -i",videopath,ffmpeg_args,tempout.name]
	cmd = " ".join(args)
	logging.info(cmd)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
	(stdout,stderr) = p.communicate()
	logging.info(stdout)

	if p.returncode != 0:
		raise Exception("Command %s exited with code %d. Stderr: %s" % (cmd, p.returncode, stderr))

        # make job outputs available
        _save_joboutput(outputs[0], tempout)

        for callback in callbacks:
            subtask(callback).delay()

        return {"success":True, "message":"ffmbc successful"}
    except Exception as e:
        logging.info("Error with ffmbc %s." % e)
        raise e
Exemple #3
0
def dumbtask(inputs,outputs,options={},callbacks=[]):
    logging.info("Processing dumb task")
    try:
        mfileid = inputs[0]
        filepath = _get_mfile(mfileid)

        toutfile = tempfile.NamedTemporaryFile(delete=False,suffix=".txt")
        joboutput = outputs[0]

        retcode = subprocess.call(["wc",filepath,toutfile.name])
        _save_joboutput(joboutput,toutfile)

        return {"success":True,"message":"Dumb task successful"}

    except Exception as e:
        logging.info("Error with dumb task %s" % e)
        raise e
Exemple #4
0
def swirl(inputs,outputs,options={},callbacks=[]):
    try:
        mfileid = inputs[0]

        path = _get_mfile(mfileid)

        logging.info("Swirling image for %s (%s)" % (input, path))
        img = PythonMagick.Image()
        img.read(str(path))
        img.swirl(90)

        # Create swirled image as job output
        toutfile = tempfile.NamedTemporaryFile(delete=False,suffix=".jpg")
        img.write(toutfile.name)
        joboutput = outputs[0]
        _save_joboutput(joboutput,toutfile)

        return {"success":True,"message":"Swirl successful"}
    except Exception ,e:
        logging.info("Error with swirl %s" % e)
Exemple #5
0
def imodel(inputs,outputs,options={},callbacks=[]):
        mfileid = inputs[0]
        path = _get_mfile(mfileid)
        logging.info("CWD: %s" % os.getcwd())
        logging.info("Running imodel on %s" % (path))

	# Run iModel in a temporary directory
	logging.info(os.environ)
        #imodel_home = "/opt/iModel-1.0-beta-3-SNAPSHOT"
        #imodel_home = os.environ["IMODEL_HOME"]
	imodel_home = settings.IMODEL_HOME
        logging.info("Running iModel from %s" % imodel_home)
	(mfile_dir, mfile_name) = os.path.split(path)
        # XXX: configuration.txt must be in CWD
        # XXX: Runtime arguments should not be provided in a file
	tempdir = tempfile.mkdtemp()
	logging.info("iModel temp dir: %s" % (tempdir))
        shutil.copy("imodel/configuration.txt", tempdir)
        shutil.copy(path, tempdir)
        p = subprocess.Popen(["java", "-cp", imodel_home + ":" + imodel_home+"/lib/*:" + imodel_home+"/bin", "uk.ac.soton.itinnovation.prestoprime.imodel.batch.start.StartArchiveSystemModel", mfile_name], cwd=tempdir, stdout=subprocess.PIPE)

        # save stdout
	stdoutfile = open(tempdir+"/stdout", 'w')
        logging.info("Temp file for stdout: %s" % (stdoutfile.name))
        (stdout, stderr) = p.communicate()
        stdoutfile.write(stdout)
        stdoutfile.close()
        _save_joboutput(outputs[1], stdoutfile)

	# Process results
	import sys
	sys.path.append("imodel")
	import parseimodel
	processedresultsfilename = tempdir+"/data.csv"
	parseimodel.parse(tempdir+"/outputSystemPerformance.log", processedresultsfilename)
        joboutput = outputs[0]
	processedresultsfile = open(processedresultsfilename, 'r')
        _save_joboutput(joboutput, processedresultsfile)

        return {"success":True,"message":"iModel simulation successful"}
def extractkeyframes(inputs,outputs,options={},callbacks=[]):
    try:
	mfileid=inputs[0]
	videopath=_get_mfile(mfileid)

	tempdir = tempfile.mkdtemp()
	logging.info("temp dir: %s" % (tempdir))

	interval = options['interval']

	# extract all I frames that are no closer than 'interval'  seconds apart
	ffmpeg_args = "-vf select='eq(pict_type\,I)*(isnan(prev_selected_t)+gte(t-prev_selected_t\,%s))' -vsync 0 -f image2" % (interval)
        args = ["ffmpeg -i",videopath, ffmpeg_args, tempdir+"/%09d.jpg"]
	cmd = " ".join(args)
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
	(stdout,stderr) = p.communicate()
	logging.info(stdout)

	if p.returncode != 0:
		raise Exception("Command %s exited with code %d. Stderr: %s" % (cmd, p.returncode, stderr))

	results_file = tempdir+"/results.zip"
	zipdir(tempdir, results_file)			

	results = open(results_file, 'r')
        # make job outputs available
        _save_joboutput(outputs[0], results)
        results.close()

        for callback in callbacks:
            subtask(callback).delay()

        return {"success":True, "message":"keyframe extraction successful"}
    except Exception as e:
        logging.info("Error with keyframe extraction %s" % e)
        raise e