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