OpenShot Library | libopenshot  0.3.2
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  // Loop through matches and find text to display (if any)
189  for (auto match = matchedCaptions.begin(); match != matchedCaptions.end(); match++) {
190 
191  // Build timestamp (00:00:04.000 --> 00:00:06.500)
192  int64_t start_frame = ((match->captured(1).toFloat() * 60.0 * 60.0 ) + (match->captured(2).toFloat() * 60.0 ) +
193  match->captured(3).toFloat() + (match->captured(4).toFloat() / 1000.0)) * fps.ToFloat();
194  int64_t end_frame = ((match->captured(5).toFloat() * 60.0 * 60.0 ) + (match->captured(6).toFloat() * 60.0 ) +
195  match->captured(7).toFloat() + (match->captured(8).toFloat() / 1000.0)) * fps.ToFloat();
196 
197  // Split multiple lines into separate paths
198  QStringList lines = match->captured(9).split("\n");
199  for(int index = 0; index < lines.length(); index++) {
200  // Multi-line
201  QString line = lines[index];
202  // Ignore lines that start with NOTE, or are <= 1 char long
203  if (!line.startsWith(QStringLiteral("NOTE")) &&
204  !line.isEmpty() && frame_number >= start_frame && frame_number <= end_frame && line.length() > 1) {
205 
206  // Calculate fade in/out ranges
207  fade_in_percentage = ((float) frame_number - (float) start_frame) / fade_in_value;
208  fade_out_percentage = 1.0 - (((float) frame_number - ((float) end_frame - fade_out_value)) / fade_out_value);
209 
210  // Loop through words, and find word-wrap boundaries
211  QStringList words = line.split(" ");
212 
213  // Wrap languages which do not use spaces
214  bool use_spaces = true;
215  if (line.length() > 20 && words.length() == 1) {
216  words = line.split("");
217  use_spaces = false;
218  }
219  int words_remaining = words.length();
220  while (words_remaining > 0) {
221  bool words_displayed = false;
222  for(int word_index = words.length(); word_index > 0; word_index--) {
223  // Current matched caption string (from the beginning to the current word index)
224  QString fitting_line = words.mid(0, word_index).join(" ");
225 
226  // Calculate size of text
227  QRectF textRect = metrics.boundingRect(caption_area, Qt::TextSingleLine, fitting_line);
228  if (textRect.width() <= caption_area.width()) {
229  // Location for text
230  QPoint p(left_margin_x, current_y);
231 
232  // Create path and add text to it (for correct border and fill)
233  QPainterPath path1;
234  QString fitting_line;
235  if (use_spaces) {
236  fitting_line = words.mid(0, word_index).join(" ");
237  } else {
238  fitting_line = words.mid(0, word_index).join("");
239  }
240  path1.addText(p, font, fitting_line);
241  text_paths.push_back(path1);
242 
243  // Update line (to remove words already drawn
244  words = words.mid(word_index, words.length());
245  words_remaining = words.length();
246  words_displayed = true;
247 
248  // Increment y-coordinate of text (for next line) + padding
249  current_y += line_height;
250 
251  // Detect max width (of widest text line)
252  if (path1.boundingRect().width() > max_text_width) {
253  max_text_width = path1.boundingRect().width();
254  }
255  // Detect top most y coordinate of text
256  if (path1.boundingRect().top() < top_y) {
257  top_y = path1.boundingRect().top();
258  }
259  // Detect bottom most y coordinate of text
260  if (path1.boundingRect().bottom() > bottom_y) {
261  bottom_y = path1.boundingRect().bottom();
262  }
263  break;
264  }
265  }
266 
267  if (!words_displayed) {
268  // Exit loop if no words displayed
269  words_remaining = 0;
270  }
271  }
272 
273  }
274  }
275  }
276 
277  // Calculate background size w/padding (based on actual text-wrapping)
278  QRectF caption_area_with_padding = QRectF(left_margin_x - (padding_value / 2.0),
279  top_y - (padding_value / 2.0),
280  max_text_width + padding_value,
281  (bottom_y - top_y) + padding_value);
282 
283  // Calculate alignment offset on X axis (force center alignment of the caption area)
284  double alignment_offset = std::max((caption_area_width - max_text_width) / 2.0, 0.0);
285 
286  // Set background color of caption
287  QBrush background_brush;
288  QColor background_qcolor = QColor(QString(background.GetColorHex(frame_number).c_str()));
289  // Align background center
290  caption_area_with_padding.translate(alignment_offset, 0.0);
291  if (fade_in_percentage < 1.0) {
292  // Fade in background
293  background_qcolor.setAlphaF(fade_in_percentage * background_alpha.GetValue(frame_number));
294  } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
295  // Fade out background
296  background_qcolor.setAlphaF(fade_out_percentage * background_alpha.GetValue(frame_number));
297  } else {
298  background_qcolor.setAlphaF(background_alpha.GetValue(frame_number));
299  }
300  background_brush.setColor(background_qcolor);
301  background_brush.setStyle(Qt::SolidPattern);
302  painter.setBrush(background_brush);
303  painter.setPen(Qt::NoPen);
304  painter.drawRoundedRect(caption_area_with_padding, background_corner_value, background_corner_value);
305 
306  // Set fill-color of text
307  QBrush font_brush;
308  QColor font_qcolor = QColor(QString(color.GetColorHex(frame_number).c_str()));
309  font_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
310  font_brush.setStyle(Qt::SolidPattern);
311 
312  // Set stroke/border color of text
313  QPen pen;
314  QColor stroke_qcolor;
315  stroke_qcolor = QColor(QString(stroke.GetColorHex(frame_number).c_str()));
316  stroke_qcolor.setAlphaF(font_alpha.GetValue(frame_number));
317  pen.setColor(stroke_qcolor);
318  pen.setWidthF(std::max(stroke_width_value, 0.0));
319  painter.setPen(pen);
320 
321  // Loop through text paths
322  for(QPainterPath path : text_paths) {
323  // Align text center (relative to background)
324  path.translate(alignment_offset, 0.0);
325  if (fade_in_percentage < 1.0) {
326  // Fade in text
327  font_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
328  stroke_qcolor.setAlphaF(fade_in_percentage * font_alpha.GetValue(frame_number));
329  } else if (fade_out_percentage >= 0.0 && fade_out_percentage <= 1.0) {
330  // Fade out text
331  font_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
332  stroke_qcolor.setAlphaF(fade_out_percentage * font_alpha.GetValue(frame_number));
333  }
334  pen.setColor(stroke_qcolor);
335  font_brush.setColor(font_qcolor);
336 
337  // Set stroke pen
338  if (stroke_width_value <= 0.0) {
339  painter.setPen(Qt::NoPen);
340  } else {
341  painter.setPen(pen);
342  }
343 
344  painter.setBrush(font_brush);
345  painter.drawPath(path);
346  }
347 
348  // End painter
349  painter.end();
350 
351  // return the modified frame
352  return frame;
353 }
354 
355 // Generate JSON string of this object
356 std::string Caption::Json() const {
357 
358  // Return formatted string
359  return JsonValue().toStyledString();
360 }
361 
362 // Generate Json::Value for this object
363 Json::Value Caption::JsonValue() const {
364 
365  // Create root json object
366  Json::Value root = EffectBase::JsonValue(); // get parent properties
367  root["type"] = info.class_name;
368  root["color"] = color.JsonValue();
369  root["stroke"] = stroke.JsonValue();
370  root["background"] = background.JsonValue();
371  root["background_alpha"] = background_alpha.JsonValue();
372  root["background_corner"] = background_corner.JsonValue();
373  root["background_padding"] = background_padding.JsonValue();
374  root["stroke_width"] = stroke_width.JsonValue();
375  root["font_size"] = font_size.JsonValue();
376  root["font_alpha"] = font_alpha.JsonValue();
377  root["fade_in"] = fade_in.JsonValue();
378  root["fade_out"] = fade_out.JsonValue();
379  root["line_spacing"] = line_spacing.JsonValue();
380  root["left"] = left.JsonValue();
381  root["top"] = top.JsonValue();
382  root["right"] = right.JsonValue();
383  root["caption_text"] = caption_text;
384  root["caption_font"] = font_name;
385 
386  // return JsonValue
387  return root;
388 }
389 
390 // Load JSON string into this object
391 void Caption::SetJson(const std::string value) {
392 
393  // Parse JSON string into JSON objects
394  try
395  {
396  const Json::Value root = openshot::stringToJson(value);
397  // Set all values that match
398  SetJsonValue(root);
399  }
400  catch (const std::exception& e)
401  {
402  // Error parsing JSON (or missing keys)
403  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
404  }
405 }
406 
407 // Load Json::Value into this object
408 void Caption::SetJsonValue(const Json::Value root) {
409 
410  // Set parent data
412 
413  // Set data from Json (if key is found)
414  if (!root["color"].isNull())
415  color.SetJsonValue(root["color"]);
416  if (!root["stroke"].isNull())
417  stroke.SetJsonValue(root["stroke"]);
418  if (!root["background"].isNull())
419  background.SetJsonValue(root["background"]);
420  if (!root["background_alpha"].isNull())
421  background_alpha.SetJsonValue(root["background_alpha"]);
422  if (!root["background_corner"].isNull())
423  background_corner.SetJsonValue(root["background_corner"]);
424  if (!root["background_padding"].isNull())
425  background_padding.SetJsonValue(root["background_padding"]);
426  if (!root["stroke_width"].isNull())
427  stroke_width.SetJsonValue(root["stroke_width"]);
428  if (!root["font_size"].isNull())
429  font_size.SetJsonValue(root["font_size"]);
430  if (!root["font_alpha"].isNull())
431  font_alpha.SetJsonValue(root["font_alpha"]);
432  if (!root["fade_in"].isNull())
433  fade_in.SetJsonValue(root["fade_in"]);
434  if (!root["fade_out"].isNull())
435  fade_out.SetJsonValue(root["fade_out"]);
436  if (!root["line_spacing"].isNull())
437  line_spacing.SetJsonValue(root["line_spacing"]);
438  if (!root["left"].isNull())
439  left.SetJsonValue(root["left"]);
440  if (!root["top"].isNull())
441  top.SetJsonValue(root["top"]);
442  if (!root["right"].isNull())
443  right.SetJsonValue(root["right"]);
444  if (!root["caption_text"].isNull())
445  caption_text = root["caption_text"].asString();
446  if (!root["caption_font"].isNull())
447  font_name = root["caption_font"].asString();
448 
449  // Mark effect as dirty to reparse Regex
450  is_dirty = true;
451 }
452 
453 // Get all properties for a specific frame
454 std::string Caption::PropertiesJSON(int64_t requested_frame) const {
455 
456  // Generate JSON properties list
457  Json::Value root = BasePropertiesJSON(requested_frame);
458 
459  // Keyframes
460  root["color"] = add_property_json("Color", 0.0, "color", "", &color.red, 0, 255, false, requested_frame);
461  root["color"]["red"] = add_property_json("Red", color.red.GetValue(requested_frame), "float", "", &color.red, 0, 255, false, requested_frame);
462  root["color"]["blue"] = add_property_json("Blue", color.blue.GetValue(requested_frame), "float", "", &color.blue, 0, 255, false, requested_frame);
463  root["color"]["green"] = add_property_json("Green", color.green.GetValue(requested_frame), "float", "", &color.green, 0, 255, false, requested_frame);
464  root["stroke"] = add_property_json("Border", 0.0, "color", "", &stroke.red, 0, 255, false, requested_frame);
465  root["stroke"]["red"] = add_property_json("Red", stroke.red.GetValue(requested_frame), "float", "", &stroke.red, 0, 255, false, requested_frame);
466  root["stroke"]["blue"] = add_property_json("Blue", stroke.blue.GetValue(requested_frame), "float", "", &stroke.blue, 0, 255, false, requested_frame);
467  root["stroke"]["green"] = add_property_json("Green", stroke.green.GetValue(requested_frame), "float", "", &stroke.green, 0, 255, false, requested_frame);
468  root["background_alpha"] = add_property_json("Background Alpha", background_alpha.GetValue(requested_frame), "float", "", &background_alpha, 0.0, 1.0, false, requested_frame);
469  root["background_corner"] = add_property_json("Background Corner Radius", background_corner.GetValue(requested_frame), "float", "", &background_corner, 0.0, 60.0, false, requested_frame);
470  root["background_padding"] = add_property_json("Background Padding", background_padding.GetValue(requested_frame), "float", "", &background_padding, 0.0, 60.0, false, requested_frame);
471  root["background"] = add_property_json("Background", 0.0, "color", "", &background.red, 0, 255, false, requested_frame);
472  root["background"]["red"] = add_property_json("Red", background.red.GetValue(requested_frame), "float", "", &background.red, 0, 255, false, requested_frame);
473  root["background"]["blue"] = add_property_json("Blue", background.blue.GetValue(requested_frame), "float", "", &background.blue, 0, 255, false, requested_frame);
474  root["background"]["green"] = add_property_json("Green", background.green.GetValue(requested_frame), "float", "", &background.green, 0, 255, false, requested_frame);
475  root["stroke_width"] = add_property_json("Stroke Width", stroke_width.GetValue(requested_frame), "float", "", &stroke_width, 0, 10.0, false, requested_frame);
476  root["font_size"] = add_property_json("Font Size", font_size.GetValue(requested_frame), "float", "", &font_size, 0, 200.0, false, requested_frame);
477  root["font_alpha"] = add_property_json("Font Alpha", font_alpha.GetValue(requested_frame), "float", "", &font_alpha, 0.0, 1.0, false, requested_frame);
478  root["fade_in"] = add_property_json("Fade In (Seconds)", fade_in.GetValue(requested_frame), "float", "", &fade_in, 0.0, 3.0, false, requested_frame);
479  root["fade_out"] = add_property_json("Fade Out (Seconds)", fade_out.GetValue(requested_frame), "float", "", &fade_out, 0.0, 3.0, false, requested_frame);
480  root["line_spacing"] = add_property_json("Line Spacing", line_spacing.GetValue(requested_frame), "float", "", &line_spacing, 0.0, 5.0, false, requested_frame);
481  root["left"] = add_property_json("Left Size", left.GetValue(requested_frame), "float", "", &left, 0.0, 0.5, false, requested_frame);
482  root["top"] = add_property_json("Top Size", top.GetValue(requested_frame), "float", "", &top, 0.0, 1.0, false, requested_frame);
483  root["right"] = add_property_json("Right Size", right.GetValue(requested_frame), "float", "", &right, 0.0, 0.5, false, requested_frame);
484  root["caption_text"] = add_property_json("Captions", 0.0, "caption", caption_text, NULL, -1, -1, false, requested_frame);
485  root["caption_font"] = add_property_json("Font", 0.0, "font", font_name, NULL, -1, -1, false, requested_frame);
486 
487  // Return formatted string
488  return root.toStyledString();
489 }
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:363
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:391
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:454
path
path
Definition: FFmpegWriter.cpp:1444
openshot::Caption::Json
std::string Json() const override
Generate JSON string of this object.
Definition: Caption.cpp:356
openshot::Caption::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Caption.cpp:408
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