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.
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.
Related
Is there a solution in python or php that will allow me to get the presenter notes from each slide in a power point file?
Thank you
You can use python-pptx.
pip install python-pptx
You can do the following to extract presenter notes:
import collections
import collections.abc
from pptx import Presentation
file = 'path/to/presentation.pptx'
ppt=Presentation(file)
notes = []
for page, slide in enumerate(ppt.slides):
# this is the notes that doesn't appear on the ppt slide,
# but really the 'presenter' note.
textNote = slide.notes_slide.notes_text_frame.text
notes.append((page,textNote))
print(notes)
The notes list will contain all notes on different pages.
If you want to extract text content on a slide, you need to do this:
for page, slide in enumerate(ppt.slides):
temp = []
for shape in slide.shapes:
# this will extract all text in text boxes on the slide.
if shape.has_text_frame and shape.text.strip():
temp.append(shape.text)
notes.append((page,temp))
I am using the below code to copy an image from one ppt to another ppt.but it is not working
ppt = win32com.client.Dispatch('Powerpoint.Application')
ppt1 = ppt.Presentations.Open("path\\temp.pptx")
ppt2 = ppt.Presentations.Open("path\\2paste.pptx")
ppt1.slide.Shapes.Copy()
ppt2.slide.Shapes.Paste()
This code opens both the ppt but it is not copying the images.
With Aspose.Slides for Python, you can easily copy any shapes from a presentation to another. The following code example shows you how to do this:
import aspose.slides as slides
file_name1 = "temp.pptx"
file_name2 = "2paste.pptx"
with slides.Presentation(file_name1) as presentation1:
with slides.Presentation(file_name2) as presentation2:
# Get the first shape from the first slide, for example.
first_shape = presentation1.slides[0].shapes[0]
# Clone the shape and add the clone to the second presentation.
presentation2.slides[0].shapes.add_clone(first_shape)
# Save the second presentation.
presentation2.save(file_name2, slides.export.SaveFormat.PPTX)
This is a paid library, but you can get a temporary licence for evaluating all features for your purposes. I work as a Support Developer at Aspose.
I'm creating a simple python app to go through a folder display each JPG and allow someone to edit the photo's Title,subject,comments and add tags, then save and move on to the next. (essentially, I want to avoid, in windows, having to right click>properties>details> and edit each of the above fields, then "OK".)
Can someone please recommend the libraries and modules I need to import to display the photo and edit the properties?
I'm new to Python, so a snippet of code to show how do do it would be most appreciated.
I'm using python 3.6 in Windows 10
Thanks in advance.
To change a photos EXIF data in python you can do something like:
Get EXIF Data:
import piexif
from PIL import Image
img = Image.open(fname)
exif_dict = piexif.load(img.info['exif'])
altitude = exif_dict['GPS'][piexif.GPSIFD.GPSAltitude]
Set / Save EXIF data:
exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
exif_bytes = piexif.dump(exif_dict)
img.save('_%s' % fname, "jpeg", exif=exif_bytes)
Taken from this Answer
I've been writing a script using MoviePy. So far I've been able to import videos, clip them, add text, replace the audio and write a new file. It's been a great learning experience. My question is this:
The movie that I'm editing has audio attached. I'd like to be able to import an audio track and add it to the movie without replacing the original audio. In other words, I'd like to mix the new audio file with the audio that's attached to the video so both can be heard.
Does anyone know how to do this?
Thanks in advance!
I wrote my own version, but then I found this here:
new_audioclip = CompositeAudioClip([videoclip.audio, audioclip])
videoclip.audio = new_audioclip
So, create a CompositeAudioClip with the audio of the video clip and the new audio clip, then set the old videoclip's audio to the composite audio track.
Full working code:
from moviepy.editor import *
videoclip = VideoFileClip("filename.mp4")
audioclip = AudioFileClip("audioname.mp3")
new_audioclip = CompositeAudioClip([videoclip.audio, audioclip])
videoclip.audio = new_audioclip
videoclip.write_videofile("new_filename.mp4")
If you want to change an individual audioclip's volume, refer to audio.fx.volumex.
Documentation
Source Code
I have an existing PowerPoint presentation with 20 slides. This presentation serves as an template with each slide having different backgrounds. I want to take this (existing) PowerPoint presentation, insert an image in slide number 4 (do nothing with the first 3) and save it as a new PowerPoint presentation.
This is what I have up until now. This code loads an existing presentation and saves it as a new one. Now I just need to know how to use this to insert an image to slide number 4 like described above.
Note: I am using normal Python.
from pptx import Presentation
def open_PowerPoint_Presentation(oldFileName, newFileName):
prs = Presentation(oldFileName)
#Here I guess I need to type something to complete the task.
prs.save(newFileName)
open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx')
I'm not really familiar with this module, but I looked at their quickstart
from pptx.util import Inches
from pptx import Presentation
def open_PowerPoint_Presentation(oldFileName, newFileName, img, left, top):
prs = Presentation(oldFileName)
slide = prs.slides[3]
pic = slide.shapes.add_picture(img, left, top)
prs.save(newFileName)
open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx',
'mypic.png', Inches(1), Inches(1))