OpenShot Video Editor  2.0.0
export_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 ##
4 #
5 # @file
6 # @brief This file tests exporting a video in a specific format/codec
7 # @author Jonathan Thomas <jonathan@openshot.org>
8 #
9 # @section LICENSE
10 #
11 # Copyright (c) 2008-2016 OpenShot Studios, LLC
12 # (http://www.openshotstudios.com). This file is part of
13 # OpenShot Video Editor (http://www.openshot.org), an open-source project
14 # dedicated to delivering high quality video editing and animation solutions
15 # to the world.
16 #
17 # OpenShot Video Editor is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation, either version 3 of the License, or
20 # (at your option) any later version.
21 #
22 # OpenShot Video Editor is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 #
30 
31 import os
32 import sys
33 
34 import openshot
35 
36 
37 
38 # Write test video to this path
39 EXPORT_TESTS = os.path.join(os.path.expanduser("~"), ".openshot_qt", "tests")
40 
41 # Check for the correct # of arguments
42 if len(sys.argv) != 15:
43  print("Error: %s is not the correct # of arguments (15 expected)" % len(sys.argv))
44  exit()
45 
46 print("Params:")
47 print(sys.argv)
48 
49 # Get video params from the arguments passed to this script
50 format = sys.argv[1]
51 codec = sys.argv[2]
52 fps = openshot.Fraction(int(sys.argv[3]), int(sys.argv[4]))
53 width = int(sys.argv[5])
54 height = int(sys.argv[6])
55 pixel_ratio = openshot.Fraction(int(sys.argv[7]), int(sys.argv[8]))
56 bitrate = int(sys.argv[9])
57 
58 # Get audio params
59 audio_codec = sys.argv[10]
60 sample_rate = int(sys.argv[11])
61 channels = int(sys.argv[12])
62 channel_layout = int(sys.argv[13])
63 audio_bitrate = int(sys.argv[14])
64 
65 
66 # Determine final exported file path
67 export_file_path = os.path.join(EXPORT_TESTS, "test.%s" % format)
68 print("Test Export to %s" % export_file_path)
69 
70 # Create FFmpegWriter
71 w = openshot.FFmpegWriter(export_file_path);
72 
73 # Set Audio & Video Options
74 w.SetVideoOptions(True, codec, fps, width, height, pixel_ratio, False, False, bitrate);
75 w.SetAudioOptions(True, audio_codec, sample_rate, channels, channel_layout, audio_bitrate);
76 
77 w.DisplayInfo()
78 
79 # Open the writer
80 w.Open();
81 
82 for frame_number in range(30):
83  # Create empty frame
84  f = openshot.Frame(frame_number, width, height, "#ffffff")
85  f.AddColor(width, height, "#ffffff")
86 
87  # Write some test frames
88  w.WriteFrame(f)
89 
90 # Close writer
91 w.Close()
92 
93 # Success if we reached this line succesfully
94 print("*SUCCESS*")