Commit 3cee1828cf22bb210e23b8a2f914588081b95d3a

Authored by Wesnydy Ribeiro
1 parent c488eb8c
Exists in release

Mixer worker release

Showing 2 changed files with 16 additions and 12 deletions   Show diff stats
core/extractor.py
1   -#!/usr/bin/python
  1 +#!/usr/bin/env python
2 2 # -*- coding: utf-8 -*-
3 3  
4 4 """
... ... @@ -44,9 +44,6 @@ logger.addHandler(ch)
44 44  
45 45 manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
46 46  
47   -#conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
48   -#conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
49   -
50 47 def run(ch, method, properties, body):
51 48 """
52 49 Execute the worker.
... ... @@ -91,7 +88,7 @@ def run(ch, method, properties, body):
91 88 body['pts'] = -1
92 89 body['index'] = index
93 90 #Number of subtitle extracted
94   - logger.info(str(index-1) + " Legendas extraídas")
  91 + logger.info(str(index-1) + " Legendas extraídas com sucesso")
95 92 # Clean temporary file
96 93 logger.info("Removendo arquivo temporário")
97 94 os.remove(filename)
... ...
core/mixer.py
... ... @@ -26,7 +26,7 @@ from thread import start_new_thread
26 26 from time import sleep
27 27 from urllib import urlretrieve
28 28  
29   -PATH_VIDEO="/home/caiomcg/videos/"
  29 +PATH_MIXED_VIDEO = os.getenv("VLIBRAS_VIDEO_MIXED")
30 30  
31 31 logger = logging.getLogger('mixer')
32 32 logger.setLevel(logging.DEBUG)
... ... @@ -44,9 +44,6 @@ ch.setFormatter(formatter)
44 44 logger.addHandler(fh)
45 45 logger.addHandler(ch)
46 46  
47   -#conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
48   -#conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0))
49   -
50 47 manager = PikaManager.PikaManager("150.165.205.10", "test", "test")
51 48  
52 49 def main_video_height(main_video):
... ... @@ -180,16 +177,15 @@ def run(ch, method, properties, body):
180 177 # -Vf param
181 178 filter_graph = ','.join([movie, scale, 'setpts=PTS-STARTPTS', overlay])
182 179 # Generates the output file path
183   - mixed_video = os.path.join(PATH_VIDEO, properties.correlation_id.encode("utf-8")+".mp4")
  180 + mixed_video = os.path.join(PATH_MIXED_VIDEO, properties.correlation_id.encode("utf-8")+".mp4")
184 181 # Mix videos using ffmpeg
185   - print ("Mixing videos...",)
  182 + print ("Mixing videos...")
186 183 logger.info("Mixando o vídeo original com a janela de libras")
187 184 try:
188 185 call(
189 186 ['ffmpeg', '-v', 'error', '-i', main_video, '-y', '-vf', filter_graph,
190 187 '-qscale', '0', '-strict', 'experimental', '-vcodec', 'libx264',
191 188 '-preset', 'fast', '-r', '30', '-threads', '8', mixed_video], shell=False)
192   - print ("Sucess")
193 189 logger.info("Mixagem bem sucedida")
194 190 except OSError as ex:
195 191 logger.error("Mixagem mal sucedida")
... ... @@ -205,6 +201,17 @@ def run(ch, method, properties, body):
205 201 manager.send_to_queue("videos", body, properties)
206 202 print ("Success")
207 203  
  204 +def keep_alive(conn_send, conn_receive):
  205 + while True:
  206 + sleep(30)
  207 + try:
  208 + conn_send.process_data_events()
  209 + conn_receive.process_data_events()
  210 + except:
  211 + continue
  212 +
  213 +start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive()))
  214 +
208 215 # Starts listening
209 216 print("Mixer listening...")
210 217 while True:
... ...