OpenShot Library | libopenshot  0.7.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), 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
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), 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
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 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  painter.setBrush(font_brush);
373  painter.drawPath(path);
374  }
375  painter.restore();
376 
377  // End painter
378  painter.end();
379 
380  // return the modified frame
381  return frame;
382 }
383 
384 // Generate JSON string of this object
385 std::string Caption::Json() const {
386 
387  // Return formatted string
388  return JsonValue().toStyledString();
389 }
390 
391 // Generate Json::Value for this object
392 Json::Value Caption::JsonValue() const {
393 
394  // Create root json object
395  Json::Value root = EffectBase::JsonValue(); // get parent properties
396  root["type"] = info.class_name;
397  root["color"] = color.JsonValue();
398  root["stroke"] = stroke.JsonValue();
399  root["background"] = background.JsonValue();
400  root["background_alpha"] = background_alpha.JsonValue();
401  root["background_corner"] = background_corner.JsonValue();
402  root["background_padding"] = background_padding.JsonValue();
403  root["stroke_width"] = stroke_width.JsonValue();
404  root["font_size"] = font_size.JsonValue();
405  root["font_alpha"] = font_alpha.JsonValue();
406  root["fade_in"] = fade_in.JsonValue();
407  root["fade_out"] = fade_out.JsonValue();
408  root["line_spacing"] = line_spacing.JsonValue();
409  root["left"] = left.JsonValue();
410  root["top"] = top.JsonValue();
411  root["right"] = right.JsonValue();
412  root["bottom"] = bottom.JsonValue();
413  root["caption_text"] = caption_text;
414  root["caption_font"] = font_name;
415 
416  // return JsonValue
417  return root;
418 }
419 
420 // Load JSON string into this object
421 void Caption::SetJson(const std::string value) {
422 
423  // Parse JSON string into JSON objects
424  try
425  {
426  const Json::Value root = openshot::stringToJson(value);
427  // Set all values that match
428  SetJsonValue(root);
429  }
430  catch (const std::exception& e)
431  {
432  // Error parsing JSON (or missing keys)
433  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
434  }
435 }
436 
437 // Load Json::Value into this object
438 void Caption::SetJsonValue(const Json::Value root) {
439 
440  // Set parent data
442 
443  // Set data from Json (if key is found)
444  if (!root["color"].isNull())
445  color.SetJsonValue(root["color"]);
446  if (!root["stroke"].isNull())
447  stroke.SetJsonValue(root["stroke"]);
448  if (!root["background"].isNull())
449  background.SetJsonValue(root["background"]);
450  if (!root["background_alpha"].isNull())
451  background_alpha.SetJsonValue(root["background_alpha"]);
452  if (!root["background_corner"].isNull())
453  background_corner.SetJsonValue(root["background_corner"]);
454  if (!root["background_padding"].isNull())
455  background_padding.SetJsonValue(root["background_padding"]);
456  if (!root["stroke_width"].isNull())
457  stroke_width.SetJsonValue(root["stroke_width"]);
458  if (!root["font_size"].isNull())
459  font_size.SetJsonValue(root["font_size"]);
460  if (!root["font_alpha"].isNull())
461  font_alpha.SetJsonValue(root["font_alpha"]);
462  if (!root["fade_in"].isNull())
463  fade_in.SetJsonValue(root["fade_in"]);
464  if (!root["fade_out"].isNull())
465  fade_out.SetJsonValue(root["fade_out"]);
466  if (!root["line_spacing"].isNull())
467  line_spacing.SetJsonValue(root["line_spacing"]);
468  if (!root["left"].isNull())
469  left.SetJsonValue(root["left"]);
470  if (!root["top"].isNull())
471  top.SetJsonValue(root["top"]);
472  if (!root["right"].isNull())
473  right.SetJsonValue(root["right"]);
474  if (!root["bottom"].isNull())
475  bottom.SetJsonValue(root["bottom"]);
476  if (!root["caption_text"].isNull())
477  caption_text = root["caption_text"].asString();
478  if (!root["caption_font"].isNull())
479  font_name = root["caption_font"].asString();
480 
481  // Mark effect as dirty to reparse Regex
482  is_dirty = true;
483 }
484 
485 // Get all properties for a specific frame
486 std::string Caption::PropertiesJSON(int64_t requested_frame) const {
487 
488  // Generate JSON properties list
489  Json::Value root = BasePropertiesJSON(requested_frame);
490 
491  // Keyframes
492  root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
493  root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame);
494  root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame);
495  root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame);
496  root["stroke"] = add_property_json("Border", 0.0, "color", "", &stroke.red, 0, 255, false, requested_frame);
497  root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
498  root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
499  root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
500  root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
501  root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "float", "", &background_corner, 0.0, 60.0, false, requested_frame);
502  root["background_padding"] = add_property_json("Background Padding", background_padding.GetValue(requested_frame), "float", "", &background_padding, 0.0, 60.0, false, requested_frame);
503  root["background"] = add_property_json("Background", 0.0, "color", "", &background.red, 0, 255, false, requested_frame);
504  root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
505  root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
506  root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
507  root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "float", "", &stroke_width, 0, 10.0, false, requested_frame);
508  root["font_size"] = add_property_json("Font Size", font_size.GetValue(requested_frame), "float", "", &font_size, 0, 200.0, false, requested_frame);
509  root["font_alpha"] = add_property_json("Font Alpha", font_alpha.GetValue(requested_frame), "float", "", &font_alpha, 0.0, 1.0, false, requested_frame);
510  root["fade_in"] = add_property_json("Fade In (Seconds)", fade_in.GetValue(requested_frame), "float", "", &fade_in, 0.0, 3.0, false, requested_frame);
511  root["fade_out"] = add_property_json("Fade Out (Seconds)", fade_out.GetValue(requested_frame), "float", "", &fade_out, 0.0, 3.0, false, requested_frame);
512  root["line_spacing"] = add_property_json("Line Spacing", line_spacing.GetValue(requested_frame), "float", "", &line_spacing, 0.0, 5.0, false, requested_frame);
513  root["left"] = add_property_json("Margin: Left", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame);
514  root["top"] = add_property_json("Margin: Top", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
515  root["right"] = add_property_json("Margin: Right", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame);
516  root["bottom"] = add_property_json("Margin: Bottom", bottom.GetValue(requested_frame), "float", "", &bottom, 0.0, 1.0, false, requested_frame);
517  root["caption_text"] = add_property_json("Captions", 0.0, "caption", caption_text, NULL, -1, -1, false, requested_frame);
518  root["caption_font"] = add_property_json("Font", 0.0, "font", font_name, NULL, -1, -1, false, requested_frame);
519 
520  // Return formatted string
521  return root.toStyledString();
522 }
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:40
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:114
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:87
openshot::Caption::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Caption.cpp:392
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24
openshot::EffectBase::ParentClip
openshot::ClipBase * ParentClip()
Parent clip object of this effect (which can be unparented and NULL)
Definition: EffectBase.cpp:654
openshot::Caption::fade_in
Keyframe fade_in
Fade in per caption (# of seconds)
Definition: Caption.h:69
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:102
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:71
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:421
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:245
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:70
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:223
openshot::Caption::color
Color color
Color of caption text.
Definition: Caption.h:55
openshot::Timeline
This class represents a timeline.
Definition: Timeline.h:153
openshot::Caption::background
Color background
Color of caption area background.
Definition: Caption.h:57
openshot::EffectBase::InitEffectInfo
void InitEffectInfo()
Definition: EffectBase.cpp:42
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:44
openshot::Caption::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Caption.cpp:486
path
path
Definition: FFmpegWriter.cpp:1481
openshot::Caption::Json
std::string Json() const override
Generate JSON string of this object.
Definition: Caption.cpp:385
openshot::Caption::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Caption.cpp:438
openshot::EffectInfoStruct::class_name
std::string class_name
The class name of the effect.
Definition: EffectBase.h:39
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:41
openshot::EffectInfoStruct::has_video
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:43
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:40
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::Caption::bottom
Keyframe bottom
Size of bottom bar.
Definition: Caption.h:68
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:146
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:77