1 /* 2 mkvmerge -- utility for splicing together matroska files 3 from component media subtypes 4 5 Distributed under the GPL v2 6 see the file COPYING for details 7 or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 8 9 Definitions for the various Codec IDs 10 11 Written by Moritz Bunkus <moritz@bunkus.org>. 12 */ 13 14 #pragma once 15 16 #include "common/common_pch.h" 17 18 #include <ostream> 19 20 #include "common/container.h" 21 #include "common/fourcc.h" 22 #include "matroska/c/libmatroska_t.h" 23 24 // see http://www.matroska.org/technical/specs/codecid/index.html 25 26 constexpr auto MKV_A_AAC = "A_AAC"; 27 constexpr auto MKV_A_AAC_2LC = "A_AAC/MPEG2/LC"; 28 constexpr auto MKV_A_AAC_2MAIN = "A_AAC/MPEG2/MAIN"; 29 constexpr auto MKV_A_AAC_2SBR = "A_AAC/MPEG2/LC/SBR"; 30 constexpr auto MKV_A_AAC_2SSR = "A_AAC/MPEG2/SSR"; 31 constexpr auto MKV_A_AAC_4LC = "A_AAC/MPEG4/LC"; 32 constexpr auto MKV_A_AAC_4LTP = "A_AAC/MPEG4/LTP"; 33 constexpr auto MKV_A_AAC_4MAIN = "A_AAC/MPEG4/MAIN"; 34 constexpr auto MKV_A_AAC_4SBR = "A_AAC/MPEG4/LC/SBR"; 35 constexpr auto MKV_A_AAC_4SSR = "A_AAC/MPEG4/SSR"; 36 constexpr auto MKV_A_AC3 = "A_AC3"; 37 constexpr auto MKV_A_ACM = "A_MS/ACM"; 38 constexpr auto MKV_A_ALAC = "A_ALAC"; 39 constexpr auto MKV_A_DTS = "A_DTS"; 40 constexpr auto MKV_A_EAC3 = "A_EAC3"; 41 constexpr auto MKV_A_FLAC = "A_FLAC"; 42 constexpr auto MKV_A_MLP = "A_MLP"; 43 constexpr auto MKV_A_MP2 = "A_MPEG/L2"; 44 constexpr auto MKV_A_MP3 = "A_MPEG/L3"; 45 constexpr auto MKV_A_OPUS = "A_OPUS"; 46 constexpr auto MKV_A_PCM = "A_PCM/INT/LIT"; 47 constexpr auto MKV_A_PCM_BE = "A_PCM/INT/BIG"; 48 constexpr auto MKV_A_PCM_FLOAT = "A_PCM/FLOAT/IEEE"; 49 constexpr auto MKV_A_QDMC = "A_QUICKTIME/QDMC"; 50 constexpr auto MKV_A_QDMC2 = "A_QUICKTIME/QDM2"; 51 constexpr auto MKV_A_QUICKTIME = "A_QUICKTIME"; 52 constexpr auto MKV_A_TRUEHD = "A_TRUEHD"; 53 constexpr auto MKV_A_TTA = "A_TTA1"; 54 constexpr auto MKV_A_VORBIS = "A_VORBIS"; 55 constexpr auto MKV_A_WAVPACK4 = "A_WAVPACK4"; 56 57 constexpr auto MKV_V_AV1 = "V_AV1"; 58 constexpr auto MKV_V_DIRAC = "V_DIRAC"; 59 constexpr auto MKV_V_MPEG1 = "V_MPEG1"; 60 constexpr auto MKV_V_MPEG2 = "V_MPEG2"; 61 constexpr auto MKV_V_MPEG4_AP = "V_MPEG4/ISO/AP"; 62 constexpr auto MKV_V_MPEG4_ASP = "V_MPEG4/ISO/ASP"; 63 constexpr auto MKV_V_MPEG4_AVC = "V_MPEG4/ISO/AVC"; 64 constexpr auto MKV_V_MPEG4_SP = "V_MPEG4/ISO/SP"; 65 constexpr auto MKV_V_MPEGH_HEVC = "V_MPEGH/ISO/HEVC"; 66 constexpr auto MKV_V_MSCOMP = "V_MS/VFW/FOURCC"; 67 constexpr auto MKV_V_PRORES = "V_PRORES"; 68 constexpr auto MKV_V_QUICKTIME = "V_QUICKTIME"; 69 constexpr auto MKV_V_REALV1 = "V_REAL/RV10"; 70 constexpr auto MKV_V_REALV2 = "V_REAL/RV20"; 71 constexpr auto MKV_V_REALV3 = "V_REAL/RV30"; 72 constexpr auto MKV_V_REALV4 = "V_REAL/RV40"; 73 constexpr auto MKV_V_THEORA = "V_THEORA"; 74 constexpr auto MKV_V_UNCOMPRESSED = "V_UNCOMPRESSED"; 75 constexpr auto MKV_V_VP8 = "V_VP8"; 76 constexpr auto MKV_V_VP9 = "V_VP9"; 77 78 constexpr auto MKV_S_DVBSUB = "S_DVBSUB"; 79 constexpr auto MKV_S_HDMV_PGS = "S_HDMV/PGS"; 80 constexpr auto MKV_S_HDMV_TEXTST = "S_HDMV/TEXTST"; 81 constexpr auto MKV_S_KATE = "S_KATE"; 82 constexpr auto MKV_S_TEXTASCII = "S_TEXT/ASCII"; 83 constexpr auto MKV_S_TEXTASS = "S_TEXT/ASS"; 84 constexpr auto MKV_S_TEXTSSA = "S_TEXT/SSA"; 85 constexpr auto MKV_S_TEXTUSF = "S_TEXT/USF"; 86 constexpr auto MKV_S_TEXTUTF8 = "S_TEXT/UTF8"; 87 constexpr auto MKV_S_TEXTWEBVTT = "S_TEXT/WEBVTT"; 88 constexpr auto MKV_S_VOBSUB = "S_VOBSUB"; 89 constexpr auto MKV_S_VOBSUBZLIB = "S_VOBSUB/ZLIB"; 90 91 constexpr auto MKV_B_VOBBTN = "B_VOBBTN"; 92 93 class codec_private_c; 94 class codec_c { 95 protected: 96 MTX_DECLARE_PRIVATE(codec_private_c) 97 98 std::unique_ptr<codec_private_c> const p_ptr; 99 100 explicit codec_c(codec_private_c &p); 101 102 public: 103 enum class type_e { 104 UNKNOWN = 0 105 , V_AV1 = 0x1000 106 , V_BITFIELDS 107 , V_CINEPAK 108 , V_DIRAC 109 , V_MPEG12 110 , V_MPEG4_P10 111 , V_MPEG4_P2 112 , V_MPEGH_P2 113 , V_PRORES 114 , V_REAL 115 , V_RLE4 116 , V_RLE8 117 , V_SVQ1 118 , V_SVQ3 119 , V_THEORA 120 , V_UNCOMPRESSED 121 , V_VC1 122 , V_VP8 123 , V_VP9 124 125 , A_AAC = 0x2000 126 , A_AC3 127 , A_ACELP_NET 128 , A_ALAC 129 , A_ATRAC3 130 , A_COOK 131 , A_DTS 132 , A_FLAC 133 , A_LD_CELP 134 , A_MLP 135 , A_MP2 136 , A_MP3 137 , A_OPUS 138 , A_PCM 139 , A_QDMC 140 , A_RALF 141 , A_TRUEHD 142 , A_TTA 143 , A_VORBIS 144 , A_VSELP 145 , A_WAVPACK4 146 147 , S_DVBSUB = 0x3000 148 , S_HDMV_PGS 149 , S_HDMV_TEXTST 150 , S_KATE 151 , S_SRT 152 , S_SSA_ASS 153 , S_USF 154 , S_VOBSUB 155 , S_WEBVTT 156 157 , B_VOBBTN = 0x4000 158 }; 159 160 enum class specialization_e { 161 none 162 163 , dts_hd_master_audio 164 , dts_hd_high_resolution 165 , dts_express 166 , dts_es 167 , dts_96_24 168 , dts_x 169 170 , mpeg_1_2_layer_1 171 , mpeg_1_2_layer_2 172 , mpeg_1_2_layer_3 173 174 , truehd_atmos 175 176 , ac3_dolby_surround_ex 177 , e_ac_3 178 }; 179 180 public: 181 codec_c(); 182 virtual ~codec_c(); 183 184 codec_c(std::string const &name, type_e type, track_type p_track_type, std::string const &match_re, uint16_t audio_format = 0u); 185 codec_c(std::string const &name, type_e type, track_type p_track_type, std::string const &match_re, fourcc_c const &fourcc); 186 codec_c(std::string const &name, type_e type, track_type p_track_type, std::string const &match_re, std::vector<uint16_t> const &audio_formats); 187 codec_c(std::string const &name, type_e type, track_type p_track_type, std::string const &match_re, std::vector<fourcc_c> const &fourccs); 188 189 codec_c(codec_c const &src); 190 191 codec_c &operator =(codec_c const &src); 192 193 bool matches(std::string const &fourcc_or_codec_id) const; 194 195 bool valid() const; 196 operator bool() const; 197 bool is(type_e type) const; 198 199 std::string const get_name(std::string fallback = "") const; 200 type_e get_type() const; 201 specialization_e get_specialization() const; 202 track_type get_track_type() const; 203 codec_c &set_specialization(specialization_e specialization); 204 codec_c specialize(specialization_e specialization) const; 205 206 std::vector<fourcc_c> const &get_fourccs() const; 207 std::vector<uint16_t> const &get_audio_formats() const; 208 209 private: 210 static void initialize(); 211 212 public: // static 213 static codec_c const look_up(std::string const &fourcc_or_codec_id); 214 static codec_c const look_up(char const *fourcc_or_codec_id); 215 static codec_c const look_up(fourcc_c const &fourcc); 216 static codec_c const look_up(type_e type); 217 static codec_c const look_up_audio_format(uint16_t audio_format); 218 static codec_c const look_up_object_type_id(unsigned int object_type_id); 219 220 static std::string const get_name(std::string const &fourcc_or_codec_id, std::string const &fallback); 221 static std::string const get_name(type_e type, std::string const &fallback); 222 }; 223 224 inline std::ostream & 225 operator <<(std::ostream &out, 226 codec_c const &codec) { 227 if (codec) 228 out << fmt::format("{0} (0x{1:04x})", codec.get_name(), static_cast<unsigned int>(codec.get_type())); 229 else 230 out << "<invalid-codec>"; 231 232 return out; 233 } 234