Metadata-Version: 2.5
Name: fxcue
Version: 0.3.0
Summary: Turn a video into a timestamped, explained effects plan (zooms, transitions, shakes, whooshes) for beginner-friendly editing apps.
Project-URL: Homepage, https://github.com/roy13dec-droid/fxcue
Project-URL: Issues, https://github.com/roy13dec-droid/fxcue/issues
Author: Anal Kanti Roy
License-Expression: MIT
License-File: LICENSE
Keywords: beats,editing,effects,ffmpeg,scene-detection,video
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.10
Requires-Dist: imageio-ffmpeg>=0.5
Requires-Dist: librosa>=0.10
Requires-Dist: numpy>=1.24
Requires-Dist: opencv-python-headless>=4.8
Requires-Dist: scenedetect>=0.6.4
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# fxcue

**Tell your users where the effects go.**

`fxcue` analyses a video and returns an **effects plan**: a list of timestamped
effect cues (zooms, transitions, shakes, whooshes…), each with the reason it was
placed there. It is built for developers making beginner-friendly editing apps,
auto-clippers and video tools. Your app decides how to show or apply each cue.

![fxcue demo: original video on the left, fxcue's suggested effects applied on the right](https://raw.githubusercontent.com/roy13dec-droid/FxCue/main/docs/demo.gif)

*Left: the original. Right: fxcue's plan applied by the example preview script. Footage: [Big Buck Bunny](https://peach.blender.org) © Blender Foundation, [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/).*

```
   0:02.0  transition  1.0  scene change
   0:02.0  whoosh_sfx  1.0  scene change
   0:12.4  zoom_in     0.6  loud moment
   0:45.2  shake       0.7  strong hit
```

- Fast, offline and lightweight. No GPU and no AI model downloads.
- Explainable: every cue says *why* it was placed.
- Never cluttered: built-in spacing keeps effects from piling up.
- Pluggable: add your own detectors and rules.
- Plain JSON output that any language can read.

## Install

```bash
pip install fxcue
```

fxcue reads video through [FFmpeg](https://ffmpeg.org). If FFmpeg isn't on your
system, the bundled `imageio-ffmpeg` binary is used automatically.

## Quickstart

```python
import fxcue

plan = fxcue.plan("video.mp4", style="energetic")
for cue in plan.cues:
    print(cue.time, cue.effect, cue.reason)
plan.save("plan.json")
```

Or from the command line:

```bash
fxcue video.mp4                    # print the plan
fxcue video.mp4 -o plan.json       # save it as JSON
fxcue video.mp4 --style calm
```

## See a plan

`examples/preview.py` renders a rough preview of a plan (effects, sound effects and labels)
so you can judge it by eye and ear:

```bash
python examples/preview.py video.mp4 preview.mp4 --side-by-side
```

It's an illustration: in your app, apply cues with your own effects.

## Effects

Effect names are generic, so your app can map each one to its own assets.

| Effect        | Kind   | Placed on (energetic style)          |
|---------------|--------|--------------------------------------|
| `transition`  | visual | scene changes                        |
| `whoosh_sfx`  | audio  | scene changes                        |
| `zoom_in`     | visual | loud moments                         |
| `punch_zoom`  | visual | very loud moments (replaces zoom_in) |
| `impact_sfx`  | audio  | very loud moments                    |
| `shake`       | visual | strong hits                          |
| `flash`       | visual | strong music beats                   |

## Styles

| Style       | Min gap between visual effects | Max visual effects per minute | Uses |
|-------------|----|----|-----------------------------------------------|
| `calm`      | 4 s   | 6  | transitions, zooms on very loud moments |
| `energetic` | 1.5 s | 20 | everything above (default) |
| `vlog`      | 2.5 s | 12 | transitions + whooshes, zooms |

There is never more than one visual effect at the same moment. When effects
collide, story moments win over decoration: scene change > loud moment >
strong hit > music beat, then the stronger one. A sound effect is dropped when
the visual effect it belongs to is dropped.

## JSON output

```json
{
  "schema_version": 1,
  "duration": 6.0,
  "style": "energetic",
  "cues": [
    {"time": 2.0, "effect": "transition", "strength": 1.0,
     "reason": "scene change", "source": "scenes", "duration": 0.5, "priority": 3,
     "explanation": "The picture changes completely here: a new shot starts"}
  ]
}
```

`duration` is a suggested length in seconds; apps may ignore it. Load a saved
plan with `fxcue.Plan.load("plan.json")`.

## Show beginners *why*

Every cue has a short `reason` (`"loud moment"`) and an `explanation` with a measured,
checkable number, something a beginner can verify by listening or watching:

```
0:09.5  zoom_in     About 19 dB louder than the rest of the clip, roughly 3.7x as loud to the ear
0:11.9  transition  The picture changes completely here: a new shot starts
0:21.4  flash       On the beat of the music (about 123 BPM)
```

Each cue also has a `strength` from 0 to 1, so your app doesn't have to treat every
suggestion the same. For example, apply strong cues and offer weak ones as optional:

```python
apply   = [c for c in plan.cues if c.strength >= 0.6]
suggest = [c for c in plan.cues if c.strength < 0.6]
```

## Re-plan part of a video

Trimmed the outro or swapped a scene? Keep the cues your user already accepted and get
fresh suggestions only for the part that changed:

```python
accepted = fxcue.Plan.load("accepted.json")          # or a list of Cue objects
plan = fxcue.plan("video_v2.mp4", start=42.0, keep=accepted)
```

- `start` / `end` (seconds) limit where **new** cues are suggested.
- `keep` cues come back unchanged; new suggestions keep their distance from them and
  respect the style's per-minute limit. Kept cues past the end of a trimmed video are dropped.

From the command line: `fxcue video_v2.mp4 --start 42 --keep accepted.json -o plan.json`

## Customise

**Your own rules** replace the style's rules but keep its spacing:

```python
from fxcue import Rule

plan = fxcue.plan("video.mp4", rules=[
    Rule("scene_change", ["flash", "whoosh_sfx"]),
    Rule("loud_peak", ["shake"], min_strength=0.5),
])
```

Event kinds from the built-in detectors are `scene_change`, `loud_peak`, `beat` and `onset`.

**Your own detector**, for example one using an AI model:

```python
from fxcue import Event

class LaughDetector:
    name = "laughs"
    needs = "audio"          # or "video"

    def detect(self, media):  # media.path, media.audio (samples, rate) or None, media.duration
        return [Event(time=12.3, kind="loud_peak", strength=0.9, source=self.name)]

fxcue.register_detector(LaughDetector())   # used by every plan() call from now on
```

## How it works

```
video ─► detectors ─► events ─► style rules ─► spacing pass ─► plan
```

- **scenes**: hard cuts, found with [PySceneDetect](https://www.scenedetect.com/)
- **loudness**: moments much louder than the clip's own typical level ([librosa](https://librosa.org/))
- **beats**: music beats and strong hits (librosa)

## Roadmap

- Optional preview render, so you can see a plan applied
- Optional AI detectors (speech emphasis, laughter, faces)
- More effects and styles, contributed by the community

## Contributing

Contributions are welcome, especially new detectors, styles and effect ideas.
See [CONTRIBUTING.md](CONTRIBUTING.md).

## Licence

MIT © Anal Kanti Roy. See [LICENSE](LICENSE).
