| FFmpegKit Linux API 6.0

Loading...
Searching...
No Matches
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
22 ffmpegkit::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}
MediaInformation.h
ffmpegkit::MediaInformation::getProperty
std::shared_ptr< rapidjson::Value > getProperty(const char *key)
Definition MediaInformation.cpp:91
ffmpegkit::MediaInformation::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)
Definition MediaInformation.cpp:22
ffmpegkit::MediaInformation::getDuration
std::shared_ptr< std::string > getDuration()
Definition MediaInformation.cpp:42
ffmpegkit::MediaInformation::getBitrate
std::shared_ptr< std::string > getBitrate()
Definition MediaInformation.cpp:50
ffmpegkit::MediaInformation::getFormatProperties
std::shared_ptr< rapidjson::Value > getFormatProperties()
Definition MediaInformation.cpp:131
ffmpegkit::MediaInformation::getStartTime
std::shared_ptr< std::string > getStartTime()
Definition MediaInformation.cpp:38
ffmpegkit::MediaInformation::getStreams
std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::StreamInformation > > > getStreams()
Definition MediaInformation.cpp:65
ffmpegkit::MediaInformation::getFormatProperty
std::shared_ptr< rapidjson::Value > getFormatProperty(const char *key)
Definition MediaInformation.cpp:120
ffmpegkit::MediaInformation::getNumberFormatProperty
std::shared_ptr< int64_t > getNumberFormatProperty(const char *key)
Definition MediaInformation.cpp:111
ffmpegkit::MediaInformation::getLongFormat
std::shared_ptr< std::string > getLongFormat()
Definition MediaInformation.cpp:34
ffmpegkit::MediaInformation::getSize
std::shared_ptr< std::string > getSize()
Definition MediaInformation.cpp:46
ffmpegkit::MediaInformation::getChapters
std::shared_ptr< std::vector< std::shared_ptr< ffmpegkit::Chapter > > > getChapters()
Definition MediaInformation.cpp:69
ffmpegkit::MediaInformation::getStringProperty
std::shared_ptr< std::string > getStringProperty(const char *key)
Definition MediaInformation.cpp:73
ffmpegkit::MediaInformation::getAllProperties
std::shared_ptr< rapidjson::Value > getAllProperties()
Definition MediaInformation.cpp:141
ffmpegkit::MediaInformation::getStringFormatProperty
std::shared_ptr< std::string > getStringFormatProperty(const char *key)
Definition MediaInformation.cpp:102
ffmpegkit::MediaInformation::getFormat
std::shared_ptr< std::string > getFormat()
Definition MediaInformation.cpp:30
ffmpegkit::MediaInformation::getNumberProperty
std::shared_ptr< int64_t > getNumberProperty(const char *key)
Definition MediaInformation.cpp:82
ffmpegkit::MediaInformation::getFilename
std::shared_ptr< std::string > getFilename()
Definition MediaInformation.cpp:26
ffmpegkit::MediaInformation::getTags
std::shared_ptr< rapidjson::Value > getTags()
Definition MediaInformation.cpp:54