MS PowerPoint allows adding media elements to the presentations such as audio and video. Video frames are used to insert the video clips from local files or web sources. In this article, you will learn how to add video frames in a PowerPoint PPT or PPTX in Python. We will also demonstrate how to embed videos from a web source such as YouTube and extract videos from a PPT.
- Python Library to Add Video Frame in PowerPoint PPT
- Add a Video Frame in a PowerPoint PPT
- Extract Video from a PowerPoint PPT
Info: You may want to check out Aspose FREE PowerPoint to Video converter because this service allows you to convert presentations into stunning and engaging videos.
Python Library to Add Video Frame in PowerPoint PPT
To add video frames in PowerPoint PPT/PPTX, we will use Aspose.Slides for Python via .NET. The library provides a complete package to create and manipulate PowerPoint presentations. You can install it from PyPI using the following pip command.
> pip install aspose.slides
Add a Video Frame to PowerPoint PPT in Python
You can add a video either from your local storage or a web source, such as YouTube. The following sections demonstrate both scenarios with the help of code samples.
Insert Video from a Local File
The following are the steps to add a video frame to a PowerPoint PPT in Python.
- First, load PPT/PPTX file or create a new one using Presentation class.
- Then, get reference of the desired slide.
- Add video into the videos collection using Presentation.videos.add_video() method and get its reference.
- Add a video frame to the slide using Slide.shapes.add_video_frame() method and get its reference.
- Set the play mode and volume of the video.
- Finally, save presentation using Presentation.save(string, SaveFormat) method.
The following code sample shows how to embed a video in a PowerPoint PPT in Python.
Embed Video in PowerPoint PPT from a Web Source
You can also add a video in the PowerPoint PPT from a web source. For demonstration, let’s embed a YouTube video into the PowerPoint PPT in Python.
- First, load PPT/PPTX file or create a new one using Presentation class.
- Then, get reference of the desired slide.
- Add YouTube video from URL using Slide.shapes.add_video_frame() method and get its reference.
- Set video thumbnail.
- Finally, save presentation using Presentation.save(string, SaveFormat) method.
The following code sample shows how to embed a YouTube video into PowerPoint PPT in Python.
Extract Video from a PowerPoint Presentation in Python
There could be the case when you want to extract the videos added to a PowerPoint presentation. The following are the steps to achieve this.
- First, load the PPT/PPTX file using Presentation class.
- Then, loop through slides in Presentation.slides collection.
- For each slide, loop through the collection of shapes it has.
- If shape is a VideoFrame, then extract and save the embedded video.
The following code sample shows how to extract videos from a PowerPoint PPT in Python.
Get a Free License
You can use Aspose.Slides for Python via .NET without evaluation limitations by getting a temporary license.
Conclusion
In this article, you have learned how to add video frames to PowerPoint PPT/PPTX in Python. We have covered how to embed video from a file or a web source such as YouTube. Moreover, you have seen how to extract videos from a presentation programmatically. Besides, you can visit the documentation to explore more about Aspose.Slides for Python. Also, you can post your queries to our forum.