Skip to main content

LongSoraGen

English | 简体中文

This project provides a full OpenAI-compatible API for generating longer Sora videos by intelligently splitting them into segments and ensuring seamless continuity.

1. Overview

LongSoraGen overcomes Sora's duration limitations by breaking down long video generation requests into multiple connected segments. The system uses AI-powered planning to create coherent narratives across segments and maintains visual continuity by using the last frame of each segment as a reference for the next.

Some of the code and idea is from https://github.com/mshumer/sora-extend, thank you for their work.

✅ Note: This codebase has been tested and verified to work correctly. If you encounter any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request.

2. How It Works

LongSoraGen's main idea follows mshumer's ideas and operates in three main stages:

  1. We segment the total video durations into segmentations, and generate prompt for each segmentation.

  2. We use the frame from the last video as the frame reference to generate the following frames.

  3. Finally, we combine all the video segments.

3. Installation

FFmpeg is needed for video processing, please install it first.

  1. Install from pypi:

We have distributed our library to PyPI, check it out:

pip install longsora
  1. Install from scratch:

We highly recommend using the uv to install the environments:

uv sync

The environment will be installed in .venv. Activate it using:

source .venv/bin/activate

Set up OpenAI API Key:

export OPENAI_API_KEY='your-api-key-here'

4. Quick Start

Basic Example (Synchronous)

from pathlib import Path
from longsora import OpenAI

output_dir = Path("resources") / "case1"
prompt = "A woman is dancing in a bunch of trees."
model = "sora-2"
seconds_per_segment = 8
num_generations = 3
print(f"the video will be {seconds_per_segment * num_generations} seconds long")

if __name__ == "__main__":
    client = OpenAI()
    client.create_video(
        prompt=prompt,
        model=model,
        seconds_per_segment=seconds_per_segment,
        output_dir=output_dir,
        num_generations=num_generations,
        verbose=True,
        save_segments=True,
        plan_model="gpt-5",
    )

Async Example

import asyncio
from pathlib import Path
from longsora import AsyncOpenAI

output_dir = Path("resources") / "case2"
prompt = "A woman is dancing in a bunch of trees."
seconds_per_segment = 8
model = "sora-2"
num_generations = 2

print(f"the video will be {seconds_per_segment * num_generations} seconds long")

async def main():
    client = AsyncOpenAI()
    await client.create_video(
        prompt=prompt,
        model=model,
        seconds_per_segment=seconds_per_segment,
        output_dir=output_dir,
        num_generations=num_generations,
        verbose=True,
        save_segments=True,
        plan_model="gpt-5",
    )

if __name__ == "__main__":
    asyncio.run(main())

5. License

MIT License

Copyright (c) 2025 LLinkedlist

See LICENSE for details.

6. Citation

If you use this project in your research or applications, please cite:

@misc{longsoragen2025,
  author = {linkedlist771},
  title = {LongSoraGen: Extended Video Generation with OpenAI Sora},
  year = {2025},
  url = {https://github.com/linkedlist771/LongSoraGen}
}

Metadata

Release files for longsora 0.1.5

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

Source distribution (sdist)

Source distribution for longsora 0.1.5
File Size Uploaded Provenance Actions
longsora-0.1.5.tar.gz 447.8 kB Without provenance Details for longsora-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 1.5 MB

Release files / longsora-0.1.5.tar.gz

Download URL longsora-0.1.5.tar.gz
Size 447.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0740e7248576a2846b0cd7894d8b7be690aaf139b2916674fef220596e3f9fc9
BLAKE2b-256 checksum
How to use checksums
32df14deb4fbee67f6bcfe88f5a1b2fb8a0d03232c98b881f1a64cd5c07796a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.0

Release files / longsora-0.1.5-py3-none-any.whl

Download URL longsora-0.1.5-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
10b35487856ef8c931b471339f19531368661a1537f7fd2bc5f59360d899ab81
BLAKE2b-256 checksum
How to use checksums
dbd5fc1dfde811c61b87c3c977432320bb0730e709883294dd45f7cedb01dc53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.0

Security for longsora 0.1.5

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.

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