OpenShot Library | libopenshot  0.4.0
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 
27 using namespace openshot;
28 
30 Caption::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
39 Caption::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
50 void 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)
69 std::string Caption::CaptionText() {
70  return caption_text;
71 }
72 
73 // Get the caption string
74 void 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
80 void 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
108 std::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) {
120  timeline = (Timeline*) clip->ParentTimeline();
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 background_corner_value = background_corner.GetValue(frame_number) * timeline_scale_factor;
166  double padding_value = background_padding.GetValue(frame_number) * timeline_scale_factor;
167  double stroke_width_value = stroke_width.GetValue(frame_number) * timeline_scale_factor;
168  double line_spacing_value = line_spacing.GetValue(frame_number);
169  double metrics_line_spacing = metrics.lineSpacing();
170 
171  // Calculate caption area (based on left, top, and right margin)
172  double left_margin_x = frame_image->width() * left_value;
173  double starting_y = (frame_image->height() * top_value) + metrics_line_spacing;
174  double current_y = starting_y;
175  double bottom_y = starting_y;
176  double top_y = starting_y;
177  double max_text_width = 0.0;
178  double right_margin_x = frame_image->width() - (frame_image->width() * right_value);
179  double caption_area_width = right_margin_x - left_margin_x;
180  QRectF caption_area = QRectF(left_margin_x, starting_y, caption_area_width, frame_image->height());
181 
182  // Keep track of all required text paths
183  std::vector<QPainterPath> text_paths;
184  double fade_in_percentage = 0.0;
185  double fade_out_percentage = 0.0;
186  double line_height = metrics_line_spacing * line_spacing_value;
187 
188  // Helper: pad fraction to 3 digits, then convert to seconds
189  auto fracToSeconds = [&](const QString &f){
190  QString ms = f.leftJustified(3, QChar('0')); // "5"→"500", "05"→"050", ""→"000"
191  return ms.toInt() / 1000.0;
192  };
193 
194  // Loop through matches and find text to display (if any)
195  for (auto match = matchedCaptions.begin(); match != matchedCaptions.end(); match++) {
196 
197  // Compute start and end in seconds
198  double startSeconds =
199  match->captured(1).toFloat() * 3600.0 +
200  match->captured(2).toFloat() * 60.0 +
201  match->captured(3).toFloat() +
202  fracToSeconds(match->captured(4));
203 
204  double endSeconds =
205  match->captured(5).toFloat() * 3600.0 +
206  match->captured(6).toFloat() * 60.0 +
207  match->captured(7).toFloat() +
208  fracToSeconds(match->captured(8));
209 
210  auto start_frame = int64_t(startSeconds * fps.ToFloat()) + 1;
211  auto end_frame = int64_t(endSeconds * fps.ToFloat());
212 
213  // Split multiple lines into separate paths
214  QStringList lines = match->captured(9).split("\n");
215  for(int index = 0; index < lines.length(); index++) {
216  // Multi-line
217  QString line = lines[index];
218  // Ignore lines that start with NOTE, or are <= 1 char long
219  if (!line.startsWith(QStringLiteral("NOTE")) &&
220  !line.isEmpty() && frame_number >= start_frame && frame_number <= end_frame && line.length() > 1) {
221 
222  // Calculate fade in/out ranges
223  fade_in_percentage = ((float) frame_number - (float) start_frame) / fade_in_value;
224  fade_out_percentage = 1.0 - (((float) frame_number - ((float) end_frame - fade_out_value)) / fade_out_value);
225 
226  // Loop through words, and find word-wrap boundaries
227  QStringList words = line.split(" ");
228 
229  // Wrap languages which do not use spaces
230  bool use_spaces = true;
231  if (line.length() > 20 && words.length() == 1) {
232  words = line.split("");
233  use_spaces = false;
234  }
235  int words_remaining = words.length();
236  while (words_remaining > 0) {
237  bool words_displayed = false;
238  for(int word_index = words.length(); word_index > 0; word_index--) {
239  // Current matched caption string (from the beginning to the current word index)
240  QString fitting_line = words.mid(0, word_index).join(" ");
241 
242  // Calculate size of text
243  QRectF textRect = metrics.boundingRect(caption_area, Qt::TextSingleLine, fitting_line);
244  if (textRect.width() <= caption_area.width()) {
245  // Location for text
246  QPoint p(left_margin_x, current_y);
247 
248  // Create path and add text to it (for correct border and fill)
249  QPainterPath path1;
250  QString fitting_line;
251  if (use_spaces) {
252  fitting_line = words.mid(0, word_index).join(" ");
253  } else {
254  fitting_line = words.mid(0, word_index).join("");
255  }
256  path1.addText(p, font, fitting_line);
257  text_paths.push_back(path1);
258 
259  // Update line (to remove words already drawn
260  words = words.mid(word_index, words.length());
261  words_remaining = words.length();
262  words_displayed = true;
263 
264  // Increment y-coordinate of text (for next line) + padding
265  current_y += line_height;
266 
267  // Detect max width (of widest text line)
268  if (path1.boundingRect().width() > max_text_width) {
269  max_text_width = path1.boundingRect().width();
270  }
271  // Detect top most y coordinate of text
272  if (path1.boundingRect().top() < top_y) {
273  top_y = path1.boundingRect().top();
274  }
275  // Detect bottom most y coordinate of text
276  if (path1.boundingRect().bottom() > bottom_y) {
277  bottom_y = path1.boundingRect().bottom();
278  }
279  break;
280  }
281  }
282 
283  if (!words_displayed) {
284  // Exit loop if no words displayed
285  words_remaining = 0;
286  }
287  }
288 
289  }
290  }
291  }
292 
293  // Calculate background size w/padding (based on actual text-wrapping)
294  QRectF caption_area_with_padding = QRectF(left_margin_x - (padding_value / 2.0),
295  top_y - (padding_value / 2.0),
296  max_text_width + padding_value,
297  (bottom_y - top_y) + padding_value);
298 
299  // Calculate alignment offset on X axis (force center alignment of the caption area)
300  double alignment_offset = std::max((caption_area_width - max_text_width) / 2.0, 0.0);
301 
302  // Set background color of caption
303  QBrush background_brush;
304  QColor background_qcolor = QColor(QString(background.GetColorHex(frame_number).c_str()));
305  // Align background center
306  caption_area_with_padding.translate(alignment_offset, 0.0);
307  if (fade_in_percentage < 1.0) {
308  // Fade in background
309  background_qcolor.setAlphaF(fade_in_percentage * background_alpha.GetValue(frame_number));
310  } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
311  // Fade out background
312  background_qcolor.setAlphaF(fade_out_percentage * background_alpha.GetValue(frame_number));
313  } else {
314  background_qcolor.setAlphaF(background_alpha.GetValue(frame_number));
315  }
316  background_brush.setColor(background_qcolor);
317  background_brush.setStyle(Qt::SolidPattern);
318  painter.setBrush(background_brush);
319  painter.setPen(Qt::NoPen);
320  painter.drawRoundedRect(caption_area_with_padding, background_corner_value, background_corner_value);
321 
322  // Set fill-color of text
323  QBrush font_brush;
324  QColor font_qcolor = QColor(QString(color.GetColorHex(frame_number).c_str()));
325  font_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
326  font_brush.setStyle(Qt::SolidPattern);
327 
328  // Set stroke/border color of text
329  QPen pen;
330  QColor stroke_qcolor;
331  stroke_qcolor = QColor(QString(stroke.GetColorHex(frame_number).c_str()));
332  stroke_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
333  pen.setColor(stroke_qcolor);
334  pen.setWidthF(std::max(stroke_width_value, 0.0));
335  painter.setPen(pen);
336 
337  // Loop through text paths
338  for(QPainterPath path : text_paths) {
339  // Align text center (relative to background)
340  path.translate(alignment_offset, 0.0);
341  if (fade_in_percentage < 1.0) {
342  // Fade in text
343  font_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
344  stroke_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
345  } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
346  // Fade out text
347  font_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
348  stroke_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
349  }
350  pen.setColor(stroke_qcolor);
351  font_brush.setColor(font_qcolor);
352 
353  // Set stroke pen
354  if (stroke_width_value <= 0.0) {
355  painter.setPen(Qt::NoPen);
356  } else {
357  painter.setPen(pen);
358  }
359 
360  painter.setBrush(font_brush);
361  painter.drawPath(path);
362  }
363 
364  // End painter
365  painter.end();
366 
367  // return the modified frame
368  return frame;
369 }
370 
371 // Generate JSON string of this object
372 std::string Caption::Json() const {
373 
374  // Return formatted string
375  return JsonValue().toStyledString();
376 }
377 
378 // Generate Json::Value for this object
379 Json::Value Caption::JsonValue() const {
380 
381  // Create root json object
382  Json::Value root = EffectBase::JsonValue(); // get parent properties
383  root["type"] = info.class_name;
384  root["color"] = color.JsonValue();
385  root["stroke"] = stroke.JsonValue();
386  root["background"] = background.JsonValue();
387  root["background_alpha"] = background_alpha.JsonValue();
388  root["background_corner"] = background_corner.JsonValue();
389  root["background_padding"] = background_padding.JsonValue();
390  root["stroke_width"] = stroke_width.JsonValue();
391  root["font_size"] = font_size.JsonValue();
392  root["font_alpha"] = font_alpha.JsonValue();
393  root["fade_in"] = fade_in.JsonValue();
394  root["fade_out"] = fade_out.JsonValue();
395  root["line_spacing"] = line_spacing.JsonValue();
396  root["left"] = left.JsonValue();
397  root["top"] = top.JsonValue();
398  root["right"] = right.JsonValue();
399  root["caption_text"] = caption_text;
400  root["caption_font"] = font_name;
401 
402  // return JsonValue
403  return root;
404 }
405 
406 // Load JSON string into this object
407 void Caption::SetJson(const std::string value) {
408 
409  // Parse JSON string into JSON objects
410  try
411  {
412  const Json::Value root = openshot::stringToJson(value);
413  // Set all values that match
414  SetJsonValue(root);
415  }
416  catch (const std::exception& e)
417  {
418  // Error parsing JSON (or missing keys)
419  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
420  }
421 }
422 
423 // Load Json::Value into this object
424 void Caption::SetJsonValue(const Json::Value root) {
425 
426  // Set parent data
428 
429  // Set data from Json (if key is found)
430  if (!root["color"].isNull())
431  color.SetJsonValue(root["color"]);
432  if (!root["stroke"].isNull())
433  stroke.SetJsonValue(root["stroke"]);
434  if (!root["background"].isNull())
435  background.SetJsonValue(root["background"]);
436  if (!root["background_alpha"].isNull())
437  background_alpha.SetJsonValue(root["background_alpha"]);
438  if (!root["background_corner"].isNull())
439  background_corner.SetJsonValue(root["background_corner"]);
440  if (!root["background_padding"].isNull())
441  background_padding.SetJsonValue(root["background_padding"]);
442  if (!root["stroke_width"].isNull())
443  stroke_width.SetJsonValue(root["stroke_width"]);
444  if (!root["font_size"].isNull())
445  font_size.SetJsonValue(root["font_size"]);
446  if (!root["font_alpha"].isNull())
447  font_alpha.SetJsonValue(root["font_alpha"]);
448  if (!root["fade_in"].isNull())
449  fade_in.SetJsonValue(root["fade_in"]);
450  if (!root["fade_out"].isNull())
451  fade_out.SetJsonValue(root["fade_out"]);
452  if (!root["line_spacing"].isNull())
453  line_spacing.SetJsonValue(root["line_spacing"]);
454  if (!root["left"].isNull())
455  left.SetJsonValue(root["left"]);
456  if (!root["top"].isNull())
457  top.SetJsonValue(root["top"]);
458  if (!root["right"].isNull())
459  right.SetJsonValue(root["right"]);
460  if (!root["caption_text"].isNull())
461  caption_text = root["caption_text"].asString();
462  if (!root["caption_font"].isNull())
463  font_name = root["caption_font"].asString();
464 
465  // Mark effect as dirty to reparse Regex
466  is_dirty = true;
467 }
468 
469 // Get all properties for a specific frame
470 std::string Caption::PropertiesJSON(int64_t requested_frame) const {
471 
472  // Generate JSON properties list
473  Json::Value root = BasePropertiesJSON(requested_frame);
474 
475  // Keyframes
476  root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
477  root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame);
478  root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame);
479  root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame);
480  root["stroke"] = add_property_json("Border", 0.0, "color", "", &stroke.red, 0, 255, false, requested_frame);
481  root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
482  root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
483  root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
484  root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
485  root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "float", "", &background_corner, 0.0, 60.0, false, requested_frame);
486  root["background_padding"] = add_property_json("Background Padding", background_padding.GetValue(requested_frame), "float", "", &background_padding, 0.0, 60.0, false, requested_frame);
487  root["background"] = add_property_json("Background", 0.0, "color", "", &background.red, 0, 255, false, requested_frame);
488  root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
489  root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
490  root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
491  root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "float", "", &stroke_width, 0, 10.0, false, requested_frame);
492  root["font_size"] = add_property_json("Font Size", font_size.GetValue(requested_frame), "float", "", &font_size, 0, 200.0, false, requested_frame);
493  root["font_alpha"] = add_property_json("Font Alpha", font_alpha.GetValue(requested_frame), "float", "", &font_alpha, 0.0, 1.0, false, requested_frame);
494  root["fade_in"] = add_property_json("Fade In (Seconds)", fade_in.GetValue(requested_frame), "float", "", &fade_in, 0.0, 3.0, false, requested_frame);
495  root["fade_out"] = add_property_json("Fade Out (Seconds)", fade_out.GetValue(requested_frame), "float", "", &fade_out, 0.0, 3.0, false, requested_frame);
496  root["line_spacing"] = add_property_json("Line Spacing", line_spacing.GetValue(requested_frame), "float", "", &line_spacing, 0.0, 5.0, false, requested_frame);
497  root["left"] = add_property_json("Left Size", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame);
498  root["top"] = add_property_json("Top Size", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
499  root["right"] = add_property_json("Right Size", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame);
500  root["caption_text"] = add_property_json("Captions", 0.0, "caption", caption_text, NULL, -1, -1, false, requested_frame);
501  root["caption_font"] = add_property_json("Font", 0.0, "font", font_name, NULL, -1, -1, false, requested_frame);
502 
503  // Return formatted string
504  return root.toStyledString();
505 }
openshot::ClipBase::add_property_json
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
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
openshot::ClipBase::timeline
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition: ClipBase.h:41
openshot::Fraction::ToFloat
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:35
openshot::EffectBase::info
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:69
openshot::Caption::stroke_width
Keyframe stroke_width
Width of text border / stroke.
Definition: Caption.h:61
openshot::Caption::GetFrame
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
openshot::Caption::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Caption.cpp:379
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::EffectBase::ParentClip
openshot::ClipBase * ParentClip()
Parent clip object of this effect (which can be unparented and NULL)
Definition: EffectBase.cpp:201
openshot::Caption::fade_in
Keyframe fade_in
Fade in per caption (# of seconds)
Definition: Caption.h:68
openshot::Clip
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:89
openshot::EffectBase::JsonValue
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: EffectBase.cpp:79
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:30
openshot::Caption::stroke
Color stroke
Color of text border / stroke.
Definition: Caption.h:56
openshot::Caption::Caption
Caption()
Blank constructor, useful when using Json to load the effect properties.
Definition: Caption.cpp:30
openshot::Caption::background_corner
Keyframe background_corner
Background cornder radius.
Definition: Caption.h:59
Caption.h
Header file for Caption effect class.
openshot::Caption::left
Keyframe left
Size of left bar.
Definition: Caption.h:65
openshot::Keyframe::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: KeyFrame.cpp:372
openshot::Caption::top
Keyframe top
Size of top bar.
Definition: Caption.h:66
openshot::Fraction::ToDouble
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:40
openshot::Caption::font_name
std::string font_name
Font string.
Definition: Caption.h:70
openshot::Keyframe::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: KeyFrame.cpp:339
openshot::Caption::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Caption.cpp:407
openshot::Caption::background_padding
Keyframe background_padding
Background padding.
Definition: Caption.h:60
openshot::EffectBase::BasePropertiesJSON
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
Definition: EffectBase.cpp:179
openshot::Color::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Color.cpp:117
openshot::Caption::right
Keyframe right
Size of right bar.
Definition: Caption.h:67
openshot::Caption::fade_out
Keyframe fade_out
Fade in per caption (# of seconds)
Definition: Caption.h:69
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:217
openshot::Caption::color
Color color
Color of caption text.
Definition: Caption.h:55
openshot::Timeline
This class represents a timeline.
Definition: Timeline.h:148
openshot::Caption::background
Color background
Color of caption area background.
Definition: Caption.h:57
openshot::EffectBase::InitEffectInfo
void InitEffectInfo()
Definition: EffectBase.cpp:24
openshot::Color::green
openshot::Keyframe green
Curve representing the green value (0 - 255)
Definition: Color.h:31
openshot::EffectInfoStruct::has_audio
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:41
openshot::Caption::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Caption.cpp:470
path
path
Definition: FFmpegWriter.cpp:1476
openshot::Caption::Json
std::string Json() const override
Generate JSON string of this object.
Definition: Caption.cpp:372
openshot::Caption::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Caption.cpp:424
openshot::EffectInfoStruct::class_name
std::string class_name
The class name of the effect.
Definition: EffectBase.h:36
openshot::Color::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Color.cpp:86
openshot::EffectInfoStruct::description
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:38
openshot::EffectInfoStruct::has_video
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:40
openshot::Caption::font_size
Keyframe font_size
Font size in points.
Definition: Caption.h:62
openshot::EffectInfoStruct::name
std::string name
The name of the effect.
Definition: EffectBase.h:37
openshot::Caption::line_spacing
Keyframe line_spacing
Distance between lines (1.0 default / 100%)
Definition: Caption.h:64
openshot::Caption::background_alpha
Keyframe background_alpha
Background color alpha.
Definition: Caption.h:58
openshot::Caption::font_alpha
Keyframe font_alpha
Font color alpha.
Definition: Caption.h:63
openshot::Color::red
openshot::Keyframe red
Curve representing the red value (0 - 255)
Definition: Color.h:30
openshot::Color::GetColorHex
std::string GetColorHex(int64_t frame_number)
Get the HEX value of a color at a specific frame.
Definition: Color.cpp:47
openshot::Caption::CaptionText
std::string CaptionText()
Set the caption string to use (see VTT format)
Definition: Caption.cpp:69
openshot::Color::blue
openshot::Keyframe blue
Curve representing the red value (0 - 255)
Definition: Color.h:32
Exceptions.h
Header file for all Exception classes.
openshot::EffectBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: EffectBase.cpp:115
openshot::Keyframe::GetValue
double GetValue(int64_t index) const
Get the value at a specific index.
Definition: KeyFrame.cpp:258
openshot::EffectBase::clip
openshot::ClipBase * clip
Pointer to the parent clip instance (if any)
Definition: EffectBase.h:59