code: def convert_video(fieldfile, force=False):
      
      instance = fieldfile.instance
      field = fieldfile.field
  
      filename = os.path.basename(fieldfile.path)
      source_path = fieldfile.path
  
      encoding_backend = get_backend()
  
      for options in settings.VIDEO_ENCODING_FORMATS[encoding_backend.name]:
          video_format, created = Format.objects.get_or_create(
              object_id=instance.pk,
              content_type=ContentType.objects.get_for_model(instance),
              field_name=field.name, format=options['name'])
  
          # do not reencode if not requested
          if video_format.file and not force:
              continue
          else:
              # set progress to 0
              video_format.reset_progress()
  
          # TODO do not upscale videos
  
          _, target_path = tempfile.mkstemp(
              suffix='_{name}.{extension}'.format(**options))
  
          try:
              encoding = encoding_backend.encode(
                  source_path, target_path, options['params'])
              while encoding:
                  try:
                      progress = next(encoding)
                  except StopIteration:
                      break
                  video_format.update_progress(progress)
          except VideoEncodingError:
              # TODO handle with more care
              video_format.delete()
              os.remove(target_path)
              continue
  
          # save encoded file
          video_format.file.save(
              '{filename}_{name}.{extension}'.format(filename=filename,
                                                     **options),
              File(open(target_path, mode='rb')))
  
          video_format.update_progress(100)  # now we are ready
  
          # remove temporary file
          os.remove(target_path)
docs: Converts a given video file into all defined formats.