refactor media information classes

This commit is contained in:
Taner Sener 2022-08-22 03:19:35 +01:00
parent 6b09e0dfed
commit eac6cd5a06
15 changed files with 314 additions and 162 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Taner Sener * Copyright (c) 2021-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -63,7 +63,7 @@ public class Chapter {
} }
public JSONObject getTags() { public JSONObject getTags() {
return getProperties(KEY_TAGS); return getProperty(KEY_TAGS);
} }
/** /**
@ -73,13 +73,13 @@ public class Chapter {
* @return chapter property as string or null if the key is not found * @return chapter property as string or null if the key is not found
*/ */
public String getStringProperty(final String key) { public String getStringProperty(final String key) {
JSONObject chapterProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (chapterProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (chapterProperties.has(key)) { if (allProperties.has(key)) {
return chapterProperties.optString(key); return allProperties.optString(key);
} else { } else {
return null; return null;
} }
@ -92,31 +92,31 @@ public class Chapter {
* @return chapter property as Long or null if the key is not found * @return chapter property as Long or null if the key is not found
*/ */
public Long getNumberProperty(String key) { public Long getNumberProperty(String key) {
JSONObject chapterProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (chapterProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (chapterProperties.has(key)) { if (allProperties.has(key)) {
return chapterProperties.optLong(key); return allProperties.optLong(key);
} else { } else {
return null; return null;
} }
} }
/** /**
* Returns the chapter properties associated with the key. * Returns the chapter property associated with the key.
* *
* @param key properties key * @param key property key
* @return chapter properties as a JSONObject or null if the key is not found * @return chapter property as a JSONObject or null if the key is not found
*/ */
public JSONObject getProperties(String key) { public JSONObject getProperty(String key) {
JSONObject chapterProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (chapterProperties == null) { if (allProperties == null) {
return null; return null;
} }
return chapterProperties.optJSONObject(key); return allProperties.optJSONObject(key);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2021 Taner Sener * Copyright (c) 2018-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -29,7 +29,7 @@ import java.util.List;
public class MediaInformation { public class MediaInformation {
/* COMMON KEYS */ /* COMMON KEYS */
public static final String KEY_MEDIA_PROPERTIES = "format"; public static final String KEY_FORMAT_PROPERTIES = "format";
public static final String KEY_FILENAME = "filename"; public static final String KEY_FILENAME = "filename";
public static final String KEY_FORMAT = "format_name"; public static final String KEY_FORMAT = "format_name";
public static final String KEY_FORMAT_LONG = "format_long_name"; public static final String KEY_FORMAT_LONG = "format_long_name";
@ -66,7 +66,7 @@ public class MediaInformation {
* @return media file name * @return media file name
*/ */
public String getFilename() { public String getFilename() {
return getStringProperty(KEY_FILENAME); return getStringFormatProperty(KEY_FILENAME);
} }
/** /**
@ -75,7 +75,7 @@ public class MediaInformation {
* @return media format * @return media format
*/ */
public String getFormat() { public String getFormat() {
return getStringProperty(KEY_FORMAT); return getStringFormatProperty(KEY_FORMAT);
} }
/** /**
@ -84,7 +84,7 @@ public class MediaInformation {
* @return media long format * @return media long format
*/ */
public String getLongFormat() { public String getLongFormat() {
return getStringProperty(KEY_FORMAT_LONG); return getStringFormatProperty(KEY_FORMAT_LONG);
} }
/** /**
@ -93,7 +93,7 @@ public class MediaInformation {
* @return media duration in "seconds.microseconds" format * @return media duration in "seconds.microseconds" format
*/ */
public String getDuration() { public String getDuration() {
return getStringProperty(KEY_DURATION); return getStringFormatProperty(KEY_DURATION);
} }
/** /**
@ -102,7 +102,7 @@ public class MediaInformation {
* @return media start time in milliseconds * @return media start time in milliseconds
*/ */
public String getStartTime() { public String getStartTime() {
return getStringProperty(KEY_START_TIME); return getStringFormatProperty(KEY_START_TIME);
} }
/** /**
@ -111,7 +111,7 @@ public class MediaInformation {
* @return media size in bytes * @return media size in bytes
*/ */
public String getSize() { public String getSize() {
return getStringProperty(KEY_SIZE); return getStringFormatProperty(KEY_SIZE);
} }
/** /**
@ -120,16 +120,16 @@ public class MediaInformation {
* @return media bitrate in kb/s * @return media bitrate in kb/s
*/ */
public String getBitrate() { public String getBitrate() {
return getStringProperty(KEY_BIT_RATE); return getStringFormatProperty(KEY_BIT_RATE);
} }
/** /**
* Returns all tags. * Returns all tags.
* *
* @return tags dictionary * @return tags as a JSONObject
*/ */
public JSONObject getTags() { public JSONObject getTags() {
return getProperties(KEY_TAGS); return getFormatProperty(KEY_TAGS);
} }
/** /**
@ -151,65 +151,118 @@ public class MediaInformation {
} }
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @param key property key * @param key property key
* @return media property as string or null if the key is not found * @return property as string or null if the key is not found
*/ */
public String getStringProperty(final String key) { public String getStringProperty(final String key) {
JSONObject mediaProperties = getMediaProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (mediaProperties.has(key)) { if (allProperties.has(key)) {
return mediaProperties.optString(key); return allProperties.optString(key);
} else { } else {
return null; return null;
} }
} }
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @param key property key * @param key property key
* @return media property as Long or null if the key is not found * @return property as Long or null if the key is not found
*/ */
public Long getNumberProperty(String key) { public Long getNumberProperty(String key) {
JSONObject mediaProperties = getMediaProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (mediaProperties.has(key)) { if (allProperties.has(key)) {
return mediaProperties.optLong(key); return allProperties.optLong(key);
} else { } else {
return null; return null;
} }
} }
/** /**
* Returns the media properties associated with the key. * Returns the property associated with the key.
* *
* @param key properties key * @param key property key
* @return media properties as a JSONObject or null if the key is not found * @return property as a JSONObject or null if the key is not found
*/ */
public JSONObject getProperties(String key) { public JSONObject getProperty(String key) {
JSONObject mediaProperties = getMediaProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
return mediaProperties.optJSONObject(key); return allProperties.optJSONObject(key);
} }
/** /**
* Returns all media properties. * Returns the format property associated with the key.
* *
* @return all media properties as a JSONObject or null if no media properties are defined * @param key property key
* @return format property as string or null if the key is not found
*/ */
public JSONObject getMediaProperties() { public String getStringFormatProperty(final String key) {
return jsonObject.optJSONObject(KEY_MEDIA_PROPERTIES); JSONObject formatProperties = getFormatProperties();
if (formatProperties == null) {
return null;
}
if (formatProperties.has(key)) {
return formatProperties.optString(key);
} else {
return null;
}
}
/**
* Returns the format property associated with the key.
*
* @param key property key
* @return format property as Long or null if the key is not found
*/
public Long getNumberFormatProperty(String key) {
JSONObject formatProperties = getFormatProperties();
if (formatProperties == null) {
return null;
}
if (formatProperties.has(key)) {
return formatProperties.optLong(key);
} else {
return null;
}
}
/**
* Returns the format property associated with the key.
*
* @param key property key
* @return format property as a JSONObject or null if the key is not found
*/
public JSONObject getFormatProperty(String key) {
JSONObject formatProperties = getFormatProperties();
if (formatProperties == null) {
return null;
}
return formatProperties.optJSONObject(key);
}
/**
* Returns all format properties defined.
*
* @return all format properties as a JSONObject or null if no format properties are defined
*/
public JSONObject getFormatProperties() {
return jsonObject.optJSONObject(KEY_FORMAT_PROPERTIES);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2021 Taner Sener * Copyright (c) 2018-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -214,7 +214,7 @@ public class StreamInformation {
* @return tags object * @return tags object
*/ */
public JSONObject getTags() { public JSONObject getTags() {
return getProperties(KEY_TAGS); return getProperty(KEY_TAGS);
} }
/** /**
@ -224,13 +224,13 @@ public class StreamInformation {
* @return stream property as string or null if the key is not found * @return stream property as string or null if the key is not found
*/ */
public String getStringProperty(final String key) { public String getStringProperty(final String key) {
JSONObject mediaProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (mediaProperties.has(key)) { if (allProperties.has(key)) {
return mediaProperties.optString(key); return allProperties.optString(key);
} else { } else {
return null; return null;
} }
@ -243,31 +243,31 @@ public class StreamInformation {
* @return stream property as Long or null if the key is not found * @return stream property as Long or null if the key is not found
*/ */
public Long getNumberProperty(String key) { public Long getNumberProperty(String key) {
JSONObject mediaProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
if (mediaProperties.has(key)) { if (allProperties.has(key)) {
return mediaProperties.optLong(key); return allProperties.optLong(key);
} else { } else {
return null; return null;
} }
} }
/** /**
* Returns the stream properties associated with the key. * Returns the stream property associated with the key.
* *
* @param key properties key * @param key property key
* @return stream properties as a JSONObject or null if the key is not found * @return stream property as a JSONObject or null if the key is not found
*/ */
public JSONObject getProperties(String key) { public JSONObject getProperty(String key) {
JSONObject mediaProperties = getAllProperties(); JSONObject allProperties = getAllProperties();
if (mediaProperties == null) { if (allProperties == null) {
return null; return null;
} }
return mediaProperties.optJSONObject(key); return allProperties.optJSONObject(key);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021 Taner Sener * Copyright (c) 2021-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -66,11 +66,11 @@ extern NSString* const ChapterKeyTags;
- (NSNumber*)getNumberProperty:(NSString*)key; - (NSNumber*)getNumberProperty:(NSString*)key;
/** /**
* Returns the chapter properties associated with the key. * Returns the chapter property associated with the key.
* *
* @return chapter properties in a dictionary or nil if the key is not found * @return chapter property as id or nil if the key is not found
*/ */
- (NSDictionary*)getProperties:(NSString*)key; - (id)getProperty:(NSString*)key;
/** /**
* Returns all chapter properties defined. * Returns all chapter properties defined.

View File

@ -70,7 +70,7 @@ NSString* const ChapterKeyTags = @"tags";
} }
- (NSDictionary*)getTags { - (NSDictionary*)getTags {
return [self getProperties:ChapterKeyTags]; return [self getProperty:ChapterKeyTags];
} }
- (NSString*)getStringProperty:(NSString*)key { - (NSString*)getStringProperty:(NSString*)key {
@ -83,15 +83,15 @@ NSString* const ChapterKeyTags = @"tags";
} }
- (NSNumber*)getNumberProperty:(NSString*)key { - (NSNumber*)getNumberProperty:(NSString*)key {
NSDictionary* mediaProperties = [self getAllProperties]; NSDictionary* allProperties = [self getAllProperties];
if (mediaProperties == nil) { if (allProperties == nil) {
return nil; return nil;
} }
return mediaProperties[key]; return allProperties[key];
} }
- (NSDictionary*)getProperties:(NSString*)key { - (id)getProperty:(NSString*)key {
NSDictionary* allProperties = [self getAllProperties]; NSDictionary* allProperties = [self getAllProperties];
if (allProperties == nil) { if (allProperties == nil) {
return nil; return nil;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2021 Taner Sener * Copyright (c) 2018-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -112,32 +112,53 @@ extern NSString* const MediaKeyTags;
- (NSArray*)getChapters; - (NSArray*)getChapters;
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @return media property as string or nil if the key is not found * @return property as string or nil if the key is not found
*/ */
- (NSString*)getStringProperty:(NSString*)key; - (NSString*)getStringProperty:(NSString*)key;
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @return media property as number or nil if the key is not found * @return property as number or nil if the key is not found
*/ */
- (NSNumber*)getNumberProperty:(NSString*)key; - (NSNumber*)getNumberProperty:(NSString*)key;
/** /**
* Returns the media properties associated with the key. * Returns the property associated with the key.
* *
* @return media properties in a dictionary or nil if the key is not found * @return property as id or nil if the key is not found
*/ */
- (NSDictionary*)getProperties:(NSString*)key; - (id)getProperty:(NSString*)key;
/** /**
* Returns all media properties. * Returns the format property associated with the key.
* *
* @return all media properties in a dictionary or nil if no media properties are defined * @return format property as string or nil if the key is not found
*/ */
- (NSDictionary*)getMediaProperties; - (NSString*)getStringFormatProperty:(NSString*)key;
/**
* Returns the format property associated with the key.
*
* @return format property as number or nil if the key is not found
*/
- (NSNumber*)getNumberFormatProperty:(NSString*)key;
/**
* Returns the format property associated with the key.
*
* @return format property as id or nil if the key is not found
*/
- (id)getFormatProperty:(NSString*)key;
/**
* Returns all format properties defined.
*
* @return all format properties in a dictionary or nil if no format properties are defined
*/
- (NSDictionary*)getFormatProperties;
/** /**
* Returns all properties defined. * Returns all properties defined.

View File

@ -19,7 +19,7 @@
#import "MediaInformation.h" #import "MediaInformation.h"
NSString* const MediaKeyMediaProperties = @"format"; NSString* const MediaKeyFormatProperties = @"format";
NSString* const MediaKeyFilename = @"filename"; NSString* const MediaKeyFilename = @"filename";
NSString* const MediaKeyFormat = @"format_name"; NSString* const MediaKeyFormat = @"format_name";
NSString* const MediaKeyFormatLong = @"format_long_name"; NSString* const MediaKeyFormatLong = @"format_long_name";
@ -60,35 +60,35 @@ NSString* const MediaKeyTags = @"tags";
} }
- (NSString*)getFilename { - (NSString*)getFilename {
return [self getStringProperty:MediaKeyFilename]; return [self getStringFormatProperty:MediaKeyFilename];
} }
- (NSString*)getFormat { - (NSString*)getFormat {
return [self getStringProperty:MediaKeyFormat]; return [self getStringFormatProperty:MediaKeyFormat];
} }
- (NSString*)getLongFormat { - (NSString*)getLongFormat {
return [self getStringProperty:MediaKeyFormatLong]; return [self getStringFormatProperty:MediaKeyFormatLong];
} }
- (NSString*)getStartTime { - (NSString*)getStartTime {
return [self getStringProperty:MediaKeyStartTime]; return [self getStringFormatProperty:MediaKeyStartTime];
} }
- (NSString*)getDuration { - (NSString*)getDuration {
return [self getStringProperty:MediaKeyDuration]; return [self getStringFormatProperty:MediaKeyDuration];
} }
- (NSString*)getSize { - (NSString*)getSize {
return [self getStringProperty:MediaKeySize]; return [self getStringFormatProperty:MediaKeySize];
} }
- (NSString*)getBitrate { - (NSString*)getBitrate {
return [self getStringProperty:MediaKeyBitRate]; return [self getStringFormatProperty:MediaKeyBitRate];
} }
- (NSDictionary*)getTags { - (NSDictionary*)getTags {
return [self getProperties:MediaKeyTags]; return [self getFormatProperty:MediaKeyTags];
} }
- (NSArray*)getStreams { - (NSArray*)getStreams {
@ -100,34 +100,61 @@ NSString* const MediaKeyTags = @"tags";
} }
- (NSString*)getStringProperty:(NSString*)key { - (NSString*)getStringProperty:(NSString*)key {
NSDictionary* mediaProperties = [self getMediaProperties]; NSDictionary* allProperties = [self getAllProperties];
if (mediaProperties == nil) { if (allProperties == nil) {
return nil; return nil;
} }
return mediaProperties[key]; return allProperties[key];
} }
- (NSNumber*)getNumberProperty:(NSString*)key { - (NSNumber*)getNumberProperty:(NSString*)key {
NSDictionary* mediaProperties = [self getMediaProperties]; NSDictionary* allProperties = [self getAllProperties];
if (mediaProperties == nil) { if (allProperties == nil) {
return nil; return nil;
} }
return mediaProperties[key]; return allProperties[key];
} }
- (NSDictionary*)getProperties:(NSString*)key { - (id)getProperty:(NSString*)key {
NSDictionary* mediaProperties = [self getMediaProperties]; NSDictionary* allProperties = [self getAllProperties];
if (mediaProperties == nil) { if (allProperties == nil) {
return nil; return nil;
} }
return mediaProperties[key]; return allProperties[key];
} }
- (NSDictionary*)getMediaProperties { - (NSString*)getStringFormatProperty:(NSString*)key {
return dictionary[MediaKeyMediaProperties]; NSDictionary* formatProperties = [self getFormatProperties];
if (formatProperties == nil) {
return nil;
}
return formatProperties[key];
}
- (NSNumber*)getNumberFormatProperty:(NSString*)key {
NSDictionary* formatProperties = [self getFormatProperties];
if (formatProperties == nil) {
return nil;
}
return formatProperties[key];
}
- (id)getFormatProperty:(NSString*)key {
NSDictionary* formatProperties = [self getFormatProperties];
if (formatProperties == nil) {
return nil;
}
return formatProperties[key];
}
- (NSDictionary*)getFormatProperties {
return dictionary[MediaKeyFormatProperties];
} }
- (NSDictionary*)getAllProperties { - (NSDictionary*)getAllProperties {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2021 Taner Sener * Copyright (c) 2018-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -189,11 +189,11 @@ extern NSString* const StreamKeyTags;
- (NSNumber*)getNumberProperty:(NSString*)key; - (NSNumber*)getNumberProperty:(NSString*)key;
/** /**
* Returns the stream properties associated with the key. * Returns the stream property associated with the key.
* *
* @return stream properties in a dictionary or nil if the key is not found * @return stream property as id or nil if the key is not found
*/ */
- (NSDictionary*)getProperties:(NSString*)key; - (id)getProperty:(NSString*)key;
/** /**
* Returns all stream properties defined. * Returns all stream properties defined.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2021 Taner Sener * Copyright (c) 2018-2022 Taner Sener
* *
* This file is part of FFmpegKit. * This file is part of FFmpegKit.
* *
@ -125,7 +125,7 @@ NSString* const StreamKeyTags = @"tags";
} }
- (NSDictionary*)getTags { - (NSDictionary*)getTags {
return [self getProperties:StreamKeyTags]; return [self getProperty:StreamKeyTags];
} }
- (NSString*)getStringProperty:(NSString*)key { - (NSString*)getStringProperty:(NSString*)key {
@ -138,15 +138,15 @@ NSString* const StreamKeyTags = @"tags";
} }
- (NSNumber*)getNumberProperty:(NSString*)key { - (NSNumber*)getNumberProperty:(NSString*)key {
NSDictionary* mediaProperties = [self getAllProperties]; NSDictionary* allProperties = [self getAllProperties];
if (mediaProperties == nil) { if (allProperties == nil) {
return nil; return nil;
} }
return mediaProperties[key]; return allProperties[key];
} }
- (NSDictionary*)getProperties:(NSString*)key { - (id)getProperty:(NSString*)key {
NSDictionary* allProperties = [self getAllProperties]; NSDictionary* allProperties = [self getAllProperties];
if (allProperties == nil) { if (allProperties == nil) {
return nil; return nil;

View File

@ -47,7 +47,7 @@ std::shared_ptr<std::string> ffmpegkit::Chapter::getEndTime() {
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::Chapter::getTags() { std::shared_ptr<rapidjson::Value> ffmpegkit::Chapter::getTags() {
return getProperties(KeyTags); return getProperty(KeyTags);
} }
std::shared_ptr<std::string> ffmpegkit::Chapter::getStringProperty(const char* key) { std::shared_ptr<std::string> ffmpegkit::Chapter::getStringProperty(const char* key) {
@ -66,7 +66,7 @@ std::shared_ptr<int64_t> ffmpegkit::Chapter::getNumberProperty(const char* key)
} }
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::Chapter::getProperties(const char* key) { std::shared_ptr<rapidjson::Value> ffmpegkit::Chapter::getProperty(const char* key) {
if (_chapterValue->HasMember(key)) { if (_chapterValue->HasMember(key)) {
auto value = std::make_shared<rapidjson::Value>(); auto value = std::make_shared<rapidjson::Value>();
*value = (*_chapterValue)[key]; *value = (*_chapterValue)[key];

View File

@ -73,11 +73,11 @@ namespace ffmpegkit {
std::shared_ptr<int64_t> getNumberProperty(const char* key); std::shared_ptr<int64_t> getNumberProperty(const char* key);
/** /**
* Returns the chapter properties associated with the key. * Returns the chapter property associated with the key.
* *
* @return chapter properties in a Value or nullptr if the key is not found * @return chapter property in a Value or nullptr if the key is not found
*/ */
std::shared_ptr<rapidjson::Value> getProperties(const char* key); std::shared_ptr<rapidjson::Value> getProperty(const char* key);
/** /**
* Returns all chapter properties defined. * Returns all chapter properties defined.

View File

@ -24,38 +24,38 @@ ffmpegkit::MediaInformation::MediaInformation(std::shared_ptr<rapidjson::Value>
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFilename() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFilename() {
return getStringProperty(KeyFilename); return getStringFormatProperty(KeyFilename);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFormat() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getFormat() {
return getStringProperty(KeyFormat); return getStringFormatProperty(KeyFormat);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getLongFormat() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getLongFormat() {
return getStringProperty(KeyFormatLong); return getStringFormatProperty(KeyFormatLong);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStartTime() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStartTime() {
return getStringProperty(KeyStartTime); return getStringFormatProperty(KeyStartTime);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getDuration() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getDuration() {
return getStringProperty(KeyDuration); return getStringFormatProperty(KeyDuration);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getSize() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getSize() {
return getStringProperty(KeySize); return getStringFormatProperty(KeySize);
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getBitrate() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getBitrate() {
return getStringProperty(KeyBitRate); return getStringFormatProperty(KeyBitRate);
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getTags() { std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getTags() {
auto mediaProperties = getMediaProperties(); auto formatProperties = getFormatProperties();
if (mediaProperties->HasMember(KeyTags)) { if (formatProperties->HasMember(KeyTags)) {
auto tags = std::make_shared<rapidjson::Value>(); auto tags = std::make_shared<rapidjson::Value>();
*tags = (*mediaProperties)[KeyTags]; *tags = (*formatProperties)[KeyTags];
return tags; return tags;
} else { } else {
return nullptr; return nullptr;
@ -71,37 +71,67 @@ std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::Chapter>>> ffmpegkit::Med
} }
std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStringProperty(const char* key) { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStringProperty(const char* key) {
auto mediaProperties = getMediaProperties(); auto allProperties = getAllProperties();
if (mediaProperties->HasMember(key)) { if (allProperties->HasMember(key)) {
return std::make_shared<std::string>((*mediaProperties)[key].GetString()); return std::make_shared<std::string>((*allProperties)[key].GetString());
} else { } else {
return nullptr; return nullptr;
} }
} }
std::shared_ptr<int64_t> ffmpegkit::MediaInformation::getNumberProperty(const char* key) { std::shared_ptr<int64_t> ffmpegkit::MediaInformation::getNumberProperty(const char* key) {
auto mediaProperties = getMediaProperties(); auto allProperties = getAllProperties();
if (mediaProperties->HasMember(key)) { if (allProperties->HasMember(key)) {
return std::make_shared<int64_t>((*mediaProperties)[key].GetInt64()); return std::make_shared<int64_t>((*allProperties)[key].GetInt64());
} else { } else {
return nullptr; return nullptr;
} }
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getProperties(const char* key) { std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getProperty(const char* key) {
if (_mediaInformationValue->HasMember(key)) { auto allProperties = getAllProperties();
if (allProperties->HasMember(key)) {
auto value = std::make_shared<rapidjson::Value>(); auto value = std::make_shared<rapidjson::Value>();
*value = (*_mediaInformationValue)[key]; *value = (*allProperties)[key];
return value; return value;
} else { } else {
return nullptr; return nullptr;
} }
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getMediaProperties() { std::shared_ptr<std::string> ffmpegkit::MediaInformation::getStringFormatProperty(const char* key) {
if (_mediaInformationValue->HasMember(KeyMediaProperties)) { auto formatProperties = getFormatProperties();
if (formatProperties->HasMember(key)) {
return std::make_shared<std::string>((*formatProperties)[key].GetString());
} else {
return nullptr;
}
}
std::shared_ptr<int64_t> ffmpegkit::MediaInformation::getNumberFormatProperty(const char* key) {
auto formatProperties = getFormatProperties();
if (formatProperties->HasMember(key)) {
return std::make_shared<int64_t>((*formatProperties)[key].GetInt64());
} else {
return nullptr;
}
}
std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getFormatProperty(const char* key) {
auto formatProperties = getFormatProperties();
if (formatProperties->HasMember(key)) {
auto value = std::make_shared<rapidjson::Value>();
*value = (*formatProperties)[key];
return value;
} else {
return nullptr;
}
}
std::shared_ptr<rapidjson::Value> ffmpegkit::MediaInformation::getFormatProperties() {
if (_mediaInformationValue->HasMember(KeyFormatProperties)) {
auto mediaProperties = std::make_shared<rapidjson::Value>(); auto mediaProperties = std::make_shared<rapidjson::Value>();
*mediaProperties = (*_mediaInformationValue)[KeyMediaProperties]; *mediaProperties = (*_mediaInformationValue)[KeyFormatProperties];
return mediaProperties; return mediaProperties;
} else { } else {
return nullptr; return nullptr;

View File

@ -32,7 +32,7 @@ namespace ffmpegkit {
*/ */
class MediaInformation { class MediaInformation {
public: public:
static constexpr const char* KeyMediaProperties = "format"; static constexpr const char* KeyFormatProperties = "format";
static constexpr const char* KeyFilename = "filename"; static constexpr const char* KeyFilename = "filename";
static constexpr const char* KeyFormat = "format_name"; static constexpr const char* KeyFormat = "format_name";
static constexpr const char* KeyFormatLong = "format_long_name"; static constexpr const char* KeyFormatLong = "format_long_name";
@ -115,32 +115,53 @@ namespace ffmpegkit {
std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::Chapter>>> getChapters(); std::shared_ptr<std::vector<std::shared_ptr<ffmpegkit::Chapter>>> getChapters();
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @return media property as string or nullptr if the key is not found * @return property as string or nullptr if the key is not found
*/ */
std::shared_ptr<std::string> getStringProperty(const char* key); std::shared_ptr<std::string> getStringProperty(const char* key);
/** /**
* Returns the media property associated with the key. * Returns the property associated with the key.
* *
* @return media property as number or nullptr if the key is not found * @return property as number or nullptr if the key is not found
*/ */
std::shared_ptr<int64_t> getNumberProperty(const char* key); std::shared_ptr<int64_t> getNumberProperty(const char* key);
/** /**
* Returns the media properties associated with the key. * Returns the property associated with the key.
* *
* @return media properties in a Value or nullptr if the key is not found * @return property in a Value or nullptr if the key is not found
*/ */
std::shared_ptr<rapidjson::Value> getProperties(const char* key); std::shared_ptr<rapidjson::Value> getProperty(const char* key);
/** /**
* Returns all media properties. * Returns the format property associated with the key.
* *
* @return all media properties in a Value or nullptr if no media properties are defined * @return format property as string or nullptr if the key is not found
*/ */
std::shared_ptr<rapidjson::Value> getMediaProperties(); std::shared_ptr<std::string> getStringFormatProperty(const char* key);
/**
* Returns the format property associated with the key.
*
* @return format property as number or nullptr if the key is not found
*/
std::shared_ptr<int64_t> getNumberFormatProperty(const char* key);
/**
* Returns the format property associated with the key.
*
* @return format property in a Value or nullptr if the key is not found
*/
std::shared_ptr<rapidjson::Value> getFormatProperty(const char* key);
/**
* Returns all format properties defined.
*
* @return all format properties in a Value or nullptr if no format properties are defined
*/
std::shared_ptr<rapidjson::Value> getFormatProperties();
/** /**
* Returns all properties defined. * Returns all properties defined.

View File

@ -91,7 +91,7 @@ std::shared_ptr<std::string> ffmpegkit::StreamInformation::getCodecTimeBase() {
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::StreamInformation::getTags() { std::shared_ptr<rapidjson::Value> ffmpegkit::StreamInformation::getTags() {
return getProperties(KeyTags); return getProperty(KeyTags);
} }
std::shared_ptr<std::string> ffmpegkit::StreamInformation::getStringProperty(const char* key) { std::shared_ptr<std::string> ffmpegkit::StreamInformation::getStringProperty(const char* key) {
@ -110,7 +110,7 @@ std::shared_ptr<int64_t> ffmpegkit::StreamInformation::getNumberProperty(const c
} }
} }
std::shared_ptr<rapidjson::Value> ffmpegkit::StreamInformation::getProperties(const char* key) { std::shared_ptr<rapidjson::Value> ffmpegkit::StreamInformation::getProperty(const char* key) {
if (_streamInformationValue->HasMember(key)) { if (_streamInformationValue->HasMember(key)) {
auto value = std::make_shared<rapidjson::Value>(); auto value = std::make_shared<rapidjson::Value>();
*value = (*_streamInformationValue)[key]; *value = (*_streamInformationValue)[key];

View File

@ -195,11 +195,11 @@ namespace ffmpegkit {
std::shared_ptr<int64_t> getNumberProperty(const char* key); std::shared_ptr<int64_t> getNumberProperty(const char* key);
/** /**
* Returns the stream properties associated with the key. * Returns the stream property associated with the key.
* *
* @return stream properties in a Value or nullptr if the key is not found * @return stream property in a Value or nullptr if the key is not found
*/ */
std::shared_ptr<rapidjson::Value> getProperties(const char* key); std::shared_ptr<rapidjson::Value> getProperty(const char* key);
/** /**
* Returns all stream properties defined. * Returns all stream properties defined.