2012-10-03 01:55:24 -05:00
|
|
|
#include "../include/Clip.h"
|
|
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Init default settings for a clip
|
|
|
|
|
void Clip::init_settings()
|
2012-10-03 01:55:24 -05:00
|
|
|
{
|
|
|
|
|
// Init clip settings
|
2012-10-04 15:07:29 -05:00
|
|
|
Position(0.0);
|
|
|
|
|
Layer(0);
|
|
|
|
|
Start(0.0);
|
|
|
|
|
End(0.0);
|
2012-10-04 16:07:58 -05:00
|
|
|
gravity = GRAVITY_CENTER;
|
|
|
|
|
scale = SCALE_FIT;
|
|
|
|
|
anchor = ANCHOR_CANVAS;
|
2012-10-03 01:55:24 -05:00
|
|
|
|
|
|
|
|
// Init scale curves
|
|
|
|
|
scale_x = Keyframe(100.0);
|
|
|
|
|
scale_y = Keyframe(100.0);
|
|
|
|
|
|
|
|
|
|
// Init location curves
|
|
|
|
|
location_x = Keyframe(0.0);
|
|
|
|
|
location_y = Keyframe(0.0);
|
|
|
|
|
|
|
|
|
|
// Init alpha & rotation
|
|
|
|
|
alpha = Keyframe(100.0);
|
|
|
|
|
rotation = Keyframe(0.0);
|
|
|
|
|
|
|
|
|
|
// Init time & volume
|
|
|
|
|
time = Keyframe(0.0);
|
|
|
|
|
volume = Keyframe(100.0);
|
|
|
|
|
|
2012-10-04 01:34:45 -05:00
|
|
|
// Init crop settings
|
2012-10-04 16:07:58 -05:00
|
|
|
crop_gravity = GRAVITY_CENTER;
|
2012-10-04 01:34:45 -05:00
|
|
|
crop_width = Keyframe(-1.0);
|
|
|
|
|
crop_height = Keyframe(-1.0);
|
|
|
|
|
crop_x = Keyframe(0.0);
|
|
|
|
|
crop_y = Keyframe(0.0);
|
|
|
|
|
|
|
|
|
|
// Init shear and perspective curves
|
|
|
|
|
shear_x = Keyframe(0.0);
|
|
|
|
|
shear_y = Keyframe(0.0);
|
|
|
|
|
perspective_c1_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c1_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c2_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c2_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c3_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c3_y = Keyframe(-1.0);
|
|
|
|
|
perspective_c4_x = Keyframe(-1.0);
|
|
|
|
|
perspective_c4_y = Keyframe(-1.0);
|
2012-10-04 16:07:58 -05:00
|
|
|
|
|
|
|
|
// Default pointers
|
|
|
|
|
frame_map = NULL;
|
|
|
|
|
file_reader = NULL;
|
2012-10-04 01:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Default Constructor for a clip
|
|
|
|
|
Clip::Clip()
|
|
|
|
|
{
|
|
|
|
|
// Init all default settings
|
|
|
|
|
init_settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Constructor with filepath
|
|
|
|
|
Clip::Clip(string path)
|
|
|
|
|
{
|
|
|
|
|
// Init all default settings
|
|
|
|
|
init_settings();
|
|
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// Get file extension (and convert to lower case)
|
|
|
|
|
string ext = get_file_extension(path);
|
|
|
|
|
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
2012-10-04 01:34:45 -05:00
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// Determine if common video formats
|
|
|
|
|
if (ext=="avi" || ext=="mov" || ext=="mpg" || ext=="mpeg" || ext=="mp3" || ext=="mp4" || ext=="mts" || ext=="ogg" || ext=="wmv" || ext=="webm" || ext=="vob")
|
|
|
|
|
{
|
2012-10-04 01:34:45 -05:00
|
|
|
try
|
|
|
|
|
{
|
2012-10-04 18:02:46 -05:00
|
|
|
// Open common video format
|
2012-10-04 01:34:45 -05:00
|
|
|
file_reader = new FFmpegReader(path);
|
|
|
|
|
cout << "READER FOUND: FFmpegReader" << endl;
|
2012-10-04 18:02:46 -05:00
|
|
|
} catch(...) { }
|
|
|
|
|
}
|
2012-10-04 01:34:45 -05:00
|
|
|
|
2012-10-04 18:02:46 -05:00
|
|
|
// If no video found, try each reader
|
|
|
|
|
if (!file_reader)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try an image reader
|
|
|
|
|
file_reader = new ImageReader(path);
|
|
|
|
|
cout << "READER FOUND: ImageReader" << endl;
|
|
|
|
|
|
|
|
|
|
} catch(...) {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try a video reader
|
|
|
|
|
file_reader = new FFmpegReader(path);
|
|
|
|
|
cout << "READER FOUND: FFmpegReader" << endl;
|
|
|
|
|
|
|
|
|
|
} catch(BaseException ex) {
|
|
|
|
|
// No Reader Found, Throw an exception
|
|
|
|
|
cout << "READER NOT FOUND" << endl;
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
2012-10-04 01:34:45 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 16:07:58 -05:00
|
|
|
// Set some clip properties from the file reader
|
|
|
|
|
End(file_reader->info.duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Map frame rate of this clip to a different frame rate
|
|
|
|
|
void Clip::MapFrames(Framerate fps, Pulldown_Method pulldown)
|
|
|
|
|
{
|
|
|
|
|
// Check for a valid file reader (required to re-map it's frame rate)
|
|
|
|
|
if (file_reader)
|
|
|
|
|
{
|
|
|
|
|
// Get original framerate
|
|
|
|
|
Framerate original_fps(file_reader->info.fps.num, file_reader->info.fps.den);
|
|
|
|
|
|
|
|
|
|
// Create and Set FrameMapper object
|
|
|
|
|
frame_map = new FrameMapper(file_reader->info.video_length, original_fps, fps, pulldown);
|
|
|
|
|
}
|
2012-10-03 01:55:24 -05:00
|
|
|
}
|
2012-10-04 18:02:46 -05:00
|
|
|
|
|
|
|
|
// Get file extension
|
|
|
|
|
string Clip::get_file_extension(string path)
|
|
|
|
|
{
|
|
|
|
|
// return last part of path
|
|
|
|
|
return path.substr(path.find_last_of(".") + 1);
|
|
|
|
|
}
|