Video variations are embedded in files
This commit is contained in:
@@ -157,7 +157,9 @@ def process_file(src_file):
|
|||||||
elif src_video_data['res_y'] >= 1080:
|
elif src_video_data['res_y'] >= 1080:
|
||||||
res_y = 1080
|
res_y = 1080
|
||||||
|
|
||||||
# Create variations in database
|
# Add variations property to the file
|
||||||
|
src_file['variations'] = []
|
||||||
|
# Create variations
|
||||||
for v in variations:
|
for v in variations:
|
||||||
root, ext = os.path.splitext(src_file['name'])
|
root, ext = os.path.splitext(src_file['name'])
|
||||||
filename = "{0}-{1}p.{2}".format(root, res_y, v)
|
filename = "{0}-{1}p.{2}".format(root, res_y, v)
|
||||||
@@ -165,12 +167,7 @@ def process_file(src_file):
|
|||||||
if src_video_data['duration']:
|
if src_video_data['duration']:
|
||||||
video_duration = src_video_data['duration']
|
video_duration = src_video_data['duration']
|
||||||
|
|
||||||
file_object = dict(
|
file_variation = dict(
|
||||||
name=os.path.split(filename)[1],
|
|
||||||
#description="Preview of file {0}".format(file_['name']),
|
|
||||||
project=src_file['project'],
|
|
||||||
user=src_file['user'],
|
|
||||||
parent=file_id,
|
|
||||||
size="{0}p".format(res_y),
|
size="{0}p".format(res_y),
|
||||||
duration=video_duration,
|
duration=video_duration,
|
||||||
format=v,
|
format=v,
|
||||||
@@ -179,38 +176,25 @@ def process_file(src_file):
|
|||||||
content_type="video/{0}".format(v),
|
content_type="video/{0}".format(v),
|
||||||
length=0, # Available after encode
|
length=0, # Available after encode
|
||||||
md5="", # Available after encode
|
md5="", # Available after encode
|
||||||
filename=os.path.split(filename)[1],
|
file_path=filename,
|
||||||
backend=src_file['backend'],
|
)
|
||||||
file_path=filename)
|
# Append file variation
|
||||||
|
src_file['variations'].append(file_variation)
|
||||||
file_object_id = files_collection.save(file_object)
|
|
||||||
# Append the ObjectId to the new list
|
|
||||||
variations[v] = file_object_id
|
|
||||||
|
|
||||||
|
|
||||||
def encode(src, variations, res_y):
|
def encode(src, variations, res_y):
|
||||||
# For every variation in the list call video_encode
|
# For every variation in the list call video_encode
|
||||||
# print "encoding {0}".format(variations)
|
# print "encoding {0}".format(variations)
|
||||||
for v in variations:
|
for v in variations:
|
||||||
path = ffmpeg_encode(file_abs_path, v, res_y)
|
path = ffmpeg_encode(file_abs_path, v['format'], res_y)
|
||||||
# Update size data after encoding
|
# Update size data after encoding
|
||||||
# (TODO) update status (non existing now)
|
v['length'] = os.stat(path).st_size
|
||||||
file_size = os.stat(path).st_size
|
|
||||||
variation = files_collection.find_one(variations[v])
|
|
||||||
variation['length'] = file_size
|
|
||||||
# print variation
|
|
||||||
file_asset = files_collection.find_and_modify(
|
|
||||||
{'_id': variations[v]},
|
|
||||||
variation)
|
|
||||||
|
|
||||||
# rsync the file file (this is async)
|
r = put_internal('files', src_file, **{'_id': ObjectId(file_id)})
|
||||||
# remote_storage_sync(path)
|
|
||||||
# push_to_storage(str(src_file['project']), path)
|
|
||||||
# When all encodes are done, delete source file
|
# When all encodes are done, delete source file
|
||||||
sync_path = os.path.split(file_abs_path)[0]
|
sync_path = os.path.split(file_abs_path)[0]
|
||||||
push_to_storage(str(src_file['project']), sync_path)
|
push_to_storage(str(src_file['project']), sync_path)
|
||||||
|
|
||||||
p = Process(target=encode, args=(file_abs_path, variations, res_y))
|
p = Process(target=encode, args=(file_abs_path, src_file['variations'], res_y))
|
||||||
p.start()
|
p.start()
|
||||||
if mime_type != 'video':
|
if mime_type != 'video':
|
||||||
# Sync the whole subdir
|
# Sync the whole subdir
|
||||||
|
Reference in New Issue
Block a user