avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
format.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <memory>
11#include <string>
12
13#include "ffmpeg.h"
14
15#if AVCPP_HAS_AVFORMAT
16
17extern "C" {
18#include "libavformat/avformat.h"
19}
20
21namespace av {
22
23// AVFormat 59 will introduce `const` for all muxer/demuxer description operations
32template<typename T>
33using avcpp_format_const = typename std::conditional<
34 std::is_const<
35 typename std::remove_pointer<
36 decltype(AVFormatContext::iformat)
37 >::type
38 >::value, const T, T>::type;
39
41using FmtCodec = class Codec;
42namespace internal {
51bool codec_supported(const AVCodecTag *const *codecTag, const FmtCodec &codec);
60bool codec_supported(const AVCodecTag *const *codecTag, AVCodecID codec_id);
61} // ::internal
62
72template<typename T>
73struct Format : public FFWrapperPtr<T>
74{
76
83 const char* name() const noexcept {
84 return RAW_GET(name, nullptr);
85 }
86
92 const char* longName() const noexcept {
93 return RAW_GET(long_name, nullptr);
94 }
95
101 int32_t flags() const noexcept {
102 return RAW_GET(flags, 0);
103 }
104
112 bool isFlags(int32_t flags) const noexcept {
113 if (m_raw) {
114 return (m_raw->flags & flags);
115 }
116 return false;
117 }
118
124 void setFormat(T* format) noexcept {
126 }
127
135 bool codecSupported(const class Codec &codec) const noexcept
136 {
137 if (!m_raw)
138 return false;
139 return internal::codec_supported(m_raw->codec_tag, codec);
140 }
141
149 bool codecSupported(AVCodecID codec_id) const noexcept
150 {
151 if (!m_raw)
152 return false;
153 return internal::codec_supported(m_raw->codec_tag, codec_id);
154 }
155
156protected:
158 using FFWrapperPtr<T>::m_raw;
159};
160
167class InputFormat : public Format<avcpp_format_const<AVInputFormat>>
168{
169public:
172
173 InputFormat() = default;
174
180 InputFormat(const std::string& name) noexcept;
181
189 bool setFormat(const std::string& name) noexcept;
190
191};
192
193
201class OutputFormat : public Format<avcpp_format_const<AVOutputFormat>>
202{
203public:
206
207 OutputFormat() = default;
208
216 OutputFormat(const std::string& name,
217 const std::string& url = std::string(),
218 const std::string& mime = std::string()) noexcept;
219
229 bool setFormat(const std::string& name,
230 const std::string& url = std::string(),
231 const std::string& mime = std::string()) noexcept;
232
238 AVCodecID defaultVideoCodecId() const noexcept;
244 AVCodecID defaultAudioCodecId() const noexcept;
245};
246
247
258 const std::string& url = std::string(),
259 const std::string& mime = std::string());
260
261} // namespace av
262
263#endif // if AVCPP_HAS_AVFORMAT
Codec descriptor.
Definition codec.h:32
InputFormat(const std::string &name) noexcept
Look a demuxer up by name.
bool setFormat(const std::string &name) noexcept
Look a demuxer up by name and point the descriptor at it.
Muxer descriptor.
Definition format.h:202
bool setFormat(const std::string &name, const std::string &url=std::string(), const std::string &mime=std::string()) noexcept
Look a muxer up and point the descriptor at it.
AVCodecID defaultAudioCodecId() const noexcept
Audio codec the muxer uses when the caller does not choose one.
OutputFormat(const std::string &name, const std::string &url=std::string(), const std::string &mime=std::string()) noexcept
Look a muxer up by name, URL or MIME type.
AVCodecID defaultVideoCodecId() const noexcept
Video codec the muxer uses when the caller does not choose one.
FFmpeg types re-exported for the public API and small value wrappers.
#define RAW_GET(field, def)
Read an AVCodecContext-style field through a possibly empty raw pointer.
Definition ffmpeg.h:114
bool codec_supported(const AVCodecTag *const *codecTag, const FmtCodec &codec)
Whether a codec tag table can carry a codec.
Root namespace of the library.
Definition audioresampler.h:19
typename std::conditional< std::is_const< typename std::remove_pointer< decltype(AVFormatContext::iformat) >::type >::value, const T, T >::type avcpp_format_const
Const or non-const FFmpeg format type, depending on the FFmpeg version.
Definition format.h:33
OutputFormat guessOutputFormat(const std::string &name, const std::string &url=std::string(), const std::string &mime=std::string())
Find the muxer FFmpeg would pick for this output.
class Codec FmtCodec
Forward declaration of av::Codec, so this header need not include it.
Definition format.h:41
STL namespace.
Base for wrappers that own a pointer to an FFmpeg object.
Definition ffmpeg.h:38
void reset(T *raw=nullptr)
Replace the stored pointer.
Definition ffmpeg.h:71
T * m_raw
The wrapped pointer; owned by the derived class, not by this template.
Definition ffmpeg.h:105
FFWrapperPtr()=default
Create an empty wrapper; isNull() is true.
Common interface of input and output format descriptors.
Definition format.h:74
void setFormat(T *format) noexcept
Point the descriptor at another format.
Definition format.h:124
const char * longName() const noexcept
Human-readable format name.
Definition format.h:92
bool isFlags(int32_t flags) const noexcept
Whether all given flags are set.
Definition format.h:112
const char * name() const noexcept
Short format name, as FFmpeg spells it.
Definition format.h:83
bool codecSupported(AVCodecID codec_id) const noexcept
Whether the format can carry a codec identifier.
Definition format.h:149
bool codecSupported(const class Codec &codec) const noexcept
Whether the format can carry a codec.
Definition format.h:135
int32_t flags() const noexcept
Raw AVFMT_* flags of the format.
Definition format.h:101