AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FormatContext.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_FORMAT_CONTEXT_HPP_
2 #define _AV_TRANSCODER_FORMAT_CONTEXT_HPP_
3 
6 
7 extern "C" {
8 #include <libavformat/avformat.h>
9 }
10 
11 namespace avtranscoder
12 {
13 
14 /**
15  * @brief Wrapper of an AVFormatContext.
16  */
17 class AvExport FormatContext
18 {
19 private:
20  FormatContext(const FormatContext& formatContext);
21  FormatContext& operator=(const FormatContext& formatContext);
22 
23 public:
24  /**
25  * @brief Allocate an AVFormatContext by opening an input file
26  */
27  FormatContext(const std::string& filename, int req_flags = 0, AVDictionary** options = NULL);
28 
29  /**
30  * @brief Allocate an AVFormatContext with default values
31  */
32  FormatContext(int req_flags = 0);
33 
34  ~FormatContext();
35 
36  /**
37  * @brief Read packets of a media file to get stream information
38  */
39  void findStreamInfo(AVDictionary** options = NULL);
40 
41  /**
42  * @brief Create and initialize a AVIOContext for accessing the resource indicated by url
43  * @param url: url of ressource
44  * @param flags: AVIO_FLAG_READ / AVIO_FLAG_WRITE / AVIO_FLAG_READ_WRITE
45  */
46  void openRessource(const std::string& url, int flags);
47 
48  /**
49  * @brief Close the resource accessed by the AVIOContext and free it
50  * @note Should be called after openRessource
51  */
52  void closeRessource();
53 
54  /**
55  * @brief Write the stream header to an output media file
56  * @note Also load options specific to the output format
57  */
58  void writeHeader(AVDictionary** options = NULL);
59 
60  /**
61  * @brief Write a packet to an output media file
62  * @param packet: packet to write (must be allocate and free by the caller
63  * @param interleaved: to ensuring correct interleaving (available by default)
64  */
65  void writeFrame(AVPacket& packet, bool interleaved = true);
66 
67  /**
68  * @brief Write the stream trailer to an output media file
69  * @note Should be called after writeHeader
70  */
71  void writeTrailer();
72 
73  void addMetaData(const std::string& key, const std::string& value);
74  AVStream& addAVStream(const AVCodec& avCodec);
75 
76  /**
77  * @brief Seek at a specific position
78  * @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
79  * @param flag: seeking mode (AVSEEK_FLAG_xxx)
80  * @return seek status
81  * @warn seeking on a raw bitstreams (without any container) could produce an error (because of a lack of timing information)
82  * @see flushDecoder
83  */
84  bool seek(const uint64_t position, const int flag);
85 
86  size_t getNbStreams() const { return _avFormatContext->nb_streams; }
87  /// Get duration of the program, in seconds
88  size_t getDuration() const { return _avFormatContext->duration; }
89  size_t getStartTime() const { return _avFormatContext->start_time; }
90 
91  OptionArray getOptions(); ///< Get options as array
92 #ifndef SWIG
93  OptionMap& getOptionsMap() { return _options; } ///< Get options as map
94 #endif
95  Option& getOption(const std::string& optionName) { return _options.at(optionName); }
96 
97  /**
98  * Guess format from arguments.
99  * Set the AVOutputFormat of AVFormatContext.
100  * @param filename: checks if it terminates with the extensions of the registered formats
101  * @param shortName: checks if it matches with the names of the registered formats
102  * @param mimeType: checks if it matches with the MIME type of the registered formats
103  */
104  void setOutputFormat(const std::string& filename, const std::string& shortName = "", const std::string& mimeType = "");
105 
106  /**
107  * Set filename of AVFormatContext.
108  */
109  void setFilename(const std::string& filename);
110 
111 #ifndef SWIG
112  AVFormatContext& getAVFormatContext() const { return *_avFormatContext; }
113  AVOutputFormat& getAVOutputFormat() const { return *_avFormatContext->oformat; }
114  AVInputFormat& getAVInputFormat() const { return *_avFormatContext->iformat; }
115  AVIOContext& getAVIOContext() const { return *_avFormatContext->pb; }
116  AVDictionary& getAVMetaData() const { return *_avFormatContext->metadata; }
117  AVStream& getAVStream(size_t index) const;
118 #endif
119 
120 private:
121  AVFormatContext* _avFormatContext; ///< Has ownership
122  const int _flags; ///< Flags with which the options are loaded (see AV_OPT_FLAG_xxx)
124  bool _isOpen; ///< Is the AVFormatContext open (in constructor with a filename)
125 };
126 }
127 
128 #endif
const int _flags
Flags with which the options are loaded (see AV_OPT_FLAG_xxx)
std::map< std::string, Option > OptionMap
Key: option name / value: option.
Definition: Option.hpp:119
std::vector< Option > OptionArray
Definition: Option.hpp:118
AVOutputFormat & getAVOutputFormat() const
AVIOContext & getAVIOContext() const
Wrapper of AVOption. Get its type to know what the option is about: Int, Double, Ratio, Choice... Parse its array of options to get the potential childs (Choice and Group).
Definition: Option.hpp:36
AVDictionary & getAVMetaData() const
Option & getOption(const std::string &optionName)
AVInputFormat & getAVInputFormat() const
OptionMap & getOptionsMap()
Get options as map.
Wrapper of an AVFormatContext.
bool _isOpen
Is the AVFormatContext open (in constructor with a filename)
AVFormatContext * _avFormatContext
Has ownership.
size_t getDuration() const
Get duration of the program, in seconds.
AVFormatContext & getAVFormatContext() const
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