diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index ace44270..eb415eda 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -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; diff --git a/src/AvTranscoder/file/InputFile.hpp b/src/AvTranscoder/file/InputFile.hpp index 46cda564..2ed6d98c 100644 --- a/src/AvTranscoder/file/InputFile.hpp +++ b/src/AvTranscoder/file/InputFile.hpp @@ -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. @@ -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; } /** diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index e4185e62..c318c771 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -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" ) diff --git a/src/AvTranscoder/file/OutputFile.hpp b/src/AvTranscoder/file/OutputFile.hpp index 8acb3f35..8a22a138 100644 --- a/src/AvTranscoder/file/OutputFile.hpp +++ b/src/AvTranscoder/file/OutputFile.hpp @@ -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; } /** diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index a98376e1..3d5225d9 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -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); diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 66e4b711..257be39d 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -19,11 +19,6 @@ namespace avtranscoder typedef std::map OptionArrayMap; typedef std::vector< std::pair > 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 */