2013-07-31 12:45:47 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @file
|
|
|
|
|
* @brief Header file for ChunkWriter class
|
2013-09-12 17:52:10 -05:00
|
|
|
* @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-12 17:52:10 -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-12 17:52:10 -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-12 17:52:10 -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-07-31 12:45:47 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
#ifndef OPENSHOT_CHUNK_WRITER_H
|
|
|
|
|
#define OPENSHOT_CHUNK_WRITER_H
|
|
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
#include "ReaderBase.h"
|
|
|
|
|
#include "WriterBase.h"
|
2013-08-27 16:57:49 -05:00
|
|
|
#include "FFmpegWriter.h"
|
2013-07-31 12:45:47 -05:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <iostream>
|
2013-08-27 14:27:24 -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>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include "Magick++.h"
|
|
|
|
|
#include "Cache.h"
|
|
|
|
|
#include "Exceptions.h"
|
2013-08-27 13:37:00 -05:00
|
|
|
#include "Json.h"
|
2013-07-31 12:45:47 -05:00
|
|
|
#include "Sleep.h"
|
|
|
|
|
|
|
|
|
|
|
2013-08-27 13:37:00 -05:00
|
|
|
|
2013-07-31 12:45:47 -05:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This class takes any reader and generates a special type of video file, built with
|
2013-09-10 22:11:47 -05:00
|
|
|
* chunks of small video and audio data.
|
|
|
|
|
*
|
|
|
|
|
* These chunks can easily be passed around in a distributed
|
|
|
|
|
* computing environment, without needing to share the entire video file. They also allow a
|
|
|
|
|
* chunk to be frame accurate, since seeking inaccuracies are removed.
|
2013-09-09 17:06:07 -05:00
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* // This example demonstrates how to feed a reader into a ChunkWriter
|
|
|
|
|
* FFmpegReader *r = new FFmpegReader("MyAwesomeVideo.mp4"); // Get a reader
|
|
|
|
|
*
|
|
|
|
|
* // Create a ChunkWriter (and a folder location on your computer)
|
|
|
|
|
* ChunkWriter w("/folder_path_to_hold_chunks/", r);
|
|
|
|
|
*
|
|
|
|
|
* // Write a block of frames to the ChunkWriter (from frame 1 to the end)
|
|
|
|
|
* w.WriteFrame(r, 1, r->info.video_length);
|
|
|
|
|
*
|
|
|
|
|
* // Close the ChunkWriter
|
|
|
|
|
* w.Close();
|
|
|
|
|
* \endcode
|
2013-07-31 12:45:47 -05:00
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class ChunkWriter : public WriterBase
|
2013-07-31 12:45:47 -05:00
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
string path;
|
2013-08-27 16:57:49 -05:00
|
|
|
int chunk_count;
|
|
|
|
|
int chunk_size;
|
|
|
|
|
int frame_count;
|
2013-07-31 12:45:47 -05:00
|
|
|
bool is_writing;
|
2013-09-08 16:40:57 -05:00
|
|
|
ReaderBase *local_reader;
|
2013-08-27 16:57:49 -05:00
|
|
|
FFmpegWriter *writer_thumb;
|
|
|
|
|
FFmpegWriter *writer_preview;
|
|
|
|
|
FFmpegWriter *writer_final;
|
2013-07-31 12:45:47 -05:00
|
|
|
tr1::shared_ptr<Frame> last_frame;
|
2013-09-15 22:21:19 -05:00
|
|
|
bool last_frame_needed;
|
2013-08-28 17:00:57 -05:00
|
|
|
string default_extension;
|
|
|
|
|
string default_vcodec;
|
|
|
|
|
string default_acodec;
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-08-01 13:45:09 -05:00
|
|
|
/// check for chunk folder
|
2014-06-30 15:37:50 -05:00
|
|
|
void create_folder(string path);
|
2013-08-01 13:45:09 -05:00
|
|
|
|
2013-08-27 16:57:49 -05:00
|
|
|
/// get a formatted path of a specific chunk
|
|
|
|
|
string get_chunk_path(int chunk_number, string folder, string extension);
|
|
|
|
|
|
2013-08-01 13:45:09 -05:00
|
|
|
/// check for valid chunk json
|
|
|
|
|
bool is_chunk_valid();
|
|
|
|
|
|
2013-08-27 13:37:00 -05:00
|
|
|
/// write json meta data
|
|
|
|
|
void write_json_meta_data();
|
|
|
|
|
|
2013-07-31 12:45:47 -05:00
|
|
|
public:
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @brief Constructor for ChunkWriter. Throws one of the following exceptions.
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param path The folder path of the chunk file to be created
|
|
|
|
|
/// @param reader The initial reader to base this chunk file's meta data on (such as fps, height, width, etc...)
|
2013-09-08 16:40:57 -05:00
|
|
|
ChunkWriter(string path, ReaderBase *reader) throw(InvalidFile, InvalidFormat, InvalidCodec, InvalidOptions, OutOfMemory);
|
2013-07-31 12:45:47 -05:00
|
|
|
|
|
|
|
|
/// Close the writer
|
|
|
|
|
void Close();
|
|
|
|
|
|
2013-08-27 16:57:49 -05:00
|
|
|
/// Get the chunk size (number of frames to write in each chunk)
|
|
|
|
|
int GetChunkSize() { return chunk_size; };
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @brief Set the chunk size (number of frames to write in each chunk)
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param new_size The number of frames to write in this chunk file
|
2014-06-30 15:37:50 -05:00
|
|
|
void SetChunkSize(int new_size) { chunk_size = new_size; };
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @brief Add a frame to the stack waiting to be encoded.
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param frame The openshot::Frame object that needs to be written to this chunk file.
|
2013-07-31 12:45:47 -05:00
|
|
|
void WriteFrame(tr1::shared_ptr<Frame> frame);
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @brief Write a block of frames from a reader
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param start The starting frame number to write (of the reader passed into the constructor)
|
|
|
|
|
/// @param length The number of frames to write (of the reader passed into the constructor)
|
2013-08-01 13:45:09 -05:00
|
|
|
void WriteFrame(int start, int length);
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @brief Write a block of frames from a reader
|
2013-09-10 22:11:47 -05:00
|
|
|
/// @param reader The reader containing the frames you need
|
|
|
|
|
/// @param start The starting frame number to write
|
|
|
|
|
/// @param length The number of frames to write
|
2013-09-08 16:40:57 -05:00
|
|
|
void WriteFrame(ReaderBase* reader, int start, int length);
|
2013-07-31 12:45:47 -05:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|