FFmpegKit Linux API 5.1
MediaInformation.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "MediaInformation.h"
21
22ffmpegkit::MediaInformation::MediaInformation(std::shared_ptr<rapidjson::Value> mediaInformationValue, std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::StreamInformation>>> streams, std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::Chapter>>> chapters) :
23 _mediaInformationValue{mediaInformationValue}, _streams{streams}, _chapters{chapters} {
24}
25
26std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFilename() {
27 return getStringFormatProperty(KeyFilename);
28}
29
30std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFormat() {
31 return getStringFormatProperty(KeyFormat);
32}
33
34std::shared_ptr<std::string> ffmpegkit::MediaInformation::getLongFormat() {
35 return getStringFormatProperty(KeyFormatLong);
36}
37
38std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStartTime() {
39 return getStringFormatProperty(KeyStartTime);
40}
41
42std::shared_ptr<std::string> ffmpegkit::MediaInformation::getDuration() {
43 return getStringFormatProperty(KeyDuration);
44}
45
46std::shared_ptr<std::string> ffmpegkit::MediaInformation::getSize() {
47 return getStringFormatProperty(KeySize);
48}
49
50std::shared_ptr<std::string> ffmpegkit::MediaInformation::getBitrate() {
51 return getStringFormatProperty(KeyBitRate);
52}
53
54std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getTags() {
55 auto formatProperties = getFormatProperties();
56 if (formatProperties->HasMember(KeyTags)) {
57 auto tags = std::make_shared<rapidjson::Value>();
58 *tags = (*formatProperties)[KeyTags];
59 return tags;
60 } else {
61 return nullptr;
62 }
63}
64
65std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::StreamInformation>>> ffmpegkit::MediaInformation::getStreams() {
66 return _streams;
67}
68
69std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::Chapter>>> ffmpegkit::MediaInformation::getChapters() {
70 return _chapters;
71}
72
73std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStringProperty(const char* key) {
74 auto allProperties = getAllProperties();
75 if (allProperties->HasMember(key)) {
76 return std::make_shared<std::string>((*allProperties)[key].GetString());
77 } else {
78 return nullptr;
79 }
80}
81
82std::shared_ptr<int64_t> ffmpegkit::MediaInformation::getNumberProperty(const char* key) {
83 auto allProperties = getAllProperties();
84 if (allProperties->HasMember(key)) {
85 return std::make_shared<int64_t>((*allProperties)[key].GetInt64());
86 } else {
87 return nullptr;
88 }
89}
90
91std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getProperty(const char* key) {
92 auto allProperties = getAllProperties();
93 if (allProperties->HasMember(key)) {
94 auto value = std::make_shared<rapidjson::Value>();
95 *value = (*allProperties)[key];
96 return value;
97 } else {
98 return nullptr;
99 }
100}
101
102std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStringFormatProperty(const char* key) {
103 auto formatProperties = getFormatProperties();
104 if (formatProperties->HasMember(key)) {
105 return std::make_shared<std::string>((*formatProperties)[key].GetString());
106 } else {
107 return nullptr;
108 }
109}
110
111std::shared_ptr<int64_t> ffmpegkit::MediaInformation::getNumberFormatProperty(const char* key) {
112 auto formatProperties = getFormatProperties();
113 if (formatProperties->HasMember(key)) {
114 return std::make_shared<int64_t>((*formatProperties)[key].GetInt64());
115 } else {
116 return nullptr;
117 }
118}
119
120std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getFormatProperty(const char* key) {
121 auto formatProperties = getFormatProperties();
122 if (formatProperties->HasMember(key)) {
123 auto value = std::make_shared<rapidjson::Value>();
124 *value = (*formatProperties)[key];
125 return value;
126 } else {
127 return nullptr;
128 }
129}
130
131std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getFormatProperties() {
132 if (_mediaInformationValue->HasMember(KeyFormatProperties)) {
133 auto mediaProperties = std::make_shared<rapidjson::Value>();
134 *mediaProperties = (*_mediaInformationValue)[KeyFormatProperties];
135 return mediaProperties;
136 } else {
137 return nullptr;
138 }
139}
140
141std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getAllProperties() {
142 if (_mediaInformationValue != nullptr) {
143 auto all = std::make_shared<rapidjson::Value>();
144 *all = (*_mediaInformationValue);
145 return all;
146 } else {
147 return nullptr;
148 }
149}
std::shared_ptr< rapidjson::Value > getProperty(const char *key)
MediaInformation(std::shared_ptr< rapidjson::Value > mediaInformationValue, std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::StreamInformation > > > streams, std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::Chapter > > > chapters)
std::shared_ptr< std::string > getDuration()
std::shared_ptr< std::string > getBitrate()
std::shared_ptr< rapidjson::Value > getFormatProperties()
std::shared_ptr< std::string > getStartTime()
std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::StreamInformation > > > getStreams()
std::shared_ptr< rapidjson::Value > getFormatProperty(const char *key)
std::shared_ptr< int64_t > getNumberFormatProperty(const char *key)
std::shared_ptr< std::string > getLongFormat()
std::shared_ptr< std::string > getSize()
std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::Chapter > > > getChapters()
std::shared_ptr< std::string > getStringProperty(const char *key)
std::shared_ptr< rapidjson::Value > getAllProperties()
std::shared_ptr< std::string > getStringFormatProperty(const char *key)
std::shared_ptr< std::string > getFormat()
std::shared_ptr< int64_t > getNumberProperty(const char *key)
std::shared_ptr< std::string > getFilename()
std::shared_ptr< rapidjson::Value > getTags()