OpenShot Library | libopenshot  0.1.9
Public Member Functions | Public Attributes | List of all members
openshot::Timeline Class Reference

This class represents a timeline. More...

#include <Timeline.h>

Inheritance diagram for openshot::Timeline:
openshot::ReaderBase

Public Member Functions

void AddClip (Clip *clip)
 Add an openshot::Clip to the timeline. More...
 
void AddEffect (EffectBase *effect)
 Add an effect to the timeline. More...
 
void ApplyJsonDiff (string value)
 Apply a special formatted JSON object, which represents a change to the timeline (add, update, delete) This is primarily designed to keep the timeline (and its child objects... such as clips and effects) in sync with another application... such as OpenShot Video Editor (http://www.openshot.org). More...
 
void ApplyMapperToClips ()
 Apply the timeline's framerate and samplerate to all clips. More...
 
bool AutoMapClips ()
 Determine if clips are automatically mapped to the timeline's framerate and samplerate. More...
 
void AutoMapClips (bool auto_map)
 Automatically map all clips to the timeline's framerate and samplerate. More...
 
void ClearAllCache ()
 Clear all cache for this timeline instance, and all clips, mappers, and readers under it. More...
 
list< Clip * > Clips ()
 Return a list of clips on the timeline. More...
 
void Close ()
 Close the timeline reader (and any resources it was consuming) More...
 
list< EffectBase * > Effects ()
 Return the list of effects on the timeline. More...
 
CacheBaseGetCache ()
 Get the cache object used by this reader. More...
 
std::shared_ptr< FrameGetFrame (int64_t requested_frame)
 
bool IsOpen ()
 Determine if reader is open or closed. More...
 
string Json ()
 Get and Set JSON methods. More...
 
Json::Value JsonValue ()
 Generate Json::JsonValue for this object. More...
 
string Name ()
 Return the type name of the class. More...
 
void Open ()
 Open the reader (and start consuming resources) More...
 
void RemoveClip (Clip *clip)
 Remove an openshot::Clip from the timeline. More...
 
void RemoveEffect (EffectBase *effect)
 Remove an effect from the timeline. More...
 
void SetCache (CacheBase *new_cache)
 Get the cache object used by this reader. More...
 
void SetJson (string value)
 Load JSON string into this object. More...
 
void SetJsonValue (Json::Value root)
 Load Json::JsonValue into this object. More...
 
 Timeline (int width, int height, Fraction fps, int sample_rate, int channels, ChannelLayout channel_layout)
 Default Constructor for the timeline (which sets the canvas width and height and FPS) More...
 
- Public Member Functions inherited from openshot::ReaderBase
void DisplayInfo ()
 Display file information in the standard output stream (stdout) More...
 
 ReaderBase ()
 Constructor for the base reader, where many things are initialized. More...
 
void SetMaxSize (int width, int height)
 Set Max Image Size (used for performance optimization) More...
 

Public Attributes

Color color
 Background color of timeline canvas. More...
 
Keyframe viewport_scale
 Curve representing the scale of the viewport (0 to 100) More...
 
Keyframe viewport_x
 Curve representing the x coordinate for the viewport. More...
 
Keyframe viewport_y
 Curve representing the y coordinate for the viewport. More...
 
- Public Attributes inherited from openshot::ReaderBase
ReaderInfo info
 Information about the current media file. More...
 

Additional Inherited Members

- Protected Attributes inherited from openshot::ReaderBase
CriticalSection getFrameCriticalSection
 Section lock for multiple threads. More...
 
int max_height
 The maximium image height needed by this clip (used for optimizations) More...
 
int max_width
 The maximum image width needed by this clip (used for optimizations) More...
 
CriticalSection processingCriticalSection
 

Detailed Description

This class represents a timeline.

The timeline is one of the most important features of a video editor, and controls all aspects of how video, image, and audio clips are combined together, and how the final video output will be rendered. It has a collection of layers and clips, that arrange, sequence, and generate the final video output.

The following graphic displays a timeline, and how clips can be arranged, scaled, and layered together. It also demonstrates how the viewport can be scaled smaller than the canvas, which can be used to zoom and pan around the canvas (i.e. pan & scan).

Timeline_Layers.png

The following graphic displays how the playhead determines which frames to combine and layer.

Playhead.png

Lets take a look at what the code looks like:

// Create a Timeline
Timeline t(1280, // width
720, // height
Fraction(25,1), // framerate
44100, // sample rate
2 // channels
);
// Create some clips
Clip c1(new ImageReader("MyAwesomeLogo.jpeg"));
Clip c2(new FFmpegReader("BackgroundVideo.webm"));
// CLIP 1 (logo) - Set some clip properties (with Keyframes)
c1.Position(0.0); // Set the position or location (in seconds) on the timeline
c1.gravity = GRAVITY_LEFT; // Set the alignment / gravity of the clip (position on the screen)
c1.scale = SCALE_CROP; // Set the scale mode (how the image is resized to fill the screen)
c1.Layer(1); // Set the layer of the timeline (higher layers cover up images of lower layers)
c1.Start(0.0); // Set the starting position of the video (trim the left side of the video)
c1.End(16.0); // Set the ending position of the video (trim the right side of the video)
c1.alpha.AddPoint(1, 0.0); // Set the alpha to transparent on frame #1
c1.alpha.AddPoint(500, 0.0); // Keep the alpha transparent until frame #500
c1.alpha.AddPoint(565, 1.0); // Animate the alpha from transparent to visible (between frame #501 and #565)
// CLIP 2 (background video) - Set some clip properties (with Keyframes)
c2.Position(0.0); // Set the position or location (in seconds) on the timeline
c2.Start(10.0); // Set the starting position of the video (trim the left side of the video)
c2.Layer(0); // Set the layer of the timeline (higher layers cover up images of lower layers)
c2.alpha.AddPoint(1, 1.0); // Set the alpha to visible on frame #1
c2.alpha.AddPoint(150, 0.0); // Animate the alpha to transparent (between frame 2 and frame #150)
c2.alpha.AddPoint(360, 0.0, LINEAR); // Keep the alpha transparent until frame #360
c2.alpha.AddPoint(384, 1.0); // Animate the alpha to visible (between frame #360 and frame #384)
// Add clips to timeline
t.AddClip(&c1);
t.AddClip(&c2);
// Open the timeline reader
t.Open();
// Get frame number 1 from the timeline (This will generate a new frame, made up from the previous clips and settings)
std::shared_ptr<Frame> f = t.GetFrame(1);
// Now that we have an openshot::Frame object, lets have some fun!
f->Display(); // Display the frame on the screen
// Close the timeline reader
t.Close();

Definition at line 145 of file Timeline.h.

Constructor & Destructor Documentation

◆ Timeline()

Timeline::Timeline ( int  width,
int  height,
Fraction  fps,
int  sample_rate,
int  channels,
ChannelLayout  channel_layout 
)

Default Constructor for the timeline (which sets the canvas width and height and FPS)

Parameters
widthThe width of the timeline (and thus, the generated openshot::Frame objects)
heightThe height of the timeline (and thus, the generated openshot::Frame objects)
fpsThe frames rate of the timeline
sample_rateThe sample rate of the timeline's audio
channelsThe number of audio channels of the timeline
channel_layoutThe channel layout (i.e. mono, stereo, 3 point surround, etc...)

Definition at line 33 of file Timeline.cpp.

Member Function Documentation

◆ AddClip()

void Timeline::AddClip ( Clip clip)

Add an openshot::Clip to the timeline.

Parameters
clipAdd an openshot::Clip to the timeline. A clip can contain any type of Reader.

Definition at line 71 of file Timeline.cpp.

◆ AddEffect()

void Timeline::AddEffect ( EffectBase effect)

Add an effect to the timeline.

Parameters
effectAdd an effect to the timeline. An effect can modify the audio or video of an openshot::Frame.

Definition at line 86 of file Timeline.cpp.

◆ ApplyJsonDiff()

void Timeline::ApplyJsonDiff ( string  value)

Apply a special formatted JSON object, which represents a change to the timeline (add, update, delete) This is primarily designed to keep the timeline (and its child objects... such as clips and effects) in sync with another application... such as OpenShot Video Editor (http://www.openshot.org).

Parameters
valueA JSON string containing a key, value, and type of change.

Definition at line 1015 of file Timeline.cpp.

◆ ApplyMapperToClips()

void Timeline::ApplyMapperToClips ( )

Apply the timeline's framerate and samplerate to all clips.

Definition at line 145 of file Timeline.cpp.

◆ AutoMapClips() [1/2]

bool openshot::Timeline::AutoMapClips ( )
inline

Determine if clips are automatically mapped to the timeline's framerate and samplerate.

Definition at line 219 of file Timeline.h.

◆ AutoMapClips() [2/2]

void openshot::Timeline::AutoMapClips ( bool  auto_map)
inline

Automatically map all clips to the timeline's framerate and samplerate.

Definition at line 222 of file Timeline.h.

◆ ClearAllCache()

void Timeline::ClearAllCache ( )

Clear all cache for this timeline instance, and all clips, mappers, and readers under it.

Definition at line 1390 of file Timeline.cpp.

◆ Clips()

list<Clip*> openshot::Timeline::Clips ( )
inline

Return a list of clips on the timeline.

Definition at line 228 of file Timeline.h.

◆ Close()

void Timeline::Close ( )
virtual

Close the timeline reader (and any resources it was consuming)

Implements openshot::ReaderBase.

Definition at line 604 of file Timeline.cpp.

◆ Effects()

list<EffectBase*> openshot::Timeline::Effects ( )
inline

Return the list of effects on the timeline.

Definition at line 234 of file Timeline.h.

◆ GetCache()

CacheBase* openshot::Timeline::GetCache ( )
inlinevirtual

Get the cache object used by this reader.

Implements openshot::ReaderBase.

Definition at line 237 of file Timeline.h.

◆ GetFrame()

std::shared_ptr< Frame > Timeline::GetFrame ( int64_t  requested_frame)
virtual

Get an openshot::Frame object for a specific frame number of this timeline.

Returns
The requested frame (containing the image)
Parameters
requested_frameThe frame number that is requested.

Implements openshot::ReaderBase.

Definition at line 639 of file Timeline.cpp.

◆ IsOpen()

bool openshot::Timeline::IsOpen ( )
inlinevirtual

Determine if reader is open or closed.

Implements openshot::ReaderBase.

Definition at line 257 of file Timeline.h.

◆ Json()

string Timeline::Json ( )
virtual

Get and Set JSON methods.

Generate JSON string of this object

Implements openshot::ReaderBase.

Definition at line 877 of file Timeline.cpp.

◆ JsonValue()

Json::Value Timeline::JsonValue ( )
virtual

Generate Json::JsonValue for this object.

Implements openshot::ReaderBase.

Definition at line 884 of file Timeline.cpp.

◆ Name()

string openshot::Timeline::Name ( )
inlinevirtual

Return the type name of the class.

Implements openshot::ReaderBase.

Definition at line 260 of file Timeline.h.

◆ Open()

void Timeline::Open ( )
virtual

Open the reader (and start consuming resources)

Implements openshot::ReaderBase.

Definition at line 627 of file Timeline.cpp.

◆ RemoveClip()

void Timeline::RemoveClip ( Clip clip)

Remove an openshot::Clip from the timeline.

Parameters
clipRemove an openshot::Clip from the timeline.

Definition at line 102 of file Timeline.cpp.

◆ RemoveEffect()

void Timeline::RemoveEffect ( EffectBase effect)

Remove an effect from the timeline.

Parameters
effectRemove an effect from the timeline.

Definition at line 96 of file Timeline.cpp.

◆ SetCache()

void Timeline::SetCache ( CacheBase new_cache)

Get the cache object used by this reader.

Definition at line 871 of file Timeline.cpp.

◆ SetJson()

void Timeline::SetJson ( string  value)
virtual

Load JSON string into this object.

Implements openshot::ReaderBase.

Definition at line 923 of file Timeline.cpp.

◆ SetJsonValue()

void Timeline::SetJsonValue ( Json::Value  root)
virtual

Load Json::JsonValue into this object.

Implements openshot::ReaderBase.

Definition at line 949 of file Timeline.cpp.

Member Data Documentation

◆ color

Color openshot::Timeline::color

Background color of timeline canvas.

Definition at line 254 of file Timeline.h.

◆ viewport_scale

Keyframe openshot::Timeline::viewport_scale

Curve representing the scale of the viewport (0 to 100)

Definition at line 249 of file Timeline.h.

◆ viewport_x

Keyframe openshot::Timeline::viewport_x

Curve representing the x coordinate for the viewport.

Definition at line 250 of file Timeline.h.

◆ viewport_y

Keyframe openshot::Timeline::viewport_y

Curve representing the y coordinate for the viewport.

Definition at line 251 of file Timeline.h.


The documentation for this class was generated from the following files: