def save_slide(data, filename, video, enrichment, recording): if len(data): slide_name, ext = os.path.splitext(os.path.basename(filename)) if FILEPICKER: homedir, created = UserFolder.objects.get_or_create( name="home", owner=video.owner) videodir, created = UserFolder.objects.get_or_create( name="%s" % video.slug, owner=video.owner) previousImage = CustomImageModel.objects.filter( name__startswith=slugify(video.title + "_" + slide_name), folder=videodir, created_by=video.owner, ) for img in previousImage: img.delete() image = CustomImageModel(folder=videodir, created_by=video.owner) image.file.save( slugify(video.title + "_" + slide_name) + ext, ContentFile(data), save=True, ) image.save() else: image = CustomImageModel() image.file.save( slugify(video.title + "_" + slide_name) + ext, ContentFile(data), save=True, ) image.save() enrichment.type = "image" enrichment.image = image enrichment.save() else: add_comment(recording.id, "file %s is empty" % filename)
def create_and_save_image(self, new_file, video): if FILEPICKER: homedir, created = UserFolder.objects.get_or_create( name='home', owner=video.owner) videodir, created = UserFolder.objects.get_or_create( name='%s' % video.slug, owner=video.owner) image = CustomImageModel( folder=videodir, created_by=video.owner ) image.file.save( os.path.basename(new_file), File(open(new_file, "rb")), save=True) image.save() else: image = CustomFileModel() image.file.save( os.path.basename(new_file), File(open(new_file, "rb")), save=True) image.save() return image
def create_and_save_thumbnails(source, image_width, video_id): msg = "\nCREATE AND SAVE THUMBNAILS : %s" % time.ctime() tempimgfile = tempfile.NamedTemporaryFile(dir=FILE_UPLOAD_TEMP_DIR, suffix='') for i in range(0, 3): percent = str((i + 1) * 25) + "%" cmd_ffmpegthumbnailer = "ffmpegthumbnailer -t \"%(percent)s\" \ -s \"%(image_width)s\" -i %(source)s -c png \ -o %(tempfile)s_%(num)s.png" % { "percent": percent, 'source': source, 'num': i, 'image_width': image_width, 'tempfile': tempimgfile.name } # subprocess.getoutput(cmd_ffmpegthumbnailer) subprocess.run(cmd_ffmpegthumbnailer, shell=True) thumbnailfilename = "%(tempfile)s_%(num)s.png" % { 'num': i, 'tempfile': tempimgfile.name } if check_file(thumbnailfilename): if FILEPICKER: video_to_encode = Video.objects.get(id=video_id) homedir, created = UserFolder.objects.get_or_create( name='home', owner=video_to_encode.owner) videodir, created = UserFolder.objects.get_or_create( name='%s' % video_to_encode.slug, owner=video_to_encode.owner) thumbnail = CustomImageModel(folder=videodir, created_by=video_to_encode.owner) thumbnail.file.save("%s_%s.png" % (video_to_encode.slug, i), File(open(thumbnailfilename, "rb")), save=True) thumbnail.save() if i == 0: video_to_encode = Video.objects.get(id=video_id) video_to_encode.thumbnail = thumbnail video_to_encode.save() else: thumbnail = CustomImageModel() thumbnail.file.save("%d_%s.png" % (video_id, i), File(open(thumbnailfilename, "rb")), save=True) thumbnail.save() if i == 0: video_to_encode = Video.objects.get(id=video_id) video_to_encode.thumbnail = thumbnail video_to_encode.save() # remove tempfile msg += "\n- thumbnailfilename %s :\n%s" % (i, thumbnail.file.path) os.remove(thumbnailfilename) else: msg += "\nERROR THUMBNAILS %s " % thumbnailfilename msg += "Wrong file or path" add_encoding_log(video_id, msg) change_encoding_step(video_id, -1, msg) send_email(msg, video_id) return msg
def import_remote_thumbnail(info_encode_thumbnail, output_dir, video_to_encode): msg = "" if type(info_encode_thumbnail) is list: info_encode_thumbnail = info_encode_thumbnail[0] thumbnailfilename = os.path.join(output_dir, info_encode_thumbnail["filename"]) if check_file(thumbnailfilename): if FILEPICKER: homedir, created = UserFolder.objects.get_or_create( name="home", owner=video_to_encode.owner ) videodir, created = UserFolder.objects.get_or_create( name="%s" % video_to_encode.slug, owner=video_to_encode.owner ) thumbnail = CustomImageModel( folder=videodir, created_by=video_to_encode.owner ) thumbnail.file.save( info_encode_thumbnail["filename"], File(open(thumbnailfilename, "rb")), save=True, ) thumbnail.save() video_to_encode.thumbnail = thumbnail video_to_encode.save() else: thumbnail = CustomImageModel() thumbnail.file.save( info_encode_thumbnail["filename"], File(open(thumbnailfilename, "rb")), save=True, ) thumbnail.save() video_to_encode.thumbnail = thumbnail video_to_encode.save() # remove tempfile msg += "\n- thumbnailfilename :\n%s" % (thumbnail.file.path) os.remove(thumbnailfilename) else: msg += "\nERROR THUMBNAILS %s " % thumbnailfilename msg += "Wrong file or path" add_encoding_log(video_to_encode.id, msg) change_encoding_step(video_to_encode.id, -1, msg) send_email(msg, video_to_encode.id) return msg