AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Transcoder.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_TRANSCODER_HPP_
2 #define _AV_TRANSCODER_TRANSCODER_HPP_
3 
10 
11 #include "StreamTranscoder.hpp"
12 
13 #include <string>
14 #include <vector>
15 
16 namespace avtranscoder
17 {
18 
19 /**
20  * @brief Enum to set a policy of how we manage the process in case of several streams.
21  * eProcessMethodShortest: stop the process at the end of the shortest stream.
22  * eProcessMethodLongest: stop the process at the end of the longest stream.
23  * eProcessMethodBasedOnStream: stop the process at the end of an indicated stream (@see _indexBasedStream attribute of
24  * Transcoder).
25  * eProcessMethodBasedOnDuration: stop the process at the end of an indicated duration, in seconds (@see _outputDuration
26  * attribute of Transcoder).
27  * eProcessMethodInfinity: stop the process by outside of avTranscoder (streaming mode)
28  */
30 {
36 };
37 
38 /**
39  * @brief A Transcoder manages a list of streams,
40  * and process a transcode to create an output media file.
41  */
42 class AvExport Transcoder
43 {
44 private:
45  Transcoder(const Transcoder& transcoder);
46  Transcoder& operator=(const Transcoder& transcoder);
47 
48 public:
49  /**
50  * @note Set FFmpeg log level to quite.
51  */
52  Transcoder(IOutputFile& outputFile);
53 
54  ~Transcoder();
55 
56  /**
57  * @brief Add all streams of the file with the given filename.
58  * All the streams will be rewrapped.
59  * @note Currently we rewrap only the video and the audio streams. The streams with an other type are skipped.
60  */
61  void add(const std::string& filename);
62 
63  /**
64  * @brief Add a stream and set a profile
65  * @note If profileName is empty, rewrap.
66  * @note offset in seconds
67  * If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before
68  * the stream to process.
69  * If offset is negative, the transcoder will seek in the stream and start process at this specific time.
70  */
71  void add(const std::string& filename, const size_t streamIndex, const std::string& profileName = "",
72  const float offset = 0);
73  /*
74  * @note If filename is empty, add a generated stream.
75  * @note If filename is empty, profileName can't be empty (no sens to rewrap a generated stream).
76  */
77  void add(const std::string& filename, const size_t streamIndex, const std::string& profileName, ICodec& codec,
78  const float offset = 0);
79 
80  /**
81  * @brief Add a stream and set a custom profile
82  * @note Profile will be updated, be sure to pass unique profile name.
83  */
84  void add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile,
85  const float offset = 0);
86  /*
87  * @note If filename is empty, add a generated stream.
88  */
89  void add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, ICodec& codec,
90  const float offset = 0);
91 
92  /**
93  * @brief Add a stream and set a profile
94  * @note If profileName is empty, rewrap.
95  * @note If subStreamIndex is negative, no substream is selected it's the stream.
96  */
97  void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex,
98  const std::string& profileName = "", const float offset = 0);
99  /**
100  * @note If filename is empty, add a generated stream.
101  * @note If filename is empty, profileName can't be empty (no sens to rewrap a generated stream).
102  */
103  void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName,
104  ICodec& codec, const float offset = 0);
105 
106  /**
107  * @brief Add a stream and set a custom profile
108  * @note Profile will be updated, be sure to pass unique profile name.
109  * @note If subStreamIndex is negative, no substream is selected it's the stream.
110  */
111  void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex,
112  const ProfileLoader::Profile& profile, const float offset = 0);
113  /**
114  * @note If filename is empty, add a generated stream.
115  */
116  void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex,
117  const ProfileLoader::Profile& profile, ICodec& codec, const float offset = 0);
118 
119  /**
120  * @brief Add the stream
121  */
122  void add(StreamTranscoder& streamTranscoder);
123 
124  /**
125  * @brief Initialize all added streams, processing codec latency.
126  * @note This can be called several times with no side effects.
127  * @note Can take a little bit of time.
128  */
129  void preProcessCodecLatency();
130 
131  /**
132  * @brief Process the next frame of all streams.
133  * @return if a frame was processed or not.
134  */
135  bool processFrame();
136 
137  /**
138  * @brief Process all the streams, and ended the process depending on the transcode politic.
139  * @note The function manages all process: init(), beginWrap(), processFrame()s, and endWrap().
140  * @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class.
141  * @return ProcessStat: object with statistics of the process for each stream.
142  * @see IProgress
143  */
144  ProcessStat process(IProgress& progress);
145  ProcessStat process(); ///< Call process with no display of progression
146 
147  /**
148  * @brief Return the list of streams added to the transcoder.
149  */
150  std::vector<StreamTranscoder*>& getStreamTranscoders() { return _streamTranscoders; }
151 
152  /**
153  * @param streamIndex: careful about the order of stream insertion of the Transcoder.
154  * @return a reference to a stream manage by the Transcoder.
155  */
156  StreamTranscoder& getStreamTranscoder(size_t streamIndex) const { return *_streamTranscoders.at(streamIndex); }
157 
158  /**
159  * @brief Get current processMethod
160  * @see EProcessMethod
161  */
162  EProcessMethod getProcessMethod() const { return _eProcessMethod; }
163 
164  /**
165  * @brief Set the transcoding policy.
166  * @note By default eProcessMethodBasedOnStream at index 0.
167  * @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the
168  * indicated stream.
169  * @param outputDuration: in case of process method eProcessMethodBasedOnDuration, stop transcode at the end of the
170  * indicated duration.
171  */
172  void setProcessMethod(const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0,
173  const double outputDuration = 0);
174 
175 private:
176  void addRewrapStream(const std::string& filename, const size_t streamIndex, const float offset);
177 
178  void addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex,
179  const float offset);
180  void addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex,
181  const ProfileLoader::Profile& profile, const float offset = 0);
182 
183  void addDummyStream(const ProfileLoader::Profile& profile, const ICodec& codec);
184 
185  /**
186  * @note If streamIndex is negative, activate all streams of the file.
187  */
188  InputFile* addInputFile(const std::string& filename, const int streamIndex, const float offset);
189 
190  ProfileLoader::Profile getProfileFromFile(InputFile& inputFile,
191  const size_t streamIndex); ///< The function analyses the inputFile
192 
193  /**
194  * @brief Get the duration of the stream, in seconds
195  * @note If the stream is a generator, return limit of double.
196  */
197  float getStreamDuration(size_t indexStream) const;
198 
199  /**
200  * @brief Get the duration of the shortest stream, in seconds
201  */
202  float getMinTotalDuration() const;
203 
204  /**
205  * @brief Get the duration of the longest stream, in seconds
206  */
207  float getMaxTotalDuration() const;
208 
209  /**
210  * @brief Get the expected duration of the output program
211  * @note Depends on the streams, the process method, and the main stream index.
212  */
213  float getExpectedOutputDuration() const;
214 
215  /**
216  * @brief Get the current duration of the output program
217  * @note Returns the duration of the smallest stream.
218  * @return -1 if there is no output stream.
219  */
220  float getCurrentOutputDuration() const;
221 
222  /**
223  * @brief Set for each StreamTranscoder if it can switch to generator at the end.
224  */
225  void manageSwitchToGenerator();
226 
227  /**
228  * @brief Fill the given ProcessStat to summarize the process.
229  */
230  void fillProcessStat(ProcessStat& processStat);
231 
232 private:
233  IOutputFile& _outputFile; ///< The output media file after process (has link)
234  std::vector<InputFile*> _inputFiles; ///< The list of input files which contain added streams (has ownership)
235 
236  std::vector<StreamTranscoder*> _streamTranscoders; ///< All streams of the output media file after process.
237  std::vector<StreamTranscoder*> _streamTranscodersAllocated; ///< Streams allocated inside the Transcoder (has ownership)
238 
239  ProfileLoader _profileLoader; ///< Objet to get existing profiles, and add new ones for the Transcoder.
240 
241  EProcessMethod _eProcessMethod; ///< Processing policy
242  size_t
243  _mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
244  float _outputDuration; ///< Duration of output media used to stop the process of transcode in case of
245  /// eProcessMethodBasedOnDuration.
246 };
247 }
248 
249 #endif
Base class of Progress. Inherit this class to have your own way to manage a progress bar...
Definition: IProgress.hpp:23
ProcessStat contains statistics given after the process.
Definition: ProcessStat.hpp:17
std::vector< InputFile * > _inputFiles
The list of input files which contain added streams (has ownership)
Definition: Transcoder.hpp:234
std::vector< StreamTranscoder * > _streamTranscodersAllocated
Streams allocated inside the Transcoder (has ownership)
Definition: Transcoder.hpp:237
IOutputfile is the interface to wrap and write medias. It can be overloaded to integrate custom wrapp...
Definition: IOutputFile.hpp:22
A Transcoder manages a list of streams, and process a transcode to create an output media file...
Definition: Transcoder.hpp:42
void add(PropertyVector &propertyVector, const std::string &key, const size_t &value)
Definition: util.cpp:16
std::map< std::string, std::string > Profile
std::vector< StreamTranscoder * > & getStreamTranscoders()
Return the list of streams added to the transcoder.
Definition: Transcoder.hpp:150
EProcessMethod
Enum to set a policy of how we manage the process in case of several streams. eProcessMethodShortest:...
Definition: Transcoder.hpp:29
EProcessMethod getProcessMethod() const
Get current processMethod.
Definition: Transcoder.hpp:162
EProcessMethod _eProcessMethod
Processing policy.
Definition: Transcoder.hpp:241
std::vector< StreamTranscoder * > _streamTranscoders
All streams of the output media file after process.
Definition: Transcoder.hpp:236
ProfileLoader _profileLoader
Objet to get existing profiles, and add new ones for the Transcoder.
Definition: Transcoder.hpp:239
StreamTranscoder & getStreamTranscoder(size_t streamIndex) const
Definition: Transcoder.hpp:156
size_t _mainStreamIndex
Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
Definition: Transcoder.hpp:243
IOutputFile & _outputFile
The output media file after process (has link)
Definition: Transcoder.hpp:233
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy