40 : path(path), chunk_size(24 * 3), is_open(false), version(chunk_version), local_reader(NULL)
43 if (!does_folder_exist(path))
45 throw InvalidFile(
"Chunk folder could not be opened.", path);
48 previous_location.
number = 0;
49 previous_location.
frame = 0;
57 bool ChunkReader::does_folder_exist(std::string path)
59 QDir dir(path.c_str());
64 void ChunkReader::load_json()
67 std::string json_path = QDir::cleanPath(QString(path.c_str()) + QDir::separator() +
"info.json").toStdString();
68 std::stringstream json_string;
71 std::ifstream myfile (json_path.c_str());
72 std::string line =
"";
77 getline (myfile, line);
85 Json::CharReaderBuilder rbuilder;
88 bool success = Json::parseFromStream(rbuilder, json_string, &root, &errors);
91 throw InvalidJSON(
"Chunk folder could not be opened.", path);
127 catch (
const std::exception& e)
130 throw InvalidJSON(
"JSON could not be parsed (or is invalid).", path);
135 ChunkLocation ChunkReader::find_chunk_frame(int64_t requested_frame)
138 int64_t chunk_number = (requested_frame / chunk_size) + 1;
141 int64_t start_frame_of_chunk = (chunk_number - 1) * chunk_size;
142 int64_t chunk_frame_number = (requested_frame - start_frame_of_chunk) + 1;
176 std::string ChunkReader::get_chunk_path(int64_t chunk_number, std::string folder, std::string extension)
179 std::stringstream chunk_count_string;
180 chunk_count_string << chunk_number;
181 QString padded_count =
"%1";
182 padded_count = padded_count.arg(chunk_count_string.str().c_str(), 6,
'0');
183 if (folder.length() != 0 && extension.length() != 0)
185 return QDir::cleanPath(QString(path.c_str()) + QDir::separator() + folder.c_str() + QDir::separator() + padded_count + extension.c_str()).toStdString();
187 else if (folder.length() == 0 && extension.length() != 0)
189 return QDir::cleanPath(QString(path.c_str()) + QDir::separator() + padded_count + extension.c_str()).toStdString();
191 else if (folder.length() != 0 && extension.length() == 0)
193 return QDir::cleanPath(QString(path.c_str()) + QDir::separator() + folder.c_str()).toStdString();
208 std::string folder_name =
"";
212 folder_name =
"thumb";
215 folder_name =
"preview";
218 folder_name =
"final";
223 std::string chunk_video_path = get_chunk_path(location.
number, folder_name,
".webm");
229 local_reader->
Close();
237 local_reader->
Open();
246 previous_location = location;
253 last_frame->number = requested_frame;
271 root[
"type"] =
"ChunkReader";
273 std::stringstream chunk_size_stream;
274 chunk_size_stream << chunk_size;
275 root[
"chunk_size"] = chunk_size_stream.str();
276 root[
"chunk_version"] = version;
291 catch (
const std::exception& e)
294 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
305 if (!root[
"path"].isNull())
306 path = root[
"path"].asString();
307 if (!root[
"chunk_size"].isNull())
308 chunk_size = std::stoll(root[
"chunk_size"].asString());
309 if (!root[
"chunk_version"].isNull())
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Get an openshot::Frame object for a specific frame number of this reader.
std::string Json() const override
Generate JSON string of this object.
int num
Numerator for the fraction.
Exception when a required chunk is missing.
int width
The width of the video (in pixesl)
ChunkReader(std::string path, ChunkVersion chunk_version)
Constructor for ChunkReader. This automatically opens the chunk file or folder and loads frame 1...
float duration
Length of time (in seconds)
The lowest quality stream contained in this chunk file.
Header file for FFmpegReader class.
void SetJson(const std::string value) override
Load JSON string into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
virtual void Close()=0
Close the reader (and any resources it was consuming)
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this file has a video stream.
int64_t file_size
Size of file (in bytes)
void Close() override
Close the reader.
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Header file for all Exception classes.
bool has_audio
Determines if this file has an audio stream.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
The highest quality stream contained in this chunk file.
int audio_stream_index
The index of the audio stream.
The medium quality stream contained in this chunk file.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
Header file for ChunkReader class.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Exception for files that can not be found or opened.
void Open() override
Open the reader. This is required before you can access frames or data from the reader.
int64_t number
The chunk number.
ChunkVersion
This enumeration allows the user to choose which version of the chunk they would like (low...
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
openshot::ReaderInfo info
Information about the current media file.
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
int video_bit_rate
The bit rate of the video stream (in bytes)
int64_t frame
The frame number.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
int den
Denominator for the fraction.
int channels
The number of audio channels used in the audio stream.
This struct holds the location of a frame within a chunk.
int video_stream_index
The index of the video stream.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
std::string acodec
The name of the audio codec used to encode / decode the video stream.
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
int sample_rate
The number of audio samples per second (44100 is a common sample rate)