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.

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

    • Install grpcurl from github.com/fullstorydev/grpcurl/releases.

      Example commands to run on Ubuntu:

      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:

      wget https://raw.githubusercontent.com/grpc/grpc/master/src/proto/grpc/health/v1/health.proto
      
    • Run the health check:

      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:

      { "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.

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

    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:

    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), 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 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:

# 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:

# 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

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

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:

cd scripts

Send a gRPC request:

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.

Usage for Preview API Request#

   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:

python synthetic-video-detector.py -h

You get a response similar to the following. All parameters are optional.

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.