Skip to content

Commit 6ba4066

Browse files
committed
Add src/examples/Example.py
1 parent 5e1e8ce commit 6ba4066

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/examples/Example.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
@file
5+
@brief Python source file for openshot.py example
6+
@author Jonathan Thomas <[email protected]>
7+
@author FeRD (Frank Dana) <[email protected]>
8+
9+
@ref License
10+
"""
11+
12+
# LICENSE
13+
#
14+
# Copyright (c) 2008-2019 OpenShot Studios, LLC
15+
# <http://www.openshotstudios.com/>. This file is part of
16+
# OpenShot Library (libopenshot), an open-source project dedicated to
17+
# delivering high quality video editing and animation solutions to the
18+
# world. For more information visit <http://www.openshot.org/>.
19+
#
20+
# OpenShot Library (libopenshot) is free software: you can redistribute it
21+
# and/or modify it under the terms of the GNU Lesser General Public License
22+
# as published by the Free Software Foundation, either version 3 of the
23+
# License, or (at your option) any later version.
24+
#
25+
# OpenShot Library (libopenshot) is distributed in the hope that it will be
26+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
# GNU Lesser General Public License for more details.
29+
#
30+
# You should have received a copy of the GNU Lesser General Public License
31+
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
32+
33+
import sys
34+
35+
# This can be run against an uninstalled build of libopenshot, just set the
36+
# environment variable PYTHONPATH to the location of the Python bindings.
37+
#
38+
# For example:
39+
# $ PYTHONPATH=../../build/src/bindings/python python3 Example.py
40+
#
41+
import openshot
42+
43+
44+
# Create an FFmpegReader
45+
r = openshot.FFmpegReader("sintel_trailer-720p.mp4")
46+
47+
r.Open() # Open the reader
48+
r.DisplayInfo() # Display metadata
49+
50+
# Set up Writer
51+
w = openshot.FFmpegWriter("pythonExample.mp4")
52+
53+
w.SetAudioOptions(True, "libmp3lame", r.info.sample_rate, r.info.channels, r.info.channel_layout, 128000)
54+
w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
55+
openshot.Fraction(1, 1), False, False, 3000000)
56+
57+
w.info.metadata["title"] = "testtest"
58+
w.info.metadata["artist"] = "aaa"
59+
w.info.metadata["album"] = "bbb"
60+
w.info.metadata["year"] = "2015"
61+
w.info.metadata["description"] = "ddd"
62+
w.info.metadata["comment"] = "eee"
63+
w.info.metadata["comment"] = "comment"
64+
w.info.metadata["copyright"] = "copyright OpenShot!"
65+
66+
# Open the Writer
67+
w.Open()
68+
69+
# Grab 30 frames from Reader and encode to Writer
70+
for frame in range(100):
71+
f = r.GetFrame(frame)
72+
w.WriteFrame(f)
73+
74+
# Close out Reader & Writer
75+
w.Close()
76+
r.Close()
77+
78+
print("Completed successfully!")

0 commit comments

Comments
 (0)