rpcsx/rpcs3/util/media_utils.h

38 lines
1,023 B
C
Raw Normal View History

#pragma once
#include <unordered_map>
namespace utils
{
struct media_info
{
2022-02-20 19:01:21 +01:00
std::string path;
s32 audio_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
s32 video_av_codec_id = 0; // 0 = AV_CODEC_ID_NONE
s32 audio_bitrate_bps = 0; // Bit rate in bit/s
s32 video_bitrate_bps = 0; // Bit rate in bit/s
s32 sample_rate = 0; // Samples per second
s64 duration_us = 0; // in AV_TIME_BASE fractional seconds (= microseconds)
std::unordered_map<std::string, std::string> metadata;
// Convenience function for metadata
template <typename T>
T get_metadata(const std::string& key, const T& def) const;
};
std::pair<bool, media_info> get_media_info(const std::string& path, s32 av_media_type);
template <typename D>
void parse_metadata(D& dst, const utils::media_info& mi, const std::string& key, const std::string& def, usz max_length)
{
std::string value = mi.get_metadata<std::string>(key, def);
if (value.size() > max_length)
{
value.resize(max_length);
}
strcpy_trunc(dst, value);
};
}