7 from Queue import Queue
13 class CIWorker(threading.Thread):
15 Content Ingestion Worker. A class which executes content ingestion jobs
18 CIWorker shares a Queue with its master where jobs are submitted.
21 def __init__(self, queue):
22 threading.Thread.__init__(self)
28 job = self.queue.get()
30 # * TRANSFER RAW VIDEO IN
31 file_transfer = config.FILE_TRANSFERER_CLASS( \
32 'tmp/raw', config.INPUT_PATH)
33 file_transfer.get([job.raw_video])
36 # * TRANSCODE RAW VIDEO
37 transcoder = config.TRANSCODER_CLASS(input_file = job.raw_video, \
38 name = job.name, prog_bin = config.TRANSCODER_BIN)
40 # Transcode the raw video in each requested format.
41 for transcode_config in job.transcode_configs:
42 transcode_config['output_file'] = transcoder.transcode( \
43 container = transcode_config.container, \
44 a_codec = transcode_config.a_codec, \
45 a_bitrate = transcode_config.a_bitrate, \
46 a_samplingrate = transcode_config.a_samplingrate, \
47 a_channels = transcode_config.a_channels, \
48 v_codec = transcode_config.v_codec, \
49 v_bitrate = transcode_config.v_bitrate, \
50 v_framerate = transcode_config.v_framerate, \
51 v_resolution = transcode_config.v_resolution, \
52 v_dar = transcode_config.dar)
54 # * EXTRACT THUMBNAIL IMAGES
55 thumb_extractor = config.THUMB_EXTRACTOR_CLASS( \
56 input_file = job.raw_video, name = job.name, \
57 prog_bin = config.THUMB_EXTRACTOR_BIN)
58 # TODO thumbnail extraction type must be got from input
59 thumb_extractor.extract_random_thumb()
60 print thumb_extractor.extract_summary_thumbs(5)
66 class TranscodeConfig:
68 Structure that contains parameters for a transcoding procedure.
71 def __init__(self, container, a_codec, v_codec,
72 a_bitrate, a_samplingrate, a_channels,
73 v_bitrate, v_framerate, v_resolution, v_dar):
75 self.container = container
76 self.a_codec = a_codec
77 self.v_codec = v_codec
78 self.a_bitrate = a_bitrate
79 self.a_samplingrate = a_samplingrate
80 self.a_channels = a_channels
81 self.v_bitrate = v_bitrate
82 self.v_framerate = v_framerate
83 self.v_resolution = v_resolution
90 Structure that contains information about a job.
92 Members are documented in the constructor.
95 def __init__(self, raw_video, name, transcode_configs):
97 @param raw_video the input raw video file name transfered from WS
98 @param name video name (must be a valid file name)
99 @param transcode_configs a list of TranscodeConfig instances
102 self.raw_video = raw_video
104 self.transcode_configs
107 if __name__ == '__main__':
112 ci_worker = CIWorker(queue)
113 ci_worker.daemon = True
117 raw_video = sys.stdin.readline().strip()
129 # transcoder = config.TRANSCODER_CLASS(sys.argv[1])
130 # 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")
132 # thumb_extractor = config.THUMB_EXTRACTOR_CLASS(sys.argv[1])
133 # #print thumb_extractor.get_video_duration()
134 # #thumb_extractor.extract_random_thumb()
135 # print thumb_extractor.extract_summary_thumbs(5)
137 # file_transfer = config.FILE_TRANSFERER_CLASS()
138 # file_transfer.get(['vim_config.tar.gz'])
139 # #file_transfer.put(['cisd.py'])
140 # file_transfer.close()
142 # create_torrent(sys.argv[1])
144 # bt_inst = bt.BitTorrent()
146 # bt_inst.download(sys.argv[1], '/tmp')
147 # bt_inst.download(sys.argv[2], '/tmp')
149 # print threading.active_count(), threading.enumerate()