OpenShot Library | libopenshot
0.4.0
|
Go to the documentation of this file.
26 QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(
""), font(QFont(
"Arial", 10)), text_color(
"#ffffff"), background_color(
"#000000"), is_open(false), gravity(
GRAVITY_CENTER)
34 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
42 text_background_color = color;
56 image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888_Premultiplied);
57 image->fill(QColor(background_color.c_str()));
60 if (!painter.begin(image.get())) {
65 if (!text_background_color.empty()) {
66 painter.setBackgroundMode(Qt::OpaqueMode);
67 painter.setBackground(QBrush(text_background_color.c_str()));
71 painter.setPen(QPen(text_color.c_str()));
74 painter.setFont(font);
81 align_flag = Qt::AlignLeft | Qt::AlignTop;
84 align_flag = Qt::AlignHCenter | Qt::AlignTop;
87 align_flag = Qt::AlignRight | Qt::AlignTop;
90 align_flag = Qt::AlignVCenter | Qt::AlignLeft;
93 align_flag = Qt::AlignCenter;
96 align_flag = Qt::AlignVCenter | Qt::AlignRight;
99 align_flag = Qt::AlignLeft | Qt::AlignBottom;
102 align_flag = Qt::AlignHCenter | Qt::AlignBottom;
105 align_flag = Qt::AlignRight | Qt::AlignBottom;
110 painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str());
167 const std::lock_guard<std::recursive_mutex> lock(
getFrameMutex);
174 auto image_frame = std::make_shared<Frame>(
175 requested_frame, image->size().width(), image->size().height(),
179 image_frame->AddImage(image);
185 auto image_frame = std::make_shared<Frame>(1, 640, 480, background_color, sample_count,
info.
channels);
204 root[
"type"] =
"QtTextReader";
205 root[
"width"] = width;
206 root[
"height"] = height;
207 root[
"x_offset"] = x_offset;
208 root[
"y_offset"] = y_offset;
210 root[
"font"] = font.toString().toStdString();
211 root[
"text_color"] = text_color;
212 root[
"background_color"] = background_color;
213 root[
"text_background_color"] = text_background_color;
214 root[
"gravity"] = gravity;
230 catch (
const std::exception& e)
233 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
244 if (!root[
"width"].isNull())
245 width = root[
"width"].asInt();
246 if (!root[
"height"].isNull())
247 height = root[
"height"].asInt();
248 if (!root[
"x_offset"].isNull())
249 x_offset = root[
"x_offset"].asInt();
250 if (!root[
"y_offset"].isNull())
251 y_offset = root[
"y_offset"].asInt();
252 if (!root[
"text"].isNull())
253 text = root[
"text"].asString();
254 if (!root[
"font"].isNull())
255 font.fromString(QString::fromStdString(root[
"font"].asString()));
256 if (!root[
"text_color"].isNull())
257 text_color = root[
"text_color"].asString();
258 if (!root[
"background_color"].isNull())
259 background_color = root[
"background_color"].asString();
260 if (!root[
"text_background_color"].isNull())
261 text_background_color = root[
"text_background_color"].asString();
262 if (!root[
"gravity"].isNull())
const Json::Value stringToJson(const std::string value)
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
std::string Json() const override
Generate JSON string of this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
void SetJson(const std::string value) override
Load JSON string into this object.
This class represents a fraction.
Header file for QtTextReader class.
openshot::ReaderInfo info
Information about the current media file.
@ GRAVITY_TOP_LEFT
Align clip to the top left of its parent.
@ GRAVITY_TOP_RIGHT
Align clip to the top right of its parent.
GravityType
This enumeration determines how clips are aligned to their parent container.
float duration
Length of time (in seconds)
bool has_video
Determines if this file has a video stream.
int width
The width of the video (in pixesl)
@ GRAVITY_RIGHT
Align clip to the right of its parent (middle aligned)
void Close() override
Close Reader.
Header file for CacheBase class.
Json::Value JsonValue() const override
Generate Json::Value for this object.
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
@ GRAVITY_TOP
Align clip to the top center of its parent.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
int num
Numerator for the fraction.
int den
Denominator for the fraction.
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
@ GRAVITY_BOTTOM
Align clip to the bottom center of its parent.
bool has_audio
Determines if this file has an audio stream.
Exception for invalid JSON.
int64_t file_size
Size of file (in bytes)
void SetTextBackgroundColor(std::string color)
bool has_single_image
Determines if this file only contains a single image.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
void Open() override
Open Reader - which is called by the constructor automatically.
Header file for Frame class.
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
@ GRAVITY_BOTTOM_LEFT
Align clip to the bottom left of its parent.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
@ GRAVITY_BOTTOM_RIGHT
Align clip to the bottom right of its parent.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
@ GRAVITY_LEFT
Align clip to the left of its parent (middle aligned)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
@ GRAVITY_CENTER
Align clip to the center of its parent (middle aligned)
QtTextReader()
Default constructor (blank text)
std::string acodec
The name of the audio codec used to encode / decode the video stream.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
int channels
The number of audio channels used in the audio stream.
Header file for all Exception classes.
std::recursive_mutex getFrameMutex
Mutex for multiple threads.