Skip to main content

ChuanSuo (穿梭)

Make videos seamlessly loopable by reordering frames.

Features

  • Extract even-indexed frames, reverse them, and append to create a seamless loop
  • Sort frames by visual similarity for smooth transitions
  • Audio handling options: reorder with video, keep original, or apply crossfade smoothing
  • Lossless compression: Multiple strategies (delta, sparse, spatial, combined) with TSP reordering
  • The output video always ends at frame 0, enabling perfect looping
  • CLI with unified flags (-V, -v, -o, --json, -q)
  • Python API with ToolResult pattern
  • OpenAI function-calling integration

Requirements

  • Python 3.10+
  • opencv-python >= 4.8.0
  • numpy >= 1.24.0
  • pydub >= 0.25.0
  • ffmpeg (system dependency for audio processing)

Installation

pip install -e .

Quick Start

# Make a video loopable
chuansuo input.mp4 -o output.mp4

# Verbose mode
chuansuo input.mp4 -o output.mp4 -v

# JSON output
chuansuo input.mp4 -o output.mp4 --json

Usage

Algorithm

Loop Mode

Given frames [0, 1, 2, 3, ..., N-1]:

  1. Split into odd-indexed frames: [1, 3, 5, ...]
  2. Split into even-indexed frames: [0, 2, 4, ...]
  3. Output: odd frames + reversed even frames

Example with 10 frames: [1, 3, 5, 7, 9, 8, 6, 4, 2, 0]

The video ends at frame 0, enabling seamless looping back to 1. Total frame count and duration are unchanged - only the order is rearranged.

Compress Mode

  1. Greedy TSP reordering: Frames are reordered using a greedy traveling salesman algorithm to minimize inter-frame pixel differences (entropy increase)
  2. Delta encoding: First frame stored as key frame (PNG lossless), subsequent frames store only changed pixels with zlib compression
  3. Lossless verification: Frames are reconstructed from deltas and verified pixel-perfect before output

Compression ratio depends on video content:

  • Static scenes: 5-15% of original raw size
  • Moderate motion: 20-40% of original raw size
  • High motion: 40-60% of original raw size

Audio is processed identically: split into frame-aligned segments, reordered using the same pattern, and merged back with the video to maintain perfect A/V sync.

CLI

usage: chuansuo [-h] [-V] [-v] [-o OUTPUT] [--json] [-q] [-m MODE] input

Make videos seamlessly loopable by reordering frames

positional arguments:
  input                 Input video file path

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         Enable verbose output
  -o OUTPUT, --output OUTPUT
                        Output video path (default: input_loop.mp4)
  --json                Output result as JSON
  -q, --quiet           Suppress non-essential output
  -m MODE, --mode MODE  Processing mode: loop, similarity, compress, or compare
  --smooth-audio        Apply crossfade between audio segments
  --audio-fade-ms MS    Crossfade duration in milliseconds (default: 50)
  --keep-audio          Keep original audio track unchanged

Python API

from chuansuo import chuansuo_make_loop

result = chuansuo_make_loop(
    input_path="input.mp4",
    output_path="output.mp4",
    verbose=True,
)
print(result.success)    # True / False
print(result.data)       # Processing metadata
print(result.metadata)   # Metadata including version

Agent Integration

from chuansuo.tools import TOOLS, dispatch

# TOOLS contains the OpenAI function-calling schema
# dispatch() routes tool calls to the appropriate API function
result = dispatch("chuansuo_make_loop", {"input_path": "video.mp4"})

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Lint
ruff format . && ruff check .

License

GPL-3.0

Metadata

Release files for chuansuo 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chuansuo 0.1.2
File Size Uploaded Provenance
chuansuo-0.1.2.tar.gz 37.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for chuansuo 0.1.2
File Interpreter ABI Platform
chuansuo-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 73.9 kB

Release files / chuansuo-0.1.2.tar.gz

Download URL chuansuo-0.1.2.tar.gz
Size 37.0 kB
Tags Source
SHA-256 checksum
How to use checksums
597c42117764b7f3816a315de80a266b175c5ed2c3d6f55526046fb769582d00
BLAKE2b-256 checksum
How to use checksums
4e06766660c2f7fce582c18d0601f47e80add209da4d6d6193f1ada28e24c37a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / chuansuo-0.1.2-py3-none-any.whl

Download URL chuansuo-0.1.2-py3-none-any.whl
Size 36.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cad3da03de92232f6e73bb1cf702f8c182689b05921178c5d42df557dc4481aa
BLAKE2b-256 checksum
How to use checksums
c51f8e79533bbe88f34aa6fce99b864d2b6bc0d90050f498421bb0f13dd2ecbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for chuansuo 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page