PPTX
Media
Embed video and audio files into slides with poster images
Embed video and audio content into your presentations using VideoFrame and AudioFrame.
Video
import { Slide, VideoFrame } from "@office-open/pptx";
import fs from "node:fs";
new Slide({
children: [
new VideoFrame({
x: 1,
y: 1,
width: 6,
height: 4,
data: fs.readFileSync("video.mp4"),
mimeType: "video/mp4",
}),
],
});
Video with Poster Image
A poster image is shown before the video starts playing:
new VideoFrame({
x: 1,
y: 1,
width: 6,
height: 4,
data: fs.readFileSync("video.mp4"),
mimeType: "video/mp4",
posterData: fs.readFileSync("poster.jpg"),
posterImageType: "jpg",
});
Audio
import { Slide, AudioFrame } from "@office-open/pptx";
import fs from "node:fs";
new Slide({
children: [
new AudioFrame({
x: 1,
y: 4,
width: 2,
height: 0.5,
data: fs.readFileSync("audio.mp3"),
mimeType: "audio/mpeg",
}),
],
});
Audio with Custom Poster
new AudioFrame({
x: 6,
y: 4,
width: 2,
height: 0.5,
data: fs.readFileSync("narration.mp3"),
mimeType: "audio/mpeg",
posterData: fs.readFileSync("speaker-icon.png"),
posterImageType: "png",
});
Supported Media Formats
Video
| Format | MIME Type |
|---|---|
| MP4 | video/mp4 |
| AVI | video/avi |
| WMV | video/x-ms-wmv |
| MOV | video/quicktime |
Audio
| Format | MIME Type |
|---|---|
| MP3 | audio/mpeg |
| WAV | audio/wav |
| WMA | audio/x-ms-wma |
| AIFF | audio/aiff |
Common Options
Both VideoFrame and AudioFrame support standard shape positioning:
new VideoFrame({
x: 1, // Left position (inches)
y: 1, // Top position (inches)
width: 6, // Width (inches)
height: 4, // Height (inches)
rotation: 0, // Rotation in degrees
data: mediaData,
mimeType: "video/mp4",
});
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.).