AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputFile.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_FILE_INPUT_FILE_HPP_
2 #define _AV_TRANSCODER_FILE_INPUT_FILE_HPP_
3 
11 
12 #include <string>
13 #include <vector>
14 
15 namespace avtranscoder
16 {
17 
18 class AvExport InputFile
19 {
20 private:
21  InputFile(const InputFile& inputFile);
22  InputFile& operator=(const InputFile& inputFile);
23 
24 public:
25  /**
26  * @brief Open a media file
27  * @note The constructor also analyses header of input file
28  * @param filename resource to access
29  * @exception ios_base::failure launched if unable to open file
30  **/
31  InputFile(const std::string& filename);
32 
33  virtual ~InputFile();
34 
35  /**
36  * @brief Run the analyse on the file after a setup.
37  * call this function before getProperties().
38  * @param progress callback to get analysis progression
39  * @param level by default eAnalyseLevelFirstGop
40  **/
41  void analyse(IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFirstGop);
42 
43  /**
44  * @brief Read the next packet of the specified stream
45  * @param data: data of next packet read
46  * @return if next packet was read succefully
47  **/
48  bool readNextPacket(CodedData& data, const size_t streamIndex);
49 
50  /**
51  * @brief Seek at a specific frame / time (in seconds)
52  * @note Seek in file by using the default stream (according to ffmpeg)
53  * @param flag: ffmpeg seek flag (by default seek to any frame, even non-keyframes)
54  * @warning If the seek is done to a non key-frame, the decoding will start from the next key-frame
55  * @return seek status
56  **/
57  bool seekAtFrame(const size_t frame, const int flag = AVSEEK_FLAG_ANY);
58  bool seekAtTime(const double time, const int flag = AVSEEK_FLAG_ANY);
59 
60  /**
61  * @brief Activate the indicated stream
62  * @note Activate a stream results in buffered its data when processing
63  **/
64  void activateStream(const size_t streamIndex, const bool activate = true);
65 
66  /**
67  * @brief Return media properties on the current InputFile.
68  * @note require to launch analyse() before to fill the property struture
69  * @return structure of media metadatas
70  **/
71  const FileProperties& getProperties() const { return *_properties; }
72 
73  /**
74  * @brief Get stream type: video, audio, subtitle, etc.
75  * @param index stream index
76  * @return media stream type of specified index stream
77  **/
78  InputStream& getStream(size_t index);
79 
80  std::string getFilename() const { return _filename; }
81 
82  FormatContext& getFormatContext() { return _formatContext; }
83 
84  /**
85  * @brief Set the format of the input file
86  * @param profile: the profile of the input format
87  */
88  virtual void setupUnwrapping(const ProfileLoader::Profile& profile);
89 
90 public:
91  /**
92  * @brief Get media file properties using static method.
93  * @param filename input filename
94  * @param progress callback to get analysis progression
95  * @return structure of media metadatas
96  **/
97  static FileProperties analyseFile(const std::string& filename, IProgress& progress,
98  const EAnalyseLevel level = eAnalyseLevelFirstGop);
99 
100 private:
101  /**
102  * @brief Get Fps from first video stream
103  * @note if there is no video stream, return 1.
104  */
105  double getFps();
106 
107 protected:
110  std::string _filename;
111  std::vector<InputStream*> _inputStreams; ///< Has ownership
112 };
113 
114 #ifndef SWIG
115 AvExport std::ostream& operator<<(std::ostream& flux, const InputFile& input);
116 #endif
117 }
118 
119 #endif
Base class of Progress. Inherit this class to have your own way to manage a progress bar...
Definition: IProgress.hpp:23
EAnalyseLevel
Level of file analysis.
Definition: util.hpp:10
std::vector< InputStream * > _inputStreams
Has ownership.
Definition: InputFile.hpp:111
std::string getFilename() const
Definition: InputFile.hpp:80
std::map< std::string, std::string > Profile
FormatContext & getFormatContext()
Definition: InputFile.hpp:82
const FileProperties & getProperties() const
Return media properties on the current InputFile.
Definition: InputFile.hpp:71
Wrapper of an AVFormatContext.
FormatContext _formatContext
Definition: InputFile.hpp:108
FileProperties * _properties
Definition: InputFile.hpp:109
This class describes coded data.
Definition: CodedData.hpp:18
std::ostream & operator<<(std::ostream &flux, const InputFile &input)
Definition: InputFile.cpp:171