# AI : Faceswap : CLI : faceswap convert
```
python faceswap.py convert -m MODELDIR -i ~/template.mp4 -o ~/converted [OPTIONS]
```
## Options
```
-i|--input-dir DIR Input directory or video. Either a directory containing the image files you wish to process or path to a video file.
NB: This should be the source video/frames NOT the source faces.
-o|--output-dir DIR Output directory. This is where the converted files will be saved.
-p|--alignments PATH Optional path to an alignments file. Leave blank if the alignments file is at the default location.
-r|--reference-video VIDEO Only required if converting from images to video.
Provide The original video that the source frames were extracted from (for extracting the fps and audio).
-m|--model-dir DIR Model directory. The directory containing the trained model you wish to use for conversion.
-c|--color-adjustment {none,avg-color,color-transfer,manual-balance,match-hist,seamless-clone}
Performs color adjustment to the swapped face.
Some of these options have configurable settings in '/config/convert.ini' or 'Settings > Configure Convert Plugins':
- avg-color : Adjust the mean of each color channel in the swapped reconstruction to equal the mean of the masked area in the original image.
- color-transfer : Transfers the color distribution from the source to the target image using the mean and standard deviations of the L*a*b* color space.
- manual-balance : Manually adjust the balance of the image in a variety of color spaces. Best used with the Preview tool to set correct values.
- match-hist : Adjust the histogram of each color channel in the swapped reconstruction to equal the histogram of the masked area in the original image.
- seamless-clone : Use cv2's seamless clone function to remove extreme gradients at the mask seam by smoothing colors. Generally does not give very satisfactory results.
- none : Don't perform color adjustment.
-M|--mask-type {none,bisenet-fp_face,bisenet-fp_head,components,custom_face,custom_head,extended,unet-dfl,vgg-clear,vgg-obstructed,predicted}
Masker to use. NB: The mask you require must exist within the alignments file.
You can add additional masks with the Mask Tool.
- none : Don't use a mask.
- bisenet-fp_face : Relatively lightweight NN based mask that provides more refined control over the area to be masked (configurable in mask settings).
Use this version of bisenet-fp if your model is trained with 'face' or 'legacy' centering.
- bisenet-fp_head : Relatively lightweight NN based mask that provides more refined control over the area to be masked (configurable in mask settings).
Use this version of bisenet-fp if your model is trained with 'head' centering.
- custom_face : Custom user created, face centered mask.
- custom_head : Custom user created, head centered mask.
- components : Mask designed to provide facial segmentation based on the positioning of landmark locations.
A convex hull is constructed around the exterior of the landmarks to create a mask.
- extended : Mask designed to provide facial segmentation based on the positioning of landmark locations.
A convex hull is constructed around the exterior of the landmarks and the mask is extended upwards onto the forehead.
- vgg-clear : Mask designed to provide smart segmentation of mostly frontal faces clear of obstructions.
Profile faces and obstructions may result in sub-par performance.
- vgg-obstructed : Mask designed to provide smart segmentation of mostly frontal faces.
The mask model has been specifically trained to recognize some facial obstructions (hands and eyeglasses).
Profile faces may result in sub-par performance.
- unet-dfl : Mask designed to provide smart segmentation of mostly frontal faces.
The mask model has been trained by community members and will need testing for further description.
Profile faces may result in sub-par performance.
- predicted : If the 'Learn Mask' option was enabled during training, this will use the mask that was created by the trained model.
-w|--writer {ffmpeg,gif,opencv,patch,pillow}
The plugin to use to output the converted images.
The writers are configurable in '/config/convert.ini' or 'Settings > Configure Convert Plugins:'
- ffmpeg : [video] Writes out the convert straight to video. When the input is a series of images then the '-ref' (--reference-video) parameter must be set.
- gif : [animated image] Create an animated gif.
- opencv : [images] The fastest image writer, but less options and formats than other plugins.
- patch : [images] Outputs the raw swapped face patch, along with the transformation matrix required to re-insert the face back into the original frame.
Use this option if you wish to post-process and composite the final face within external tools.
- pillow : [images] Slower than opencv, but has more options and supports more formats.
-O|--output-scale SCALE Scale the final output frames by this amount. 100% will output the frames at source dimensions. 50% at half size 200% at double size.
-R|--frame-ranges R1 [...] Frame ranges to apply transfer to e.g. For frames 10 to 50 and 90 to 100 use --frame-ranges 10-50 90-100.
Frames falling outside of the selected range will be discarded unless '-k' (--keep-unchanged) is selected.
NB: If you are converting from images, then the filenames must end with the frame-number!
-S|--face-scale SCALE Scale the swapped face by this percentage. Positive values will enlarge the face, negative values will shrink the face.
-a|--input-aligned-dir DIR If you have not cleansed your alignments file, then you can filter out faces by defining a folder here that contains the faces extracted from your input files/video.
If this folder is defined, then only faces that exist within your alignments file and also exist within the specified folder will be converted.
Leaving this blank will convert all faces that exist within the alignments file.
-n|--nfilter NFILTER1 [...] Optionally filter out people who you do not wish to process by passing in an image of that person.
Should be a front portrait with a single person in the image. Multiple images can be added space separated.
NB: Using face filter will significantly decrease extraction speed and its accuracy cannot be guaranteed.
-f|--filter FILTER1 [...] Optionally select people you wish to process by passing in an image of that person. Should be a front portrait with a single person in the image.
Multiple images can be added space separated. NB: Using face filter will significantly decrease extraction speed and its accuracy cannot be guaranteed.
-l|--ref_threshold VAL For use with the optional nfilter/filter files. Threshold for positive face recognition. Lower values are stricter.
NB: Using face filter will significantly decrease extraction speed and its accuracy cannot be guaranteed.
-j|--jobs JOBS The maximum number of parallel processes for performing conversion.
Converting images is system RAM heavy so it is possible to run out of memory if you have a lot of processes and not enough RAM to accommodate them all.
Setting this to 0 will use the maximum available.
No matter what you set this to, it will never attempt to use more processes than are available on your system.
If singleprocess is enabled this setting will be ignored.
-T|--on-the-fly Enable On-The-Fly Conversion. NOT recommended. You should generate a clean alignments file for your destination video.
However, if you wish you can generate the alignments on-the-fly by enabling this option.
This will use an inferior extraction pipeline and will lead to substandard results.
If an alignments file is found, this option will be ignored.
-k|--keep-unchanged When used with --frame-ranges outputs the unchanged frames that are not processed instead of discarding them.
-s|--swap-model Swap the model. Instead converting from of A -> B, converts B -> A
-P|--singleprocess Disable multiprocessing. Slower but less resource intensive.
```