in scripts/maintenance/produce_videos.py [0:0]
def produce_worker(task, ffmpeg_path):
try:
p_num, intent, object_name = task
p_id = 'full{:d}_{:s}'.format(p_num, intent)
dload_dir=osp.join('data', 'contactpose_data')
data_dir = osp.join(dload_dir, p_id, object_name, 'images_full')
# download
downloader = ContactPoseDownloader()
if osp.isdir(data_dir):
shutil.rmtree(data_dir)
print('Deleted {:s}'.format(data_dir))
downloader.download_images(p_num, intent, dload_dir,
include_objects=(object_name,))
if not osp.isdir(data_dir):
print('Could not download {:s} {:s}'.format(p_id, object_name))
# check if the data actually exists
if object_name in urls[p_id]:
return False
else:
print('But that is OK because underlying data does not exist')
return True
# process
for camera_position in ('left', 'right', 'middle'):
camera_name = 'kinect2_{:s}'.format(camera_position)
this_data_dir = osp.join(data_dir, camera_name)
if not osp.isdir(this_data_dir):
print('{:s} does not have {:s} camera'.format(this_data_dir, camera_position))
continue
for mode, params in video_params.items():
if not params['valid']:
shutil.rmtree(osp.join(this_data_dir, mode))
continue
# video encoding
output_filename = osp.join(this_data_dir,
'{:s}.{:s}'.format(mode, params['ext']))
(
ffmpeg
.input(osp.join(this_data_dir, mode, 'frame%03d.png'), framerate=30)
.output(output_filename, **params['ffmpeg_kwargs'])
.overwrite_output()
.run(cmd=ffmpeg_path)
)
print('{:s} written'.format(output_filename), flush=True)
shutil.rmtree(osp.join(this_data_dir, mode))
# upload
dropbox_path = osp.join('/', 'contactpose',
'videos_full',
p_id, object_name, mode,
'{:s}.mp4'.format(camera_name))
if not nutils.upload_dropbox(output_filename, dropbox_path):
return False
return True
except Exception as e:
print('Error somewhere in ', task)
print(str(e))
return False