class smartfields.processors.BaseProcessor
process(value, instance=None, field=None, dependee=None, stashed_value=None, **kwargs)
  • value – New value that is being assigned to the field.
  • instance – Model instance that a field is attached to.
  • field – Field instance that the dependency, which holds this processor, was supplied to.
  • dependee – Instance of a field that depends on the field. It is decided by the attname or suffix argument to the
  • stashed_value – This is a previous value that a field was holding. Very useful for comparing it to new values.
class smartfields.processors.FFMPEGProcessor
process(value, **kwargs)

Here is an examlple of how to convert a video to MP4 format. In this example every time MediaModel is instanciated 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 FFMPEGProcessor and ffmpeg to convert that video file to mp4 format and will assign it the same name as original video with mp4 suffix and file extension. While converting a video file it will set progress between 0 and 1, 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', #
            height = 720,
            threads = 0, # use all cores
            abitrate = '96k',
            format = 'mp4',
            vcodec = 'libx264',
            acodec = 'libfdk_aac'))])