avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
format.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
6 #include "ffmpeg.h"
7 
8 namespace av {
9 
10 // AVFormat 59 will introduce `const` for all muxer/demuxer description operations
11 template<typename T>
12 using avcpp_format_const = typename std::conditional<
13  std::is_const<
14  typename std::remove_pointer<
15  decltype(AVFormatContext::iformat)
16  >::type
17  >::value, const T, T>::type;
18 
19 using FmtCodec = class Codec;
20 namespace internal {
21 bool codec_supported(const AVCodecTag *const *codecTag, const FmtCodec &codec);
22 bool codec_supported(const AVCodecTag *const *codecTag, AVCodecID codec_id);
23 } // ::internal
24 
25 template<typename T>
26 struct Format : public FFWrapperPtr<T>
27 {
29 
30  const char* name() const noexcept {
31  return RAW_GET(name, nullptr);
32  }
33 
34  const char* longName() const noexcept {
35  return RAW_GET(long_name, nullptr);
36  }
37 
38  int32_t flags() const noexcept {
39  return RAW_GET(flags, 0);
40  }
41 
42  bool isFlags(int32_t flags) const noexcept {
43  if (m_raw) {
44  return (m_raw->flags & flags);
45  }
46  return false;
47  }
48 
49  void setFormat(T* format) noexcept {
50  FFWrapperPtr<T>::reset(format);
51  }
52 
53  bool codecSupported(const class Codec &codec) const noexcept
54  {
55  if (!m_raw)
56  return false;
57  return internal::codec_supported(m_raw->codec_tag, codec);
58  }
59 
60  bool codecSupported(AVCodecID codec_id) const noexcept
61  {
62  if (!m_raw)
63  return false;
64  return internal::codec_supported(m_raw->codec_tag, codec_id);
65  }
66 
67 protected:
69 };
70 
71 class InputFormat : public Format<avcpp_format_const<AVInputFormat>>
72 {
73 public:
76 
77  InputFormat() = default;
78 
79  InputFormat(const std::string& name) noexcept;
80 
81  bool setFormat(const std::string& name) noexcept;
82 
83 };
84 
85 
86 class OutputFormat : public Format<avcpp_format_const<AVOutputFormat>>
87 {
88 public:
91 
92  OutputFormat() = default;
93 
94  OutputFormat(const std::string& name,
95  const std::string& url = std::string(),
96  const std::string& mime = std::string()) noexcept;
97 
98  bool setFormat(const std::string& name,
99  const std::string& url = std::string(),
100  const std::string& mime = std::string()) noexcept;
101 
102  AVCodecID defaultVideoCodecId() const noexcept;
103  AVCodecID defaultAudioCodecId() const noexcept;
104 };
105 
106 
107 OutputFormat guessOutputFormat(const std::string& name,
108  const std::string& url = std::string(),
109  const std::string& mime = std::string());
110 
111 } // namespace av
112 
av::Format::setFormat
void setFormat(T *format) noexcept
Definition: format.h:49
av::FmtCodec
class Codec FmtCodec
Definition: format.h:19
av::OutputFormat
Definition: format.h:86
av::Format::isFlags
bool isFlags(int32_t flags) const noexcept
Definition: format.h:42
av::InputFormat
Definition: format.h:71
ffmpeg.h
av::OutputFormat::defaultVideoCodecId
AVCodecID defaultVideoCodecId() const noexcept
Definition: format.cpp:57
FFWrapperPtr
Definition: ffmpeg.h:68
av::avcpp_format_const
typename std::conditional< std::is_const< typename std::remove_pointer< decltype(AVFormatContext::iformat) >::type >::value, const T, T >::type avcpp_format_const
Definition: format.h:17
av::Format
Definition: format.h:26
av::internal::codec_supported
bool codec_supported(const AVCodecTag *const *codecTag, const FmtCodec &codec)
Definition: format.cpp:8
av::OutputFormat::setFormat
bool setFormat(const std::string &name, const std::string &url=std::string(), const std::string &mime=std::string()) noexcept
Definition: format.cpp:45
av::InputFormat::InputFormat
InputFormat()=default
RAW_GET
#define RAW_GET(field, def)
Definition: ffmpeg.h:94
av::guessOutputFormat
OutputFormat guessOutputFormat(const std::string &name, const std::string &url, const std::string &mime)
Definition: format.cpp:69
av::Format::codecSupported
bool codecSupported(const class Codec &codec) const noexcept
Definition: format.h:53
av::Format::flags
int32_t flags() const noexcept
Definition: format.h:38
av::OutputFormat::OutputFormat
OutputFormat()=default
av::Format::longName
const char * longName() const noexcept
Definition: format.h:34
av
Definition: audioresampler.cpp:8
FFWrapperPtr::m_raw
T * m_raw
Definition: ffmpeg.h:91
av::InputFormat::setFormat
bool setFormat(const std::string &name) noexcept
Definition: format.cpp:30
FFWrapperPtr::reset
void reset(T *raw=nullptr)
Definition: ffmpeg.h:76
av::Codec
Definition: codec.h:17
av::OutputFormat::defaultAudioCodecId
AVCodecID defaultAudioCodecId() const noexcept
Definition: format.cpp:63
av::Format::name
const char * name() const noexcept
Definition: format.h:30
av::Format::codecSupported
bool codecSupported(AVCodecID codec_id) const noexcept
Definition: format.h:60