Skip to content

Commit c5e936f

Browse files
committed
Merge pull request #198 from cchampet/dev_mimeType
InputFile/OutputFile: can get format name/long name/mime type
2 parents ae287ba + 1b0f75f commit c5e936f

File tree

6 files changed

+101
-24
lines changed

6 files changed

+101
-24
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,42 @@ InputStream& InputFile::getStream( size_t index )
116116
}
117117
}
118118

119+
120+
std::string InputFile::getFormatName() const
121+
{
122+
if( _formatContext.getAVInputFormat().name == NULL )
123+
{
124+
LOG_WARN("Unknown demuxer format name of '" << _filename << "'.")
125+
return "";
126+
}
127+
return std::string(_formatContext.getAVInputFormat().name);
128+
}
129+
130+
std::string InputFile::getFormatLongName() const
131+
{
132+
if( _formatContext.getAVInputFormat().long_name == NULL )
133+
{
134+
LOG_WARN("Unknown demuxer format long name of '" << _filename << "'.")
135+
return "";
136+
}
137+
return std::string(_formatContext.getAVInputFormat().long_name);
138+
}
139+
140+
std::string InputFile::getFormatMimeType() const
141+
{
142+
#if LIBAVFORMAT_VERSION_MAJOR <= 55
143+
LOG_WARN("Cannot get mime type format of '" << _filename << "' because your libavformat library has a major version <= 55.")
144+
return "not available";
145+
#else
146+
if( _formatContext.getAVInputFormat().mime_type == NULL )
147+
{
148+
LOG_WARN("Unknown demuxer format mime type of '" << _filename << "'.")
149+
return "";
150+
}
151+
return std::string(_formatContext.getAVInputFormat().mime_type);
152+
#endif
153+
}
154+
119155
double InputFile::getFps()
120156
{
121157
double fps = 1;

src/AvTranscoder/file/InputFile.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class AvExport InputFile
6060
* @note Activate a stream results in buffered its data when processing
6161
**/
6262
void activateStream( const size_t streamIndex, const bool activate = true );
63-
64-
/**
65-
* @return Return the resource to access
66-
**/
67-
std::string getFilename() const { return _filename; }
6863

6964
/**
7065
* @brief Return media properties on the current InputFile.
@@ -80,6 +75,23 @@ class AvExport InputFile
8075
**/
8176
InputStream& getStream( size_t index );
8277

78+
std::string getFilename() const { return _filename; }
79+
80+
/**
81+
* @brief A comma separated list of short names for the format, or empty if unknown.
82+
*/
83+
std::string getFormatName() const;
84+
85+
/**
86+
* @brief Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
87+
*/
88+
std::string getFormatLongName() const;
89+
90+
/**
91+
* @brief Comma-separated list of mime types, or empty if unknown.
92+
*/
93+
std::string getFormatMimeType() const;
94+
8395
FormatContext& getFormatContext() { return _formatContext; }
8496

8597
/**

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,36 @@ IOutputStream& OutputFile::getStream( const size_t streamId )
8585
return *_outputStreams.at( streamId );
8686
}
8787

88+
std::string OutputFile::getFormatName() const
89+
{
90+
if( _formatContext.getAVOutputFormat().name == NULL )
91+
{
92+
LOG_WARN("Unknown muxer format name of '" << _filename << "'.")
93+
return "";
94+
}
95+
return std::string(_formatContext.getAVOutputFormat().name);
96+
}
97+
98+
std::string OutputFile::getFormatLongName() const
99+
{
100+
if( _formatContext.getAVOutputFormat().long_name == NULL )
101+
{
102+
LOG_WARN("Unknown muxer format long name of '" << _filename << "'.")
103+
return "";
104+
}
105+
return std::string(_formatContext.getAVOutputFormat().long_name);
106+
}
107+
108+
std::string OutputFile::getFormatMimeType() const
109+
{
110+
if( _formatContext.getAVOutputFormat().mime_type == NULL )
111+
{
112+
LOG_WARN("Unknown muxer format mime type of '" << _filename << "'.")
113+
return "";
114+
}
115+
return std::string(_formatContext.getAVOutputFormat().mime_type);
116+
}
117+
88118
bool OutputFile::beginWrap( )
89119
{
90120
LOG_DEBUG( "Begin wrap of OutputFile" )

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ class AvExport OutputFile : public IOutputFile
5353
void addMetadata( const std::string& key, const std::string& value );
5454

5555
IOutputStream& getStream( const size_t streamId );
56+
57+
std::string getFilename() const { return _filename; }
58+
59+
/**
60+
* @brief A comma separated list of short names for the format, or empty if unknown.
61+
*/
62+
std::string getFormatName() const;
63+
64+
/**
65+
* @brief Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
66+
*/
67+
std::string getFormatLongName() const;
68+
69+
/**
70+
* @brief Comma-separated list of mime types, or empty if unknown.
71+
*/
72+
std::string getFormatMimeType() const;
73+
5674
FormatContext& getFormatContext() { return _formatContext; }
5775

5876
/**

src/AvTranscoder/util.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ extern "C" {
1212
namespace avtranscoder
1313
{
1414

15-
std::string getFormat( const std::string& filename )
16-
{
17-
std::string format( "" );
18-
19-
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
20-
if( avOutputFormat )
21-
{
22-
if( avOutputFormat->name )
23-
format = std::string( avOutputFormat->name );
24-
}
25-
26-
return format;
27-
}
28-
2915
bool matchFormat( const std::string& format, const std::string& filename )
3016
{
3117
AVOutputFormat* avOutputFormat = av_guess_format( format.c_str(), filename.c_str(), NULL);

src/AvTranscoder/util.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace avtranscoder
1919
typedef std::map<std::string, OptionArray> OptionArrayMap;
2020
typedef std::vector< std::pair<std::string, std::string> > NamesArray; //< short/long names of format/video codec/audio codec
2121

22-
/**
23-
* @brief Get format name from a given filename
24-
*/
25-
std::string AvExport getFormat( const std::string& filename );
26-
2722
/**
2823
* @brief Check if a format name corresponds to the format of a given filename
2924
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy