OpenShot Library | libopenshot 0.3.1
Caption.cpp
Go to the documentation of this file.
1
9// Copyright (c) 2008-2019 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#include "Caption.h"
14#include "Exceptions.h"
15#include "../Clip.h"
16#include "../Timeline.h"
17
18#include <QGuiApplication>
19#include <QString>
20#include <QPoint>
21#include <QRect>
22#include <QPen>
23#include <QBrush>
24#include <QPainter>
25#include <QPainterPath>
26
27using namespace openshot;
28
30Caption::Caption() : color("#ffffff"), stroke("#a9a9a9"), background("#ff000000"), background_alpha(0.0), left(0.1), top(0.75), right(0.1),
31 stroke_width(0.5), font_size(30.0), font_alpha(1.0), is_dirty(true), font_name("sans"), font(NULL), metrics(NULL),
32 fade_in(0.35), fade_out(0.35), background_corner(10.0), background_padding(20.0), line_spacing(1.0)
33{
34 // Init effect properties
35 init_effect_details();
36}
37
38// Default constructor
39Caption::Caption(std::string captions) :
40 color("#ffffff"), stroke("#a9a9a9"), background("#ff000000"), background_alpha(0.0), left(0.1), top(0.75), right(0.1),
41 stroke_width(0.5), font_size(30.0), font_alpha(1.0), is_dirty(true), font_name("sans"), font(NULL), metrics(NULL),
42 fade_in(0.35), fade_out(0.35), background_corner(10.0), background_padding(20.0), line_spacing(1.0),
43 caption_text(captions)
44{
45 // Init effect properties
46 init_effect_details();
47}
48
49// Init effect settings
50void Caption::init_effect_details()
51{
54
56 info.class_name = "Caption";
57 info.name = "Caption";
58 info.description = "Add text captions on top of your video.";
59 info.has_audio = false;
60 info.has_video = true;
61
62 // Init placeholder caption (for demo)
63 if (caption_text.length() == 0) {
64 caption_text = "00:00:00:000 --> 00:10:00:000\nEdit this caption with our caption editor";
65 }
66}
67
68// Set the caption string to use (see VTT format)
69std::string Caption::CaptionText() {
70 return caption_text;
71}
72
73// Get the caption string
74void Caption::CaptionText(std::string new_caption_text) {
75 caption_text = new_caption_text;
76 is_dirty = true;
77}
78
79// Process regex string only when dirty
80void Caption::process_regex() {
81 if (is_dirty) {
82 is_dirty = false;
83
84 // Clear existing matches
85 matchedCaptions.clear();
86
87 QString caption_prepared = QString(caption_text.c_str());
88 if (caption_prepared.endsWith("\n\n") == false) {
89 // We need a couple line ends at the end of the caption string (for our regex to work correctly)
90 caption_prepared.append("\n\n");
91 }
92
93 // Parse regex and find all matches (i.e. 00:00.000 --> 00:10.000\ncaption-text)
94 QRegularExpression allPathsRegex(QStringLiteral("(\\d{2})?:*(\\d{2}):(\\d{2}).(\\d{2,3})\\s*-->\\s*(\\d{2})?:*(\\d{2}):(\\d{2}).(\\d{2,3})([\\s\\S]*?)(.*?)(?=\\d{2}.\\d{2,3}|\\Z)"), QRegularExpression::MultilineOption);
95 QRegularExpressionMatchIterator i = allPathsRegex.globalMatch(caption_prepared);
96 while (i.hasNext()) {
97 QRegularExpressionMatch match = i.next();
98 if (match.hasMatch()) {
99 // Push all match objects into a vector (so we can reverse them later)
100 matchedCaptions.push_back(match);
101 }
102 }
103 }
104}
105
106// This method is required for all derived classes of EffectBase, and returns a
107// modified openshot::Frame object
108std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
109{
110 // Process regex (if needed)
111 process_regex();
112
113 // Get the Clip and Timeline pointers (if available)
114 Clip* clip = (Clip*) ParentClip();
115 Timeline* timeline = NULL;
116 Fraction fps;
117
118 if (clip && clip->ParentTimeline() != NULL) {
120 } else if (this->ParentTimeline() != NULL) {
121 timeline = (Timeline*) this->ParentTimeline();
122 }
123
124 // Get the FPS from the parent object (Timeline or Clip's Reader)
125 if (timeline != NULL) {
126 fps = timeline->info.fps;
127 } else if (clip != NULL && clip->Reader() != NULL) {
128 fps = clip->Reader()->info.fps;
129 }
130
131 // Get the frame's image
132 std::shared_ptr<QImage> frame_image = frame->GetImage();
133
134 // Calculate scale factor, to keep different resolutions from
135 // having dramatically different font sizes
136 double timeline_scale_factor = frame->GetImage()->width() / 600.0;
137
138 // Load timeline's new frame image into a QPainter
139 QPainter painter(frame_image.get());
140 painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
141
142 // Composite a new layer onto the image
143 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
144
145 // Font options and metrics for caption text
146 double font_size_value = font_size.GetValue(frame_number) * timeline_scale_factor;
147 QFont font(QString(font_name.c_str()), int(font_size_value));
148 font.setPixelSize(std::max(font_size_value, 1.0));
149 QFontMetricsF metrics = QFontMetricsF(font);
150
151 // Get current keyframe values
152 double left_value = left.GetValue(frame_number);
153 double top_value = top.GetValue(frame_number);
154 double fade_in_value = fade_in.GetValue(frame_number) * fps.ToDouble();
155 double fade_out_value = fade_out.GetValue(frame_number) * fps.ToDouble();
156 double right_value = right.GetValue(frame_number);
157 double background_corner_value = background_corner.GetValue(frame_number) * timeline_scale_factor;
158 double padding_value = background_padding.GetValue(frame_number) * timeline_scale_factor;
159 double stroke_width_value = stroke_width.GetValue(frame_number) * timeline_scale_factor;
160 double line_spacing_value = line_spacing.GetValue(frame_number);
161 double metrics_line_spacing = metrics.lineSpacing();
162
163 // Calculate caption area (based on left, top, and right margin)
164 double left_margin_x = frame_image->width() * left_value;
165 double starting_y = (frame_image->height() * top_value) + metrics_line_spacing;
166 double current_y = starting_y;
167 double bottom_y = starting_y;
168 double top_y = starting_y;
169 double max_text_width = 0.0;
170 double right_margin_x = frame_image->width() - (frame_image->width() * right_value);
171 double caption_area_width = right_margin_x - left_margin_x;
172 QRectF caption_area = QRectF(left_margin_x, starting_y, caption_area_width, frame_image->height());
173
174 // Keep track of all required text paths
175 std::vector<QPainterPath> text_paths;
176 double fade_in_percentage = 0.0;
177 double fade_out_percentage = 0.0;
178 double line_height = metrics_line_spacing * line_spacing_value;
179
180 // Loop through matches and find text to display (if any)
181 for (auto match = matchedCaptions.begin(); match != matchedCaptions.end(); match++) {
182
183 // Build timestamp (00:00:04.000 --> 00:00:06.500)
184 int64_t start_frame = ((match->captured(1).toFloat() * 60.0 * 60.0 ) + (match->captured(2).toFloat() * 60.0 ) +
185 match->captured(3).toFloat() + (match->captured(4).toFloat() / 1000.0)) * fps.ToFloat();
186 int64_t end_frame = ((match->captured(5).toFloat() * 60.0 * 60.0 ) + (match->captured(6).toFloat() * 60.0 ) +
187 match->captured(7).toFloat() + (match->captured(8).toFloat() / 1000.0)) * fps.ToFloat();
188
189 // Split multiple lines into separate paths
190 QStringList lines = match->captured(9).split("\n");
191 for(int index = 0; index < lines.length(); index++) {
192 // Multi-line
193 QString line = lines[index];
194 // Ignore lines that start with NOTE, or are <= 1 char long
195 if (!line.startsWith(QStringLiteral("NOTE")) &&
196 !line.isEmpty() && frame_number >= start_frame && frame_number <= end_frame && line.length() > 1) {
197
198 // Calculate fade in/out ranges
199 fade_in_percentage = ((float) frame_number - (float) start_frame) / fade_in_value;
200 fade_out_percentage = 1.0 - (((float) frame_number - ((float) end_frame - fade_out_value)) / fade_out_value);
201
202 // Loop through words, and find word-wrap boundaries
203 QStringList words = line.split(" ");
204
205 // Wrap languages which do not use spaces
206 bool use_spaces = true;
207 if (line.length() > 20 && words.length() == 1) {
208 words = line.split("");
209 use_spaces = false;
210 }
211 int words_remaining = words.length();
212 while (words_remaining > 0) {
213 bool words_displayed = false;
214 for(int word_index = words.length(); word_index > 0; word_index--) {
215 // Current matched caption string (from the beginning to the current word index)
216 QString fitting_line = words.mid(0, word_index).join(" ");
217
218 // Calculate size of text
219 QRectF textRect = metrics.boundingRect(caption_area, Qt::TextSingleLine, fitting_line);
220 if (textRect.width() <= caption_area.width()) {
221 // Location for text
222 QPoint p(left_margin_x, current_y);
223
224 // Create path and add text to it (for correct border and fill)
225 QPainterPath path1;
226 QString fitting_line;
227 if (use_spaces) {
228 fitting_line = words.mid(0, word_index).join(" ");
229 } else {
230 fitting_line = words.mid(0, word_index).join("");
231 }
232 path1.addText(p, font, fitting_line);
233 text_paths.push_back(path1);
234
235 // Update line (to remove words already drawn
236 words = words.mid(word_index, words.length());
237 words_remaining = words.length();
238 words_displayed = true;
239
240 // Increment y-coordinate of text (for next line) + padding
241 current_y += line_height;
242
243 // Detect max width (of widest text line)
244 if (path1.boundingRect().width() > max_text_width) {
245 max_text_width = path1.boundingRect().width();
246 }
247 // Detect top most y coordinate of text
248 if (path1.boundingRect().top() < top_y) {
249 top_y = path1.boundingRect().top();
250 }
251 // Detect bottom most y coordinate of text
252 if (path1.boundingRect().bottom() > bottom_y) {
253 bottom_y = path1.boundingRect().bottom();
254 }
255 break;
256 }
257 }
258
259 if (!words_displayed) {
260 // Exit loop if no words displayed
261 words_remaining = 0;
262 }
263 }
264
265 }
266 }
267 }
268
269 // Calculate background size w/padding (based on actual text-wrapping)
270 QRectF caption_area_with_padding = QRectF(left_margin_x - (padding_value / 2.0),
271 top_y - (padding_value / 2.0),
272 max_text_width + padding_value,
273 (bottom_y - top_y) + padding_value);
274
275 // Calculate alignment offset on X axis (force center alignment of the caption area)
276 double alignment_offset = std::max((caption_area_width - max_text_width) / 2.0, 0.0);
277
278 // Set background color of caption
279 QBrush background_brush;
280 QColor background_qcolor = QColor(QString(background.GetColorHex(frame_number).c_str()));
281 // Align background center
282 caption_area_with_padding.translate(alignment_offset, 0.0);
283 if (fade_in_percentage < 1.0) {
284 // Fade in background
285 background_qcolor.setAlphaF(fade_in_percentage * background_alpha.GetValue(frame_number));
286 } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
287 // Fade out background
288 background_qcolor.setAlphaF(fade_out_percentage * background_alpha.GetValue(frame_number));
289 } else {
290 background_qcolor.setAlphaF(background_alpha.GetValue(frame_number));
291 }
292 background_brush.setColor(background_qcolor);
293 background_brush.setStyle(Qt::SolidPattern);
294 painter.setBrush(background_brush);
295 painter.setPen(Qt::NoPen);
296 painter.drawRoundedRect(caption_area_with_padding, background_corner_value, background_corner_value);
297
298 // Set fill-color of text
299 QBrush font_brush;
300 QColor font_qcolor = QColor(QString(color.GetColorHex(frame_number).c_str()));
301 font_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
302 font_brush.setStyle(Qt::SolidPattern);
303
304 // Set stroke/border color of text
305 QPen pen;
306 QColor stroke_qcolor;
307 stroke_qcolor = QColor(QString(stroke.GetColorHex(frame_number).c_str()));
308 stroke_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
309 pen.setColor(stroke_qcolor);
310 pen.setWidthF(std::max(stroke_width_value, 0.0));
311 painter.setPen(pen);
312
313 // Loop through text paths
314 for(QPainterPath path : text_paths) {
315 // Align text center (relative to background)
316 path.translate(alignment_offset, 0.0);
317 if (fade_in_percentage < 1.0) {
318 // Fade in text
319 font_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
320 stroke_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
321 } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
322 // Fade out text
323 font_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
324 stroke_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
325 }
326 pen.setColor(stroke_qcolor);
327 font_brush.setColor(font_qcolor);
328
329 // Set stroke pen
330 if (stroke_width_value <= 0.0) {
331 painter.setPen(Qt::NoPen);
332 } else {
333 painter.setPen(pen);
334 }
335
336 painter.setBrush(font_brush);
337 painter.drawPath(path);
338 }
339
340 // End painter
341 painter.end();
342
343 // return the modified frame
344 return frame;
345}
346
347// Generate JSON string of this object
348std::string Caption::Json() const {
349
350 // Return formatted string
351 return JsonValue().toStyledString();
352}
353
354// Generate Json::Value for this object
355Json::Value Caption::JsonValue() const {
356
357 // Create root json object
358 Json::Value root = EffectBase::JsonValue(); // get parent properties
359 root["type"] = info.class_name;
360 root["color"] = color.JsonValue();
361 root["stroke"] = stroke.JsonValue();
362 root["background"] = background.JsonValue();
363 root["background_alpha"] = background_alpha.JsonValue();
364 root["background_corner"] = background_corner.JsonValue();
365 root["background_padding"] = background_padding.JsonValue();
366 root["stroke_width"] = stroke_width.JsonValue();
367 root["font_size"] = font_size.JsonValue();
368 root["font_alpha"] = font_alpha.JsonValue();
369 root["fade_in"] = fade_in.JsonValue();
370 root["fade_out"] = fade_out.JsonValue();
371 root["line_spacing"] = line_spacing.JsonValue();
372 root["left"] = left.JsonValue();
373 root["top"] = top.JsonValue();
374 root["right"] = right.JsonValue();
375 root["caption_text"] = caption_text;
376 root["caption_font"] = font_name;
377
378 // return JsonValue
379 return root;
380}
381
382// Load JSON string into this object
383void Caption::SetJson(const std::string value) {
384
385 // Parse JSON string into JSON objects
386 try
387 {
388 const Json::Value root = openshot::stringToJson(value);
389 // Set all values that match
390 SetJsonValue(root);
391 }
392 catch (const std::exception& e)
393 {
394 // Error parsing JSON (or missing keys)
395 throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
396 }
397}
398
399// Load Json::Value into this object
400void Caption::SetJsonValue(const Json::Value root) {
401
402 // Set parent data
404
405 // Set data from Json (if key is found)
406 if (!root["color"].isNull())
407 color.SetJsonValue(root["color"]);
408 if (!root["stroke"].isNull())
409 stroke.SetJsonValue(root["stroke"]);
410 if (!root["background"].isNull())
411 background.SetJsonValue(root["background"]);
412 if (!root["background_alpha"].isNull())
413 background_alpha.SetJsonValue(root["background_alpha"]);
414 if (!root["background_corner"].isNull())
415 background_corner.SetJsonValue(root["background_corner"]);
416 if (!root["background_padding"].isNull())
417 background_padding.SetJsonValue(root["background_padding"]);
418 if (!root["stroke_width"].isNull())
419 stroke_width.SetJsonValue(root["stroke_width"]);
420 if (!root["font_size"].isNull())
421 font_size.SetJsonValue(root["font_size"]);
422 if (!root["font_alpha"].isNull())
423 font_alpha.SetJsonValue(root["font_alpha"]);
424 if (!root["fade_in"].isNull())
425 fade_in.SetJsonValue(root["fade_in"]);
426 if (!root["fade_out"].isNull())
427 fade_out.SetJsonValue(root["fade_out"]);
428 if (!root["line_spacing"].isNull())
429 line_spacing.SetJsonValue(root["line_spacing"]);
430 if (!root["left"].isNull())
431 left.SetJsonValue(root["left"]);
432 if (!root["top"].isNull())
433 top.SetJsonValue(root["top"]);
434 if (!root["right"].isNull())
435 right.SetJsonValue(root["right"]);
436 if (!root["caption_text"].isNull())
437 caption_text = root["caption_text"].asString();
438 if (!root["caption_font"].isNull())
439 font_name = root["caption_font"].asString();
440
441 // Mark effect as dirty to reparse Regex
442 is_dirty = true;
443}
444
445// Get all properties for a specific frame
446std::string Caption::PropertiesJSON(int64_t requested_frame) const {
447
448 // Generate JSON properties list
449 Json::Value root;
450 root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
451 root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
452 root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
453 root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
454 root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 1000 * 60 * 30, false, requested_frame);
455 root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 1000 * 60 * 30, true, requested_frame);
456
457 // Keyframes
458 root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
459 root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame);
460 root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame);
461 root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame);
462 root["stroke"] = add_property_json("Border", 0.0, "color", "", &stroke.red, 0, 255, false, requested_frame);
463 root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
464 root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
465 root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
466 root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
467 root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "float", "", &background_corner, 0.0, 60.0, false, requested_frame);
468 root["background_padding"] = add_property_json("Background Padding", background_padding.GetValue(requested_frame), "float", "", &background_padding, 0.0, 60.0, false, requested_frame);
469 root["background"] = add_property_json("Background", 0.0, "color", "", &background.red, 0, 255, false, requested_frame);
470 root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
471 root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
472 root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
473 root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "float", "", &stroke_width, 0, 10.0, false, requested_frame);
474 root["font_size"] = add_property_json("Font Size", font_size.GetValue(requested_frame), "float", "", &font_size, 0, 200.0, false, requested_frame);
475 root["font_alpha"] = add_property_json("Font Alpha", font_alpha.GetValue(requested_frame), "float", "", &font_alpha, 0.0, 1.0, false, requested_frame);
476 root["fade_in"] = add_property_json("Fade In (Seconds)", fade_in.GetValue(requested_frame), "float", "", &fade_in, 0.0, 3.0, false, requested_frame);
477 root["fade_out"] = add_property_json("Fade Out (Seconds)", fade_out.GetValue(requested_frame), "float", "", &fade_out, 0.0, 3.0, false, requested_frame);
478 root["line_spacing"] = add_property_json("Line Spacing", line_spacing.GetValue(requested_frame), "float", "", &line_spacing, 0.0, 5.0, false, requested_frame);
479 root["left"] = add_property_json("Left Size", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame);
480 root["top"] = add_property_json("Top Size", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
481 root["right"] = add_property_json("Right Size", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame);
482 root["caption_text"] = add_property_json("Captions", 0.0, "caption", caption_text, NULL, -1, -1, false, requested_frame);
483 root["caption_font"] = add_property_json("Font", 0.0, "font", font_name, NULL, -1, -1, false, requested_frame);
484
485 // Set the parent effect which properties this effect will inherit
486 root["parent_effect_id"] = add_property_json("Parent", 0.0, "string", info.parent_effect_id, NULL, -1, -1, false, requested_frame);
487
488 // Return formatted string
489 return root.toStyledString();
490}
Header file for Caption effect class.
Header file for all Exception classes.
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Caption.cpp:446
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: Caption.h:86
Keyframe background_padding
Background padding.
Definition: Caption.h:60
Caption()
Blank constructor, useful when using Json to load the effect properties.
Definition: Caption.cpp:30
Keyframe stroke_width
Width of text border / stroke.
Definition: Caption.h:61
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Caption.cpp:355
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Caption.cpp:400
std::string Json() const override
Generate JSON string of this object.
Definition: Caption.cpp:348
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Caption.cpp:383
std::string font_name
Font string.
Definition: Caption.h:70
Color background
Color of caption area background.
Definition: Caption.h:57
Keyframe font_size
Font size in points.
Definition: Caption.h:62
Keyframe font_alpha
Font color alpha.
Definition: Caption.h:63
Keyframe background_alpha
Background color alpha.
Definition: Caption.h:58
Keyframe fade_out
Fade in per caption (# of seconds)
Definition: Caption.h:69
Keyframe background_corner
Background cornder radius.
Definition: Caption.h:59
Keyframe fade_in
Fade in per caption (# of seconds)
Definition: Caption.h:68
Keyframe line_spacing
Distance between lines (1.0 default / 100%)
Definition: Caption.h:64
Keyframe top
Size of top bar.
Definition: Caption.h:66
Color stroke
Color of text border / stroke.
Definition: Caption.h:56
std::string CaptionText()
Set the caption string to use (see VTT format)
Definition: Caption.cpp:69
Keyframe right
Size of right bar.
Definition: Caption.h:67
Color color
Color of caption text.
Definition: Caption.h:55
Keyframe left
Size of left bar.
Definition: Caption.h:65
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:88
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:90
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:89
std::string Id() const
Get the Id of this clip object.
Definition: ClipBase.h:85
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:87
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition: ClipBase.h:41
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:86
virtual openshot::TimelineBase * ParentTimeline()
Get the associated Timeline pointer (if any)
Definition: ClipBase.h:91
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
Definition: ClipBase.cpp:96
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:91
std::string GetColorHex(int64_t frame_number)
Get the HEX value of a color at a specific frame.
Definition: Color.cpp:47
openshot::Keyframe blue
Curve representing the red value (0 - 255)
Definition: Color.h:32
openshot::Keyframe red
Curve representing the red value (0 - 255)
Definition: Color.h:30
openshot::Keyframe green
Curve representing the green value (0 - 255)
Definition: Color.h:31
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Color.cpp:117
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Color.cpp:86
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: EffectBase.cpp:77
openshot::ClipBase * ParentClip()
Parent clip object of this effect (which can be unparented and NULL)
Definition: EffectBase.cpp:173
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: EffectBase.cpp:112
openshot::ClipBase * clip
Pointer to the parent clip instance (if any)
Definition: EffectBase.h:58
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:69
This class represents a fraction.
Definition: Fraction.h:30
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:35
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:40
Exception for invalid JSON.
Definition: Exceptions.h:218
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: KeyFrame.cpp:372
double GetValue(int64_t index) const
Get the value at a specific index.
Definition: KeyFrame.cpp:258
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: KeyFrame.cpp:339
This class represents a timeline.
Definition: Timeline.h:150
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:29
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:40
std::string parent_effect_id
Id of the parent effect (if there is one)
Definition: EffectBase.h:39
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:41
std::string class_name
The class name of the effect.
Definition: EffectBase.h:36
std::string name
The name of the effect.
Definition: EffectBase.h:37
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:38