PPTX
Media
Embed video and audio files into slides with poster images
Embed video and audio content into your presentations using the video and audio slide element types.
The data and poster fields accept raw bytes (Uint8Array, ArrayBuffer, Buffer) or a base64 data URL such as data:image/png;base64,....
Video
import { generatePresentation } from "@office-open/pptx";
{
"slides": [
{
"children": [
{
"video": {
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "10.6cm",
"data": "data:video/mp4;base64,AAAAHGZ0eXBtcDQy...",
"type": "mp4"
}
}
]
}
]
}
generatePresentation({
slides: [
{
children: [
{
video: {
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "10.6cm",
data: new Uint8Array(fs.readFileSync("video.mp4")),
type: "mp4",
},
},
],
},
],
});
Video with Poster Image
A poster image is shown before the video starts playing:
{
"slides": [
{
"children": [
{
"video": {
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "10.6cm",
"data": "data:video/mp4;base64,AAAAHGZ0eXBtcDQy...",
"type": "mp4",
"poster": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
"posterType": "jpg"
}
}
]
}
]
}
generatePresentation({
slides: [
{
children: [
{
video: {
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "10.6cm",
data: new Uint8Array(fs.readFileSync("video.mp4")),
type: "mp4",
poster: new Uint8Array(fs.readFileSync("poster.jpg")),
posterType: "jpg",
},
},
],
},
],
});
If no poster is provided, a minimal transparent placeholder is used automatically.
Audio
import { generatePresentation } from "@office-open/pptx";
{
"slides": [
{
"children": [
{
"audio": {
"x": "1.3cm",
"y": "10.1cm",
"width": "5.3cm",
"height": "1.3cm",
"data": "data:audio/mp3;base64,SUQzBAAAAAAAI...",
"type": "mp3"
}
}
]
}
]
}
generatePresentation({
slides: [
{
children: [
{
audio: {
x: "1.3cm",
y: "10.1cm",
width: "5.3cm",
height: "1.3cm",
data: new Uint8Array(fs.readFileSync("audio.mp3")),
type: "mp3",
},
},
],
},
],
});
Supported Formats
Video (type)
| Value | Format |
|---|---|
mp4 | MP4 |
mov | MOV |
wmv | WMV |
avi | AVI |
Audio (type)
| Value | Format |
|---|---|
mp3 | MP3 |
wav | WAV |
wma | WMA |
aac | AAC |
Options
Video
| Property | Type | Default | Description |
|---|---|---|---|
x | number | UniversalMeasure | 0 | Left position (EMU or UniversalMeasure) |
y | number | UniversalMeasure | 0 | Top position (EMU or UniversalMeasure) |
width | number | UniversalMeasure | 0 | Width (EMU or UniversalMeasure) |
height | number | UniversalMeasure | 0 | Height (EMU or UniversalMeasure) |
data | Uint8Array | - | Video file data |
type | "mp4" | "mov" | "wmv" | "avi" | - | Video format |
name | string | auto | Display name |
poster | Uint8Array | auto | Poster image data |
posterType | "png" | "jpg" | "png" | Poster image format |
animation | AnimationOptions | - | Play animation |
Audio
| Property | Type | Default | Description |
|---|---|---|---|
x | number | UniversalMeasure | 0 | Left position (EMU or UniversalMeasure) |
y | number | UniversalMeasure | 0 | Top position (EMU or UniversalMeasure) |
width | number | UniversalMeasure | 0 | Width (EMU or UniversalMeasure) |
height | number | UniversalMeasure | 0 | Height (EMU or UniversalMeasure) |
data | Uint8Array | - | Audio file data |
type | "mp3" | "wav" | "wma" | "aac" | - | Audio format |
name | string | auto | Display name |
animation | AnimationOptions | - | Play animation |
Tips
- Provide a poster image for videos to ensure a visual preview is shown before playback.
- Audio frames are typically small and positioned at the bottom of a slide.
- Media files are embedded directly into the
.pptxfile — keep file sizes reasonable for performance. - Supported playback depends on the presentation viewer (PowerPoint, Keynote, Google Slides, etc.).