Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active February 15, 2022 02:56
Show Gist options
  • Save aspose-com-gists/6edfdea39b39361dace7737013acc82d to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6edfdea39b39361dace7737013acc82d to your computer and use it in GitHub Desktop.
Add Video Frame in PowerPoint PPT using Python
import aspose.slides as slides
from urllib.request import urlopen
# load presentation
with slides.Presentation("presentation.pptx") as presentation:
#add video frame
videoFrame = presentation.slides[0].shapes.add_video_frame(10, 10, 427, 240, "https://www.youtube.com/embed/s5JbfQZ5Cc0")
videoFrame.play_mode = slides.VideoPlayModePreset.AUTO
# load thumbnail
thumbnail_uri = "http://img.youtube.com/vi/s5JbfQZ5Cc0/hqdefault.jpg"
f = urlopen(thumbnail_uri)
videoFrame.picture_format.picture.image = presentation.images.add_image(f.read())
# save presentation
presentation.save("add-video-frame-from-web.pptx", slides.export.SaveFormat.PPTX)
import aspose.slides as slides
# load presentation
with slides.Presentation("presentation.pptx") as presentation:
# select slide
slide = presentation.slides[0]
# load video file
with open("Wildlife.mp4", "rb") as in_file:
# add video to presentation
vid = presentation.videos.add_video(in_file)
# add video frame
vf = slide.shapes.add_video_frame(50, 150, 300, 350, vid)
# set video to video frame
vf.embedded_video = vid
# set play mode and volume of the video
vf.play_mode = slides.VideoPlayModePreset.AUTO
vf.volume = slides.AudioVolumeMode.LOUD
# save presentation
presentation.save("add-video-frame.pptx", slides.export.SaveFormat.PPTX)
import aspose.slides as slides
# load presentation
with slides.Presentation("presentation.pptx") as presentation:
# loop through slides
for slide in presentation.slides:
# loop through shapes
for shape in slide.shapes:
# check type of the shape
if type(shape) is slides.VideoFrame:
# get content type
content_type = shape.embedded_video.content_type
# get video data
buffer = shape.embedded_video.binary_data
# save video
with open("extracted-video." + content_type[content_type.rfind('/') + 1:len(content_type)], "wb") as stream:
stream.write(buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment