X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=cis%2Fcisd.py;h=d4c20deff7e3d8ab18da506f8b41a59304eb7298;hb=3cf4f616f7d4095623ad5eae5db9fb1149ee1238;hp=aa50b33aa4d9226a14ad071e4a55d35b4d23a2e9;hpb=42cb85273f6ef35a40c183f1184313bbc06afa05;p=living-lab-site.git diff --git a/cis/cisd.py b/cis/cisd.py index aa50b33..d4c20de 100755 --- a/cis/cisd.py +++ b/cis/cisd.py @@ -1,10 +1,150 @@ #!/usr/bin/env python import sys +import os +import time +import threading +from Queue import Queue + import config -import cis_exceptions +import bt + + +class CIWorker(threading.Thread): + """ + Content Ingestion Worker. A class which executes content ingestion jobs + on a separate thread. + + CIWorker shares a Queue with its master where jobs are submitted. + """ + + def __init__(self, queue): + threading.Thread.__init__(self) + + self.queue = queue + + def run(self): + while True: + job = self.queue.get() + + # * TRANSFER RAW VIDEO IN + file_transfer = config.FILE_TRANSFERER_CLASS( \ + 'tmp/raw', config.INPUT_PATH) + file_transfer.get([job.raw_video]) + file_transfer.close() + + # * TRANSCODE RAW VIDEO + transcoder = config.TRANSCODER_CLASS(input_file = job.raw_video, \ + name = job.name, prog_bin = config.TRANSCODER_BIN) + + # Transcode the raw video in each requested format. + for transcode_config in job.transcode_configs: + transcode_config['output_file'] = transcoder.transcode( \ + container = transcode_config.container, \ + a_codec = transcode_config.a_codec, \ + a_bitrate = transcode_config.a_bitrate, \ + a_samplingrate = transcode_config.a_samplingrate, \ + a_channels = transcode_config.a_channels, \ + v_codec = transcode_config.v_codec, \ + v_bitrate = transcode_config.v_bitrate, \ + v_framerate = transcode_config.v_framerate, \ + v_resolution = transcode_config.v_resolution, \ + v_dar = transcode_config.dar) + + # * EXTRACT THUMBNAIL IMAGES + thumb_extractor = config.THUMB_EXTRACTOR_CLASS( \ + input_file = job.raw_video, name = job.name, \ + prog_bin = config.THUMB_EXTRACTOR_BIN) + # TODO thumbnail extraction type must be got from input + thumb_extractor.extract_random_thumb() + print thumb_extractor.extract_summary_thumbs(5) + + + queue.task_done() + + +class TranscodeConfig: + """ + Structure that contains parameters for a transcoding procedure. + """ + + def __init__(self, container, a_codec, v_codec, + a_bitrate, a_samplingrate, a_channels, + v_bitrate, v_framerate, v_resolution, v_dar): + + self.container = container + self.a_codec = a_codec + self.v_codec = v_codec + self.a_bitrate = a_bitrate + self.a_samplingrate = a_samplingrate + self.a_channels = a_channels + self.v_bitrate = v_bitrate + self.v_framerate = v_framerate + self.v_resolution = v_resolution + self.v_dar = v_dar + + + +class Job: + """ + Structure that contains information about a job. + + Members are documented in the constructor. + """ + + def __init__(self, raw_video, name, transcode_configs): + """ + @param raw_video the input raw video file name transfered from WS + @param name video name (must be a valid file name) + @param transcode_configs a list of TranscodeConfig instances + """ + + self.raw_video = raw_video + self.name = name + self.transcode_configs if __name__ == '__main__': - transcoder = config.TRANSCODER_CLASS("../data/media/test.ogv") - transcoder.transcode('ogg', "vorbis", "theora", a_bitrate="192k", a_samplingrate=44100, a_channels=2, v_bitrate="700k", v_framerate=25, v_resolution="800x600", v_dar="16:9") + # Jobs queue. + queue = Queue() + + # Worker thread. + ci_worker = CIWorker(queue) + ci_worker.daemon = True + ci_worker.start() + + while True: + raw_video = sys.stdin.readline().strip() + if raw_video == 'x': + break + + job = Job(raw_video) + queue.put(job) + + queue.join() + + + + +# transcoder = config.TRANSCODER_CLASS(sys.argv[1]) +# transcoder.transcode('webm', "vorbis", "vp8", a_bitrate="128k", a_samplingrate=22050, a_channels=2, v_bitrate="256k", v_framerate=15, v_resolution="320x240", v_dar="4:3") + +# thumb_extractor = config.THUMB_EXTRACTOR_CLASS(sys.argv[1]) +# #print thumb_extractor.get_video_duration() +# #thumb_extractor.extract_random_thumb() +# print thumb_extractor.extract_summary_thumbs(5) + +# file_transfer = config.FILE_TRANSFERER_CLASS() +# file_transfer.get(['vim_config.tar.gz']) +# #file_transfer.put(['cisd.py']) +# file_transfer.close() + +# create_torrent(sys.argv[1]) + +# bt_inst = bt.BitTorrent() +# +# bt_inst.download(sys.argv[1], '/tmp') +# bt_inst.download(sys.argv[2], '/tmp') +# +# print threading.active_count(), threading.enumerate() +# time.sleep(30)