          self.set_destination_serializer()
          if self.verbose:
              print("{} items loaded".format(self.count))
  
      def process(self):
          """ Commmand to run if calling the reformat command """
          print("\n[REFORMAT ALIGNMENTS]")  # Tidy up cli output
          self.save_alignments()
  
      def check_alignments_file_exists(self):
          """ Check the alignments file exists"""
          if not os.path.isfile(self.alignments_file):
              print("ERROR: alignments file not "
                    "found at: {}".format(self.alignments_file))
              exit(0)
 
</s> remove                   "found at: {}".format(self.alignments_file))
 </s> add                   "found at: {}".format(self.file)) </s> remove         if not os.path.isfile(self.alignments_file):
 </s> add         if os.path.split(self.file.lower())[1] == "dfl":
            self.file = "dfl"
        if self.file.lower() == "dfl":
            print("Using extracted pngs for alignments")
            return
        if not os.path.isfile(self.file): </s> remove             print("Alignments file exists at {}".format(self.alignments_file))
 </s> add             print("Alignments file exists at {}".format(self.file))
        return

    def get_source_format(self):
        """ Get the source alignments format """
        if self.file.lower() == "dfl":
            return "dfl"
        return os.path.splitext(self.file)[1].lower() </s> remove class Extract(object):
 </s> add class Reformat():
    """ Reformat Alignment file """
    def __init__(self, alignments, arguments):
        self.verbose = arguments.verbose
        self.alignments = alignments
        self.frames_dir = arguments.frames_dir
        if self.alignments.src_format == "dfl":
            self.frames = Frames(self.frames_dir,
                                 self.verbose).items
            self.faces = Faces(arguments.faces_dir,
                               self.verbose)

    def process(self):
        """ Run reformat """
        print("\n[REFORMAT ALIGNMENTS]")  # Tidy up cli output
        if self.alignments.src_format == "dfl":
            self.alignments.alignments = self.load_dfl()
            self.alignments.file = os.path.join(self.frames_dir,
                                                "alignments.json")
        self.alignments.save_alignments()

    def load_dfl(self):
        """ Load alignments from DeepFaceLab and format for Faceswap """
        alignments = dict()
        frames = {item[0]: item[1]
                  for item in self.frames.values()}
        for face in self.faces.file_list_sorted:
            if not self.validate_dfl(face, frames):
                continue

            fullpath = os.path.join(self.faces.folder, face[0] + face[1])
            dfl = self.get_dfl_alignment(fullpath)

            if not dfl:
                continue

            sourcefile = face[2] + frames[face[2]]
            self.convert_dfl_alignment(dfl, sourcefile, alignments)
        return alignments

    def validate_dfl(self, face, frames):
        """ Validate that current file is good for dfl extraction """
        if face[1] != ".png":
            if self.verbose:
                print("{} is not a png. Skipping".format(face[0] + face[1]))
            return False
        if face[2] not in frames.keys():
            if self.verbose:
                print("{} does not have a matching source frame for {} in "
                      "frames directory. Skipping".format(face[0] + face[1],
                                                          face[2]))
            return False
        return True

    @staticmethod
    def get_dfl_alignment(filename):
        """ Process the alignment of one face """
        with open(filename, "rb") as dfl:
            header = dfl.read(8)
            if header != b"\x89PNG\r\n\x1a\n":
                print("ERROR: No Valid PNG header: {}".format(filename))
                return
            while True:
                chunk_start = dfl.tell()
                chunk_hdr = dfl.read(8)
                if not chunk_hdr:
                    break
                chunk_length, chunk_name = struct.unpack("!I4s", chunk_hdr)
                dfl.seek(chunk_start, os.SEEK_SET)
                if chunk_name == b"fcWp":
                    chunk = dfl.read(chunk_length + 12)
                    return pickle.loads(chunk[8:-4])
                else:
                    dfl.seek(chunk_length+12, os.SEEK_CUR)
            print("ERROR: Couldn't find DFL alignments: {}".format(filename))

    @staticmethod
    def convert_dfl_alignment(dfl_alignments, sourcefile, alignments):
        """ Add DFL Alignments to alignments in Faceswap format """
        if not alignments.get(sourcefile, None):
            alignments[sourcefile] = list()

        left, top, right, bottom = dfl_alignments["source_rect"]
        alignment = {"r": 0,
                     "x": left,
                     "w": right - left,
                     "y": top,
                     "h": bottom - top,
                     "landmarksXY": dfl_alignments["source_landmarks"]}

        alignments[sourcefile].append(alignment)


class Extract(): </s> remove         if not self.folder or not os.path.isdir(self.folder):
            print("ERROR: The folder {} could not "
                  "be found".format(self.folder))
 </s> add         err = None
        loadtype = self.__class__.__name__
        if not self.folder:
            err = "ERROR: A {} folder must be specified".format(loadtype)
        elif not os.path.isdir(self.folder):
            err = ("ERROR: The {} folder {} could not be "
                   "found".format(loadtype, self.folder))
        if err:
            print(err)
    def check_file_exists(self):
          self.set_destination_serializer()
          if self.verbose:
              print("{} items loaded".format(self.count))
  
    def check_file_exists(self):
    def check_file_exists(self):
    def check_file_exists(self):
    def check_file_exists(self):
    def check_file_exists(self):
    def check_file_exists(self):
          """ Check the alignments file exists"""
          if not os.path.isfile(self.alignments_file):
              print("ERROR: alignments file not "
                    "found at: {}".format(self.alignments_file))
              exit(0)
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Alignments tool - Import from DeepFaceLab (#487)

* Import alignments from DeepFaceLab 
tools/alignments.py