2013-09-08 23:09:54 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Header file for ChunkReader class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
|
|
|
|
* @section LICENSE
|
|
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* Copyright (c) 2008-2014 OpenShot Studios, LLC
|
|
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
|
|
|
|
* and/or modify it under the terms of the GNU Affero General Public License
|
|
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Also, if your software can interact with users remotely through a computer
|
|
|
|
|
* network, you should also make sure that it provides a way for users to
|
|
|
|
|
* get its source. For example, if your program is a web application, its
|
|
|
|
|
* interface could display a "Source" link that leads users to an archive
|
|
|
|
|
* of the code. There are many ways you could offer source, and different
|
|
|
|
|
* solutions will be better for different programs; see section 13 for the
|
|
|
|
|
* specific requirements.
|
|
|
|
|
*
|
|
|
|
|
* You should also get your employer (if you work as a programmer) or school,
|
|
|
|
|
* if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
|
|
|
* For more information on this, and how to apply and follow the GNU AGPL, see
|
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2013-09-08 23:09:54 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-07-31 12:45:47 -05:00
|
|
|
#ifndef OPENSHOT_CHUNK_READER_H
|
|
|
|
|
#define OPENSHOT_CHUNK_READER_H
|
|
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
#include "ReaderBase.h"
|
2013-08-28 15:28:19 -05:00
|
|
|
#include "FFmpegReader.h"
|
2013-07-31 12:45:47 -05:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <iostream>
|
2013-08-28 13:51:22 -05:00
|
|
|
#include <fstream>
|
2013-07-31 12:45:47 -05:00
|
|
|
#include <omp.h>
|
2013-11-25 00:48:49 -06:00
|
|
|
#include <QtCore/qdir.h>
|
2013-07-31 12:45:47 -05:00
|
|
|
#include <stdio.h>
|
2013-08-28 13:51:22 -05:00
|
|
|
#include <stdlib.h>
|
2013-07-31 12:45:47 -05:00
|
|
|
#include <tr1/memory>
|
2013-08-28 13:51:22 -05:00
|
|
|
#include "Json.h"
|
2013-07-31 12:45:47 -05:00
|
|
|
#include "Magick++.h"
|
|
|
|
|
#include "Cache.h"
|
|
|
|
|
#include "Exceptions.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
|
2013-09-08 23:09:54 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This struct holds the location of a frame within a chunk.
|
2013-09-08 23:09:54 -05:00
|
|
|
*
|
|
|
|
|
* Chunks are small video files, which typically contain a few seconds of video each.
|
|
|
|
|
* Locating a frame among these small video files is accomplished by using
|
|
|
|
|
* this struct.
|
|
|
|
|
*/
|
|
|
|
|
struct ChunkLocation
|
2013-08-28 15:28:19 -05:00
|
|
|
{
|
2013-09-08 23:09:54 -05:00
|
|
|
int number; ///< The chunk number
|
|
|
|
|
int frame; ///< The frame number
|
2013-08-28 15:28:19 -05:00
|
|
|
};
|
|
|
|
|
|
2013-09-08 23:09:54 -05:00
|
|
|
/**
|
2013-09-10 12:59:06 -05:00
|
|
|
* @brief This enumeration allows the user to choose which version
|
|
|
|
|
* of the chunk they would like (low, medium, or high quality).
|
2013-09-09 17:06:07 -05:00
|
|
|
*
|
|
|
|
|
* Since chunks contain multiple video streams, this version enumeration
|
|
|
|
|
* allows the user to choose which version of the chunk they would like.
|
|
|
|
|
* For example, if you want a small version with reduced quality, you can
|
|
|
|
|
* choose the THUMBNAIL version. This is used on the ChunkReader
|
|
|
|
|
* constructor.
|
2013-09-08 23:09:54 -05:00
|
|
|
*/
|
2013-08-28 15:28:19 -05:00
|
|
|
enum ChunkVersion
|
|
|
|
|
{
|
2013-09-10 22:11:47 -05:00
|
|
|
THUMBNAIL, ///< The lowest quality stream contained in this chunk file
|
|
|
|
|
PREVIEW, ///< The medium quality stream contained in this chunk file
|
|
|
|
|
FINAL ///< The highest quality stream contained in this chunk file
|
2013-08-28 15:28:19 -05:00
|
|
|
};
|
|
|
|
|
|
2013-07-31 12:45:47 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This class reads a special chunk-formatted file, which can be easily
|
2013-09-10 12:59:06 -05:00
|
|
|
* shared in a distributed environment.
|
|
|
|
|
*
|
|
|
|
|
* It stores the video in small "chunks", which are really just short video clips,
|
|
|
|
|
* a few seconds each. A ChunkReader only needs the part of the chunk that contains
|
|
|
|
|
* the frames it is looking for. For example, if you only need the end of a video,
|
|
|
|
|
* only the last few chunks might be needed to successfully access those openshot::Frame objects.
|
2013-09-09 17:06:07 -05:00
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* // This example demonstrates how to read a chunk folder and access frame objects inside it.
|
|
|
|
|
* ChunkReader r("/home/jonathan/apps/chunks/chunk1/", FINAL); // Load highest quality version of this chunk file
|
|
|
|
|
* r.DisplayInfo(); // Display all known details about this chunk file
|
|
|
|
|
* r.Open(); // Open the reader
|
|
|
|
|
*
|
|
|
|
|
* // Access frame 1
|
|
|
|
|
* r.GetFrame(1)->Display();
|
|
|
|
|
*
|
|
|
|
|
* // Close the reader
|
|
|
|
|
* r.Close();
|
|
|
|
|
* \endcode
|
2013-07-31 12:45:47 -05:00
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class ChunkReader : public ReaderBase
|
2013-07-31 12:45:47 -05:00
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
string path;
|
|
|
|
|
bool is_open;
|
2013-08-28 15:28:19 -05:00
|
|
|
int chunk_size;
|
|
|
|
|
FFmpegReader *local_reader;
|
2013-09-08 23:09:54 -05:00
|
|
|
ChunkLocation previous_location;
|
2013-08-28 15:28:19 -05:00
|
|
|
ChunkVersion version;
|
2013-09-08 16:08:56 -05:00
|
|
|
tr1::shared_ptr<Frame> last_frame;
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-08-28 13:51:22 -05:00
|
|
|
/// Check if folder path existing
|
|
|
|
|
bool does_folder_exist(string path);
|
|
|
|
|
|
2013-08-28 15:28:19 -05:00
|
|
|
/// Find the location of a frame in a chunk
|
2013-09-08 23:09:54 -05:00
|
|
|
ChunkLocation find_chunk_frame(int requested_frame);
|
2013-08-28 15:28:19 -05:00
|
|
|
|
|
|
|
|
/// get a formatted path of a specific chunk
|
|
|
|
|
string get_chunk_path(int chunk_number, string folder, string extension);
|
|
|
|
|
|
2013-08-28 13:51:22 -05:00
|
|
|
/// Load JSON meta data about this chunk folder
|
|
|
|
|
void load_json();
|
|
|
|
|
|
2013-07-31 12:45:47 -05:00
|
|
|
public:
|
|
|
|
|
|
2013-09-09 23:32:16 -05:00
|
|
|
/// @brief Constructor for ChunkReader. This automatically opens the chunk file or folder and loads
|
2013-07-31 12:45:47 -05:00
|
|
|
/// frame 1, or it throws one of the following exceptions.
|
2013-09-09 17:06:07 -05:00
|
|
|
/// @param path The folder path / location of a chunk (chunks are stored as folders)
|
|
|
|
|
/// @param chunk_version Choose the video version / quality (THUMBNAIL, PREVIEW, or FINAL)
|
2013-08-28 15:28:19 -05:00
|
|
|
ChunkReader(string path, ChunkVersion chunk_version) throw(InvalidFile, InvalidJSON);
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-09-09 17:06:07 -05:00
|
|
|
/// Close the reader
|
2013-07-31 12:45:47 -05:00
|
|
|
void Close();
|
|
|
|
|
|
2013-09-09 23:32:16 -05:00
|
|
|
/// @brief Get the chunk size (number of frames to write in each chunk)
|
2013-09-09 17:06:07 -05:00
|
|
|
/// @returns The number of frames in this chunk
|
2013-08-28 15:28:19 -05:00
|
|
|
int GetChunkSize() { return chunk_size; };
|
|
|
|
|
|
2013-09-09 23:32:16 -05:00
|
|
|
/// @brief Set the chunk size (number of frames to write in each chunk)
|
2013-09-09 17:06:07 -05:00
|
|
|
/// @param new_size The number of frames per chunk
|
|
|
|
|
void SetChunkSize(int new_size) { chunk_size = new_size; };
|
2013-08-28 15:28:19 -05:00
|
|
|
|
2013-09-09 23:32:16 -05:00
|
|
|
/// @brief Get an openshot::Frame object for a specific frame number of this reader.
|
2013-09-09 17:06:07 -05:00
|
|
|
/// @returns The requested frame (containing the image and audio)
|
|
|
|
|
/// @param requested_frame The frame number you want to retrieve
|
2013-08-28 15:28:19 -05:00
|
|
|
tr1::shared_ptr<Frame> GetFrame(int requested_frame) throw(ReaderClosed, ChunkNotFound);
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-12-18 21:55:43 -06:00
|
|
|
/// Determine if reader is open or closed
|
|
|
|
|
bool IsOpen() { return is_open; };
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
/// Get and Set JSON methods
|
|
|
|
|
string Json(); ///< Generate JSON string of this object
|
|
|
|
|
void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
|
|
|
|
|
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
|
|
|
|
void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
|
|
|
|
|
|
2013-09-09 17:06:07 -05:00
|
|
|
/// Open the reader. This is required before you can access frames or data from the reader.
|
2013-07-31 12:45:47 -05:00
|
|
|
void Open() throw(InvalidFile);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|