How the `--exp` and `--fps` Parameters Control Video Interpolation in `inference_video.py`

The --exp parameter defines a power-of-two multiplier for frame generation (default 1 = 2× frames), while --fps optionally overrides the output frame rate regardless of the interpolation factor.

The inference_video.py script in the RIFE (Real-Time Intermediate Flow Estimation) repository serves as the primary command-line interface for video frame interpolation. These two arguments directly govern the temporal resolution of your output, controlling both how many intermediate frames the neural network synthesizes and the playback speed encoded in the final video file.

Understanding the --exp Interpolation Exponent

The --exp parameter acts as an exponent to determine the upsampling factor. In inference_video.py, the argument parser defines it with a default value of 1:

parser.add_argument('--exp', dest='exp', type=int, default=1)

The script calculates the total interpolation factor as 2 ** args.exp. This value drives three critical operations in the source code:

  • Frame rate multiplication: At lines 118-121, the script computes args.fps = fps * (2 ** args.exp) to determine the target playback rate when --fps is not manually specified.
  • Filename annotation: Lines 150-152 build the output filename using '{}_{}X_{}fps.'.format(..., 2**args.exp, ...) to indicate the upsampling level.
  • Frame generation count: The make_inference call at lines 258-260 receives 2**args.exp-1, dictating exactly how many intermediate frames to generate between each pair of source frames.

For example:

  • exp=1 generates 1 intermediate frame between each source pair (2× total frames)
  • exp=2 generates 3 intermediate frames (4× total frames)
  • exp=3 generates 7 intermediate frames (8× total frames)

Performance Implications

Higher exponent values produce smoother motion but increase computational load exponentially. Because the script calls the inference model 2^exp - 1 times per source interval, setting --exp 3 requires generating seven times more frames than the original video, significantly increasing GPU memory usage and processing time.

Understanding the --fps Output Override

While --exp determines interpolation density, --fps controls the temporal metadata written to the output video container. The argument is defined at lines 66-68:

parser.add_argument('--fps', dest='fps', type=int, default=None)

When omitted, the script defaults to None and automatically calculates the output FPS based on the source FPS multiplied by 2 ** args.exp (lines 118-121). When you provide a specific integer, the script bypasses this calculation and passes your value directly to cv2.VideoWriter at line 152.

This decoupling allows specific use cases: you can generate 4× intermediate frames (--exp 2) but encode the video at 60 FPS to create slow-motion footage, or force 24 FPS to match film standards regardless of the source material.

Practical Usage Examples

Here are concrete command-line scenarios demonstrating parameter interaction:

Double the frame rate using default settings:

python inference_video.py --video input.mp4 --output out.mp4

Quadruple the frame rate with explicit exponent (auto-calculates output FPS to 4× source):

python inference_video.py --video input.mp4 --exp 2 --output out_quad.mp4

Generate 4× frames but force 60 FPS output (creating slow-motion if source was 30 FPS):

python inference_video.py --video input.mp4 --exp 2 --fps 60 --output out_60fps.mp4

Process an image sequence with 8× upsampling:

python inference_video.py --img ./frames/ --exp 3 --output seq_out.mp4

Summary

  • --exp sets the interpolation exponent; the script generates 2^exp - 1 frames between each source pair and multiplies the source frame rate by 2^exp when --fps is not specified.
  • --fps overrides the output frame rate metadata in inference_video.py, allowing custom playback speeds independent of the interpolation factor.
  • Default behavior: With --exp 1 and no --fps, the script doubles the source frame rate automatically using the logic at lines 118-121.
  • Key implementation: The upsampling logic resides in inference_video.py lines 118-121 and 258-260, with the final video encoding performed at line 152 using the calculated or overridden FPS value.

Frequently Asked Questions

What is the default value of --exp in inference_video.py?

The default value is 1, which produces a 2× upsampling factor (one interpolated frame between each source frame). This is defined in the argument parser near the beginning of the script and results in the output frame rate being double the input rate unless --fps is specified.

How does the --exp value affect GPU memory usage?

Processing requirements scale with 2 ** exp because the script calls the make_inference function 2^exp - 1 times per source frame interval. Setting --exp 3 requires the model to generate seven intermediate frames for every source frame, significantly increasing VRAM consumption and compute time compared to the default --exp 1.

Should I use --fps or let the script calculate the frame rate automatically?

Use automatic calculation (omit --fps) when you want the output to play at normal speed with higher temporal resolution. Specify --fps when you need to match specific broadcast standards (e.g., 24p, 60p) or create slow-motion effects where the interpolation factor exceeds the desired playback rate.

Can I use --fps without --exp?

Yes. If you specify --fps without changing --exp from its default of 1, the script will still generate 2× frames (one interpolation per source pair) but encode them at your specified rate. This effectively speeds up or slows down the video playback relative to real-time, depending on whether your specified FPS is higher or lower than the source FPS multiplied by 2.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →