OpenShot Library | libopenshot  0.3.0
ChunkWriter.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CHUNK_WRITER_H
14 #define OPENSHOT_CHUNK_WRITER_H
15 
16 #include "ReaderBase.h"
17 #include "WriterBase.h"
18 #include "FFmpegWriter.h"
19 #include "CacheMemory.h"
20 #include "Json.h"
21 
22 #include <cmath>
23 #include <ctime>
24 #include <iostream>
25 #include <fstream>
26 #include <cstdio>
27 #include <sstream>
28 #include <unistd.h>
29 #include <omp.h>
30 #include <QtCore/QDir>
31 
32 
33 namespace openshot
34 {
62  class ChunkWriter : public WriterBase
63  {
64  private:
65  std::string path;
66  int64_t chunk_count;
67  int64_t chunk_size;
68  int64_t frame_count;
69  bool is_open;
70  bool is_writing;
71  openshot::ReaderBase *local_reader;
72  openshot::FFmpegWriter *writer_thumb;
73  openshot::FFmpegWriter *writer_preview;
74  openshot::FFmpegWriter *writer_final;
75  std::shared_ptr<Frame> last_frame;
76  bool last_frame_needed;
77  std::string default_extension;
78  std::string default_vcodec;
79  std::string default_acodec;
80 
82  void create_folder(std::string path);
83 
85  std::string get_chunk_path(int64_t chunk_number, std::string folder, std::string extension);
86 
88  bool is_chunk_valid();
89 
91  void write_json_meta_data();
92 
93  public:
94 
98  ChunkWriter(std::string path, openshot::ReaderBase *reader);
99 
101  void Close();
102 
104  int64_t GetChunkSize() { return chunk_size; };
105 
107  bool IsOpen() { return is_open; };
108 
110  void Open();
111 
114  void SetChunkSize(int64_t new_size) { chunk_size = new_size; };
115 
118  void WriteFrame(std::shared_ptr<openshot::Frame> frame);
119 
123  void WriteFrame(int64_t start, int64_t length);
124 
129  void WriteFrame(openshot::ReaderBase* reader, int64_t start, int64_t length);
130 
131  };
132 
133 }
134 
135 #endif
Header file for CacheMemory class.
Header file for FFmpegWriter class.
Header file for JSON class.
Header file for ReaderBase class.
Header file for WriterBase class.
This class takes any reader and generates a special type of video file, built with chunks of small vi...
Definition: ChunkWriter.h:63
void Close()
Close the writer.
bool IsOpen()
Determine if writer is open or closed.
Definition: ChunkWriter.h:107
void SetChunkSize(int64_t new_size)
Set the chunk size (number of frames to write in each chunk)
Definition: ChunkWriter.h:114
int64_t GetChunkSize()
Get the chunk size (number of frames to write in each chunk)
Definition: ChunkWriter.h:104
ChunkWriter(std::string path, openshot::ReaderBase *reader)
Constructor for ChunkWriter. Throws one of the following exceptions.
Definition: ChunkWriter.cpp:19
void Open()
Open writer.
void WriteFrame(std::shared_ptr< openshot::Frame > frame)
Add a frame to the stack waiting to be encoded.
Definition: ChunkWriter.cpp:64
This class uses the FFmpeg libraries, to write and encode video files and audio files.
Definition: FFmpegWriter.h:116
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:76
This abstract class is the base class, used by writers. Writers are types of classes that encode vide...
Definition: WriterBase.h:70
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:29