# normalize_video

## nominal.experimental.video_processing.normalize_video(input_path, output_path, key_frame_interval=DEFAULT_KEY_FRAME_INTERVAL_SEC, force=True, resolution=None, num_threads=None)

Convert video file to an h264 encoded video file using ffmpeg.

This function will also perform several other processing tasks to ensure that video is
properly encoded in a way that is best supported by nominal.
This includes:

- Ensuring that there are key-frames (I-frames) present approximately every 2s of video content
- Video is encoded with H264
- Audio is encoded with AAC
- Video has YUV4:2:0 planar color space

While this package includes bindings to use ffmpeg installed on your local system, it does not
include ffmpeg as a dependency due to the GPLv3 licensing present in the standard H264 processing library
contained within, thus, you must have ffmpeg installed locally to use this.

Parameters:
:   - **input_path** ([*Path*](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Path to video file on local filesystem.
    - **output_path** ([*Path*](https://docs.python.org/3/library/pathlib.html#pathlib.Path "(in Python v3.15)") *|* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"))

      Path to write converted video file to.

      **Note:** It is expected that the output file is either an mkv or a mp4 file.
    - **key_frame_interval** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      Number of seconds between keyframes allowed in the output video.

      **Note:** While this field is technically optional, setting the right value here
      can be essential to allowing fluid playback on the frontend, in particular,
      in network constrained environments. Setting this value too low or too high
      can impact performance negatively– typically, a value at or around 2s is considered
      “best of both worlds” as a reasonable default value.
    - **force** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)"))

      If true, forcibly delete existing output path if already exists.
    - **resolution** ([*Literal*](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")*[**'480p'**,* *'720p'**,* *'1080p'**,* *'1440p'**,* *'2160p'**]* *|* *~nominal.experimental.video_processing.resolution.VideoResolution* *|* *None*)

      If provided, re-scale the video to fit within the provided resolution, preserving aspect ratio
    - **num_threads** ([*int*](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)") *|* *None*)

      If provided, the number of CPU cores to tell ffmpeg to use.

      **Note:** If not provided, ffmpeg will choose. Typically, this amounts to the number of cores present
      on the machine.

> **Note**
>
> This requires that you have installed ffmpeg on your system with support for H264.
