Skip to main content

Automated frame-by-frame rendering and video synthesis for physics simulations and generative game shorts.

Project description

DeepFlow-Engine

PyPI Downloads License

pygame

🚀 What is DeepFlow?

DeepFlow is a frame-by-frame simulation engine designed for games and physics systems that lets you:

  • 🎮 Run games interactively (like normal pygame) with optional playback recording
  • ⚙️ Simulate them headlessly (no window) for batch processing
  • 🎞️ Generate frames automatically for video synthesis
  • 🔊 Log events (like collisions) and trigger audio events
  • 🎬 Render videos with perfectly synced audio (ready for reels/shorts)
  • 📤 Publish outputs directly (Telegram, Discord coming soon)

🧠 Core Idea

Write your game once, and use it in multiple modes:

Game Logic → Engine → Frames → Video → Publish

This separation of concerns allows you to:

  • Develop interactively with real-time feedback
  • Generate content programmatically for automation
  • Test deterministically in headless mode
  • Scale to batch video generation

📦 Installation

pip install deepflow-engine

Requirements: Python 3.12+


📚 Documentation & Examples

For complete working examples, check out the example/ directory:

  • 🎮 Full game implementation with collision detection
  • 🎬 Interactive and headless modes
  • 📹 Video rendering with audio
  • 🎯 Best practices and patterns

Run examples:

cd example
python main.py --help

⚡ Quick Start

1. Create a Game

Extend DeepFlowGame with your game logic:

import deepflow_engine as dfe
import pygame


class MyGame(dfe.DeepFlowGame):
    def start(self):
        """Initialize game state"""
        self.x = 100

    def update(self):
        """Update game logic (called every frame)"""
        self.x += 100 * self.dt  # Always use dt for frame-independent movement!

    def render(self, canvas):
        """Render game state to canvas"""
        canvas.fill((255, 255, 255))
        pygame.draw.circle(canvas, (0, 0, 255), (int(self.x), 200), 20)

    def get_audio_map(self):
        """Map event types to audio files"""
        return {}

2. Run the Engine

Interactive Mode (Preview & Play)

game = MyGame()
engine = dfe.DeepFlowEngine(game, interactive=True)
dfe.run_pipeline(engine)

Headless Mode (Generate Video)

game = MyGame()
engine = dfe.DeepFlowEngine(
    game,
    interactive=False,
    frames_dir="frames",
    video_length_seconds=10,
)

output = dfe.run_pipeline(engine)
print(f"Video saved: {output}")

🎯 Complete Example

For a complete, production-ready example with collision detection, event handling, and video generation, see the example/ directory:

# Run interactive mode
python example/main.py --interactive

# Generate video headlessly
python example/main.py --headless --duration 10

The example demonstrates best practices for building games with DeepFlow.


🎥 Output

DeepFlow automatically:

  1. Simulates your game frame-by-frame
  2. Saves frames to disk
  3. Logs events (collisions, audio triggers, etc.)
  4. Renders video with synced audio

Output structure:

frames/                    # Individual frames
collisions_log.json       # Event log
deepflow_output.mp4       # Final video

🔊 Audio System

Define Audio Assets

In your game class:

def get_audio_map(self):
    return {
        "collision": "assets/crash.wav",
        "score": "assets/point.wav",
    }

Trigger Events

During gameplay:

def update(self):
    if self.collision_detected():
        self.play_audio("collision")

Behavior

  • Interactive mode: Plays sound instantly
  • Headless mode: Logs event for final video rendering

🎮 Input Handling

Use get_input() abstraction:

def get_input(self):
    if self._engine.interactive:
        return pygame.key.get_pressed()
    return None

⏱️ Time-Based Movement (IMPORTANT)

Always use dt:

self.x += speed * self.dt

❌ Don’t do:

self.x += 5

🧩 Engine Modes

Mode Use Case Interactive
Interactive Play/preview the game in real-time Yes
Interactive + Record Play while recording frames for video Yes
Headless Batch generate deterministic simulations No
Pipeline Full automated video generation No

📤 Publishing (Optional)

Telegram

Send generated videos directly to Telegram:

from deepflow_engine.publisher import TelegramPublisher

publisher = TelegramPublisher(bot_token="YOUR_BOT_TOKEN", chat_id="YOUR_CHAT_ID")
publisher.send_video("deepflow_output.mp4")

Discord (Open for Contributions 🚀)

A Discord publisher is in the roadmap.

Interested in implementing it?

  • Implement DiscordPublisher extending BasePublisher
  • Follow the existing TelegramPublisher pattern
  • Open a PR with tests

🧠 Design Philosophy

DeepFlow follows clean architecture principles:

Game     → Pure game logic (independent of engine)
Engine   → Execution engine (runs game at any speed)
Renderer → Video output (handles frame->video conversion)
Publisher→ Distribution (sends to external services)

This separation ensures:

  • ✅ Games are testable and reusable
  • ✅ Easy to add new modes (headless, interactive, streaming)
  • ✅ Simple to integrate with other tools

🔥 Use Cases

  • 🎮 Game Automation: Auto-play games and record gameplay
  • 🎬 Content Creation: Generate Instagram Reels/YouTube Shorts automatically
  • 🧪 Simulation & Visualization: Physics simulations with video output
  • 🤖 AI/RL Training: Gym-style environments with video logging (coming soon)
  • 🧠 Generative Content: Batch create variations of games for viral content

🛠️ Roadmap

  • Discord publisher
  • CLI tool (deepflow run game.py)
  • Gymnasium/Gym integration for RL
  • Multi-event timeline system
  • Streaming output support
  • WebGL renderer for browser playback

🤝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and write tests
  4. Commit with clear messages (git commit -m 'Add amazing feature')
  5. Push and open a Pull Request

Guidelines:

  • Keep the API clean and intuitive
  • Avoid tight coupling between game and engine
  • Prefer composition over inheritance
  • Add tests for new features
  • Update documentation

📜 License

Apache 2.0 License - see LICENSE for details


👀 Final Note

DeepFlow is not just a game engine.

It's a content engine - designed to transform game logic into automated, scalable content production.

Use it to build interactive experiences, and let it generate the reels.


Made with ❤️ by deependujha

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepflow_engine-0.1.5.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepflow_engine-0.1.5-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file deepflow_engine-0.1.5.tar.gz.

File metadata

  • Download URL: deepflow_engine-0.1.5.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for deepflow_engine-0.1.5.tar.gz
Algorithm Hash digest
SHA256 213c87e4a714efaab7cc948c62296f3a689ef1088837a91fa9ed97c03f81b346
MD5 7030f4264e1c8f178dfcd4e77e84e827
BLAKE2b-256 16dce98adb7e59fe8498ca3faddca70a7cc060d48c1d00f975ef408f2eb321f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepflow_engine-0.1.5.tar.gz:

Publisher: release-pypi.yml on deependujha/DeepFlow-Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepflow_engine-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for deepflow_engine-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 51da4dace816713472d89c95eecbb2a37f793fb8b7f2c91ed9097fe5b57491ad
MD5 84e5749e8cd825f7a28de6f14db33d6c
BLAKE2b-256 db2bb3760d2cdd10147255d59d4697654f58bbb6ffec61d66cffd22915f4a7af

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepflow_engine-0.1.5-py3-none-any.whl:

Publisher: release-pypi.yml on deependujha/DeepFlow-Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page