Fixes Issue #2 #4

Merged
dafo5502 merged 59 commits from developer into master 2021-10-25 14:41:37 +02:00
Showing only changes of commit d31691b67d - Show all commits

View File

@ -33,10 +33,16 @@ class Transcoder:
self.logger.debug("%s - Pool created", package_id)
for stream in package['sources']:
transcodes = {}
# If the strean is a colection of slide images that has to be converted to a video
if 'demux_file' in stream:
self.logger.debug("%s - Processing stream %s", package_id, 'slides job in demux.txt')
# Create the different variants
for maxheight in self.variants:
crf, preset = self.variants[maxheight]
# Call the _Worker function asyncronously
transcodes[maxheight] = pool.apply_async(_Worker.make_slides_video,
(self.worker,
package_id,
@ -47,14 +53,21 @@ class Transcoder:
slides_thumb = 'slides_thumb{}'.format(ext)
shutil.copy2(stream['poster'],os.path.join(workbase, slides_thumb))
stream['poster'] = slides_thumb
stream.pop('demux_file')
# Remove the reference to the demuxfile since it is no longer needed
stream.pop('demux_file')
# If the strean is a regualr video it needs to be transcoded with new resolution
elif 'video' in stream:
streampath_rel = stream['video']
streampath_abs = os.path.join(base, streampath_rel)
self.logger.debug("%s - Processing stream %s", package_id, streampath_rel)
# Create the different variants
for maxheight in self.variants:
crf, preset = self.variants[maxheight]
# Call the _Worker function asyncronously
transcodes[maxheight] = pool.apply_async(_Worker.transcode,
(self.worker,
package_id,
@ -77,9 +90,11 @@ class Transcoder:
workbase))
transcodes['poster'] = thumbjob
# Store the jobs and streams in the pending array
pending.append({'jobs': transcodes,
'data': stream})
# Close the pool
pool.close()
pool.join()
self.logger.info("%s - Finished transcoding", package_id)
@ -90,6 +105,7 @@ class Transcoder:
jobs = item['jobs']
streams = {}
for maxheight in self.variants:
# Get the jobs. If not done wait until they are ready.
streams[maxheight] = jobs[maxheight].get()
stream['video'] = streams
if 'poster' in jobs:
@ -98,6 +114,7 @@ class Transcoder:
package['thumb'] = stream['poster']
package['sources'].append(stream)
# Return the finished streams
return package
class _Worker: