forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileProperties.hpp
More file actions
136 lines (114 loc) · 6 KB
/
FileProperties.hpp
File metadata and controls
136 lines (114 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _AV_TRANSCODER_MEDIA_PROPERTY_FILE_PROPERTIES_HPP
#define _AV_TRANSCODER_MEDIA_PROPERTY_FILE_PROPERTIES_HPP
#include <AvTranscoder/common.hpp>
#include <AvTranscoder/properties/util.hpp>
#include <AvTranscoder/file/InputFile.hpp>
#include <AvTranscoder/progress/IProgress.hpp>
#include <AvTranscoder/properties/StreamProperties.hpp>
#include <AvTranscoder/properties/VideoProperties.hpp>
#include <AvTranscoder/properties/AudioProperties.hpp>
#include <AvTranscoder/properties/DataProperties.hpp>
#include <AvTranscoder/properties/SubtitleProperties.hpp>
#include <AvTranscoder/properties/AttachementProperties.hpp>
#include <AvTranscoder/properties/UnknownProperties.hpp>
#include <string>
#include <vector>
#include <map>
namespace avtranscoder
{
class AvExport FileProperties
{
public:
/**
* @brief Analayse a file from its FormatContext
* @note The default streams analyse level is eAnalyseLevelHeader
* @see FormatContext
*/
FileProperties(const InputFile& file);
/**
* @brief Relaunch streams analysis with a specific level.
* @param progress callback to get analysis progression
* @param level of analysis
*/
void extractStreamProperties(IProgress& progress, const EAnalyseLevel level);
std::string getFilename() const;
std::string getFormatName() const; ///< A comma separated list of short names for the format, or empty if unknown.
std::string getFormatLongName()
const; ///< Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
bool isRawFormat() const; ///< Is there a container, or a raw bitstreams without access to timing information.
std::string getFormatMimeType() const; ///< Comma-separated list of mime types, or empty if unknown.
size_t getProgramsCount() const;
double getStartTime() const;
float getDuration() const; ///< in seconds, 0 if not available
size_t getBitRate() const; ///< total stream bitrate in bit/s, 0 if not available (result of a computation by ffmpeg)
/**
* @note Use uint64_t instead of size_t to ensure 64 bits size on 32-bits OS so we can manage Files > 4Go
*/
uint64_t getFileSize() const; ///< in bytes
size_t getPacketSize() const;
const PropertyVector& getMetadatas() const { return _metadatas; }
size_t getNbStreams() const;
size_t getNbVideoStreams() const { return _videoStreams.size(); }
size_t getNbAudioStreams() const { return _audioStreams.size(); }
size_t getNbDataStreams() const { return _dataStreams.size(); }
size_t getNbSubtitleStreams() const { return _subtitleStreams.size(); }
size_t getNbAttachementStreams() const { return _attachementStreams.size(); }
size_t getNbUnknownStreams() const { return _unknownStreams.size(); }
const InputFile& getInputFile() const { return _file; }
//@{
// @brief Get the properties at the indicated stream index
// @throws A runtime error if the streamIndex does not match any stream
const avtranscoder::StreamProperties& getStreamPropertiesWithIndex(const size_t streamIndex) const;
//@}
//@{
// @brief Get the list of properties for a given type (video, audio...)
const std::vector<avtranscoder::StreamProperties*> getStreamProperties() const;
const std::vector<avtranscoder::VideoProperties>& getVideoProperties() const { return _videoStreams; }
const std::vector<avtranscoder::AudioProperties>& getAudioProperties() const { return _audioStreams; }
const std::vector<avtranscoder::DataProperties>& getDataProperties() const { return _dataStreams; }
const std::vector<avtranscoder::SubtitleProperties>& getSubtitleProperties() const { return _subtitleStreams; }
const std::vector<avtranscoder::AttachementProperties>& getAttachementProperties() const { return _attachementStreams; }
const std::vector<avtranscoder::UnknownProperties>& getUnknownProperties() const { return _unknownStreams; }
//@}
#ifndef SWIG
const AVFormatContext& getAVFormatContext() const { return *_avFormatContext; }
#endif
std::string allPropertiesAsJson() const; ///< Return all properties as a json format.
std::string asJson() const; ///< Return all format properties as a json format.
PropertyMap asMap() const; ///< Return format properties as a map (name of property, value)
PropertyVector asVector() const; ///< Return format properties as a vector (name of property: value)
PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
private:
#ifndef SWIG
template <typename T>
void addProperty(PropertyVector& data, const std::string& key, T (FileProperties::*getter)(void) const) const
{
try
{
detail::add(data, key, (this->*getter)());
}
catch(const std::exception& e)
{
detail::add(data, key, detail::propertyValueIfError);
}
}
#endif
private:
const InputFile& _file; ///< Has link (no ownership)
const FormatContext* _formatContext; ///< Has link (no ownership)
const AVFormatContext* _avFormatContext; ///< Has link (no ownership)
std::map<size_t, StreamProperties*>
_streamsProperties; ///< Map of properties per stream index (of all types) - only references to the following properties
std::vector<VideoProperties> _videoStreams; ///< Array of properties per video stream
std::vector<AudioProperties> _audioStreams; ///< Array of properties per audio stream
std::vector<DataProperties> _dataStreams; ///< Array of properties per data stream
std::vector<SubtitleProperties> _subtitleStreams; ///< Array of properties per subtitle stream
std::vector<AttachementProperties> _attachementStreams; ///< Array of properties per attachement stream
std::vector<UnknownProperties> _unknownStreams; ///< Array of properties per unknown stream
PropertyVector _metadatas;
};
#ifndef SWIG
AvExport std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties);
#endif
}
#endif