Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can python-pptx module insert video?

according to the documentation, python-pptx can insert videos, however, the documentation does not give very good examples. Anybody have any code snippets to add video1.avi to my pptx?

from pptx import Presentation
pptx1 = Presentation()
slide = pptx1.slides.add_slide(blank_slide_layout)

not sure what inputs I need

slide.placeholders.element.add_placeholder(id_,name,ph_type, orient, sz,idx)

thanks

like image 757
nagordon Avatar asked Sep 21 '25 03:09

nagordon


2 Answers

The library now has a function for adding videos to slides:

slide.shapes.add_movie(video_file, x_pos, y_pos, width, height, poster_frame_image=thumbnail_image_file)
like image 70
Yoshi Askharoun Avatar answered Sep 22 '25 17:09

Yoshi Askharoun


UPDATE: python-pptx now supports inserting videos (and probably audio in many cases using the same method).


I'm not sure where in the documentation it says it can insert videos, but if you can cite a particular location I'll fix it.

We've looked at this feature, but it turns out to be quite complex as different video formats require a substantial amount of undocumented customization to the metadata inserted into the XML surrounding the embedded video object. Also as I recall one needs a way to get a still image (first frame maybe) from the video to insert in it's place while it's not running, and libraries for this sort of thing are not readily available in Python last time we looked.

Anyway, the short answer is no, it's not supported yet. And it's not likely to come soon unless there's a motivated contributor or sponsor. Sorry I didn't have happier news for you :(

like image 43
scanny Avatar answered Sep 22 '25 16:09

scanny