# AI : Faceswap : CLI : tools alignments
```
python tools.py alignments -j ... -a FSA
```
## Options
```
-j|--job {draw,extract,export,from-faces,missing-alignments,missing-frames,multi-faces,no-faces,remove-faces,rename,sort,spatial}
NB: All actions require an alignments file (-a) to be passed in.
- draw : Draw landmarks on frames in the selected folder/video. A subfolder will be created within the frames folder to hold the output. Must Pass in a frames folder/source video file (-r).
- export : Export the contents of an alignments file to a json file. Can be used for editing alignment information in external tools and then re-importing by using Faceswap's Extract 'Import' plugins. Note: masks and identity vectors will not be included in the exported file, so will be re-generated when the json file is imported back into Faceswap. All data is exported with the origin (0, 0) at the top left of the canvas.
- extract : Re-extract faces from the source frames/video based on alignment data. This is a lot quicker than re-detecting faces. Can pass in the '-een' (--extract-every-n) parameter to only extract every nth frame. Must Pass in a frames folder/source video file AND a faces folder (-r and -c).
- from-faces : Generate alignment file(s) from a folder of extracted faces. If the folder of faces comes from multiple sources, then multiple alignments files will be created. NB: for faces which have been extracted from folders of source images, rather than a video, a single alignments file will be created as there is no way for the process to know how many folders of images were originally used. You do not need to provide an alignments file path to run this job. Must Pass in a faces folder (-c).
- missing-alignments : Identify frames that do not exist in the alignments file. Use the output option (-o) to process results. Must Pass in a frames folder/source video file (-r).
- missing-frames : Identify frames in the alignments file that do not appear within the frames folder/video. Use the output option (-o) to process results. Must Pass in a frames folder/source video file (-r).
- multi-faces : Identify where multiple faces exist within the alignments file. Use the output option (-o) to process results. Must Pass in either a frames folder/source video file OR a faces folder (-r or -c).
- no-faces : Identify frames that exist within the alignment file but no faces were detected. Use the output option (-o) to process results. Must Pass in a frames folder/source video file (-r).
- remove-faces : Remove deleted faces from an alignments file. The original alignments file will be backed up. Must Pass in a faces folder (-c).
- rename : Rename faces to correspond with their parent frame and position index in the alignments file (i.e. how they are named after running extract). Must Pass in a faces folder (-c).
- sort : Re-index the alignments from left to right. For alignments with multiple faces this will ensure that the left-most face is at index 0.
- spatial : Perform spatial and temporal filtering to smooth alignments (EXPERIMENTAL!)
-o|--output {console,file,move}
How to output discovered items ('faces' and 'frames' only):
- console : Print the list of frames to the screen. (DEFAULT)
- file : Output the list of frames to a text file (stored within the source directory).
- move : Move the discovered items to a sub-folder within the source directory.
-a|--alignments_file PATH Full path to the alignments file to be processed. If you have input a 'frames_dir' and don't provide this option, the process will try to find the alignments file at the default location. All jobs require an alignments file with the exception of 'from-faces' when the alignments file will be generated in the specified faces folder.
-c|-faces_folder DIR
Directory containing extracted faces.
-r|-frames_folder DIR
Directory containing source frames that faces were extracted from.
-B|--batch-mode Run the aligmnents tool on multiple sources. The following jobs support batch mode: draw, extract, from-faces, missing-alignments, missing-frames, no-faces, sort, spatial
If batch mode is selected then the other options should be set as follows:
- alignments_file : For 'sort' and 'spatial' this should point to the parent folder containing the alignments files to be processed. For all other jobs this option is ignored, and the alignments files must exist at their default location relative to the original frames folder/video.
- faces_dir : For 'from-faces' this should be a parent folder, containing sub-folders of extracted faces from which to generate alignments files. For 'extract' this should be a parent folder where sub-folders will be created for each extraction to be run. For all other jobs this option is ignored.
- frames_dir : For 'draw', 'extract', 'missing-alignments', 'missing-frames' and 'no-faces' this should be a parent folder containing video files or sub-folders of images to perform the alignments job on. The alignments file should exist at the default location. For all other jobs this option is ignored.
-N|--extract-every-n N [Extract only] Extract every 'nth' frame. This option will skip frames when extracting faces. For example a value of 1 will extract faces from every frame, a value of 10 will extract faces from every 10th frame.
-z|--size SIZE [Extract only] The output size of extracted faces.
-m|--min-size SIZE [Extract only] Only extract faces that have been resized by this percent or more to meet the specified extract size (`-sz`, `--size`). Useful for excluding low-res images from a training set. Set to 0 to extract all faces. Eg: For an extract size of 512px, A setting of 50 will only include faces that have been resized from 256px or above. Setting to 100 will only extract faces that have been resized from 512px or above. A setting of 200 will only extract faces that have been downscaled from 1024px or above.
```