| 
    OpenShot Library | libopenshot
    0.4.0
    
   | 
 
 
 
 
Go to the documentation of this file.
   24         : 
path(
path), chunk_size(24 * 3), is_open(false), version(chunk_version), local_reader(NULL)
 
   27     if (!does_folder_exist(
path))
 
   32     previous_location.
number = 0;
 
   33     previous_location.
frame = 0;
 
   41 bool ChunkReader::does_folder_exist(std::string 
path)
 
   43     QDir dir(
path.c_str());
 
   48 void ChunkReader::load_json()
 
   51     std::string json_path = QDir::cleanPath(QString(
path.c_str()) + QDir::separator() + 
"info.json").toStdString();
 
   52     std::stringstream json_string;
 
   55     std::ifstream myfile (json_path.c_str());
 
   56     std::string line = 
"";
 
   61             getline (myfile, line);
 
   69     Json::CharReaderBuilder rbuilder;
 
   72     bool success = Json::parseFromStream(rbuilder, json_string, &root, &errors);
 
   75         throw InvalidJSON(
"Chunk folder could not be opened.", path);
 
  111     catch (
const std::exception& e)
 
  114         throw InvalidJSON(
"JSON could not be parsed (or is invalid).", path);
 
  119 ChunkLocation ChunkReader::find_chunk_frame(int64_t requested_frame)
 
  122     int64_t chunk_number = (requested_frame / chunk_size) + 1;
 
  125     int64_t start_frame_of_chunk = (chunk_number - 1) * chunk_size;
 
  126     int64_t chunk_frame_number = (requested_frame - start_frame_of_chunk) + 1; 
 
  160 std::string ChunkReader::get_chunk_path(int64_t chunk_number, std::string folder, std::string extension)
 
  163     std::stringstream chunk_count_string;
 
  164     chunk_count_string << chunk_number;
 
  165     QString padded_count = 
"%1"; 
 
  166     padded_count = padded_count.arg(chunk_count_string.str().c_str(), 6, 
'0');
 
  167     if (folder.length() != 0 && extension.length() != 0)
 
  169         return QDir::cleanPath(QString(
path.c_str()) + QDir::separator() + folder.c_str() + QDir::separator() + padded_count + extension.c_str()).toStdString();
 
  171     else if (folder.length() == 0 && extension.length() != 0)
 
  173         return QDir::cleanPath(QString(
path.c_str()) + QDir::separator() + padded_count + extension.c_str()).toStdString();
 
  175     else if (folder.length() != 0 && extension.length() == 0)
 
  177         return QDir::cleanPath(QString(
path.c_str()) + QDir::separator() + folder.c_str()).toStdString();
 
  192         std::string folder_name = 
"";
 
  196             folder_name = 
"thumb";
 
  199             folder_name = 
"preview";
 
  202             folder_name = 
"final";
 
  207         std::string chunk_video_path = get_chunk_path(location.
number, folder_name, 
".webm");
 
  213             local_reader->
Close();
 
  221             local_reader->
Open(); 
 
  230         previous_location = location;
 
  237     last_frame->number = requested_frame;
 
  255     root[
"type"] = 
"ChunkReader";
 
  257     std::stringstream chunk_size_stream;
 
  258     chunk_size_stream << chunk_size;
 
  259     root[
"chunk_size"] = chunk_size_stream.str();
 
  260     root[
"chunk_version"] = version;
 
  275     catch (
const std::exception& e)
 
  278         throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
 
  289     if (!root[
"path"].isNull())
 
  290         path = root[
"path"].asString();
 
  291     if (!root[
"chunk_size"].isNull())
 
  292         chunk_size = std::stoll(root[
"chunk_size"].asString());
 
  293     if (!root[
"chunk_version"].isNull())
 
  
const Json::Value stringToJson(const std::string value)
 
void SetJson(const std::string value) override
Load JSON string into this object.
 
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
 
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Get an openshot::Frame object for a specific frame number of this reader.
 
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
 
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
 
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.
 
openshot::ReaderInfo info
Information about the current media file.
 
int audio_bit_rate
The bit rate of the audio stream (in bytes)
 
float duration
Length of time (in seconds)
 
This struct holds the location of a frame within a chunk.
 
bool has_video
Determines if this file has a video stream.
 
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
 
int width
The width of the video (in pixesl)
 
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.
 
Exception when a required chunk is missing.
 
int den
Denominator for the fraction.
 
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
 
bool has_audio
Determines if this file has an audio stream.
 
Exception for invalid JSON.
 
int64_t file_size
Size of file (in bytes)
 
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
 
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
 
Header file for ChunkReader class.
 
Exception for files that can not be found or opened.
 
int audio_stream_index
The index of the audio stream.
 
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
 
int64_t number
The chunk number.
 
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
 
std::string vcodec
The name of the video codec used to encode / decode the video stream.
 
std::string Json() const override
Generate JSON string of this object.
 
void Close() override
Close the reader.
 
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
 
int video_bit_rate
The bit rate of the video stream (in bytes)
 
virtual void Close()=0
Close the reader (and any resources it was consuming)
 
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
 
int64_t frame
The frame number.
 
int video_stream_index
The index of the video stream.
 
void Open() override
Open the reader. This is required before you can access frames or data from the reader.
 
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)
 
ChunkVersion
This enumeration allows the user to choose which version of the chunk they would like (low,...
 
int channels
The number of audio channels used in the audio stream.
 
@ THUMBNAIL
The lowest quality stream contained in this chunk file.
 
ChunkReader(std::string path, ChunkVersion chunk_version)
Constructor for ChunkReader. This automatically opens the chunk file or folder and loads frame 1,...
 
Header file for all Exception classes.
 
Json::Value JsonValue() const override
Generate Json::Value for this object.
 
Header file for FFmpegReader class.
 
@ FINAL
The highest quality stream contained in this chunk file.
 
@ PREVIEW
The medium quality stream contained in this chunk file.