31 #include "../include/ImageWriter.h" 36 path(path), cache_size(8), is_writing(false), write_video_count(0), image_quality(75), number_of_loops(1),
37 combine_frames(true), is_open(false)
46 int quality,
int loops,
bool combine)
53 image_quality = quality;
54 number_of_loops = loops;
55 combine_frames = combine;
79 ZmqLogger::Instance()->
AppendDebugMethod(
"ImageWriter::SetVideoOptions (" + format +
")",
"width", width,
"height", height,
"size.num", size.
num,
"size.den", size.
den,
"fps.num", fps.
num,
"fps.den", fps.
den);
93 throw WriterClosed(
"The ImageWriter is closed. Call Open() before calling this method.", path);
97 std::shared_ptr<Magick::Image> frame_image = frame->GetMagickImage();
99 frame_image->backgroundColor(Magick::Color(
"none"));
100 frame_image->matte(
true);
101 frame_image->quality(image_quality);
103 frame_image->animationIterations(number_of_loops);
107 int new_height =
info.
height * frame->GetPixelRatio().Reciprocal().ToDouble();
110 Magick::Geometry new_size(new_width, new_height);
111 new_size.aspect(
true);
112 frame_image->resize(new_size);
116 frames.push_back(*frame_image.get());
125 ZmqLogger::Instance()->
AppendDebugMethod(
"ImageWriter::WriteFrame (from Reader)",
"start", start,
"length", length,
"", -1,
"", -1,
"", -1,
"", -1);
128 for (int64_t number = start; number <= length; number++)
131 std::shared_ptr<Frame> f = reader->
GetFrame(number);
142 Magick::writeImages(frames.begin(), frames.end(), path, combine_frames);
148 write_video_count = 0;
153 ZmqLogger::Instance()->
AppendDebugMethod(
"ImageWriter::Close",
"", -1,
"", -1,
"", -1,
"", -1,
"", -1,
"", -1);
ImageWriter(string path)
Constructor for ImageWriter. Throws one of the following exceptions.
int num
Numerator for the fraction.
WriterInfo info
Information about the current media file.
int video_bit_rate
The bit rate of the video stream (in bytes)
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
void WriteFrame(std::shared_ptr< Frame > frame)
Add a frame to the stack waiting to be encoded.
string vcodec
The name of the video codec used to encode / decode the video stream.
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
void SetVideoOptions(string format, Fraction fps, int width, int height, int quality, int loops, bool combine)
Set the video export options.
This abstract class is the base class, used by all readers in libopenshot.
int width
The width of the video (in pixels)
Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
void Close()
Close the writer and encode/output final image to the disk. This is a requirement of ImageMagick...
virtual std::shared_ptr< Frame > GetFrame(int64_t number)=0
void AppendDebugMethod(string method_name, string arg1_name, float arg1_value, string arg2_name, float arg2_value, string arg3_name, float arg3_value, string arg4_name, float arg4_value, string arg5_name, float arg5_value, string arg6_name, float arg6_value)
Append debug information.
This class represents a fraction.
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
bool has_video
Determines if this file has a video stream.
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
This namespace is the default namespace for all code in the openshot library.
bool has_audio
Determines if this file has an audio stream.
Exception when a writer is closed, and a frame is requested.
int height
The height of the video (in pixels)
int den
Denominator for the fraction.