0

I have to insert a video in ppt using python-pptx library. And also i have added the below code to insert it:

from pptx import Presentation
from pptx.util import Inches
prs = Presentation('template.pptx')
filepath =  "file2.pptx"
layout =  prs.slide_layouts[0]
slide = prs.slides.add_slide(layout9) 
path = 'video.mp4'
movie=slide.shapes.add_movie(path
    , Inches(4.51), Inches(1.53), Inches(6.98), 
  Inches(4.69),poster_frame_image=None,mime_type='video/unknown'
)
prs.save(filepath)

This code successfully creates video shape. It show a big speaker icon when i click it for preview, it doesn't play at all . I dont know what i missed here. If anyone could help me please give some suggestion for this.

Lavii
  • 63
  • 1
  • 4
  • Perhaps some more of your code could be useful. – JerodG Feb 16 '20 at 05:40
  • Hi @JerodG , i have added the code. Please check it now and please tell me what i did wrong here – Lavii Feb 16 '20 at 06:00
  • I believe movies only play in slide-show mode, have you tried it in that mode? Also make sure that movie works when you add it manually using PowerPoint directly. – scanny Feb 16 '20 at 06:11
  • @scanny Video works when manually added to powerpoint without any issues. And also tried it in slide-show mode still am getting this problem. Any corrections in code? – Lavii Feb 16 '20 at 06:18
  • Try changing the filename either to a relative or absolute path. – cup Feb 16 '20 at 06:19
  • @cup Sorry, actually in my original code am having absolute path. Here given file name only for analyze purpose – Lavii Feb 16 '20 at 06:26
  • If your version of powerpoint is after 2013, try the record feature and check what it generates in VBA (I'm still running 2010 which doesn't have a record feature). There may be something extra it adds to add_movie or it may be using a completely different call. pptx is just a front end for VBA. – cup Feb 16 '20 at 12:55

1 Answers1

0

Aspose.Slides for Python makes it easy to add video to a presentation slide. The following code example shows you how to do this:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    # Add a video frame to the slide.
    video_frame = slide.shapes.add_video_frame(20, 20, 400, 300, "video.mp4")

    # Add a poster image to presentation resources.
    with open("poster.png", "rb") as poster_stream:
        poster_image = presentation.images.add_image(poster_stream)

    # Set the poster for the video.
    video_frame.picture_format.picture.image = poster_image

    presentation.save("example.pptx", slides.export.SaveFormat.PPTX)

This a paid product, but you can get a temporary license to evaluate all features of this library. I work as a Support Developer at Aspose.

Andrey Potapov
  • 29
  • 2
  • 14