X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=cis%2Fcisd.py;h=d4c20deff7e3d8ab18da506f8b41a59304eb7298;hb=3cf4f616f7d4095623ad5eae5db9fb1149ee1238;hp=3f0dc25afcb5277a1ff3bbfdbea35b2716c6fb63;hpb=aa1e24b4e3a9d99a72c8e440b0dafe2118a72816;p=living-lab-site.git diff --git a/cis/cisd.py b/cis/cisd.py index 3f0dc25..d4c20de 100755 --- a/cis/cisd.py +++ b/cis/cisd.py @@ -1,35 +1,131 @@ #!/usr/bin/env python import sys -import config import os +import time +import threading +from Queue import Queue + +import config +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) + -from BaseLib.Core.API import * + queue.task_done() -def create_torrent(source): - """ Creates a torrent file for the video source file. """ - if isinstance(source, unicode): - usource = source - else: - usource = source.decode(sys.getfilesystemencoding()) +class TranscodeConfig: + """ + Structure that contains parameters for a transcoding procedure. + """ - duration = config.AVINFO_CLASS.get_video_duration(source, True) + def __init__(self, container, a_codec, v_codec, + a_bitrate, a_samplingrate, a_channels, + v_bitrate, v_framerate, v_resolution, v_dar): - print config.BT_TRACKER, duration, source + 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 - tdef = TorrentDef() - tdef.add_content(usource, playtime=duration) - tdef.set_tracker(config.BT_TRACKER) - tdef.set_piece_length(32768) - tdef.finalize() - tdef.save(source + '.tstream') +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__': - pass + # 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") @@ -43,4 +139,12 @@ if __name__ == '__main__': # #file_transfer.put(['cisd.py']) # file_transfer.close() - create_torrent(sys.argv[1]) +# 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)