defineVideoConfig
Declare video configuration directly in your component. This is a compile-time macro — you don't need to import it.
Basic Usage
<script setup>
// No import needed! defineVideoConfig is a compiler macro
defineVideoConfig({
durationInSeconds: 5
})
import { useFrame } from 'pellicule'
const frame = useFrame()
</script>Then render with zero flags:
npx pellicule Video.vueThat's it! Pellicule reads the duration from your component.
Why a Macro?
defineVideoConfig works like Vue's defineProps — it's recognized by the compiler and doesn't exist at runtime. This gives you:
- Zero boilerplate — no imports needed
- Self-documenting components — duration is declared where it's used
- IDE support — static analysis tools can read the config
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
durationInSeconds | number | - | Duration in seconds (recommended) |
durationInFrames | number | 90 | Duration in frames |
fps | number | 30 | Frames per second |
width | number | 1920 | Video width in pixels |
height | number | 1080 | Video height in pixels |
audio | string | - | Path to audio file (relative to component) |
Use either durationInSeconds or durationInFrames, not both.
Examples
Simple Duration
<script setup>
defineVideoConfig({
durationInSeconds: 5
})
</script>4K Video at 60fps
<script setup>
defineVideoConfig({
durationInSeconds: 10,
fps: 60,
width: 3840,
height: 2160
})
</script>Square Video (Instagram)
<script setup>
defineVideoConfig({
durationInSeconds: 15,
width: 1080,
height: 1080
})
</script>Precise Frame Count
<script setup>
defineVideoConfig({
durationInFrames: 147 // Exactly 147 frames
})
</script>With Background Audio
<script setup>
defineVideoConfig({
durationInSeconds: 30,
audio: './background-music.mp3'
})
</script>The audio path is resolved relative to the component file. Supported formats include MP3, WAV, AAC, and any format FFmpeg supports.
TIP
Audio does not affect video duration. If audio is shorter, it ends early. If longer, it's truncated to match the video length.
How It Works
┌─────────────────────────────────────────────────────────────┐
│ 1. You write defineVideoConfig() in <script setup> │
│ 2. CLI extracts config before rendering │
│ 3. Vite plugin strips the call during compilation │
│ 4. Component gets values via useVideoConfig() at runtime │
└─────────────────────────────────────────────────────────────┘The macro is processed at compile time:
- CLI extracts — Parses your
.vuefile and reads the config values - Plugin strips — Removes the
defineVideoConfig()call before Vue compiles - Runtime receives — Your component accesses values via
useVideoConfig()
Priority Order
CLI flags always win:
CLI flags > defineVideoConfig > built-in defaultsOverride component config with CLI flags:
# Component says 5 seconds, but render 10 instead
npx pellicule Video.vue -d 300Relationship with useVideoConfig
defineVideoConfig | useVideoConfig | |
|---|---|---|
| When | Compile time | Runtime |
| Purpose | Declare intended config | Access actual values |
| Import | Not needed (macro) | Required |
| Used by | CLI | Component code |
Use both together:
<script setup>
// Macro - declares what this video should be
defineVideoConfig({
durationInSeconds: 5
})
// Composable - reads actual values (might differ if CLI overrides)
import { useFrame, useVideoConfig } from 'pellicule'
const frame = useFrame()
const { fps, durationInFrames, width, height } = useVideoConfig()
</script>Static Values Only
The macro extracts values at compile time, so use literal values:
<script setup>
// ✅ Works - literal values
defineVideoConfig({
durationInSeconds: 5,
fps: 30
})
// ❌ Won't work - computed values
const FPS = 30
defineVideoConfig({
durationInFrames: FPS * 5 // Can't evaluate at compile time
})
</script>Use durationInSeconds instead of computing frames manually.