I need to make a thumbnail from a video and save it to Django's ImageField.
I already have the working code which saves the thumbnail to a specified folder but what I want is to redirect the output of FFmpeg directly to Imagefield (or to a in memory uploaded file and then to Imagefield)
This is my current code:
def clean(self):
video_file = self.files['file']
output_thumb = os.path.join(settings.MEDIA_ROOT, 'post/videos/thumbs', video_file.name)
video_input_path = video_file.temporary_file_path()
subprocess.call(
['ffmpeg', '-i', video_input_path, '-ss', '00:00:01', '-vf', 'scale=200:220',
'-vframes', '1', output_thumb])
self.instance.video = video_file
self.instance.video_thumb = output_thumb
Model:
video = models.FileField(upload_to='post/videos/', blank=True,
validators=[FileExtensionValidator(allowed_extensions=['mp4', 'webm'])])
video_thumb = models.ImageField(upload_to='post/videos/thumbs', blank=True)
I'd like to do it so that I wouldn't need to specify the folder to save the thumb in (output_thumb in the code) and for Django to save it automatically using the upload_to='post/videos/thumbs option in the model definition
Please point me in the right direction of how to do this.