process(value, instance=None, field=None, dependee=None, stashed_value=None, **kwargs)¶
- value – New value that is being assigned to the parent field.
- instance – Model instance that a field is attached to.
- field – Parent field instance.
- dependee – Instance of a field that depends on the
field. It is decided by the
suffixargument to the
- stashed_value – This is a previous value that a
dependeefield was holding. Very useful for comparing it to new values.
Here is an examlple of how to convert a video to MP4 format. In this example
MediaModel is instantiated
FileDependency will automatically attach
another field like attribute to the model
video_mp4. Moreover, whenever a
new video file is uploaded or simply assigned to a
video field, it will use
ffmpeg to convert
that video file to mp4 format and will assign it the same name as original video
mp4 suffix and file extension. While converting a video file it will
set progress between 0.0 and 1.0, which can be retrieved from field’s status.
from django.db import models from smartfields import fields, dependencies from smartfields.processors import FFMPEGProcessor class MediaModel(models.Model): video = feilds.FileField(dependencies=[ dependencies.FileDependency(suffix='mp4', processor=FFMPEGProcessor( vbitrate = '1M', maxrate = '1M', bufsize = '2M', width = 'trunc(oh*a/2)*2', # http://ffmpeg.org/ffmpeg-all.html#scale height = 720, threads = 0, # use all cores abitrate = '96k', format = 'mp4', vcodec = 'libx264', acodec = 'libfdk_aac'))])