diff --git a/.travis.yml b/.travis.yml index 9d565e17..08f7ca96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,14 @@ +env: + matrix: + - DEPENDENCY_MODE=libav + - DEPENDENCY_MODE=ffmpeg + +language: cpp + os: - linux - osx -language: cpp - compiler: - gcc - clang @@ -28,4 +33,4 @@ script: # Launch tests - cd .. - chmod +x tools/travis.python.nosetests.sh - - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./tools/travis.python.nosetests.sh; fi + - if [ "${TRAVIS_OS_NAME}" = "linux" && "${DEPENDENCY_MODE}" = "ffmpeg" ]; then ./tools/travis.python.nosetests.sh; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index c1a87a08..851b02de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(AvTranscoder) # Set AvTranscoder versions set(AVTRANSCODER_VERSION_MAJOR "0") set(AVTRANSCODER_VERSION_MINOR "5") -set(AVTRANSCODER_VERSION_MICRO "4") +set(AVTRANSCODER_VERSION_MICRO "5") set(AVTRANSCODER_VERSION ${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO}) # Define AvTranscoder versions diff --git a/ressource/v_h264.prf b/ressource/v_h264.prf deleted file mode 100644 index 2f3fe261..00000000 --- a/ressource/v_h264.prf +++ /dev/null @@ -1,5 +0,0 @@ -avProfileName=h264 -avProfileLongName=h264 High -avProfileType=avProfileTypeVideo -codec=h264 -profile=High diff --git a/ressource/v_h264_hq.prf b/ressource/v_h264_hq.prf new file mode 100755 index 00000000..28b5fec0 --- /dev/null +++ b/ressource/v_h264_hq.prf @@ -0,0 +1,9 @@ +avProfileName=h264-hq +avProfileLongName=H.264 High Quality +avProfileType=avProfileTypeVideo +codec=h264 +pix_fmt=yuv422p +profile=high422 +preset=slow +tune=fastdecode,zerolatency +level=5 diff --git a/ressource/v_h264_lq.prf b/ressource/v_h264_lq.prf new file mode 100755 index 00000000..396bd0b9 --- /dev/null +++ b/ressource/v_h264_lq.prf @@ -0,0 +1,9 @@ +avProfileName=h264-lq +avProfileLongName=H.264 Low Quality +avProfileType=avProfileTypeVideo +codec=h264 +pix_fmt=yuv420p +profile=baseline +preset=ultrafast +tune=fastdecode,zerolatency +level=3 diff --git a/src/AvTranscoder/avTranscoder.i b/src/AvTranscoder/avTranscoder.i index 6ea1ddd8..8d463428 100644 --- a/src/AvTranscoder/avTranscoder.i +++ b/src/AvTranscoder/avTranscoder.i @@ -16,23 +16,19 @@ %{ #include -#include #include %} -namespace std { -%template(IntPair) pair< size_t, size_t >; -} - %include "AvTranscoder/progress/progress.i" %include "AvTranscoder/mediaProperty/mediaProperty.i" %include "AvTranscoder/frame/frame.i" %include "AvTranscoder/profile/profile.i" %include -%include %include +%include "AvTranscoder/option.i" +%include "AvTranscoder/util.i" %include "AvTranscoder/codec/codec.i" %include "AvTranscoder/stream/stream.i" %include "AvTranscoder/decoder/decoder.i" diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index b7bbf9aa..21e91d16 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -147,6 +147,8 @@ bool AudioDecoder::decodeNextFrame() void AudioDecoder::setProfile( const ProfileLoader::Profile& profile ) { + LOG_DEBUG( "Set profile of audio decoder with:\n" << profile ) + AudioCodec& codec = _inputStream->getAudioCodec(); // set threads before any other options diff --git a/src/AvTranscoder/decoder/VideoDecoder.cpp b/src/AvTranscoder/decoder/VideoDecoder.cpp index 2dca1a8e..8e8b4543 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.cpp +++ b/src/AvTranscoder/decoder/VideoDecoder.cpp @@ -105,7 +105,9 @@ void VideoDecoder::flushDecoder() } void VideoDecoder::setProfile( const ProfileLoader::Profile& profile ) -{ +{ + LOG_DEBUG( "Set profile of video decoder with:\n" << profile ) + VideoCodec& codec = _inputStream->getVideoCodec(); // set threads before any other options diff --git a/src/AvTranscoder/encoder/AudioEncoder.cpp b/src/AvTranscoder/encoder/AudioEncoder.cpp index ca250e06..bb3d6acb 100644 --- a/src/AvTranscoder/encoder/AudioEncoder.cpp +++ b/src/AvTranscoder/encoder/AudioEncoder.cpp @@ -135,6 +135,8 @@ bool AudioEncoder::encodeFrame( Frame& codedFrame ) void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const AudioFrameDesc& frameDesc ) { + LOG_DEBUG( "Set profile of audio encoder with:\n" << profile ) + // set sampleRate, number of channels, sample format _codec.setAudioParameters( frameDesc ); diff --git a/src/AvTranscoder/encoder/VideoEncoder.cpp b/src/AvTranscoder/encoder/VideoEncoder.cpp index 2272add6..1b462417 100644 --- a/src/AvTranscoder/encoder/VideoEncoder.cpp +++ b/src/AvTranscoder/encoder/VideoEncoder.cpp @@ -128,6 +128,8 @@ bool VideoEncoder::encodeFrame( Frame& codedFrame ) void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtranscoder::VideoFrameDesc& frameDesc ) { + LOG_DEBUG( "Set profile of video encoder with:\n" << profile ) + // set width, height, pixel format, fps _codec.setImageParameters( frameDesc ); diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index f87b66c0..e0cfda87 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -199,7 +199,9 @@ double InputFile::getFps() } void InputFile::setProfile( const ProfileLoader::Profile& profile ) -{ +{ + LOG_DEBUG( "Set profile of input file with:\n" << profile ) + for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it ) { if( (*it).first == constants::avProfileIdentificator || diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index 5177bf79..1e4c38dd 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -132,9 +132,9 @@ bool OutputFile::endWrap( ) return true; } -void OutputFile::addMetadata( const PropertiesMap& dataMap ) +void OutputFile::addMetadata( const PropertyVector& data ) { - for( PropertiesMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it ) + for( PropertyVector::const_iterator it = data.begin(); it != data.end(); ++it ) { addMetadata( it->first, it->second ); } @@ -147,6 +147,8 @@ void OutputFile::addMetadata( const std::string& key, const std::string& value ) void OutputFile::setProfile( const ProfileLoader::Profile& profile ) { + LOG_DEBUG( "Set profile of output file with:\n" << profile ) + // check if output format indicated is valid with the filename extension if( ! matchFormat( profile.find( constants::avProfileFormat )->second, _filename ) ) { diff --git a/src/AvTranscoder/file/OutputFile.hpp b/src/AvTranscoder/file/OutputFile.hpp index e7a44147..d48222c1 100644 --- a/src/AvTranscoder/file/OutputFile.hpp +++ b/src/AvTranscoder/file/OutputFile.hpp @@ -41,7 +41,7 @@ class AvExport OutputFile : public IOutputFile * @brief Add metadata to the output file. * @note Depending on the format, you are not sure to find your metadata after the transcode. */ - void addMetadata( const PropertiesMap& dataMap ); + void addMetadata( const PropertyVector& data ); void addMetadata( const std::string& key, const std::string& value ); IOutputStream& getStream( const size_t streamId ); diff --git a/src/AvTranscoder/mediaProperty/AttachementProperties.cpp b/src/AvTranscoder/mediaProperty/AttachementProperties.cpp deleted file mode 100644 index 0424ce55..00000000 --- a/src/AvTranscoder/mediaProperty/AttachementProperties.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "AttachementProperties.hpp" - -#include - -namespace avtranscoder -{ - -AttachementProperties::AttachementProperties( const FormatContext& formatContext, const size_t index ) - : _formatContext( &formatContext.getAVFormatContext() ) - , _streamIndex( index ) -{ - if( _formatContext ) - detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas ); -} - -size_t AttachementProperties::getStreamId() const -{ - if( ! _formatContext ) - throw std::runtime_error( "unknown format context" ); - return _formatContext->streams[_streamIndex]->id; -} - -PropertiesMap AttachementProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - try - { - detail::add( dataMap, "streamId", getStreamId() ); - } - catch( const std::exception& e ) - { - detail::add( dataMap, "streamId", e.what() ); - } - - for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) - { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); - } - - return dataMap; -} - -} diff --git a/src/AvTranscoder/mediaProperty/AttachementProperties.hpp b/src/AvTranscoder/mediaProperty/AttachementProperties.hpp index 4d5af3ca..944c6a77 100644 --- a/src/AvTranscoder/mediaProperty/AttachementProperties.hpp +++ b/src/AvTranscoder/mediaProperty/AttachementProperties.hpp @@ -1,33 +1,17 @@ #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_ATTACHEMENT_PROPERTIES_HPP #define _AV_TRANSCODER_MEDIA_PROPERTY_ATTACHEMENT_PROPERTIES_HPP -#include -#include -#include +#include namespace avtranscoder { -class AvExport AttachementProperties +class AvExport AttachementProperties: public StreamProperties { public: - AttachementProperties( const FormatContext& formatContext, const size_t index ); - - size_t getStreamIndex() const { return _streamIndex; } - size_t getStreamId() const; - PropertiesMap& getMetadatas() { return _metadatas; } - -#ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } -#endif - - PropertiesMap getPropertiesAsMap() const; ///< Return all attachement properties as a map (name of property: value) - -private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) - - size_t _streamIndex; - PropertiesMap _metadatas; + AttachementProperties( const FormatContext& formatContext, const size_t index ) + : StreamProperties( formatContext, index ) + {} }; } diff --git a/src/AvTranscoder/mediaProperty/AudioProperties.cpp b/src/AvTranscoder/mediaProperty/AudioProperties.cpp index f30698b3..ac0412bd 100644 --- a/src/AvTranscoder/mediaProperty/AudioProperties.cpp +++ b/src/AvTranscoder/mediaProperty/AudioProperties.cpp @@ -14,10 +14,7 @@ namespace avtranscoder { AudioProperties::AudioProperties( const FormatContext& formatContext, const size_t index ) - : _formatContext( &formatContext.getAVFormatContext() ) - , _codecContext( NULL ) - , _codec( NULL ) - , _streamIndex( index ) + : StreamProperties( formatContext, index ) { if( _formatContext ) _codecContext = _formatContext->streams[index]->codec; @@ -202,33 +199,34 @@ double AudioProperties::getDuration() const return duration; } -PropertiesMap AudioProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - addProperty( dataMap, "streamId", &AudioProperties::getStreamId ); - addProperty( dataMap, "codecId", &AudioProperties::getCodecId ); - addProperty( dataMap, "codecName", &AudioProperties::getCodecName ); - addProperty( dataMap, "codecLongName", &AudioProperties::getCodecLongName ); - addProperty( dataMap, "sampleFormatName", &AudioProperties::getSampleFormatName ); - addProperty( dataMap, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName ); - addProperty( dataMap, "sampleRate", &AudioProperties::getSampleRate ); - addProperty( dataMap, "bitRate", &AudioProperties::getBitRate ); - addProperty( dataMap, "nbSamples", &AudioProperties::getNbSamples ); - addProperty( dataMap, "channels", &AudioProperties::getChannels ); - addProperty( dataMap, "channelLayout", &AudioProperties::getChannelLayout ); - addProperty( dataMap, "channelName", &AudioProperties::getChannelName ); - addProperty( dataMap, "channelDescription", &AudioProperties::getChannelDescription ); - addProperty( dataMap, "ticksPerFrame", &AudioProperties::getTicksPerFrame ); - addProperty( dataMap, "timeBase", &AudioProperties::getTimeBase ); - addProperty( dataMap, "duration", &AudioProperties::getDuration ); +PropertyVector AudioProperties::getPropertiesAsVector() const +{ + PropertyVector data; + + addProperty( data, "streamId", &AudioProperties::getStreamId ); + detail::add( data, "streamIndex", getStreamIndex() ); + addProperty( data, "codecId", &AudioProperties::getCodecId ); + addProperty( data, "codecName", &AudioProperties::getCodecName ); + addProperty( data, "codecLongName", &AudioProperties::getCodecLongName ); + addProperty( data, "sampleFormatName", &AudioProperties::getSampleFormatName ); + addProperty( data, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName ); + addProperty( data, "sampleRate", &AudioProperties::getSampleRate ); + addProperty( data, "bitRate", &AudioProperties::getBitRate ); + addProperty( data, "nbSamples", &AudioProperties::getNbSamples ); + addProperty( data, "channels", &AudioProperties::getChannels ); + addProperty( data, "channelLayout", &AudioProperties::getChannelLayout ); + addProperty( data, "channelName", &AudioProperties::getChannelName ); + addProperty( data, "channelDescription", &AudioProperties::getChannelDescription ); + addProperty( data, "ticksPerFrame", &AudioProperties::getTicksPerFrame ); + addProperty( data, "timeBase", &AudioProperties::getTimeBase ); + addProperty( data, "duration", &AudioProperties::getDuration ); for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); + detail::add( data, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); } - return dataMap; + return data; } } diff --git a/src/AvTranscoder/mediaProperty/AudioProperties.hpp b/src/AvTranscoder/mediaProperty/AudioProperties.hpp index 54805c33..06952be9 100644 --- a/src/AvTranscoder/mediaProperty/AudioProperties.hpp +++ b/src/AvTranscoder/mediaProperty/AudioProperties.hpp @@ -1,16 +1,14 @@ #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_AUDIO_PROPERTIES_HPP #define _AV_TRANSCODER_MEDIA_PROPERTY_AUDIO_PROPERTIES_HPP -#include -#include -#include +#include #include namespace avtranscoder { -class AvExport AudioProperties +class AvExport AudioProperties : public StreamProperties { public: AudioProperties( const FormatContext& formatContext, const size_t index ); @@ -23,7 +21,6 @@ class AvExport AudioProperties std::string getChannelName() const; std::string getChannelDescription() const; - size_t getStreamIndex() const { return _streamIndex; } size_t getStreamId() const; size_t getCodecId() const; size_t getSampleRate() const; @@ -35,38 +32,31 @@ class AvExport AudioProperties Rational getTimeBase() const; double getDuration() const; - PropertiesMap& getMetadatas() { return _metadatas; } - #ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } AVCodecContext& getAVCodecContext() { return *_codecContext; } #endif - PropertiesMap getPropertiesAsMap() const; ///< Return all audio properties as a map (name of property: value) + PropertyVector getPropertiesAsVector() const; private: #ifndef SWIG template - void addProperty( PropertiesMap& dataMap, const std::string& key, T (AudioProperties::*getter)(void) const ) const + void addProperty( PropertyVector& data, const std::string& key, T (AudioProperties::*getter)(void) const ) const { try { - detail::add( dataMap, key, (this->*getter)() ); + detail::add( data, key, (this->*getter)() ); } catch( const std::exception& e ) { - detail::add( dataMap, key, e.what() ); + detail::add( data, key, e.what() ); } } #endif private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) AVCodecContext* _codecContext; ///< Has link (no ownership) AVCodec* _codec; ///< Has link (no ownership) - - size_t _streamIndex; - PropertiesMap _metadatas; }; } diff --git a/src/AvTranscoder/mediaProperty/DataProperties.cpp b/src/AvTranscoder/mediaProperty/DataProperties.cpp index fb876a5d..b552dda4 100644 --- a/src/AvTranscoder/mediaProperty/DataProperties.cpp +++ b/src/AvTranscoder/mediaProperty/DataProperties.cpp @@ -2,54 +2,13 @@ extern "C" { #include -#include -#include } #include -#include namespace avtranscoder { -DataProperties::DataProperties( const FormatContext& formatContext, const size_t index ) - : _formatContext( &formatContext.getAVFormatContext() ) - , _streamIndex( index ) -{ - //detectAncillaryData( _formatContext, _streamIndex ); - - if( _formatContext ) - detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas ); -} - -size_t DataProperties::getStreamId() const -{ - if( ! _formatContext ) - throw std::runtime_error( "unknown format context" ); - return _formatContext->streams[_streamIndex]->id; -} - -PropertiesMap DataProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - try - { - detail::add( dataMap, "streamId", getStreamId() ); - } - catch( const std::exception& e ) - { - detail::add( dataMap, "streamId", e.what() ); - } - - for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) - { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); - } - - return dataMap; -} - void DataProperties::detectAncillaryData() { AVPacket pkt; diff --git a/src/AvTranscoder/mediaProperty/DataProperties.hpp b/src/AvTranscoder/mediaProperty/DataProperties.hpp index 53ae480a..55c44d28 100644 --- a/src/AvTranscoder/mediaProperty/DataProperties.hpp +++ b/src/AvTranscoder/mediaProperty/DataProperties.hpp @@ -1,36 +1,20 @@ #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_DATA_PROPERTIES_HPP #define _AV_TRANSCODER_MEDIA_PROPERTY_DATA_PROPERTIES_HPP -#include -#include -#include +#include namespace avtranscoder { -class AvExport DataProperties +class AvExport DataProperties : public StreamProperties { public: - DataProperties( const FormatContext& formatContext, const size_t index ); - - size_t getStreamIndex() const { return _streamIndex; } - size_t getStreamId() const; - PropertiesMap& getMetadatas() { return _metadatas; } - -#ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } -#endif - - PropertiesMap getPropertiesAsMap() const; ///< Return all data properties as a map (name of property: value) + DataProperties( const FormatContext& formatContext, const size_t index ) + : StreamProperties( formatContext, index ) + {} private: void detectAncillaryData(); - -private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) - - size_t _streamIndex; - PropertiesMap _metadatas; }; } diff --git a/src/AvTranscoder/mediaProperty/FileProperties.cpp b/src/AvTranscoder/mediaProperty/FileProperties.cpp index 76a87c7e..14870dd9 100644 --- a/src/AvTranscoder/mediaProperty/FileProperties.cpp +++ b/src/AvTranscoder/mediaProperty/FileProperties.cpp @@ -129,33 +129,33 @@ size_t FileProperties::getNbStreams() const return _formatContext->nb_streams; } -PropertiesMap FileProperties::getPropertiesAsMap() const +PropertyVector FileProperties::getPropertiesAsVector() const { - PropertiesMap dataMap; + PropertyVector data; - addProperty( dataMap, "filename", &FileProperties::getFilename ); - addProperty( dataMap, "formatName", &FileProperties::getFormatName ); - addProperty( dataMap, "formatLongName", &FileProperties::getFormatLongName ); + addProperty( data, "filename", &FileProperties::getFilename ); + addProperty( data, "formatName", &FileProperties::getFormatName ); + addProperty( data, "formatLongName", &FileProperties::getFormatLongName ); - addProperty( dataMap, "startTime", &FileProperties::getStartTime ); - addProperty( dataMap, "duration", &FileProperties::getDuration ); - addProperty( dataMap, "bitrate", &FileProperties::getBitRate ); - addProperty( dataMap, "numberOfStreams", &FileProperties::getNbStreams ); - addProperty( dataMap, "numberOfPrograms", &FileProperties::getProgramsCount ); + addProperty( data, "startTime", &FileProperties::getStartTime ); + addProperty( data, "duration", &FileProperties::getDuration ); + addProperty( data, "bitrate", &FileProperties::getBitRate ); + addProperty( data, "numberOfStreams", &FileProperties::getNbStreams ); + addProperty( data, "numberOfPrograms", &FileProperties::getProgramsCount ); - detail::add( dataMap, "numberOfVideoStreams", getNbVideoStreams() ); - detail::add( dataMap, "numberOfAudioStreams", getNbAudioStreams() ); - detail::add( dataMap, "numberOfDataStreams", getNbDataStreams() ); - detail::add( dataMap, "numberOfSubtitleStreams", getNbSubtitleStreams() ); - detail::add( dataMap, "numberOfAttachementStreams", getNbAttachementStreams() ); - detail::add( dataMap, "numberOfUnknownStreams", getNbUnknownStreams() ); + detail::add( data, "numberOfVideoStreams", getNbVideoStreams() ); + detail::add( data, "numberOfAudioStreams", getNbAudioStreams() ); + detail::add( data, "numberOfDataStreams", getNbDataStreams() ); + detail::add( data, "numberOfSubtitleStreams", getNbSubtitleStreams() ); + detail::add( data, "numberOfAttachementStreams", getNbAttachementStreams() ); + detail::add( data, "numberOfUnknownStreams", getNbUnknownStreams() ); for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); + detail::add( data, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); } - return dataMap; + return data; } void FileProperties::clearStreamProperties() diff --git a/src/AvTranscoder/mediaProperty/FileProperties.hpp b/src/AvTranscoder/mediaProperty/FileProperties.hpp index 98dc1ce7..82747b1f 100644 --- a/src/AvTranscoder/mediaProperty/FileProperties.hpp +++ b/src/AvTranscoder/mediaProperty/FileProperties.hpp @@ -32,7 +32,7 @@ class AvExport FileProperties size_t getBitRate() const; ///< total stream bitrate in bit/s, 0 if not available (result of a computation by ffmpeg) size_t getPacketSize() const; - PropertiesMap& getMetadatas() { return _metadatas; } + PropertyVector& getMetadatas() { return _metadatas; } size_t getNbStreams() const; size_t getNbVideoStreams() const { return _videoStreams.size(); } @@ -72,22 +72,22 @@ class AvExport FileProperties const std::vector< avtranscoder::UnknownProperties >& getUnknownPropertiesProperties() const { return _unknownStreams; } #endif - PropertiesMap getPropertiesAsMap() const; ///< Return all file properties as a map (name of property: value) + PropertyVector getPropertiesAsVector() const; ///< Return all file properties as a vector (name of property: value) void clearStreamProperties(); ///< Clear all array of stream properties private: #ifndef SWIG template - void addProperty( PropertiesMap& dataMap, const std::string& key, T (FileProperties::*getter)(void) const ) const + void addProperty( PropertyVector& data, const std::string& key, T (FileProperties::*getter)(void) const ) const { try { - detail::add( dataMap, key, (this->*getter)() ); + detail::add( data, key, (this->*getter)() ); } catch( const std::exception& e ) { - detail::add( dataMap, key, e.what() ); + detail::add( data, key, e.what() ); } } #endif @@ -102,7 +102,7 @@ class AvExport FileProperties std::vector< AttachementProperties > _attachementStreams; ///< Array of properties per attachement stream std::vector< UnknownProperties > _unknownStreams; ///< Array of properties per unknown stream - PropertiesMap _metadatas; + PropertyVector _metadatas; }; } diff --git a/src/AvTranscoder/mediaProperty/PixelProperties.cpp b/src/AvTranscoder/mediaProperty/PixelProperties.cpp index f18fa7a8..e476c435 100644 --- a/src/AvTranscoder/mediaProperty/PixelProperties.cpp +++ b/src/AvTranscoder/mediaProperty/PixelProperties.cpp @@ -223,16 +223,16 @@ std::vector PixelProperties::getChannels() const return channels; } -PropertiesMap PixelProperties::getPropertiesAsMap() const +PropertyVector PixelProperties::getPropertiesAsVector() const { - PropertiesMap dataMap; + PropertyVector data; - addProperty( dataMap, "pixelName", &PixelProperties::getPixelName ); - addProperty( dataMap, "pixelFormatName", &PixelProperties::getPixelFormatName ); - addProperty( dataMap, "bitDepth", &PixelProperties::getBitsPerPixel ); - addProperty( dataMap, "nbComponents", &PixelProperties::getNbComponents ); - addProperty( dataMap, "chromaWidth", &PixelProperties::getChromaWidth ); - addProperty( dataMap, "chromaHeight", &PixelProperties::getChromaHeight ); + addProperty( data, "pixelName", &PixelProperties::getPixelName ); + addProperty( data, "pixelFormatName", &PixelProperties::getPixelFormatName ); + addProperty( data, "bitDepth", &PixelProperties::getBitsPerPixel ); + addProperty( data, "nbComponents", &PixelProperties::getNbComponents ); + addProperty( data, "chromaWidth", &PixelProperties::getChromaWidth ); + addProperty( data, "chromaHeight", &PixelProperties::getChromaHeight ); try { @@ -255,11 +255,11 @@ PropertiesMap PixelProperties::getPropertiesAsMap() const colorComponents = "YUV"; break; } - detail::add( dataMap, "colorComponents", colorComponents ); + detail::add( data, "colorComponents", colorComponents ); } catch( const std::exception& e ) { - detail::add( dataMap, "colorComponents", e.what() ); + detail::add( data, "colorComponents", e.what() ); } try @@ -286,21 +286,21 @@ PropertiesMap PixelProperties::getPropertiesAsMap() const subsampling = "None"; break; } - detail::add( dataMap, "subsampling", subsampling ); + detail::add( data, "subsampling", subsampling ); } catch( const std::exception& e ) { - detail::add( dataMap, "subsampling", e.what() ); + detail::add( data, "subsampling", e.what() ); } - addProperty( dataMap, "isBigEndian", &PixelProperties::isBigEndian ); - addProperty( dataMap, "hasAlpha", &PixelProperties::hasAlpha ); - addProperty( dataMap, "isPlanar", &PixelProperties::isPlanar ); - addProperty( dataMap, "isIndexedColors", &PixelProperties::isIndexedColors ); - addProperty( dataMap, "bitWiseAcked", &PixelProperties::isBitWisePacked ); - addProperty( dataMap, "isHardwareAccelerated", &PixelProperties::isHardwareAccelerated ); - addProperty( dataMap, "rgbPixel", &PixelProperties::isRgbPixelData ); - addProperty( dataMap, "isPseudoPaletted", &PixelProperties::isPseudoPaletted ); + addProperty( data, "isBigEndian", &PixelProperties::isBigEndian ); + addProperty( data, "hasAlpha", &PixelProperties::hasAlpha ); + addProperty( data, "isPlanar", &PixelProperties::isPlanar ); + addProperty( data, "isIndexedColors", &PixelProperties::isIndexedColors ); + addProperty( data, "bitWiseAcked", &PixelProperties::isBitWisePacked ); + addProperty( data, "isHardwareAccelerated", &PixelProperties::isHardwareAccelerated ); + addProperty( data, "rgbPixel", &PixelProperties::isRgbPixelData ); + addProperty( data, "isPseudoPaletted", &PixelProperties::isPseudoPaletted ); try { @@ -315,15 +315,15 @@ PropertiesMap PixelProperties::getPropertiesAsMap() const channelValue << " - "; channelValue << "bitStep " << channels.at( channelIndex ).bitStep; - detail::add( dataMap, channelName.str(), channelValue.str() ); + detail::add( data, channelName.str(), channelValue.str() ); } } catch( const std::exception& e ) { - detail::add( dataMap, "channels", e.what() ); + detail::add( data, "channels", e.what() ); } - return dataMap; + return data; } } diff --git a/src/AvTranscoder/mediaProperty/PixelProperties.hpp b/src/AvTranscoder/mediaProperty/PixelProperties.hpp index b94b3d5d..945fd1db 100644 --- a/src/AvTranscoder/mediaProperty/PixelProperties.hpp +++ b/src/AvTranscoder/mediaProperty/PixelProperties.hpp @@ -79,22 +79,22 @@ class AvExport PixelProperties const AVPixFmtDescriptor* getAVPixFmtDescriptor() const { return _pixelDesc; } #endif - PropertiesMap getPropertiesAsMap() const; ///< Return all pixel properties as a map (name of property: value) + PropertyVector getPropertiesAsVector() const; ///< Return all pixel properties as a vector (name of property: value) private: void init( const AVPixelFormat avPixelFormat ); #ifndef SWIG template - void addProperty( PropertiesMap& dataMap, const std::string& key, T (PixelProperties::*getter)(void) const ) const + void addProperty( PropertyVector& data, const std::string& key, T (PixelProperties::*getter)(void) const ) const { try { - detail::add( dataMap, key, (this->*getter)() ); + detail::add( data, key, (this->*getter)() ); } catch( const std::exception& e ) { - detail::add( dataMap, key, e.what() ); + detail::add( data, key, e.what() ); } } #endif diff --git a/src/AvTranscoder/mediaProperty/StreamProperties.cpp b/src/AvTranscoder/mediaProperty/StreamProperties.cpp new file mode 100644 index 00000000..dbfca9eb --- /dev/null +++ b/src/AvTranscoder/mediaProperty/StreamProperties.cpp @@ -0,0 +1,65 @@ +#include "StreamProperties.hpp" + +#include + +namespace avtranscoder +{ + +StreamProperties::StreamProperties( const FormatContext& formatContext, const size_t index ) + : _formatContext( &formatContext.getAVFormatContext() ) + , _streamIndex( index ) +{ + if( _formatContext ) + detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas ); +} + +StreamProperties::~StreamProperties() +{ + +} + +size_t StreamProperties::getStreamId() const +{ + if( ! _formatContext ) + throw std::runtime_error( "unknown format context" ); + return _formatContext->streams[_streamIndex]->id; +} + +PropertyVector StreamProperties::getPropertiesAsVector() const +{ + PropertyVector data; + + try + { + detail::add( data, "streamId", getStreamId() ); + } + catch( const std::exception& e ) + { + detail::add( data, "streamId", e.what() ); + } + detail::add( data, "streamIndex", getStreamIndex() ); + + for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) + { + detail::add( data, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); + } + + return data; +} + +PropertyMap StreamProperties::getPropertiesAsMap() const +{ + PropertyMap dataMap; + + PropertyVector dataVector( getPropertiesAsVector() ); + for( PropertyVector::const_iterator it = dataVector.begin(); + it != dataVector.end(); + ++it ) + { + dataMap.insert( std::make_pair( it->first, it->second ) ); + } + + return dataMap; +} + +} diff --git a/src/AvTranscoder/mediaProperty/StreamProperties.hpp b/src/AvTranscoder/mediaProperty/StreamProperties.hpp new file mode 100644 index 00000000..773ca70f --- /dev/null +++ b/src/AvTranscoder/mediaProperty/StreamProperties.hpp @@ -0,0 +1,38 @@ +#ifndef _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP +#define _AV_TRANSCODER_MEDIA_PROPERTY_STREAM_PROPERTIES_HPP + +#include +#include +#include + +namespace avtranscoder +{ + +/// Virtual based class of properties for all types of stream +class AvExport StreamProperties +{ +public: + StreamProperties( const FormatContext& formatContext, const size_t index ); + virtual ~StreamProperties() = 0; + + size_t getStreamIndex() const { return _streamIndex; } + size_t getStreamId() const; + PropertyVector& getMetadatas() { return _metadatas; } + +#ifndef SWIG + const AVFormatContext& getAVFormatContext() { return *_formatContext; } +#endif + + PropertyMap getPropertiesAsMap() const; ///< Return all properties as a map (name of property, value) + PropertyVector getPropertiesAsVector() const; ///< Same data with a specific order + +protected: + const AVFormatContext* _formatContext; ///< Has link (no ownership) + + size_t _streamIndex; + PropertyVector _metadatas; +}; + +} + +#endif diff --git a/src/AvTranscoder/mediaProperty/SubtitleProperties.cpp b/src/AvTranscoder/mediaProperty/SubtitleProperties.cpp deleted file mode 100644 index e4aa15ad..00000000 --- a/src/AvTranscoder/mediaProperty/SubtitleProperties.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "SubtitleProperties.hpp" - -#include - -namespace avtranscoder -{ - -SubtitleProperties::SubtitleProperties( const FormatContext& formatContext, const size_t index ) - : _formatContext( &formatContext.getAVFormatContext() ) - , _streamIndex( index ) -{ - if( _formatContext ) - detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas ); -} - -size_t SubtitleProperties::getStreamId() const -{ - if( ! _formatContext ) - throw std::runtime_error( "unknown format context" ); - return _formatContext->streams[_streamIndex]->id; -} - -PropertiesMap SubtitleProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - try - { - detail::add( dataMap, "streamId", getStreamId() ); - } - catch( const std::exception& e ) - { - detail::add( dataMap, "streamId", e.what() ); - } - - for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) - { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); - } - - return dataMap; -} - -} diff --git a/src/AvTranscoder/mediaProperty/SubtitleProperties.hpp b/src/AvTranscoder/mediaProperty/SubtitleProperties.hpp index 96816d80..98bb54ce 100644 --- a/src/AvTranscoder/mediaProperty/SubtitleProperties.hpp +++ b/src/AvTranscoder/mediaProperty/SubtitleProperties.hpp @@ -1,33 +1,17 @@ #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_SUBTITLE_PROPERTIES_HPP #define _AV_TRANSCODER_MEDIA_PROPERTY_SUBTITLE_PROPERTIES_HPP -#include -#include -#include +#include namespace avtranscoder { -class AvExport SubtitleProperties +class AvExport SubtitleProperties : public StreamProperties { public: - SubtitleProperties( const FormatContext& formatContext, const size_t index ); - - size_t getStreamIndex() const { return _streamIndex; } - size_t getStreamId() const; - PropertiesMap& getMetadatas() { return _metadatas; } - -#ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } -#endif - - PropertiesMap getPropertiesAsMap() const; ///< Return all subtitle properties as a map (name of property: value) - -private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) - - size_t _streamIndex; - PropertiesMap _metadatas; + SubtitleProperties( const FormatContext& formatContext, const size_t index ) + : StreamProperties( formatContext, index ) + {} }; } diff --git a/src/AvTranscoder/mediaProperty/UnknownProperties.cpp b/src/AvTranscoder/mediaProperty/UnknownProperties.cpp deleted file mode 100644 index ce80113b..00000000 --- a/src/AvTranscoder/mediaProperty/UnknownProperties.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "UnknownProperties.hpp" - -#include - -namespace avtranscoder -{ - -UnknownProperties::UnknownProperties( const FormatContext& formatContext, const size_t index ) - : _formatContext( &formatContext.getAVFormatContext() ) - , _streamIndex( index ) -{ - if( _formatContext ) - detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas ); -} - -size_t UnknownProperties::getStreamId() const -{ - if( ! _formatContext ) - throw std::runtime_error( "unknown format context" ); - return _formatContext->streams[_streamIndex]->id; -} - -PropertiesMap UnknownProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - try - { - detail::add( dataMap, "streamId", getStreamId() ); - } - catch( const std::exception& e ) - { - detail::add( dataMap, "streamId", e.what() ); - } - - for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) - { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); - } - - return dataMap; -} - -} diff --git a/src/AvTranscoder/mediaProperty/UnknownProperties.hpp b/src/AvTranscoder/mediaProperty/UnknownProperties.hpp index 91f83351..b396035f 100644 --- a/src/AvTranscoder/mediaProperty/UnknownProperties.hpp +++ b/src/AvTranscoder/mediaProperty/UnknownProperties.hpp @@ -1,33 +1,17 @@ #ifndef _AV_TRANSCODER_MEDIA_PROPERTY_UNKNOWN_PROPERTIES_HPP #define _AV_TRANSCODER_MEDIA_PROPERTY_UNKNOWN_PROPERTIES_HPP -#include -#include -#include +#include namespace avtranscoder { -class AvExport UnknownProperties +class AvExport UnknownProperties : public StreamProperties { public: - UnknownProperties( const FormatContext& formatContext, const size_t index ); - - size_t getStreamIndex() const { return _streamIndex; } - size_t getStreamId() const; - PropertiesMap& getMetadatas() { return _metadatas; } - -#ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } -#endif - - PropertiesMap getPropertiesAsMap() const; ///< Return unknown properties as a map (name of property: value) - -private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) - - size_t _streamIndex; - PropertiesMap _metadatas; + UnknownProperties( const FormatContext& formatContext, const size_t index ) + : StreamProperties( formatContext, index ) + {} }; } diff --git a/src/AvTranscoder/mediaProperty/VideoProperties.cpp b/src/AvTranscoder/mediaProperty/VideoProperties.cpp index 7e522ce4..289bfcb3 100644 --- a/src/AvTranscoder/mediaProperty/VideoProperties.cpp +++ b/src/AvTranscoder/mediaProperty/VideoProperties.cpp @@ -16,10 +16,9 @@ namespace avtranscoder { VideoProperties::VideoProperties( const FormatContext& formatContext, const size_t index, IProgress& progress, const EAnalyseLevel level ) - : _formatContext( &formatContext.getAVFormatContext() ) + : StreamProperties( formatContext, index ) , _codecContext( NULL ) , _codec( NULL ) - , _streamIndex( index ) , _pixelProperties() , _isInterlaced( false ) , _isTopFieldFirst( false ) @@ -405,7 +404,7 @@ size_t VideoProperties::getBitRate() const if( ! _codecContext->width || ! _codecContext->height ) throw std::runtime_error( "cannot compute bit rate: invalid frame size" ); - + // discard no frame type when decode _codecContext->skip_frame = AVDISCARD_NONE; @@ -429,7 +428,11 @@ size_t VideoProperties::getBitRate() const avcodec_decode_video2( _codecContext, frame, &gotFrame, &pkt ); if( gotFrame ) { - gopFramesSize += frame->pkt_size; +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 54, 7, 100 ) + gopFramesSize += av_frame_get_pkt_size( frame ); +#else + gopFramesSize += pkt.size; +#endif ++count; } } @@ -637,40 +640,41 @@ void VideoProperties::analyseGopStructure( IProgress& progress ) } } -PropertiesMap VideoProperties::getPropertiesAsMap() const -{ - PropertiesMap dataMap; - - addProperty( dataMap, "streamId", &VideoProperties::getStreamId ); - addProperty( dataMap, "codecId", &VideoProperties::getCodecId ); - addProperty( dataMap, "codecName", &VideoProperties::getCodecName ); - addProperty( dataMap, "codecLongName", &VideoProperties::getCodecLongName ); - addProperty( dataMap, "profile", &VideoProperties::getProfile ); - addProperty( dataMap, "profileName", &VideoProperties::getProfileName ); - addProperty( dataMap, "level", &VideoProperties::getLevel ); - addProperty( dataMap, "startTimecode", &VideoProperties::getStartTimecodeString ); - addProperty( dataMap, "width", &VideoProperties::getWidth ); - addProperty( dataMap, "height", &VideoProperties::getHeight ); - addProperty( dataMap, "pixelAspectRatio", &VideoProperties::getSar ); - addProperty( dataMap, "displayAspectRatio", &VideoProperties::getDar ); - addProperty( dataMap, "dtgActiveFormat", &VideoProperties::getDtgActiveFormat ); - addProperty( dataMap, "colorTransfert", &VideoProperties::getColorTransfert ); - addProperty( dataMap, "colorspace", &VideoProperties::getColorspace ); - addProperty( dataMap, "colorRange", &VideoProperties::getColorRange ); - addProperty( dataMap, "colorPrimaries", &VideoProperties::getColorPrimaries ); - addProperty( dataMap, "chromaSampleLocation", &VideoProperties::getChromaSampleLocation ); - addProperty( dataMap, "interlaced ", &VideoProperties::isInterlaced ); - addProperty( dataMap, "topFieldFirst", &VideoProperties::isTopFieldFirst ); - addProperty( dataMap, "fieldOrder", &VideoProperties::getFieldOrder ); - addProperty( dataMap, "timeBase", &VideoProperties::getTimeBase ); - addProperty( dataMap, "duration", &VideoProperties::getDuration ); - addProperty( dataMap, "fps", &VideoProperties::getFps ); - addProperty( dataMap, "nbFrame", &VideoProperties::getNbFrames ); - addProperty( dataMap, "ticksPerFrame", &VideoProperties::getTicksPerFrame ); - addProperty( dataMap, "bitRate", &VideoProperties::getBitRate ); - addProperty( dataMap, "maxBitRate", &VideoProperties::getMaxBitRate ); - addProperty( dataMap, "minBitRate", &VideoProperties::getMinBitRate ); - addProperty( dataMap, "gopSize", &VideoProperties::getGopSize ); +PropertyVector VideoProperties::getPropertiesAsVector() const +{ + PropertyVector data; + + addProperty( data, "streamId", &VideoProperties::getStreamId ); + detail::add( data, "streamIndex", getStreamIndex() ); + addProperty( data, "codecId", &VideoProperties::getCodecId ); + addProperty( data, "codecName", &VideoProperties::getCodecName ); + addProperty( data, "codecLongName", &VideoProperties::getCodecLongName ); + addProperty( data, "profile", &VideoProperties::getProfile ); + addProperty( data, "profileName", &VideoProperties::getProfileName ); + addProperty( data, "level", &VideoProperties::getLevel ); + addProperty( data, "startTimecode", &VideoProperties::getStartTimecodeString ); + addProperty( data, "width", &VideoProperties::getWidth ); + addProperty( data, "height", &VideoProperties::getHeight ); + addProperty( data, "pixelAspectRatio", &VideoProperties::getSar ); + addProperty( data, "displayAspectRatio", &VideoProperties::getDar ); + addProperty( data, "dtgActiveFormat", &VideoProperties::getDtgActiveFormat ); + addProperty( data, "colorTransfert", &VideoProperties::getColorTransfert ); + addProperty( data, "colorspace", &VideoProperties::getColorspace ); + addProperty( data, "colorRange", &VideoProperties::getColorRange ); + addProperty( data, "colorPrimaries", &VideoProperties::getColorPrimaries ); + addProperty( data, "chromaSampleLocation", &VideoProperties::getChromaSampleLocation ); + addProperty( data, "interlaced ", &VideoProperties::isInterlaced ); + addProperty( data, "topFieldFirst", &VideoProperties::isTopFieldFirst ); + addProperty( data, "fieldOrder", &VideoProperties::getFieldOrder ); + addProperty( data, "timeBase", &VideoProperties::getTimeBase ); + addProperty( data, "duration", &VideoProperties::getDuration ); + addProperty( data, "fps", &VideoProperties::getFps ); + addProperty( data, "nbFrame", &VideoProperties::getNbFrames ); + addProperty( data, "ticksPerFrame", &VideoProperties::getTicksPerFrame ); + addProperty( data, "bitRate", &VideoProperties::getBitRate ); + addProperty( data, "maxBitRate", &VideoProperties::getMaxBitRate ); + addProperty( data, "minBitRate", &VideoProperties::getMinBitRate ); + addProperty( data, "gopSize", &VideoProperties::getGopSize ); std::string gop; for( size_t frameIndex = 0; frameIndex < _gopStructure.size(); ++frameIndex ) @@ -678,22 +682,22 @@ PropertiesMap VideoProperties::getPropertiesAsMap() const gop += _gopStructure.at( frameIndex ).first; gop += " "; } - detail::add( dataMap, "gop", gop ); - //detail::add( dataMap, "isClosedGop", isClosedGop() ); + detail::add( data, "gop", gop ); + //detail::add( data, "isClosedGop", isClosedGop() ); - addProperty( dataMap, "hasBFrames", &VideoProperties::hasBFrames ); - addProperty( dataMap, "referencesFrames", &VideoProperties::getReferencesFrames ); + addProperty( data, "hasBFrames", &VideoProperties::hasBFrames ); + addProperty( data, "referencesFrames", &VideoProperties::getReferencesFrames ); for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex ) { - detail::add( dataMap, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); + detail::add( data, _metadatas.at( metadataIndex ).first, _metadatas.at( metadataIndex ).second ); } // Add properties of the pixel - PropertiesMap pixelProperties = _pixelProperties.getPropertiesAsMap(); - dataMap.insert( dataMap.end(), pixelProperties.begin(), pixelProperties.end() ); + PropertyVector pixelProperties = _pixelProperties.getPropertiesAsVector(); + data.insert( data.end(), pixelProperties.begin(), pixelProperties.end() ); - return dataMap; + return data; } } diff --git a/src/AvTranscoder/mediaProperty/VideoProperties.hpp b/src/AvTranscoder/mediaProperty/VideoProperties.hpp index 22bc4f03..adddb098 100644 --- a/src/AvTranscoder/mediaProperty/VideoProperties.hpp +++ b/src/AvTranscoder/mediaProperty/VideoProperties.hpp @@ -3,10 +3,8 @@ #include "PixelProperties.hpp" -#include -#include +#include #include -#include #include extern "C" { @@ -20,7 +18,7 @@ extern "C" { namespace avtranscoder { -class AvExport VideoProperties +class AvExport VideoProperties : public StreamProperties { public: VideoProperties( const FormatContext& formatContext, const size_t index, IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFirstGop ); @@ -44,7 +42,6 @@ class AvExport VideoProperties Rational getSar() const; // sample/pixel aspect ratio Rational getDar() const; // display aspect ratio - size_t getStreamIndex() const { return _streamIndex; } size_t getStreamId() const; size_t getCodecId() const; size_t getBitRate() const; ///< in bits/s @@ -75,15 +72,12 @@ class AvExport VideoProperties std::vector< std::pair< char, bool > > getGopStructure() const { return _gopStructure; } //@} - PropertiesMap& getMetadatas() { return _metadatas; } - #ifndef SWIG - const AVFormatContext& getAVFormatContext() { return *_formatContext; } AVCodecContext& getAVCodecContext() { return *_codecContext; } const PixelProperties& getPixelProperties() const { return _pixelProperties; } #endif - PropertiesMap getPropertiesAsMap() const; ///< Return all video and pixel properties as a map (name of property: value) + PropertyVector getPropertiesAsVector() const; private: /** @@ -94,25 +88,23 @@ class AvExport VideoProperties #ifndef SWIG template - void addProperty( PropertiesMap& dataMap, const std::string& key, T (VideoProperties::*getter)(void) const ) const + void addProperty( PropertyVector& dataVector, const std::string& key, T (VideoProperties::*getter)(void) const ) const { try { - detail::add( dataMap, key, (this->*getter)() ); + detail::add( dataVector, key, (this->*getter)() ); } catch( const std::exception& e ) { - detail::add( dataMap, key, e.what() ); + detail::add( dataVector, key, e.what() ); } } #endif private: - const AVFormatContext* _formatContext; ///< Has link (no ownership) AVCodecContext* _codecContext; ///< Has link (no ownership) AVCodec* _codec; ///< Has link (no ownership) - size_t _streamIndex; PixelProperties _pixelProperties; //@{ // Can acces these data when analyse first gop @@ -120,7 +112,6 @@ class AvExport VideoProperties bool _isTopFieldFirst; std::vector< std::pair< char, bool > > _gopStructure; //@} - PropertiesMap _metadatas; }; } diff --git a/src/AvTranscoder/mediaProperty/mediaProperty.i b/src/AvTranscoder/mediaProperty/mediaProperty.i index 75a734c7..a814a2cd 100644 --- a/src/AvTranscoder/mediaProperty/mediaProperty.i +++ b/src/AvTranscoder/mediaProperty/mediaProperty.i @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ namespace std { %include %include %include +%include %include %include %include diff --git a/src/AvTranscoder/mediaProperty/print.hpp b/src/AvTranscoder/mediaProperty/print.hpp index f9c96324..05399ec8 100644 --- a/src/AvTranscoder/mediaProperty/print.hpp +++ b/src/AvTranscoder/mediaProperty/print.hpp @@ -19,8 +19,8 @@ std::ostream& operator<<( std::ostream& flux, const FileProperties& fileProperti flux << std::left; flux << separator << " Wrapper " << separator << std::endl; - PropertiesMap properties = fileProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = fileProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -33,8 +33,8 @@ std::ostream& operator<<( std::ostream& flux, const VideoProperties& videoProper flux << std::left; flux << separator << " Video stream " << separator << std::endl; - PropertiesMap properties = videoProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = videoProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -47,8 +47,8 @@ std::ostream& operator<<( std::ostream& flux, const AudioProperties& audioProper flux << std::left; flux << separator << " Audio stream " << separator << std::endl; - PropertiesMap properties = audioProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = audioProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -60,8 +60,8 @@ std::ostream& operator<<( std::ostream& flux, const DataProperties& dataProperti { flux << separator << " Data stream " << separator << std::endl; - PropertiesMap properties = dataProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = dataProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -73,8 +73,8 @@ std::ostream& operator<<( std::ostream& flux, const SubtitleProperties& subtitle { flux << separator << " Subtitle stream " << separator << std::endl; - PropertiesMap properties = subtitleProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = subtitleProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -86,8 +86,8 @@ std::ostream& operator<<( std::ostream& flux, const AttachementProperties& attac { flux << separator << " Attachement stream " << separator << std::endl; - PropertiesMap properties = attachementProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = attachementProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } @@ -99,8 +99,8 @@ std::ostream& operator<<( std::ostream& flux, const UnknownProperties& unknownPr { flux << separator << " Unknown stream " << separator << std::endl; - PropertiesMap properties = unknownProperties.getPropertiesAsMap(); - for( PropertiesMap::iterator it = properties.begin(); it != properties.end(); ++it ) + PropertyVector properties = unknownProperties.getPropertiesAsVector(); + for( PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it ) { flux << std::setw( keyWidth ) << it->first << ": " << it->second << std::endl; } diff --git a/src/AvTranscoder/mediaProperty/util.cpp b/src/AvTranscoder/mediaProperty/util.cpp index 1f752e57..7be54102 100644 --- a/src/AvTranscoder/mediaProperty/util.cpp +++ b/src/AvTranscoder/mediaProperty/util.cpp @@ -9,24 +9,24 @@ namespace detail { template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const std::string& value ) +void add( PropertyVector& propertyVector, const std::string& key, const std::string& value ) { - propertiesMap.push_back( std::make_pair( key, value ) ); + propertyVector.push_back( std::make_pair( key, value ) ); } template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const bool& value ) +void add( PropertyVector& propertyVector, const std::string& key, const bool& value ) { - add( propertiesMap, key, value ? "True" : "False" ); + add( propertyVector, key, value ? "True" : "False" ); } template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const Rational& value ) +void add( PropertyVector& propertyVector, const std::string& key, const Rational& value ) { - add( propertiesMap, key, value.num / (double) value.den ); + add( propertyVector, key, value.num / (double) value.den ); } -void fillMetadataDictionnary( AVDictionary* avdictionnary, PropertiesMap& metadata ) +void fillMetadataDictionnary( AVDictionary* avdictionnary, PropertyVector& metadata ) { AVDictionaryEntry* tag = NULL; while( ( tag = av_dict_get( avdictionnary, "", tag, AV_DICT_IGNORE_SUFFIX ) ) ) diff --git a/src/AvTranscoder/mediaProperty/util.hpp b/src/AvTranscoder/mediaProperty/util.hpp index 0e49e9a8..69122fe6 100644 --- a/src/AvTranscoder/mediaProperty/util.hpp +++ b/src/AvTranscoder/mediaProperty/util.hpp @@ -9,6 +9,7 @@ extern "C" { #include #include +#include #include #include @@ -16,34 +17,35 @@ namespace avtranscoder { /** - * @brief PropertyMap is a vector of pair, because the order of properties matters to us. + * @brief PropertyVector is a vector of pair, because the order of properties matters to us. */ -typedef std::vector< std::pair > PropertiesMap; +typedef std::vector< std::pair > PropertyVector; +typedef std::map< std::string, std::string > PropertyMap; namespace detail { template -void add( PropertiesMap& propertiesMap, const std::string& key, const T& value ) +void add( PropertyVector& propertyVector, const std::string& key, const T& value ) { std::stringstream ss; ss << value; - add( propertiesMap, key, ss.str() ); + add( propertyVector, key, ss.str() ); } template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const std::string& value ); +void add( PropertyVector& propertyVector, const std::string& key, const std::string& value ); template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const bool& value ); +void add( PropertyVector& propertyVector, const std::string& key, const bool& value ); template<> -void add( PropertiesMap& propertiesMap, const std::string& key, const Rational& value ); +void add( PropertyVector& propertyVector, const std::string& key, const Rational& value ); /** * @brief Fill metadata parameter with the given AVDictionary. */ -void AvExport fillMetadataDictionnary( AVDictionary* avdictionnary, PropertiesMap& metadata ); +void AvExport fillMetadataDictionnary( AVDictionary* avdictionnary, PropertyVector& metadata ); } diff --git a/src/AvTranscoder/option.i b/src/AvTranscoder/option.i new file mode 100644 index 00000000..ff550d2e --- /dev/null +++ b/src/AvTranscoder/option.i @@ -0,0 +1,15 @@ +%{ +#include +%} + +namespace std { +// Allow vector of object with no default constructor +%ignore vector< avtranscoder::Option >::vector(size_type); +%ignore vector< avtranscoder::Option >::resize; + +// Create instantiations of a template classes +%template(OptionArray) vector< avtranscoder::Option >; +%template(IntPair) pair< size_t, size_t >; +} + +%include diff --git a/src/AvTranscoder/profile/util.hpp b/src/AvTranscoder/profile/util.hpp index 144c25e4..16122779 100644 --- a/src/AvTranscoder/profile/util.hpp +++ b/src/AvTranscoder/profile/util.hpp @@ -59,7 +59,7 @@ int getFilesInDir( const std::string& dir, std::vector< std::string >& files ) { const std::string filename( findData.cFileName ); bool isdir = ( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0; - if( ! isdir ) + if( ! isdir && filename.find(".prf") != std::string::npos ) files.push_back( filename ); int rval = FindNextFile( findHandle, &findData ); @@ -81,7 +81,8 @@ int getFilesInDir( const std::string& dir, std::vector< std::string >& files ) const std::string filename( dirp->d_name ); if( filename == "." || filename == ".." ) continue; - files.push_back( filename ); + if( filename.find(".prf") != std::string::npos ) + files.push_back( filename ); } closedir( dp ); #endif diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 8246ed68..eb968b13 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -69,8 +69,18 @@ class AvExport StreamTranscoder */ double getDuration() const; - /// Returns a reference to the current decoder used by the streamTranscoder (from input file or from generator) + /// Returns a reference to the current decoder (from input file or from generator) IDecoder& getCurrentDecoder() const { return *_currentDecoder; } + /// Returns a reference to the encoder + IEncoder& getEncoder() const { return *_outputEncoder; } + + /// Returns a reference to the object which transforms the decoded data + ITransform& getTransform() const { return *_transform; } + + /// Returns a reference to the stream which unwraps data + IInputStream& getInputStream() const { return *_inputStream; } + /// Returns a reference to the stream which wraps data + IOutputStream& getOutputStream() const { return *_outputStream; } /** * @brief Returns if the stream can switch to a generator when ended diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 16705616..a02c4f87 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -224,6 +224,12 @@ bool Transcoder::processFrame() return true; } +void Transcoder::process() +{ + NoDisplayProgress progress; + process( progress ); +} + void Transcoder::process( IProgress& progress ) { if( _streamTranscoders.size() == 0 ) @@ -345,7 +351,8 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s for( std::vector< InputFile* >::iterator it = _inputFiles.begin(); it != _inputFiles.end(); ++it ) { - if( ( (*it)->getFilename() == filename ) ) + if( ( (*it)->getFilename() == filename ) && + ! (*it)->getStream( streamIndex ).isActivated() ) { referenceFile = (*it); LOG_DEBUG( "Get instance of InputFile from '" << filename << "'" ) diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 56c30922..43729344 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -120,6 +120,12 @@ class AvExport Transcoder * @see IProgress */ void process( IProgress& progress ); + void process(); ///< Call process with no display of progression + + /** + * @brief Return the list of streams added to the transcoder. + */ + std::vector< StreamTranscoder* >& getStreamTranscoders() { return _streamTranscoders; } /** * @param streamIndex: careful about the order of stream insertion of the Transcoder. @@ -127,6 +133,12 @@ class AvExport Transcoder */ StreamTranscoder& getStreamTranscoder( size_t streamIndex ) const { return *_streamTranscoders.at( streamIndex ); } + /** + * @brief Get current processMethod + * @see EProcessMethod + */ + EProcessMethod getProcessMethod() const { return _eProcessMethod; } + /** * @brief Set the transcoding policy. * @note By default eProcessMethodBasedOnStream at index 0. diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 1d567077..a98376e1 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -6,6 +6,9 @@ extern "C" { #include } +#include +#include + namespace avtranscoder { @@ -116,27 +119,9 @@ AVSampleFormat getAVSampleFormat( const std::string& sampleFormat ) return av_get_sample_fmt( sampleFormat.c_str() ); } -std::vector getFormatsLongNames() -{ - std::vector formatsLongNames; - - AVOutputFormat* fmt = NULL; - while( ( fmt = av_oformat_next( fmt ) ) ) - { - // skip undefined codec - if( fmt->video_codec == AV_CODEC_ID_NONE ) - continue; - - if( ! fmt->long_name ) - continue; - - formatsLongNames.push_back( std::string( fmt->long_name ) ); - } - return formatsLongNames; -} -std::vector getFormatsShortNames() +NamesArray getFormatsNames() { - std::vector formatsShortNames; + NamesArray formatsNames; AVOutputFormat* fmt = NULL; while( ( fmt = av_oformat_next( fmt ) ) ) @@ -145,141 +130,65 @@ std::vector getFormatsShortNames() if( fmt->video_codec == AV_CODEC_ID_NONE ) continue; - if( ! fmt->name ) + if( ! fmt->name && ! fmt->long_name ) continue; - formatsShortNames.push_back( std::string( fmt->name ) ); + formatsNames.push_back( std::make_pair( std::string( fmt->name ? fmt->name : "" ), std::string( fmt->long_name ? fmt->long_name : "" ) ) ); } - return formatsShortNames; + return formatsNames; } -std::vector getVideoCodecsLongNames() +NamesArray getVideoCodecsNames() { - std::vector videoCodecsLongNames; + NamesArray videoCodecsNames; AVCodec* c = NULL; while( ( c = av_codec_next( c ) ) != NULL ) { -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) - if( ! c->encode ) - continue; -#else - if( ! c->encode2 ) - continue; -#endif - switch( c->type ) + if( c->type == AVMEDIA_TYPE_VIDEO) { - case AVMEDIA_TYPE_VIDEO: - { - if( ! c->long_name ) - continue; + if( ! c->name && ! c->long_name ) + continue; - videoCodecsLongNames.push_back( std::string( c->long_name ) ); - break; - } - default: - break; - } - } - return videoCodecsLongNames; -} -std::vector getVideoCodecsShortNames() -{ - std::vector videoCodecsShortNames; + std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ); - AVCodec* c = NULL; - while( ( c = av_codec_next( c ) ) != NULL ) - { -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) - if( ! c->encode ) - continue; -#else - if( ! c->encode2 ) - continue; -#endif - switch( c->type ) - { - case AVMEDIA_TYPE_VIDEO: - { - if( ! c->name ) - continue; + // skip duplicates + if( std::find( videoCodecsNames.begin(), videoCodecsNames.end(), codecNames ) != videoCodecsNames.end() ) + continue; - videoCodecsShortNames.push_back( std::string( c->name ) ); - break; - } - default: - break; + videoCodecsNames.push_back( codecNames ); } } - return videoCodecsShortNames; + return videoCodecsNames; } -std::vector getAudioCodecsLongNames() +NamesArray getAudioCodecsNames() { - std::vector audioCodecsLongNames; + NamesArray audioCodecsNames; AVCodec* c = NULL; while( ( c = av_codec_next( c ) ) != NULL ) { -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) - if( ! c->encode ) - continue; -#else - if( ! c->encode2 ) - continue; -#endif - switch( c->type ) + if( c->type == AVMEDIA_TYPE_AUDIO ) { - case AVMEDIA_TYPE_AUDIO: - { - if( ! c->long_name ) - continue; + if( ! c->name && ! c->long_name ) + continue; - audioCodecsLongNames.push_back( std::string( c->long_name ) ); - break; - } - default: - break; - } - } - return audioCodecsLongNames; -} -std::vector getAudioCodecsShortNames() -{ - std::vector audioCodecsShortNames; + std::pair< std::string, std::string > codecNames( std::string( c->name ? c->name : "" ), std::string( c->long_name ? c->long_name : "" ) ); - AVCodec* c = NULL; - while( ( c = av_codec_next( c ) ) != NULL ) - { -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) - if( ! c->encode ) - continue; -#else - if( ! c->encode2 ) - continue; -#endif - switch( c->type ) - { - case AVMEDIA_TYPE_AUDIO: - { - if( ! c->name ) - continue; + // skip duplicates + if( std::find( audioCodecsNames.begin(), audioCodecsNames.end(), codecNames ) != audioCodecsNames.end() ) + continue; - audioCodecsShortNames.push_back( std::string( c->name ) ); - break; - } - default: - break; + audioCodecsNames.push_back( codecNames ); } } - return audioCodecsShortNames; + return audioCodecsNames; } OptionArrayMap getOutputFormatOptions() { - av_register_all(); - - std::map< std::string, std::vector