OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
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), bottom(0.0),
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.0), fade_out(0.0), 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), bottom(0.0),
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.0), fade_out(0.0), 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 QSize image_size(1, 1);
118
119 if (clip && clip->ParentTimeline() != NULL) {
121 } else if (this->ParentTimeline() != NULL) {
122 timeline = (Timeline*) this->ParentTimeline();
123 }
124
125 // Get the FPS from the parent object (Timeline or Clip's Reader)
126 if (timeline != NULL) {
127 fps = timeline->info.fps;
128 image_size = QSize(timeline->info.width, timeline->info.height);
129 } else if (clip != NULL && clip->Reader() != NULL) {
130 fps = clip->Reader()->info.fps;
131 image_size = QSize(clip->Reader()->info.width, clip->Reader()->info.height);
132 }
133
134 if (!frame->has_image_data) {
135 // Give audio-only files a full frame image of solid color
136 frame->AddColor(image_size.width(), image_size.height(), "#000000");
137 }
138
139 // Get the frame's image
140 std::shared_ptr<QImage> frame_image = frame->GetImage();
141
142 // Calculate scale factor, to keep different resolutions from
143 // having dramatically different font sizes
144 double timeline_scale_factor = frame_image->width() / 600.0;
145
146 // Load timeline's new frame image into a QPainter
147 QPainter painter(frame_image.get());
148 painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
149
150 // Composite a new layer onto the image
151 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
152
153 // Font options and metrics for caption text
154 double font_size_value = font_size.GetValue(frame_number) * timeline_scale_factor;
155 QFont font(QString(font_name.c_str()), int(font_size_value));
156 font.setPixelSize(std::max(font_size_value, 1.0));
157 QFontMetricsF metrics = QFontMetricsF(font);
158
159 // Get current keyframe values
160 double left_value = left.GetValue(frame_number);
161 double top_value = top.GetValue(frame_number);
162 double fade_in_value = fade_in.GetValue(frame_number) * fps.ToDouble();
163 double fade_out_value = fade_out.GetValue(frame_number) * fps.ToDouble();
164 double right_value = right.GetValue(frame_number);
165 double bottom_value = bottom.GetValue(frame_number);
166 double background_corner_value = background_corner.GetValue(frame_number) * timeline_scale_factor;
167 double padding_value = background_padding.GetValue(frame_number) * timeline_scale_factor;
168 double stroke_width_value = stroke_width.GetValue(frame_number) * timeline_scale_factor;
169 double line_spacing_value = line_spacing.GetValue(frame_number);
170 double metrics_line_spacing = metrics.lineSpacing();
171
172 // Calculate caption area (based on left, top, right, and bottom margin)
173 double left_margin_x = frame_image->width() * left_value;
174 double top_margin_y = frame_image->height() * top_value;
175 double starting_y = top_margin_y + metrics_line_spacing;
176 double current_y = starting_y;
177 double bottom_y = starting_y;
178 double top_y = starting_y;
179 double max_text_width = 0.0;
180 double right_margin_x = frame_image->width() - (frame_image->width() * right_value);
181 double caption_area_width = right_margin_x - left_margin_x;
182 double bottom_margin_y = frame_image->height() - (frame_image->height() * bottom_value);
183 double caption_area_height = std::max(bottom_margin_y - starting_y, 0.0);
184 QRectF caption_area = QRectF(left_margin_x, starting_y, caption_area_width, caption_area_height);
185 QRectF caption_clip_area = QRectF(left_margin_x, top_margin_y, caption_area_width,
186 std::max(bottom_margin_y - top_margin_y, 0.0));
187
188 // Keep track of all required text paths
189 std::vector<QPainterPath> text_paths;
190 double fade_in_percentage = 0.0;
191 double fade_out_percentage = 0.0;
192 double line_height = metrics_line_spacing * line_spacing_value;
193
194 // Helper: pad fraction to 3 digits, then convert to seconds
195 auto fracToSeconds = [&](const QString &f){
196 QString ms = f.leftJustified(3, QChar('0')); // "5"→"500", "05"→"050", ""→"000"
197 return ms.toInt() / 1000.0;
198 };
199
200 // Loop through matches and find text to display (if any)
201 for (auto match = matchedCaptions.begin(); match != matchedCaptions.end(); match++) {
202
203 // Compute start and end in seconds
204 double startSeconds =
205 match->captured(1).toFloat() * 3600.0 +
206 match->captured(2).toFloat() * 60.0 +
207 match->captured(3).toFloat() +
208 fracToSeconds(match->captured(4));
209
210 double endSeconds =
211 match->captured(5).toFloat() * 3600.0 +
212 match->captured(6).toFloat() * 60.0 +
213 match->captured(7).toFloat() +
214 fracToSeconds(match->captured(8));
215
216 auto start_frame = int64_t(startSeconds * fps.ToFloat()) + 1;
217 auto end_frame = int64_t(endSeconds * fps.ToFloat());
218
219 // Split multiple lines into separate paths
220 QStringList lines = match->captured(9).split("\n");
221 for(int index = 0; index < lines.length(); index++) {
222 // Multi-line
223 QString line = lines[index];
224 // Ignore lines that start with NOTE, or are <= 1 char long
225 if (!line.startsWith(QStringLiteral("NOTE")) &&
226 !line.isEmpty() && frame_number >= start_frame && frame_number <= end_frame && line.length() > 1) {
227
228 // Calculate fade in/out ranges
229 fade_in_percentage = fade_in_value > 0.0
230 ? ((float) frame_number - (float) start_frame) / fade_in_value
231 : 1.0;
232 fade_out_percentage = fade_out_value > 0.0
233 ? 1.0 - (((float) frame_number - ((float) end_frame - fade_out_value)) / fade_out_value)
234 : -1.0;
235
236 // Loop through words, and find word-wrap boundaries
237 QStringList words = line.split(" ");
238
239 // Wrap languages which do not use spaces
240 bool use_spaces = true;
241 if (line.length() > 20 && words.length() == 1) {
242 words = line.split("");
243 use_spaces = false;
244 }
245 int words_remaining = words.length();
246 while (words_remaining > 0) {
247 bool words_displayed = false;
248 for(int word_index = words.length(); word_index > 0; word_index--) {
249 // Current matched caption string (from the beginning to the current word index)
250 QString fitting_line = words.mid(0, word_index).join(" ");
251
252 // Calculate size of text
253 QRectF textRect = metrics.boundingRect(caption_area, Qt::TextSingleLine, fitting_line);
254 if (textRect.width() <= caption_area.width()) {
255 // Location for text
256 QPoint p(left_margin_x, current_y);
257
258 // Create path and add text to it (for correct border and fill)
259 QPainterPath path1;
260 QString fitting_line;
261 if (use_spaces) {
262 fitting_line = words.mid(0, word_index).join(" ");
263 } else {
264 fitting_line = words.mid(0, word_index).join("");
265 }
266 path1.addText(p, font, fitting_line);
267 text_paths.push_back(path1);
268
269 // Update line (to remove words already drawn
270 words = words.mid(word_index, words.length());
271 words_remaining = words.length();
272 words_displayed = true;
273
274 // Increment y-coordinate of text (for next line) + padding
275 current_y += line_height;
276
277 // Detect max width (of widest text line)
278 if (path1.boundingRect().width() > max_text_width) {
279 max_text_width = path1.boundingRect().width();
280 }
281 // Detect top most y coordinate of text
282 if (path1.boundingRect().top() < top_y) {
283 top_y = path1.boundingRect().top();
284 }
285 // Detect bottom most y coordinate of text
286 if (path1.boundingRect().bottom() > bottom_y) {
287 bottom_y = path1.boundingRect().bottom();
288 }
289 break;
290 }
291 }
292
293 if (!words_displayed) {
294 // Exit loop if no words displayed
295 words_remaining = 0;
296 }
297 }
298
299 }
300 }
301 }
302
303 // Calculate background size w/padding (based on actual text-wrapping)
304 QRectF caption_area_with_padding = QRectF(left_margin_x - (padding_value / 2.0),
305 top_y - (padding_value / 2.0),
306 max_text_width + padding_value,
307 (bottom_y - top_y) + padding_value);
308
309 // Calculate alignment offset on X axis (force center alignment of the caption area)
310 double alignment_offset = std::max((caption_area_width - max_text_width) / 2.0, 0.0);
311
312 // Set background color of caption
313 QBrush background_brush;
314 QColor background_qcolor = QColor(QString(background.GetColorHex(frame_number).c_str()));
315 // Align background center
316 caption_area_with_padding.translate(alignment_offset, 0.0);
317 if (fade_in_percentage < 1.0) {
318 // Fade in background
319 background_qcolor.setAlphaF(fade_in_percentage * background_alpha.GetValue(frame_number));
320 } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
321 // Fade out background
322 background_qcolor.setAlphaF(fade_out_percentage * background_alpha.GetValue(frame_number));
323 } else {
324 background_qcolor.setAlphaF(background_alpha.GetValue(frame_number));
325 }
326 background_brush.setColor(background_qcolor);
327 background_brush.setStyle(Qt::SolidPattern);
328 painter.setBrush(background_brush);
329 painter.setPen(Qt::NoPen);
330 painter.save();
331 painter.setClipRect(caption_clip_area);
332 painter.drawRoundedRect(caption_area_with_padding, background_corner_value, background_corner_value);
333
334 // Set fill-color of text
335 QBrush font_brush;
336 QColor font_qcolor = QColor(QString(color.GetColorHex(frame_number).c_str()));
337 font_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
338 font_brush.setStyle(Qt::SolidPattern);
339
340 // Set stroke/border color of text
341 QPen pen;
342 QColor stroke_qcolor;
343 stroke_qcolor = QColor(QString(stroke.GetColorHex(frame_number).c_str()));
344 stroke_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
345 pen.setColor(stroke_qcolor);
346 pen.setWidthF(std::max(stroke_width_value, 0.0));
347 painter.setPen(pen);
348
349 // Loop through text paths
350 for(QPainterPath path : text_paths) {
351 // Align text center (relative to background)
352 path.translate(alignment_offset, 0.0);
353 if (fade_in_percentage < 1.0) {
354 // Fade in text
355 font_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
356 stroke_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
357 } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
358 // Fade out text
359 font_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
360 stroke_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
361 }
362 pen.setColor(stroke_qcolor);
363 font_brush.setColor(font_qcolor);
364
365 // Set stroke pen
366 if (stroke_width_value <= 0.0) {
367 painter.setPen(Qt::NoPen);
368 } else {
369 painter.setPen(pen);
370 }
371
372 // Draw the text outline first, then the fill so the border
373 // does not obscure the interior of the caption characters.
374 if (stroke_width_value > 0.0) {
375 painter.setBrush(Qt::NoBrush);
376 painter.drawPath(path);
377 }
378
379 painter.setPen(Qt::NoPen);
380 painter.setBrush(font_brush);
381 painter.drawPath(path);
382 }
383 painter.restore();
384
385 // End painter
386 painter.end();
387
388 // return the modified frame
389 return frame;
390}
391
392// Generate JSON string of this object
393std::string Caption::Json() const {
394
395 // Return formatted string
396 return JsonValue().toStyledString();
397}
398
399// Generate Json::Value for this object
400Json::Value Caption::JsonValue() const {
401
402 // Create root json object
403 Json::Value root = EffectBase::JsonValue(); // get parent properties
404 root["type"] = info.class_name;
405 root["color"] = color.JsonValue();
406 root["stroke"] = stroke.JsonValue();
407 root["background"] = background.JsonValue();
408 root["background_alpha"] = background_alpha.JsonValue();
409 root["background_corner"] = background_corner.JsonValue();
410 root["background_padding"] = background_padding.JsonValue();
411 root["stroke_width"] = stroke_width.JsonValue();
412 root["font_size"] = font_size.JsonValue();
413 root["font_alpha"] = font_alpha.JsonValue();
414 root["fade_in"] = fade_in.JsonValue();
415 root["fade_out"] = fade_out.JsonValue();
416 root["line_spacing"] = line_spacing.JsonValue();
417 root["left"] = left.JsonValue();
418 root["top"] = top.JsonValue();
419 root["right"] = right.JsonValue();
420 root["bottom"] = bottom.JsonValue();
421 root["caption_text"] = caption_text;
422 root["caption_font"] = font_name;
423
424 // return JsonValue
425 return root;
426}
427
428// Load JSON string into this object
429void Caption::SetJson(const std::string value) {
430
431 // Parse JSON string into JSON objects
432 try
433 {
434 const Json::Value root = openshot::stringToJson(value);
435 // Set all values that match
436 SetJsonValue(root);
437 }
438 catch (const std::exception& e)
439 {
440 // Error parsing JSON (or missing keys)
441 throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
442 }
443}
444
445// Load Json::Value into this object
446void Caption::SetJsonValue(const Json::Value root) {
447
448 // Set parent data
450
451 // Set data from Json (if key is found)
452 if (!root["color"].isNull())
453 color.SetJsonValue(root["color"]);
454 if (!root["stroke"].isNull())
455 stroke.SetJsonValue(root["stroke"]);
456 if (!root["background"].isNull())
457 background.SetJsonValue(root["background"]);
458 if (!root["background_alpha"].isNull())
459 background_alpha.SetJsonValue(root["background_alpha"]);
460 if (!root["background_corner"].isNull())
461 background_corner.SetJsonValue(root["background_corner"]);
462 if (!root["background_padding"].isNull())
463 background_padding.SetJsonValue(root["background_padding"]);
464 if (!root["stroke_width"].isNull())
465 stroke_width.SetJsonValue(root["stroke_width"]);
466 if (!root["font_size"].isNull())
467 font_size.SetJsonValue(root["font_size"]);
468 if (!root["font_alpha"].isNull())
469 font_alpha.SetJsonValue(root["font_alpha"]);
470 if (!root["fade_in"].isNull())
471 fade_in.SetJsonValue(root["fade_in"]);
472 if (!root["fade_out"].isNull())
473 fade_out.SetJsonValue(root["fade_out"]);
474 if (!root["line_spacing"].isNull())
475 line_spacing.SetJsonValue(root["line_spacing"]);
476 if (!root["left"].isNull())
477 left.SetJsonValue(root["left"]);
478 if (!root["top"].isNull())
479 top.SetJsonValue(root["top"]);
480 if (!root["right"].isNull())
481 right.SetJsonValue(root["right"]);
482 if (!root["bottom"].isNull())
483 bottom.SetJsonValue(root["bottom"]);
484 if (!root["caption_text"].isNull())
485 caption_text = root["caption_text"].asString();
486 if (!root["caption_font"].isNull())
487 font_name = root["caption_font"].asString();
488
489 // Mark effect as dirty to reparse Regex
490 is_dirty = true;
491}
492
493// Get all properties for a specific frame
494std::string Caption::PropertiesJSON(int64_t requested_frame) const {
495
496 // Generate JSON properties list
497 Json::Value root = BasePropertiesJSON(requested_frame);
498
499 // Keyframes
500 root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
501 root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame);
502 root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame);
503 root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame);
504 root["stroke"] = add_property_json("Border", 0.0, "color", "", &stroke.red, 0, 255, false, requested_frame);
505 root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
506 root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
507 root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
508 root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
509 root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "float", "", &background_corner, 0.0, 60.0, false, requested_frame);
510 root["background_padding"] = add_property_json("Background Padding", background_padding.GetValue(requested_frame), "float", "", &background_padding, 0.0, 60.0, false, requested_frame);
511 root["background"] = add_property_json("Background", 0.0, "color", "", &background.red, 0, 255, false, requested_frame);
512 root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
513 root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
514 root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
515 root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "float", "", &stroke_width, 0, 10.0, false, requested_frame);
516 root["font_size"] = add_property_json("Font Size", font_size.GetValue(requested_frame), "float", "", &font_size, 0, 200.0, false, requested_frame);
517 root["font_alpha"] = add_property_json("Font Alpha", font_alpha.GetValue(requested_frame), "float", "", &font_alpha, 0.0, 1.0, false, requested_frame);
518 root["fade_in"] = add_property_json("Fade In (Seconds)", fade_in.GetValue(requested_frame), "float", "", &fade_in, 0.0, 3.0, false, requested_frame);
519 root["fade_out"] = add_property_json("Fade Out (Seconds)", fade_out.GetValue(requested_frame), "float", "", &fade_out, 0.0, 3.0, false, requested_frame);
520 root["line_spacing"] = add_property_json("Line Spacing", line_spacing.GetValue(requested_frame), "float", "", &line_spacing, 0.0, 5.0, false, requested_frame);
521 root["left"] = add_property_json("Margin: Left", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame);
522 root["top"] = add_property_json("Margin: Top", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
523 root["right"] = add_property_json("Margin: Right", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame);
524 root["bottom"] = add_property_json("Margin: Bottom", bottom.GetValue(requested_frame), "float", "", &bottom, 0.0, 1.0, false, requested_frame);
525 root["caption_text"] = add_property_json("Captions", 0.0, "caption", caption_text, NULL, -1, -1, false, requested_frame);
526 root["caption_font"] = add_property_json("Font", 0.0, "font", font_name, NULL, -1, -1, false, requested_frame);
527
528 // Return formatted string
529 return root.toStyledString();
530}
Header file for Caption effect class.
Header file for all Exception classes.
std::string PropertiesJSON(int64_t requested_frame) const override
Definition Caption.cpp:494
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:87
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:400
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition Caption.cpp:446
std::string Json() const override
Generate JSON string of this object.
Definition Caption.cpp:393
void SetJson(const std::string value) override
Load JSON string into this object.
Definition Caption.cpp:429
std::string font_name
Font string.
Definition Caption.h:71
Keyframe bottom
Size of bottom bar.
Definition Caption.h:68
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:70
Keyframe background_corner
Background cornder radius.
Definition Caption.h:59
Keyframe fade_in
Fade in per caption (# of seconds)
Definition Caption.h:69
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
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition ClipBase.h:40
virtual openshot::TimelineBase * ParentTimeline()
Get the associated Timeline pointer (if any)
Definition ClipBase.h:94
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:100
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
std::string GetColorHex(int64_t frame_number)
Get the HEX value of a color at a specific frame.
Definition Color.cpp:48
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:118
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition Color.cpp:87
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
openshot::ClipBase * ParentClip()
Parent clip object of this effect (which can be unparented and NULL)
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
openshot::ClipBase * clip
Pointer to the parent clip instance (if any)
Definition EffectBase.h:77
EffectInfoStruct info
Information about the current effect.
Definition EffectBase.h:114
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:224
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:154
This namespace is the default namespace for all code in the openshot library.
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:43
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition EffectBase.h:44
std::string class_name
The class name of the effect.
Definition EffectBase.h:39
std::string name
The name of the effect.
Definition EffectBase.h:40
std::string description
The description of this effect and what it does.
Definition EffectBase.h:41