Skip to content

Commit 9f15bc1

Browse files
committed
Created user input list for slides creation.
1 parent 2fb0aa0 commit 9f15bc1

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

ppt2video/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
env
1+
env
2+
test_video.mp4
3+
test.pptx

ppt2video/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ For other systems it would require to use Python2.7 version to be able to instal
77

88
You can create <a href="https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/">virtual environment</a> to install the dependencies in a separate environment not to interfere with other packages on your machine.
99

10-
### If you are using Python2.7 version
11-
You can install the package with:
12-
```
13-
python -m pip install pywin32
14-
# or
15-
pip install -U pypiwin32
16-
```
17-
To develop this application I am using Python 3.10.2 through bash console.
1810

1911
## To install dependencies
2012
```

ppt2video/convertor.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
from operator import index
12
import win32com.client
23
import os
34
import sys
45

56
# PpSaveAsFileType enumeration (PowerPoint)
67
ppSaveAsMP4 = 39
8+
# PpSlideLayout enumeration (PowerPoint)
9+
ppLayoutText = 6
10+
# msoShapeRectangle
11+
msoShapeRectangle = 1
712

813

9-
def ppt2video(pptx, video, timing, duration, resolution, frames, quality):
14+
def ppt2video(pptx, video, timing, duration,
15+
resolution, frames, quality, input_list):
1016

1117
# Check if system requirements are met.
1218
if sys.platform == "win32":
@@ -25,6 +31,27 @@ def ppt2video(pptx, video, timing, duration, resolution, frames, quality):
2531
# Open presentation
2632
presentation = ppt.Presentations.Open(ppt_path, WithWindow=False)
2733

34+
slides_len = len(presentation.Slides)
35+
36+
while input_list:
37+
if len(input_list) == slides_len:
38+
n = 1 # To track the slide number to be created
39+
x = 0 # Index in the user input list
40+
while x < slides_len:
41+
# Create slide and insert it at n position with
42+
# input_list[x] text
43+
slide = presentation.Slides.Add(n, ppLayoutText)
44+
slide.Shapes.addShape(
45+
msoShapeRectangle, 150, 150, 250, 250). \
46+
TextFrame.TextRange.Text = input_list[x]
47+
n += 2
48+
x += 1
49+
break
50+
else:
51+
print("The length of input data should be equal to the \
52+
slides count")
53+
break
54+
2855
# Presentation.CreateVideo method (PowerPoint)
2956
# https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
3057
presentation.CreateVideo(video_path, timing, duration,
@@ -33,8 +60,8 @@ def ppt2video(pptx, video, timing, duration, resolution, frames, quality):
3360
try:
3461
# Update the video file, if already exists.
3562
os.rename(video_path, video_path)
36-
print(f'The video from PowerPoint Presentation \
37-
{pptx} has been created.')
63+
print(f'The video from PowerPoint Presentation {pptx} \
64+
has been created.')
3865
break
3966
except Exception:
4067
pass
@@ -47,12 +74,16 @@ def ppt2video(pptx, video, timing, duration, resolution, frames, quality):
4774
file_name = "" # e.g.:test.pptx, file expected to be in the root folder
4875
video_name = "" # e.g.: test_video, will be created in the root folder
4976
UseTimingsAndNarrations = False # Boolean value
50-
DefaultSlideDuration = 2 # Int
51-
VertResolution = 480 # Int
77+
DefaultSlideDuration = 2 # Int
78+
VertResolution = 720 # Int
5279
FramesPerSecond = 24 # Int
5380
Quality = 60 # Int
81+
# A list of user input text to insert before slides, starts with
82+
# the first slide. You can leave it blank and no additional
83+
# slides will be inserted in the video.
84+
user_input_list = ["1", "2", "3", "4", "5"]
5485

5586
ppt2video(f"./{file_name}", f"./{video_name}.mp4",
5687
UseTimingsAndNarrations,
5788
DefaultSlideDuration, VertResolution,
58-
FramesPerSecond, Quality)
89+
FramesPerSecond, Quality, user_input_list)

0 commit comments

Comments
 (0)