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

View File

@ -159,7 +159,11 @@ class Server(Resource):
url = 'http://%s:%s/get/%s' % (request.host.host, request.host.port, oshash)
output = '/tmp/%s.%s' % (oshash, self.client.profile(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
self.update_status(oshash, 'active')
print(oshash, f)