> This page is for NVIDIA Synthetic Video Detector NIM, version 1.0.0.
> For other versions, use one of these documentation indexes:
> - 2.0.0 (Latest) (default): https://docs.nvidia.com/nim/maxine/synthetic-video-detector/2.0.0/llms.txt
> - 1.0.0: https://docs.nvidia.com/nim/maxine/synthetic-video-detector/1.0.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nim/maxine/llms.txt.

# Basic Inference

This guide demonstrates how to perform basic inference with the Synthetic Video Detector NIM over gRPC.

## Prerequisites

1. Ensure that the Synthetic Video Detector NIM container is running. For container launch instructions, refer to [Getting Started](/nim/maxine/synthetic-video-detector/1.0.0/getting-started).

2. Verify that the service is accessible by performing a health check on the gRPC endpoint.

   - Install `grpcurl` from [github.com/fullstorydev/grpcurl/releases](https://github.com/fullstorydev/grpcurl/releases).

      Example commands to run on Ubuntu:

      ```bash
      wget https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_amd64.deb
      sudo dpkg -i grpcurl_1.9.1_linux_amd64.deb
      ```

   - Download the health checking proto:

      ```bash
      wget https://raw.githubusercontent.com/grpc/grpc/master/src/proto/grpc/health/v1/health.proto
      ```

   - Run the health check:

      ```bash
      grpcurl --plaintext --proto health.proto localhost:8001 grpc.health.v1.Health/Check
      ```

     If the service is ready, you get a response similar to the following:

      ```bash
      { "status": "SERVING" }
      ```
   <Note>
   For using grpcurl with an SSL-enabled server, avoid using the `--plaintext` argument, and use `--cacert` with a CA certificate, `--key` with a private key, or `--cert` with a certificate file. For more details, refer to `grpcurl --help`.
   </Note>

3. Download the Synthetic Video Detector Python client code by cloning the Clients repository ([NVIDIA-Maxine/nim-clients](https://github.com/NVIDIA-Maxine/nim-clients)):

   ```bash
   git clone https://github.com/NVIDIA-Maxine/nim-clients.git

   # Go to the 'synthetic-video-detector' folder

   cd nim-clients/synthetic-video-detector/ 
   ```

4. Install the required dependencies:

   ```bash
   sudo apt-get install python3-pip
   pip install -r requirements.txt
   ```   


##  Compile the Protos (Optional)

If you want to use the client code provided in the Clients repository ([NVIDIA-Maxine/nim-clients](https://github.com/NVIDIA-Maxine/nim-clients)), you can skip this step.

The proto files are available in the `synthetic-video-detector/protos` folder. You can compile them to generate client interfaces in your preferred programming language. For more details, refer to [Supported languages](https://grpc.io/docs/languages/) in the gRPC documentation.

The following is an example of how to compile the protos for Python on Linux and Windows.
The `grpcio` version needed for compilation can be referred from `requirements.txt`

To compile protos on Linux:

```bash
# Go to synthetic-video-detector/protos/linux folder
cd synthetic-video-detector/protos/linux

chmod +x compile_protos.sh
./compile_protos.sh
```

To compile protos on Windows:

```bash
# Go to synthetic-video-detector/protos/windows folder
cd synthetic-video-detector/protos/windows

./compile_protos.bat
```

## Input and Output

The input and output of the Synthetic Video Detector NIM are `mp4` files. The input file must use the H.264 codec for video and can include audio. The output file contains an overall synthetic probability, with optional intermediate results for analysis.

<Note>
Videos with Variable Frame Rate (VFR) are not supported.
</Note>

<Note>
The Synthetic Video Detector is sensitive to video transcoding and compression; detection accuracy may degrade as compression levels increase.
</Note>

## Running Inference

To run the Synthetic Video Detector NIM, run the Synthetic Video Detector sample client without any additional flags:

Go to the `scripts` directory:

```bash
cd scripts
```

Send a gRPC request:

```bash
python synthetic-video-detector.py --target <server_ip:port> \
   --video-input <input file path> \
   --save-csv
```

<Note>
The first inference is not indicative of the model's actual performance because it includes the time taken by the inference server to load the models in addition to the time required to process the inference request. 
</Note>

### Usage for Preview API Request

```bash
   python synthetic-video-detector.py --preview-mode \
      --target grpc.nvcf.nvidia.com:443 \
      --function-id <function_id> \
      --api-key $NGC_API_KEY \
      --video-input <input_file_path> \
      --output <output_file_path>
```

To view details of command-line arguments, run the following command:

```bash
python synthetic-video-detector.py -h
```
You get a response similar to the following. All parameters are optional.

```text
options:
  -h, --help                        show this help message and exit
  --ssl-mode {DISABLED,MTLS,TLS}    Flag to set SSL mode, default is DISABLED (default: DISABLED)
  --ssl-key SSL_KEY                 The path to ssl private key. (default: ../ssl_key/ssl_key_client.pem)
  --ssl-cert SSL_CERT               The path to ssl certificate chain. (default: ../ssl_key/ssl_cert_client.pem)
  --ssl-root-cert SSL_ROOT_CERT     The path to ssl root certificate. (default: ../ssl_key/ssl_ca_cert.pem)
  --target TARGET                   IP:port of gRPC service, when hosted locally. Use grpc.nvcf.nvidia.com:443 when hosted on NVCF. (default: 127.0.0.1:8001)
  --preview-mode                    Flag to send request to preview NVCF NIM server on https://build.nvidia.com/nvidia/synthetic-video-detector/api. (default: False)
  --api-key API_KEY                 NGC API key required for authentication, utilized when using TRY API ignored otherwise (default: None)
  --function-id FUNCTION_ID         NVCF function ID for the service, utilized when using TRY API ignored otherwise (default: None)
  --video-input VIDEO_INPUT         Path to the input video file to analyze (supports MP4 only) (default: ../assets/fake_sample_video.mp4)
  --save-csv [FILENAME]             Save results to CSV. Optionally specify a custom filename, otherwise uses the input video's base name (e.g., video.csv) (default: False)
```

### Python Notebook

For an interactive experience and to explore all feature parameters, we provide a comprehensive Python notebook that demonstrates the Synthetic Video Detector service capabilities.

The Python notebook is located at `notebook/synthetic_video_detector_notebook.ipynb` in the `synthetic-video-detector` client folder.