Skip to content

InputFile/OutputFile: can get format name/long name/mime type #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/AvTranscoder/file/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,42 @@ InputStream& InputFile::getStream( size_t index )
}
}


std::string InputFile::getFormatName() const
{
if( _formatContext.getAVInputFormat().name == NULL )
{
LOG_WARN("Unknown demuxer format name of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVInputFormat().name);
}

std::string InputFile::getFormatLongName() const
{
if( _formatContext.getAVInputFormat().long_name == NULL )
{
LOG_WARN("Unknown demuxer format long name of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVInputFormat().long_name);
}

std::string InputFile::getFormatMimeType() const
{
#if LIBAVFORMAT_VERSION_MAJOR <= 55
LOG_WARN("Cannot get mime type format of '" << _filename << "' because your libavformat library has a major version <= 55.")
return "not available";
#else
if( _formatContext.getAVInputFormat().mime_type == NULL )
{
LOG_WARN("Unknown demuxer format mime type of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVInputFormat().mime_type);
#endif
}

double InputFile::getFps()
{
double fps = 1;
Expand Down
22 changes: 17 additions & 5 deletions src/AvTranscoder/file/InputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class AvExport InputFile
* @note Activate a stream results in buffered its data when processing
**/
void activateStream( const size_t streamIndex, const bool activate = true );

/**
* @return Return the resource to access
**/
std::string getFilename() const { return _filename; }

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

std::string getFilename() const { return _filename; }

/**
* @brief A comma separated list of short names for the format, or empty if unknown.
*/
std::string getFormatName() const;

/**
* @brief Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
*/
std::string getFormatLongName() const;

/**
* @brief Comma-separated list of mime types, or empty if unknown.
*/
std::string getFormatMimeType() const;

FormatContext& getFormatContext() { return _formatContext; }

/**
Expand Down
30 changes: 30 additions & 0 deletions src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ IOutputStream& OutputFile::getStream( const size_t streamId )
return *_outputStreams.at( streamId );
}

std::string OutputFile::getFormatName() const
{
if( _formatContext.getAVOutputFormat().name == NULL )
{
LOG_WARN("Unknown muxer format name of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVOutputFormat().name);
}

std::string OutputFile::getFormatLongName() const
{
if( _formatContext.getAVOutputFormat().long_name == NULL )
{
LOG_WARN("Unknown muxer format long name of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVOutputFormat().long_name);
}

std::string OutputFile::getFormatMimeType() const
{
if( _formatContext.getAVOutputFormat().mime_type == NULL )
{
LOG_WARN("Unknown muxer format mime type of '" << _filename << "'.")
return "";
}
return std::string(_formatContext.getAVOutputFormat().mime_type);
}

bool OutputFile::beginWrap( )
{
LOG_DEBUG( "Begin wrap of OutputFile" )
Expand Down
18 changes: 18 additions & 0 deletions src/AvTranscoder/file/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ class AvExport OutputFile : public IOutputFile
void addMetadata( const std::string& key, const std::string& value );

IOutputStream& getStream( const size_t streamId );

std::string getFilename() const { return _filename; }

/**
* @brief A comma separated list of short names for the format, or empty if unknown.
*/
std::string getFormatName() const;

/**
* @brief Descriptive name for the format, meant to be more human-readable than name, or empty if unknown.
*/
std::string getFormatLongName() const;

/**
* @brief Comma-separated list of mime types, or empty if unknown.
*/
std::string getFormatMimeType() const;

FormatContext& getFormatContext() { return _formatContext; }

/**
Expand Down
14 changes: 0 additions & 14 deletions src/AvTranscoder/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ extern "C" {
namespace avtranscoder
{

std::string getFormat( const std::string& filename )
{
std::string format( "" );

AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
if( avOutputFormat )
{
if( avOutputFormat->name )
format = std::string( avOutputFormat->name );
}

return format;
}

bool matchFormat( const std::string& format, const std::string& filename )
{
AVOutputFormat* avOutputFormat = av_guess_format( format.c_str(), filename.c_str(), NULL);
Expand Down
5 changes: 0 additions & 5 deletions src/AvTranscoder/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ namespace avtranscoder
typedef std::map<std::string, OptionArray> OptionArrayMap;
typedef std::vector< std::pair<std::string, std::string> > NamesArray; //< short/long names of format/video codec/audio codec

/**
* @brief Get format name from a given filename
*/
std::string AvExport getFormat( const std::string& filename );

/**
* @brief Check if a format name corresponds to the format of a given filename
*/
Expand Down