fix multipass encoding for server/client

This commit is contained in:
j 2017-12-08 09:15:06 +01:00
parent 8df27cfb21
commit bb2aafcb9d
2 changed files with 39 additions and 30 deletions

View file

@ -44,35 +44,40 @@ class DistributedClient:
return True return True
return False return False
def encode(self, oshash, cmd, output): def encode(self, oshash, cmds, output):
cmd[0] = extract.command('ffmpeg') if not isinstance(cmds[0], list):
if 'webm' in cmd and not self.supported_formats['webm']: cmds = [cmds]
print("ffmpeg is compiled without WebM support") for cmd in cmds:
return cmd[0] = extract.command('ffmpeg')
elif cmd[-1].endswith('.mp4') and not self.supported_formats['webm']: if 'webm' in cmd and not self.supported_formats['webm']:
print("ffmpeg is compiled without H.264 support") print("ffmpeg is compiled without WebM support")
return return
try: elif cmd[-1].endswith('.mp4') and not self.supported_formats['webm']:
p = subprocess.Popen(cmd) print("ffmpeg is compiled without H.264 support")
r = None return
n = 0 try:
while True: p = subprocess.Popen(cmd)
r = p.poll() r = None
if r is None: n = 0
if n % 60 == 0: while True:
self.ping(oshash) r = p.poll()
n = 0 if r is None:
time.sleep(2) if n % 60 == 0:
n += 2 self.ping(oshash)
else: n = 0
break time.sleep(2)
except KeyboardInterrupt: n += 2
p.kill() else:
#encoding was stopped, put back in queue break
self.status(oshash, '') except KeyboardInterrupt:
if os.path.exists(output): p.kill()
os.unlink(output) #encoding was stopped, put back in queue
sys.exit(1) self.status(oshash, '')
if os.path.exists(output):
os.unlink(output)
sys.exit(1)
if r != 0:
break
if r == 0: if r == 0:
self.upload(oshash, output) self.upload(oshash, output)
else: else:

View file

@ -159,7 +159,11 @@ class Server(Resource):
url = 'http://%s:%s/get/%s' % (request.host.host, request.host.port, oshash) url = 'http://%s:%s/get/%s' % (request.host.host, request.host.port, oshash)
output = '/tmp/%s.%s' % (oshash, self.client.profile(info)) output = '/tmp/%s.%s' % (oshash, self.client.profile(info))
response['cmd'] = extract.video_cmd(url, output, self.client.profile(info), info) response['cmd'] = extract.video_cmd(url, output, self.client.profile(info), info)
response['cmd'][0] = 'ffmpeg' if isinstance(response['cmd'][0], list):
for part in response['cmd']:
part[0] = 'ffmpeg'
else:
response['cmd'][0] = 'ffmpeg'
response['output'] = output response['output'] = output
self.update_status(oshash, 'active') self.update_status(oshash, 'active')
print(oshash, f) print(oshash, f)