From c53ab7f2b989dfe709716dd862c90cbcb9e22dc4 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 13 Jul 2016 19:16:44 +0200 Subject: [PATCH 01/31] StreamTranscoder: create input codec from the profile in case of generated streams Warning: the profile should define information to instanciate the codec: * for video: width, height, pixel format * for audio: sampleRate, nbChannels, sample format. --- src/AvTranscoder/transcoder/StreamTranscoder.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 67f3e8a4..1645fcf0 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -243,7 +243,11 @@ StreamTranscoder::StreamTranscoder(const ICodec& inputCodec, IOutputFile& output { if(profile.find(constants::avProfileType)->second == constants::avProfileTypeVideo) { - const VideoCodec& inputVideoCodec = static_cast(inputCodec); + VideoCodec inputVideoCodec(eCodecTypeEncoder, profile.find(constants::avProfileCodec)->second); + VideoFrameDesc inputFrameDesc; + inputFrameDesc.setParameters(profile); + inputVideoCodec.setImageParameters(inputFrameDesc); + // generator decoder _generator = new VideoGenerator(inputVideoCodec.getVideoFrameDesc()); _currentDecoder = _generator; @@ -252,7 +256,6 @@ StreamTranscoder::StreamTranscoder(const ICodec& inputCodec, IOutputFile& output _filterGraph = new FilterGraph(inputVideoCodec); // buffers to process - VideoFrameDesc inputFrameDesc = inputVideoCodec.getVideoFrameDesc(); VideoFrameDesc outputFrameDesc = inputFrameDesc; outputFrameDesc.setParameters(profile); _sourceBuffer = new VideoFrame(inputFrameDesc); @@ -271,7 +274,11 @@ StreamTranscoder::StreamTranscoder(const ICodec& inputCodec, IOutputFile& output } else if(profile.find(constants::avProfileType)->second == constants::avProfileTypeAudio) { - const AudioCodec& inputAudioCodec = static_cast(inputCodec); + AudioCodec inputAudioCodec(eCodecTypeEncoder, profile.find(constants::avProfileCodec)->second); + AudioFrameDesc inputFrameDesc; + inputFrameDesc.setParameters(profile); + inputAudioCodec.setAudioParameters(inputFrameDesc); + // generator decoder _generator = new AudioGenerator(inputAudioCodec.getAudioFrameDesc()); _currentDecoder = _generator; @@ -280,7 +287,6 @@ StreamTranscoder::StreamTranscoder(const ICodec& inputCodec, IOutputFile& output _filterGraph = new FilterGraph(inputAudioCodec); // buffers to process - AudioFrameDesc inputFrameDesc = inputAudioCodec.getAudioFrameDesc(); AudioFrameDesc outputFrameDesc = inputFrameDesc; outputFrameDesc.setParameters(profile); _sourceBuffer = new AudioFrame(inputFrameDesc); From 01e5eae8c83a916b6298e3872a2023191ffc378c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 13 Jul 2016 19:43:31 +0200 Subject: [PATCH 02/31] Transcoder: removed add method to rewrap all the streams of a given file Will cause conflicts in the next commit (refactoring). --- app/pyRewrap/pyrewrap.py | 3 +- src/AvTranscoder/transcoder/Transcoder.cpp | 15 ---------- src/AvTranscoder/transcoder/Transcoder.hpp | 7 ----- test/pyTest/testTranscoderAdd.py | 35 ---------------------- 4 files changed, 2 insertions(+), 58 deletions(-) diff --git a/app/pyRewrap/pyrewrap.py b/app/pyRewrap/pyrewrap.py index 101e1d3f..abe3f020 100644 --- a/app/pyRewrap/pyrewrap.py +++ b/app/pyRewrap/pyrewrap.py @@ -70,7 +70,8 @@ # create transcoder transcoder = av.Transcoder( outputFile ) -transcoder.add( args.inputFileName ) +for streamIndex in range(0, inputFile.getProperties().getNbStreams()): + transcoder.add(args.inputFileName, streamIndex) # launch process progress = av.ConsoleProgress() diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 247fc5b2..5675e4a7 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -35,21 +35,6 @@ Transcoder::~Transcoder() } } -void Transcoder::add(const std::string& filename) -{ - const int streamIndex = -1; - const float offset = 0; - const InputFile* referenceFile = addInputFile(filename, streamIndex, offset); - const std::vector& inputStreams = referenceFile->getProperties().getStreamProperties(); - for(size_t index = 0; index < inputStreams.size(); ++index) - { - const AVMediaType streamType = referenceFile->getProperties().getStreamPropertiesWithIndex(index).getStreamType(); - // skip the stream if it is not video nor audio - if(streamType == AVMEDIA_TYPE_VIDEO || streamType == AVMEDIA_TYPE_AUDIO) - addRewrapStream(filename, index, offset); - } -} - void Transcoder::add(const std::string& filename, const size_t streamIndex, const std::string& profileName, const float offset) { diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 289db061..1b701d92 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -53,13 +53,6 @@ class AvExport Transcoder ~Transcoder(); - /** - * @brief Add all streams of the file with the given filename. - * All the streams will be rewrapped. - * @note Currently we rewrap only the video and the audio streams. The streams with an other type are skipped. - */ - void add(const std::string& filename); - /** * @brief Add a stream and set a profile * @note If profileName is empty, rewrap. diff --git a/test/pyTest/testTranscoderAdd.py b/test/pyTest/testTranscoderAdd.py index 50a2c9ac..0513f085 100644 --- a/test/pyTest/testTranscoderAdd.py +++ b/test/pyTest/testTranscoderAdd.py @@ -53,38 +53,3 @@ def testAddAllStreamsOfFileWhichDoesNotExist(): # process progress = av.ConsoleProgress() transcoder.process( progress ) - - -def testAddAllStreamsOfAGivenFile(): - """ - Add all streams from a given file. - """ - # input - inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] - - # output - outputFileName = "testAddAllStreamsOfAGivenFile.mov" - ouputFile = av.OutputFile( outputFileName ) - - transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName ) - - # process - progress = av.ConsoleProgress() - transcoder.process( progress ) - - # get src file - src_inputFile = av.InputFile( inputFileName ) - src_properties = src_inputFile.getProperties() - src_streams_properties = src_properties.getStreamProperties() - - # get dst file - dst_inputFile = av.InputFile( outputFileName ) - dst_properties = dst_inputFile.getProperties() - dst_streams_properties = dst_properties.getStreamProperties() - - import testTranscoderRewrap - # for each stream - for src_stream, dst_stream in zip(src_streams_properties, dst_streams_properties): - # check properties - testTranscoderRewrap.checkStream(src_stream, dst_stream) From 321ef8919b76cc3daff9fc6415c3a472b505a85d Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 13 Jul 2016 19:48:14 +0200 Subject: [PATCH 03/31] Transocder: removed ICodec parameter to generate streams * Now we are using the codec properties defined in the given profile. * Next step: remove re-encoding process and directly wrap the generated data. --- app/avProcessor/avProcessor.cpp | 45 +-------- .../transcoder/StreamTranscoder.cpp | 2 +- .../transcoder/StreamTranscoder.hpp | 2 +- src/AvTranscoder/transcoder/Transcoder.cpp | 97 ++----------------- src/AvTranscoder/transcoder/Transcoder.hpp | 30 ++---- 5 files changed, 22 insertions(+), 154 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 2236caa6..3bbaab79 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -9,18 +9,6 @@ #include #include -static const size_t dummyWidth = 1920; -static const size_t dummyHeight = 1080; -static const std::string dummyPixelFormat = "yuv420p"; -static const std::string dummyVideoCodec = "mpeg2video"; - -static const size_t dummySampleRate = 48000; -static const size_t dummyChannels = 1; -static const std::string dummySampleFormat = "s16"; -static const std::string dummyAudioCodec = "pcm_s16le"; - -static bool useVideoGenerator = false; - void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder& transcoder) { std::ifstream configFile(configFilename.c_str(), std::ifstream::in); @@ -47,32 +35,11 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder if(separator == '.') ss >> subStreamIndex; - // dummy stream, need a ICodec (audio or video) + // generated stream if(!filename.length()) - { - if(useVideoGenerator) - { - // video - avtranscoder::VideoCodec inputCodec(avtranscoder::eCodecTypeEncoder, dummyVideoCodec); - avtranscoder::VideoFrameDesc imageDesc(dummyWidth, dummyHeight, dummyPixelFormat); - inputCodec.setImageParameters(imageDesc); - - transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec); - } - else - { - // audio - avtranscoder::AudioCodec inputCodec(avtranscoder::eCodecTypeEncoder, dummyAudioCodec); - avtranscoder::AudioFrameDesc audioDesc(dummySampleRate, dummyChannels, dummySampleFormat); - inputCodec.setAudioParameters(audioDesc); - - transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec); - } - } + transcoder.add(transcodeProfile); else - { transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile); - } } } } @@ -93,8 +60,6 @@ int main(int argc, char** argv) help += "\tNo subStreamId: will process of channels of the stream\n"; help += "\tNo profileName: will rewrap the stream\n"; help += "Command line options\n"; - help += "\t--generate-black: stream which not referred to an input, will generate an output video stream with black " - "images (by default generate audio stream with silence)\n"; help += "\t--verbose: set log level to AV_LOG_DEBUG\n"; help += "\t--logFile: put log in 'avtranscoder.log' file\n"; help += "\t--help: display this help\n"; @@ -116,10 +81,6 @@ int main(int argc, char** argv) std::cout << help << std::endl; return 0; } - else if(arguments.at(argument) == "--generate-black") - { - useVideoGenerator = true; - } else if(arguments.at(argument) == "--verbose") { avtranscoder::Logger::setLogLevel(AV_LOG_DEBUG); @@ -144,7 +105,7 @@ int main(int argc, char** argv) avtranscoder::OutputFile outputFile(argv[2]); avtranscoder::Transcoder transcoder(outputFile); - transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnStream, 0); + transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnDuration, 0, 5); parseConfigFile(inputConfigFile, transcoder); diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 1645fcf0..7acfbfbb 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -226,7 +226,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu setOffset(offset); } -StreamTranscoder::StreamTranscoder(const ICodec& inputCodec, IOutputFile& outputFile, const ProfileLoader::Profile& profile) +StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader::Profile& profile) : _inputStream(NULL) , _outputStream(NULL) , _sourceBuffer(NULL) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 7c8a8c5d..4d2dfdc8 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -41,7 +41,7 @@ class AvExport StreamTranscoder * @brief encode from a generated stream * @note offset feature has no sense here **/ - StreamTranscoder(const ICodec& inputCodec, IOutputFile& outputFile, const ProfileLoader::Profile& profile); + StreamTranscoder(IOutputFile& outputFile, const ProfileLoader::Profile& profile); ~StreamTranscoder(); diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 5675e4a7..ac7898fe 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -55,26 +55,6 @@ void Transcoder::add(const std::string& filename, const size_t streamIndex, cons } } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const std::string& profileName, ICodec& codec, - const float offset) -{ - // Re-wrap - if(profileName.length() == 0) - { - // Check filename - if(filename.length() == 0) - throw std::runtime_error("Can't re-wrap a stream without filename indicated"); - - addRewrapStream(filename, streamIndex, offset); - } - // Transcode - else - { - const ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile(profileName); - add(filename, streamIndex, transcodeProfile, codec, offset); - } -} - void Transcoder::add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, const float offset) { @@ -85,21 +65,6 @@ void Transcoder::add(const std::string& filename, const size_t streamIndex, cons addTranscodeStream(filename, streamIndex, -1, profile, offset); } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, - ICodec& codec, const float offset) -{ - // Generator - if(!filename.length()) - { - addDummyStream(profile, codec); - } - // Transcode - else - { - addTranscodeStream(filename, streamIndex, -1, profile, offset); - } -} - void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName, const float offset) { @@ -131,38 +96,6 @@ void Transcoder::add(const std::string& filename, const size_t streamIndex, cons } } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, - const std::string& profileName, ICodec& codec, const float offset) -{ - // No subStream selected - if(subStreamIndex < 0) - { - add(filename, streamIndex, profileName, codec); - return; - } - - // Re-wrap - if(profileName.length() == 0) - { - // Re-wrap - if(subStreamIndex < 0) - { - addRewrapStream(filename, streamIndex, offset); - } - // Transcode (transparent for the user) - else - { - addTranscodeStream(filename, streamIndex, subStreamIndex, offset); - } - } - // Transcode - else - { - const ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile(profileName); - add(filename, streamIndex, subStreamIndex, transcodeProfile, codec, offset); - } -} - void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile& profile, const float offset) { @@ -180,24 +113,15 @@ void Transcoder::add(const std::string& filename, const size_t streamIndex, cons addTranscodeStream(filename, streamIndex, subStreamIndex, profile, offset); } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, - const ProfileLoader::Profile& profile, ICodec& codec, const float offset) +void Transcoder::add(const std::string& profile) { - // No subStream selected - if(subStreamIndex < 0) - { - add(filename, streamIndex, profile); - return; - } - - // Generator - if(!filename.length()) - { - addDummyStream(profile, codec); - return; - } + const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(profile); + add(encodingProfile); +} - addTranscodeStream(filename, streamIndex, subStreamIndex, profile, offset); +void Transcoder::add(const ProfileLoader::Profile& profile) +{ + addDummyStream(profile); } void Transcoder::add(StreamTranscoder& stream) @@ -375,16 +299,15 @@ void Transcoder::addTranscodeStream(const std::string& filename, const size_t st } } -void Transcoder::addDummyStream(const ProfileLoader::Profile& profile, const ICodec& codec) +void Transcoder::addDummyStream(const ProfileLoader::Profile& profile) { // Add profile if(!_profileLoader.hasProfile(profile)) _profileLoader.loadProfile(profile); - LOG_INFO("Add generated stream with codec '" - << codec.getCodecName() << "' / encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman)) + LOG_INFO("Add generated stream with encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman)) - _streamTranscodersAllocated.push_back(new StreamTranscoder(codec, _outputFile, profile)); + _streamTranscodersAllocated.push_back(new StreamTranscoder(_outputFile, profile)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 1b701d92..16378e91 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -63,12 +63,6 @@ class AvExport Transcoder */ void add(const std::string& filename, const size_t streamIndex, const std::string& profileName = "", const float offset = 0); - /* - * @note If filename is empty, add a generated stream. - * @note If filename is empty, profileName can't be empty (no sens to rewrap a generated stream). - */ - void add(const std::string& filename, const size_t streamIndex, const std::string& profileName, ICodec& codec, - const float offset = 0); /** * @brief Add a stream and set a custom profile @@ -76,11 +70,6 @@ class AvExport Transcoder */ void add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, const float offset = 0); - /* - * @note If filename is empty, add a generated stream. - */ - void add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, ICodec& codec, - const float offset = 0); /** * @brief Add a stream and set a profile @@ -89,12 +78,6 @@ class AvExport Transcoder */ void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName = "", const float offset = 0); - /** - * @note If filename is empty, add a generated stream. - * @note If filename is empty, profileName can't be empty (no sens to rewrap a generated stream). - */ - void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName, - ICodec& codec, const float offset = 0); /** * @brief Add a stream and set a custom profile @@ -103,11 +86,12 @@ class AvExport Transcoder */ void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile& profile, const float offset = 0); - /** - * @note If filename is empty, add a generated stream. - */ - void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, - const ProfileLoader::Profile& profile, ICodec& codec, const float offset = 0); + + //@{ + // @brief Add a generated stream. + void add(const std::string& profile); + void add(const ProfileLoader::Profile& profile); + //@} /** * @brief Add the stream @@ -173,7 +157,7 @@ class AvExport Transcoder void addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile& profile, const float offset = 0); - void addDummyStream(const ProfileLoader::Profile& profile, const ICodec& codec); + void addDummyStream(const ProfileLoader::Profile& profile); /** * @note If streamIndex is negative, activate all streams of the file. From 7570203d6dd50a28076be11759095cf1a77291e4 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 10:28:37 +0200 Subject: [PATCH 04/31] Transcoder: added InputStreamDesc to describe the source data to extract * This struct is given as parameter to the 'add' method of the Transcoder. * Updated python tests. --- app/avProcessor/avProcessor.cpp | 7 +- app/pyProcessor/pyprocessor.py | 5 +- app/pyRewrap/pyrewrap.py | 2 +- src/AvTranscoder/transcoder/Transcoder.cpp | 96 +++++-------------- src/AvTranscoder/transcoder/Transcoder.hpp | 58 ++++++----- test/pyTest/testEProcessMethod.py | 20 ++-- test/pyTest/testFilter.py | 4 +- test/pyTest/testNbFrames.py | 4 +- test/pyTest/testNbSamples.py | 4 +- test/pyTest/testOffset.py | 24 ++--- test/pyTest/testProcessStat.py | 2 +- test/pyTest/testProperties.py | 6 +- test/pyTest/testSetFrame.py | 29 +++--- test/pyTest/testTranscoderAdd.py | 2 +- test/pyTest/testTranscoderDummy.py | 61 +++++------- test/pyTest/testTranscoderRewrap.py | 20 ++-- .../pyTest/testTranscoderTranscodeAudioMov.py | 6 +- .../testTranscoderTranscodeAudioWave.py | 10 +- test/pyTest/testTranscoderTranscodeImage.py | 4 +- test/pyTest/testTranscoderTranscodeVideo.py | 8 +- 20 files changed, 161 insertions(+), 211 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 3bbaab79..4fa8eb95 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -39,7 +39,10 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder if(!filename.length()) transcoder.add(transcodeProfile); else - transcoder.add(filename, streamIndex, subStreamIndex, transcodeProfile); + { + avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, subStreamIndex); + transcoder.add(inputDesc, transcodeProfile); + } } } } @@ -105,7 +108,7 @@ int main(int argc, char** argv) avtranscoder::OutputFile outputFile(argv[2]); avtranscoder::Transcoder transcoder(outputFile); - transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnDuration, 0, 5); + transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnStream, 0); parseConfigFile(inputConfigFile, transcoder); diff --git a/app/pyProcessor/pyprocessor.py b/app/pyProcessor/pyprocessor.py index e9eaca96..0979b2c6 100644 --- a/app/pyProcessor/pyprocessor.py +++ b/app/pyProcessor/pyprocessor.py @@ -19,7 +19,8 @@ def parseConfigFile( inputConfigFile, transcoder ): streamIndex = int(streamIndexes) subStreamIndex = -1 - transcoder.add( filename, streamIndex, subStreamIndex, profileName ) + inputDesc = av.InputStreamDesc(filename, streamIndex, subStreamIndex) + transcoder.add(inputDesc, profileName) # Create command-line interface @@ -35,7 +36,7 @@ def parseConfigFile( inputConfigFile, transcoder ): args = parser.parse_args() # setup avtranscoder -logger = av.Logger().setLogLevel(av.AV_LOG_QUIET) +av.Logger().setLogLevel(av.AV_LOG_QUIET) av.preloadCodecsAndFormats() # create Transcoder diff --git a/app/pyRewrap/pyrewrap.py b/app/pyRewrap/pyrewrap.py index abe3f020..25e0f0b9 100644 --- a/app/pyRewrap/pyrewrap.py +++ b/app/pyRewrap/pyrewrap.py @@ -71,7 +71,7 @@ # create transcoder transcoder = av.Transcoder( outputFile ) for streamIndex in range(0, inputFile.getProperties().getNbStreams()): - transcoder.add(args.inputFileName, streamIndex) + transcoder.add(av.InputStreamDesc(args.inputFileName, streamIndex)) # launch process progress = av.ConsoleProgress() diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index ac7898fe..dbeef852 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -35,82 +35,38 @@ Transcoder::~Transcoder() } } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const std::string& profileName, - const float offset) -{ - // Re-wrap - if(profileName.length() == 0) - { - // Check filename - if(filename.length() == 0) - throw std::runtime_error("Can't re-wrap a stream without filename indicated"); - - addRewrapStream(filename, streamIndex, offset); - } - // Transcode - else - { - const ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile(profileName); - add(filename, streamIndex, transcodeProfile, offset); - } -} - -void Transcoder::add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, - const float offset) -{ - // Check filename - if(!filename.length()) - throw std::runtime_error("Can't transcode a stream without filename indicated"); - - addTranscodeStream(filename, streamIndex, -1, profile, offset); -} - -void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, +void Transcoder::add(const InputStreamDesc& inputStreamDesc, const std::string& profileName, const float offset) { - // No subStream selected - if(subStreamIndex < 0) - { - add(filename, streamIndex, profileName, offset); - return; - } + // Check filename + if(inputStreamDesc._filename.length() == 0) + throw std::runtime_error("Can't process a stream without a filename indicated."); if(profileName.length() == 0) { // Re-wrap - if(subStreamIndex < 0) - { - addRewrapStream(filename, streamIndex, offset); - } + if(inputStreamDesc._channelIndex < 0) + addRewrapStream(inputStreamDesc, offset); // Transcode (transparent for the user) else - { - addTranscodeStream(filename, streamIndex, subStreamIndex, offset); - } + addTranscodeStream(inputStreamDesc, offset); } // Transcode else { - const ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile(profileName); - add(filename, streamIndex, subStreamIndex, transcodeProfile, offset); + const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(profileName); + add(inputStreamDesc, encodingProfile, offset); } } -void Transcoder::add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, +void Transcoder::add(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset) { - // No subStream selected - if(subStreamIndex < 0) - { - add(filename, streamIndex, profile, offset); - return; - } - // Check filename - if(!filename.length()) - throw std::runtime_error("Can't transcode a stream without filename indicated"); + if(!inputStreamDesc._filename.length()) + throw std::runtime_error("Can't transcode a stream without a filename indicated."); - addTranscodeStream(filename, streamIndex, subStreamIndex, profile, offset); + addTranscodeStream(inputStreamDesc, profile, offset); } void Transcoder::add(const std::string& profile) @@ -240,32 +196,32 @@ void Transcoder::setProcessMethod(const EProcessMethod eProcessMethod, const siz _outputDuration = outputDuration; } -void Transcoder::addRewrapStream(const std::string& filename, const size_t streamIndex, const float offset) +void Transcoder::addRewrapStream(const InputStreamDesc& inputStreamDesc, const float offset) { - LOG_INFO("Add rewrap stream from file '" << filename << "' / index=" << streamIndex << " / offset=" << offset << "s") + LOG_INFO("Add rewrap stream from file '" << inputStreamDesc._filename << "' / index=" << inputStreamDesc._streamIndex << " / offset=" << offset << "s") - InputFile* referenceFile = addInputFile(filename, streamIndex, offset); + InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); - _streamTranscodersAllocated.push_back(new StreamTranscoder(referenceFile->getStream(streamIndex), _outputFile, offset)); + _streamTranscodersAllocated.push_back(new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); } -void Transcoder::addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex, +void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, const float offset) { // Get profile from input file - InputFile inputFile(filename); - ProfileLoader::Profile profile = getProfileFromFile(inputFile, streamIndex); + InputFile inputFile(inputStreamDesc._filename); + ProfileLoader::Profile profile = getProfileFromFile(inputFile, inputStreamDesc._streamIndex); // override channels parameter to manage demultiplexing ProfileLoader::Profile::iterator it = profile.find(constants::avProfileChannel); if(it != profile.end()) it->second = "1"; - addTranscodeStream(filename, streamIndex, subStreamIndex, profile, offset); + addTranscodeStream(inputStreamDesc, profile, offset); } -void Transcoder::addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex, +void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset) { // Add profile @@ -273,19 +229,19 @@ void Transcoder::addTranscodeStream(const std::string& filename, const size_t st _profileLoader.loadProfile(profile); LOG_INFO("Add transcode stream from file '" - << filename << "' / index=" << streamIndex << " / channel=" << subStreamIndex + << inputStreamDesc._filename << "' / index=" << inputStreamDesc._streamIndex << " / channel=" << inputStreamDesc._channelIndex << " / encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman) << " / offset=" << offset << "s") // Add input file - InputFile* referenceFile = addInputFile(filename, streamIndex, offset); + InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); - switch(referenceFile->getStream(streamIndex).getProperties().getStreamType()) + switch(referenceFile->getStream(inputStreamDesc._streamIndex).getProperties().getStreamType()) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(referenceFile->getStream(streamIndex), _outputFile, profile, subStreamIndex, offset)); + new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelIndex, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 16378e91..050075f3 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -16,6 +16,28 @@ namespace avtranscoder { +/** + * @brief Structure to describe the source data to extract. + */ +struct InputStreamDesc { + + InputStreamDesc(const std::string& filename, const size_t streamIndex, const int channelIndex) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelIndex(channelIndex) + {} + + InputStreamDesc(const std::string& filename, const size_t streamIndex) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelIndex(-1) + {} + + std::string _filename; ///< Source file path. + size_t _streamIndex; ///< Source stream to extract. + int _channelIndex; ///< Source channel to extract from the stream (no demultiplexing if -1) +}; + /** * @brief Enum to set a policy of how we manage the process in case of several streams. * eProcessMethodShortest: stop the process at the end of the shortest stream. @@ -54,41 +76,25 @@ class AvExport Transcoder ~Transcoder(); /** - * @brief Add a stream and set a profile - * @note If profileName is empty, rewrap. - * @note offset in seconds + * @brief Create an output stream from the given input description to process. + * @param profileName: the encoding profile (rewrap if empty) + * @param offset: in seconds * If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before * the stream to process. * If offset is negative, the transcoder will seek in the stream and start process at this specific time. */ - void add(const std::string& filename, const size_t streamIndex, const std::string& profileName = "", - const float offset = 0); - - /** - * @brief Add a stream and set a custom profile - * @note Profile will be updated, be sure to pass unique profile name. - */ - void add(const std::string& filename, const size_t streamIndex, const ProfileLoader::Profile& profile, - const float offset = 0); - - /** - * @brief Add a stream and set a profile - * @note If profileName is empty, rewrap. - * @note If subStreamIndex is negative, no substream is selected it's the stream. - */ - void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, + void add(const InputStreamDesc& inputStreamDesc, const std::string& profileName = "", const float offset = 0); /** - * @brief Add a stream and set a custom profile + * @brief Create an output stream from the given input description to process. * @note Profile will be updated, be sure to pass unique profile name. - * @note If subStreamIndex is negative, no substream is selected it's the stream. */ - void add(const std::string& filename, const size_t streamIndex, const int subStreamIndex, + void add(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); //@{ - // @brief Add a generated stream. + // @brief Create an output generated stream. void add(const std::string& profile); void add(const ProfileLoader::Profile& profile); //@} @@ -150,11 +156,11 @@ class AvExport Transcoder const double outputDuration = 0); private: - void addRewrapStream(const std::string& filename, const size_t streamIndex, const float offset); + void addRewrapStream(const InputStreamDesc& inputStreamDesc, const float offset); - void addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex, + void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const float offset); - void addTranscodeStream(const std::string& filename, const size_t streamIndex, const int subStreamIndex, + void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); void addDummyStream(const ProfileLoader::Profile& profile); diff --git a/test/pyTest/testEProcessMethod.py b/test/pyTest/testEProcessMethod.py index 4fee610f..a091e307 100644 --- a/test/pyTest/testEProcessMethod.py +++ b/test/pyTest/testEProcessMethod.py @@ -27,8 +27,8 @@ def testEProcessMethodShortest(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodShortest ) - transcoder.add( inputFileName_longest, 0 ) - transcoder.add( inputFileName_shortest, 0 ) + transcoder.add( av.InputStreamDesc(inputFileName_longest, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_shortest, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -57,8 +57,8 @@ def testEProcessMethodLongest(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodLongest ) - transcoder.add( inputFileName_longest, 0 ) - transcoder.add( inputFileName_shortest, 0 ) + transcoder.add( av.InputStreamDesc(inputFileName_longest, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_shortest, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -88,9 +88,9 @@ def testEProcessMethodBasedOnStream(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodBasedOnStream, 1 ) - transcoder.add( inputFileName_first, 0 ) - transcoder.add( inputFileName_second, 0 ) - transcoder.add( inputFileName_third, 0 ) + transcoder.add( av.InputStreamDesc(inputFileName_first, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_second, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_third, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -121,9 +121,9 @@ def testEProcessMethodBasedOnDuration(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodBasedOnDuration, 0, outputDuration ) - transcoder.add( inputFileName_first, 0 ) - transcoder.add( inputFileName_second, 0 ) - transcoder.add( inputFileName_third, 0 ) + transcoder.add( av.InputStreamDesc(inputFileName_first, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_second, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName_third, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testFilter.py b/test/pyTest/testFilter.py index 8bf84278..52bd67c5 100644 --- a/test/pyTest/testFilter.py +++ b/test/pyTest/testFilter.py @@ -65,7 +65,7 @@ def testVideoTranscodeWithFilter(): customProfile[av.avProfileType] = av.avProfileTypeVideo customProfile[av.avProfileCodec] = "mpeg2video" customProfile[av.avProfilePixelFormat] = "yuv420p" - transcoder.add( inputFileName, videoStreamIndex, customProfile ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) # add yadif filter streamTranscoder = transcoder.getStreamTranscoder(0) @@ -104,7 +104,7 @@ def testAudioTranscodeWithFilter(): # transcode the video stream audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave24b48kmono" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) # add volume filter (here +150% of current volume) streamTranscoder = transcoder.getStreamTranscoder(0) diff --git a/test/pyTest/testNbFrames.py b/test/pyTest/testNbFrames.py index 71217cb2..cec20b0d 100644 --- a/test/pyTest/testNbFrames.py +++ b/test/pyTest/testNbFrames.py @@ -20,7 +20,7 @@ def testNbFramesVideoRewrap(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "" ) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -47,7 +47,7 @@ def testNbFramesVideoTranscode(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "mpeg2" ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2" ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testNbSamples.py b/test/pyTest/testNbSamples.py index d373a884..d419abb5 100644 --- a/test/pyTest/testNbSamples.py +++ b/test/pyTest/testNbSamples.py @@ -20,7 +20,7 @@ def testNbSamplesAudioRewrap(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "" ) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -54,7 +54,7 @@ def testNbSamplesAudioTranscode(): customProfile[av.avProfileType] = av.avProfileTypeAudio customProfile[av.avProfileCodec] = "pcm_s16le" - transcoder.add( inputFileName, 0, customProfile ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), customProfile ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 8e9128bf..58ce86e1 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -26,7 +26,7 @@ def testTranscodeAudioPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "wave24b48kmono", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -56,7 +56,7 @@ def testTranscodeAudioNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "wave24b48kmono", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -86,7 +86,7 @@ def testRewrapAudioPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -117,7 +117,7 @@ def testRewrapAudioNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -148,7 +148,7 @@ def testTranscodeVideoPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "mpeg2", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -178,7 +178,7 @@ def testTranscodeVideoNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "mpeg2", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -208,7 +208,7 @@ def testRewrapVideoPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -239,7 +239,7 @@ def testRewrapVideoNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -273,8 +273,8 @@ def testMultipleOffsetFromSameInputFile(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset_1 ) - transcoder.add( inputFileName, 1, "", offset_2 ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) + transcoder.add( av.InputStreamDesc(inputFileName, 1), "", offset_2 ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -310,8 +310,8 @@ def testMultipleOffsetFromSameStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0, "", offset_1 ) - transcoder.add( inputFileName, 0, "", offset_2 ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) + transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_2 ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testProcessStat.py b/test/pyTest/testProcessStat.py index 29831469..ab9f5407 100644 --- a/test/pyTest/testProcessStat.py +++ b/test/pyTest/testProcessStat.py @@ -33,7 +33,7 @@ def testProcessWithStatistics(): src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, customProfile ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testProperties.py b/test/pyTest/testProperties.py index cf20ea0e..35bf2e1c 100644 --- a/test/pyTest/testProperties.py +++ b/test/pyTest/testProperties.py @@ -21,13 +21,14 @@ def testAddPossibleMetadata(): """ Add metadata 'date' to the outputFile. """ + inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAddMetadataDate.wav" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) # rewrap a stream - transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0, "") + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) # add a set of metadata metadata_to_check = av.PropertyVector() @@ -49,13 +50,14 @@ def testAddImpossibleMetadata(): """ Can't add an impossible metadata to the outputFile. """ + inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] outputFileName = "testAddMetadataPlop.wav" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) # rewrap a stream - transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0, "") + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) # add one metadata metadata_to_check = ("undefinedMetadataKey", "undefinedMetadataValue") diff --git a/test/pyTest/testSetFrame.py b/test/pyTest/testSetFrame.py index b0807d03..2ccd6cdc 100644 --- a/test/pyTest/testSetFrame.py +++ b/test/pyTest/testSetFrame.py @@ -7,19 +7,23 @@ def testSetVideoFrame(): """ Generate a video stream, and set its frame during process. """ - # create output outputFileName = "testSetVideoFrame.mov" ouputFile = av.OutputFile( outputFileName ) - # create video frame and codec - inputVideoCodec = av.VideoCodec( av.eCodecTypeEncoder, "mpeg2video" ); - imageDesc = av.VideoFrameDesc( 1920, 1080, "rgb24" ) - inputVideoCodec.setImageParameters( imageDesc ) + # create custom profile + encodingProfile = av.ProfileMap() + encodingProfile[av.avProfileIdentificator] = "encodingProfile" + encodingProfile[av.avProfileIdentificatorHuman] = "custom profile" + encodingProfile[av.avProfileType] = av.avProfileTypeVideo + encodingProfile[av.avProfileCodec] = "mpeg2video" + encodingProfile[av.avProfilePixelFormat] = "yuv422p" + encodingProfile[av.avProfileWidth] = "1920" + encodingProfile[av.avProfileHeight] = "1080" # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.add( "", 0, "mpeg2", inputVideoCodec ) + transcoder.add( encodingProfile ) videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process @@ -34,7 +38,7 @@ def testSetVideoFrame(): p.progress( i, nbFrames ) # set video frame - frame = av.VideoFrame( imageDesc ) + frame = av.VideoFrame( av.VideoFrameDesc(1920, 1080, "yuv422p") ) frame.assign(i) videoDecoder.setNextFrame( frame ) @@ -59,19 +63,13 @@ def testSetAudioFrame(): """ Generate a audio stream, and set its frame during process. """ - # create output outputFileName = "testSetAudioFrame.wav" ouputFile = av.OutputFile( outputFileName ) - # create video frame and codec - inputAudioCodec = av.AudioCodec( av.eCodecTypeEncoder, "pcm_s24le" ); - audioDesc = av.AudioFrameDesc( 48000, 1, "s32" ) - inputAudioCodec.setAudioParameters( audioDesc ); - # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.add( "", 0, "wave24b48kmono", inputAudioCodec ) + transcoder.add( "wave24b48kmono" ) audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process @@ -86,7 +84,7 @@ def testSetAudioFrame(): p.progress( i, nbFrames ) # set video frame - frame = av.AudioFrame( audioDesc ) + frame = av.AudioFrame( av.AudioFrameDesc(48000, 1, "s32") ) frame.assign(i) audioDecoder.setNextFrame( frame ) @@ -105,4 +103,3 @@ def testSetAudioFrame(): assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() ) assert_equals( 48000, dst_audioStream.getSampleRate() ) assert_equals( 1, dst_audioStream.getNbChannels() ) - diff --git a/test/pyTest/testTranscoderAdd.py b/test/pyTest/testTranscoderAdd.py index 0513f085..618568ed 100644 --- a/test/pyTest/testTranscoderAdd.py +++ b/test/pyTest/testTranscoderAdd.py @@ -48,7 +48,7 @@ def testAddAllStreamsOfFileWhichDoesNotExist(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName ) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) # process progress = av.ConsoleProgress() diff --git a/test/pyTest/testTranscoderDummy.py b/test/pyTest/testTranscoderDummy.py index f9f7035e..1a3505b6 100644 --- a/test/pyTest/testTranscoderDummy.py +++ b/test/pyTest/testTranscoderDummy.py @@ -18,54 +18,50 @@ def testTranscodeNoStream(): @raises(RuntimeError) -def testRewrapDummy(): +def testGenerateVideoWithIncompleteProfile(): """ - Can't rewrap a dummy stream (no sense). + Can't generate a video stream without an encoding profile with: + - codec name + - pixel format + - width + - height """ - outputFileName = "testRewrapDummy.avi" + outputFileName = "testGenerateVideoWithIncompleteProfile.avi" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( "", 0, "") - transcoder.add( "", 0, -1, "") + encodingProfile = { + av.avProfileIdentificator : "newVideoPreset", + av.avProfileIdentificatorHuman : "New video preset", + av.avProfileType : av.avProfileTypeVideo, + } + transcoder.add( encodingProfile ) progress = av.NoDisplayProgress() transcoder.process( progress ) -@raises(RuntimeError) -def testTranscodeDummyExistingProfileWithNoEssenceDesc(): - """ - Can't add a dummy stream with no essence desc (for encoder). - """ - outputFileName = "testTranscodeDummyExistingProfileWithNoEssenceDesc.avi" - - ouputFile = av.OutputFile( outputFileName ) - transcoder = av.Transcoder( ouputFile ) - - transcoder.add( "", 0, "dnxhd120" ) - transcoder.add( "", 0, -1, "dnxhd120" ) - - progress = av.NoDisplayProgress() - transcoder.process( progress ) @raises(RuntimeError) -def testTranscodeDummyNewProfileWithNoEssenceDesc(): +def testGenerateAudioWithIncompleteProfile(): """ - Can't add a dummy stream with no essence desc (for encoder). + Can't generate an audio stream without an encoding profile with: + - codec name + - sample format + - sample rate + - number of channels """ - outputFileName = "testTranscodeDummyNewProfileWithNoEssenceDesc.avi" + outputFileName = "testGenerateAudioWithIncompleteProfile.wav" ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - newProfile = { + encodingProfile = { av.avProfileIdentificator : "newAudioPreset", av.avProfileIdentificatorHuman : "New audio preset", av.avProfileType : av.avProfileTypeAudio, } - transcoder.add( "", 0, newProfile ) - transcoder.add( "", 0, -1, newProfile ) + transcoder.add( encodingProfile ) progress = av.NoDisplayProgress() transcoder.process( progress ) @@ -79,11 +75,8 @@ def testTranscodeDummyAudio(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - # add a dummy video stream - audioCodec = av.AudioCodec( av.eCodecTypeEncoder, "pcm_s16le" ) - audioDesc = av.AudioFrameDesc( 48000, 1, "s16" ) - audioCodec.setAudioParameters( audioDesc ) - transcoder.add( "", 0, "wave24b48kmono", audioCodec ) + # add a dummy audio stream + transcoder.add( "wave24b48kmono" ) ouputFile.beginWrap() transcoder.processFrame() @@ -99,11 +92,7 @@ def testTranscodeDummyVideo(): transcoder = av.Transcoder( ouputFile ) # add a dummy video stream - videoCodec = av.VideoCodec( av.eCodecTypeEncoder, "mpeg2video" ) - imageDesc = av.VideoFrameDesc( 1920, 1080, "yuv422p" ) - videoCodec.setImageParameters( imageDesc ) - - transcoder.add( "", 0, "dnxhd120", videoCodec ) + transcoder.add( "dnxhd120" ) ouputFile.beginWrap() transcoder.processFrame() diff --git a/test/pyTest/testTranscoderRewrap.py b/test/pyTest/testTranscoderRewrap.py index ea3fa1ba..1c1f62f4 100644 --- a/test/pyTest/testTranscoderRewrap.py +++ b/test/pyTest/testTranscoderRewrap.py @@ -72,9 +72,8 @@ def testRewrapAudioStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0 ) - progress = av.NoDisplayProgress() - processStat = transcoder.process( progress ) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + processStat = transcoder.process() # check process stat returned audioStat = processStat.getAudioStat(0) @@ -107,9 +106,8 @@ def testRewrapAVIVideoStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 0 ) - progress = av.NoDisplayProgress() - processStat = transcoder.process( progress ) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + processStat = transcoder.process() # check process stat returned checkVideoStat(src_videoStream, processStat.getVideoStat(0)) @@ -141,9 +139,8 @@ def testRewrapMOVVideoStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( inputFileName, 1 ) - progress = av.NoDisplayProgress() - processStat = transcoder.process( progress ) + transcoder.add( av.InputStreamDesc(inputFileName, 1) ) + processStat = transcoder.process() # check process stat returned checkVideoStat(src_videoStream, processStat.getVideoStat(0)) @@ -175,9 +172,8 @@ def testRewrapRawVideoStream(): ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) - transcoder.add(inputFileName, 0) - progress = av.NoDisplayProgress() - processStat = transcoder.process(progress) + transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + processStat = transcoder.process() # check process stat returned checkVideoStat(src_videoStream, processStat.getVideoStat(0)) diff --git a/test/pyTest/testTranscoderTranscodeAudioMov.py b/test/pyTest/testTranscoderTranscodeAudioMov.py index 114466fc..c7f7349a 100644 --- a/test/pyTest/testTranscoderTranscodeAudioMov.py +++ b/test/pyTest/testTranscoderTranscodeAudioMov.py @@ -32,7 +32,7 @@ def testTranscodeMovVariableNbSamplesPerFrame(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, customProfile ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -64,8 +64,8 @@ def testTranscodeMovExtractChannels(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, 0 ) - transcoder.add( inputFileName, audioStreamIndex, 3 ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex, 0) ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex, 3) ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeAudioWave.py b/test/pyTest/testTranscoderTranscodeAudioWave.py index 36a44b99..e5a33eff 100644 --- a/test/pyTest/testTranscoderTranscodeAudioWave.py +++ b/test/pyTest/testTranscoderTranscodeAudioWave.py @@ -23,7 +23,7 @@ def testTranscodeWave24b48k5_1(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave24b48k5_1" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48k5_1" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -57,7 +57,7 @@ def testTranscodeWave24b48kstereo(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave24b48kstereo" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kstereo" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -91,7 +91,7 @@ def testTranscodeWave24b48kmono(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave24b48kmono" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -125,7 +125,7 @@ def testTranscodeWave16b48kmono(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave16b48kmono" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -162,7 +162,7 @@ def testTranscodeWave16b48kmonoWithSilence(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( inputFileName, audioStreamIndex, "wave16b48kmono" ) + transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeImage.py b/test/pyTest/testTranscoderTranscodeImage.py index 5e1db9b9..fb272832 100644 --- a/test/pyTest/testTranscoderTranscodeImage.py +++ b/test/pyTest/testTranscoderTranscodeImage.py @@ -26,7 +26,7 @@ def testTranscodePngToMjpeg(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, "mjpeg" ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -57,7 +57,7 @@ def testTranscodeJpgToMjpeg(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, "mjpeg" ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeVideo.py b/test/pyTest/testTranscoderTranscodeVideo.py index 8f486f94..623afb94 100644 --- a/test/pyTest/testTranscoderTranscodeVideo.py +++ b/test/pyTest/testTranscoderTranscodeVideo.py @@ -23,7 +23,7 @@ def testTranscodeDnxhd120(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, "dnxhd120" ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd120" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -61,7 +61,7 @@ def testTranscodeDnxhd185(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, "dnxhd185" ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -99,7 +99,7 @@ def testTranscodeDnxhd185x(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, "dnxhd185x" ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185x" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -145,7 +145,7 @@ def testTranscodeYUV420(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( inputFileName, videoStreamIndex, customProfile ) + transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) From 003df71983ab7f3108363b932b818e935370f839 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 10:38:20 +0200 Subject: [PATCH 05/31] pyTest: renamed Dummy tests to GenerateStream --- .../{testTranscoderDummy.py => testTranscoderGenerateStream.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/pyTest/{testTranscoderDummy.py => testTranscoderGenerateStream.py} (100%) diff --git a/test/pyTest/testTranscoderDummy.py b/test/pyTest/testTranscoderGenerateStream.py similarity index 100% rename from test/pyTest/testTranscoderDummy.py rename to test/pyTest/testTranscoderGenerateStream.py From 29af8e23957aeaa10e68da0ef56fbf2b35c13c64 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 10:38:39 +0200 Subject: [PATCH 06/31] Transcoder: renamed private method addDummyStream to addGeneratedStream --- src/AvTranscoder/transcoder/Transcoder.cpp | 4 ++-- src/AvTranscoder/transcoder/Transcoder.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index dbeef852..38f50543 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -77,7 +77,7 @@ void Transcoder::add(const std::string& profile) void Transcoder::add(const ProfileLoader::Profile& profile) { - addDummyStream(profile); + addGeneratedStream(profile); } void Transcoder::add(StreamTranscoder& stream) @@ -255,7 +255,7 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, } } -void Transcoder::addDummyStream(const ProfileLoader::Profile& profile) +void Transcoder::addGeneratedStream(const ProfileLoader::Profile& profile) { // Add profile if(!_profileLoader.hasProfile(profile)) diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 050075f3..73d9d2b5 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -163,7 +163,7 @@ class AvExport Transcoder void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); - void addDummyStream(const ProfileLoader::Profile& profile); + void addGeneratedStream(const ProfileLoader::Profile& profile); /** * @note If streamIndex is negative, activate all streams of the file. From 1b84b88756cfebd18f751e5216e24ed589e86b09 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 10:44:25 +0200 Subject: [PATCH 07/31] Transcoder: renamed 'add' methods to generate streams to 'addGeneratedStream' * Removed private method 'addGeneratedStream' (no more needed). * Updated python tests. --- app/avProcessor/avProcessor.cpp | 2 +- src/AvTranscoder/transcoder/Transcoder.cpp | 29 +++++++++------------ src/AvTranscoder/transcoder/Transcoder.hpp | 6 ++--- test/pyTest/testTranscoderGenerateStream.py | 18 ++++++------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 4fa8eb95..301888f9 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -37,7 +37,7 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder // generated stream if(!filename.length()) - transcoder.add(transcodeProfile); + transcoder.addGeneratedStream(transcodeProfile); else { avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, subStreamIndex); diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 38f50543..2588e488 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -69,15 +69,22 @@ void Transcoder::add(const InputStreamDesc& inputStreamDesc, addTranscodeStream(inputStreamDesc, profile, offset); } -void Transcoder::add(const std::string& profile) +void Transcoder::addGeneratedStream(const std::string& encodingProfileName) { - const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(profile); - add(encodingProfile); + const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(encodingProfileName); + addGeneratedStream(encodingProfile); } -void Transcoder::add(const ProfileLoader::Profile& profile) +void Transcoder::addGeneratedStream(const ProfileLoader::Profile& encodingProfile) { - addGeneratedStream(profile); + // Add profile + if(!_profileLoader.hasProfile(encodingProfile)) + _profileLoader.loadProfile(encodingProfile); + + LOG_INFO("Add generated stream with encodingProfile=" << encodingProfile.at(constants::avProfileIdentificatorHuman)) + + _streamTranscodersAllocated.push_back(new StreamTranscoder(_outputFile, encodingProfile)); + _streamTranscoders.push_back(_streamTranscodersAllocated.back()); } void Transcoder::add(StreamTranscoder& stream) @@ -255,18 +262,6 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, } } -void Transcoder::addGeneratedStream(const ProfileLoader::Profile& profile) -{ - // Add profile - if(!_profileLoader.hasProfile(profile)) - _profileLoader.loadProfile(profile); - - LOG_INFO("Add generated stream with encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman)) - - _streamTranscodersAllocated.push_back(new StreamTranscoder(_outputFile, profile)); - _streamTranscoders.push_back(_streamTranscodersAllocated.back()); -} - InputFile* Transcoder::addInputFile(const std::string& filename, const int streamIndex, const float offset) { InputFile* referenceFile = NULL; diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 73d9d2b5..4f065580 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -95,8 +95,8 @@ class AvExport Transcoder //@{ // @brief Create an output generated stream. - void add(const std::string& profile); - void add(const ProfileLoader::Profile& profile); + void addGeneratedStream(const std::string& encodingProfileName); + void addGeneratedStream(const ProfileLoader::Profile& encodingProfile); //@} /** @@ -163,8 +163,6 @@ class AvExport Transcoder void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); - void addGeneratedStream(const ProfileLoader::Profile& profile); - /** * @note If streamIndex is negative, activate all streams of the file. */ diff --git a/test/pyTest/testTranscoderGenerateStream.py b/test/pyTest/testTranscoderGenerateStream.py index 1a3505b6..89edf87b 100644 --- a/test/pyTest/testTranscoderGenerateStream.py +++ b/test/pyTest/testTranscoderGenerateStream.py @@ -36,10 +36,9 @@ def testGenerateVideoWithIncompleteProfile(): av.avProfileIdentificatorHuman : "New video preset", av.avProfileType : av.avProfileTypeVideo, } - transcoder.add( encodingProfile ) + transcoder.addGeneratedStream( encodingProfile ) - progress = av.NoDisplayProgress() - transcoder.process( progress ) + transcoder.process() @raises(RuntimeError) @@ -61,10 +60,9 @@ def testGenerateAudioWithIncompleteProfile(): av.avProfileIdentificatorHuman : "New audio preset", av.avProfileType : av.avProfileTypeAudio, } - transcoder.add( encodingProfile ) + transcoder.addGeneratedStream( encodingProfile ) - progress = av.NoDisplayProgress() - transcoder.process( progress ) + transcoder.process() def testTranscodeDummyAudio(): """ @@ -75,8 +73,8 @@ def testTranscodeDummyAudio(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - # add a dummy audio stream - transcoder.add( "wave24b48kmono" ) + # generate an audio stream + transcoder.addGeneratedStream( "wave24b48kmono" ) ouputFile.beginWrap() transcoder.processFrame() @@ -91,8 +89,8 @@ def testTranscodeDummyVideo(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - # add a dummy video stream - transcoder.add( "dnxhd120" ) + # generate a video stream + transcoder.addGeneratedStream( "dnxhd120" ) ouputFile.beginWrap() transcoder.processFrame() From 068df30205fe9e35e2e07b1f7d3b949f732f3703 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 10:52:09 +0200 Subject: [PATCH 08/31] Transcoder: renamed 'add' methods to 'addStream' * Updated their doc. * Updated python tests. --- app/avProcessor/avProcessor.cpp | 2 +- app/pyProcessor/pyprocessor.py | 2 +- app/pyRewrap/pyrewrap.py | 2 +- app/pyThumbnail/pythumbnail.py | 2 +- src/AvTranscoder/transcoder/Transcoder.cpp | 8 +++---- src/AvTranscoder/transcoder/Transcoder.hpp | 12 +++++----- test/pyTest/testEProcessMethod.py | 20 ++++++++-------- test/pyTest/testFilter.py | 4 ++-- test/pyTest/testNbFrames.py | 4 ++-- test/pyTest/testNbSamples.py | 4 ++-- test/pyTest/testOffset.py | 24 +++++++++---------- test/pyTest/testProcessStat.py | 2 +- test/pyTest/testProperties.py | 4 ++-- test/pyTest/testSetFrame.py | 4 ++-- test/pyTest/testTranscoderAdd.py | 4 ++-- test/pyTest/testTranscoderRewrap.py | 8 +++---- .../pyTest/testTranscoderTranscodeAudioMov.py | 6 ++--- .../testTranscoderTranscodeAudioWave.py | 10 ++++---- test/pyTest/testTranscoderTranscodeImage.py | 4 ++-- test/pyTest/testTranscoderTranscodeVideo.py | 8 +++---- 20 files changed, 67 insertions(+), 67 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 301888f9..0841b1df 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -41,7 +41,7 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder else { avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, subStreamIndex); - transcoder.add(inputDesc, transcodeProfile); + transcoder.addStream(inputDesc, transcodeProfile); } } } diff --git a/app/pyProcessor/pyprocessor.py b/app/pyProcessor/pyprocessor.py index 0979b2c6..fcbf2c34 100644 --- a/app/pyProcessor/pyprocessor.py +++ b/app/pyProcessor/pyprocessor.py @@ -20,7 +20,7 @@ def parseConfigFile( inputConfigFile, transcoder ): subStreamIndex = -1 inputDesc = av.InputStreamDesc(filename, streamIndex, subStreamIndex) - transcoder.add(inputDesc, profileName) + transcoder.addStream(inputDesc, profileName) # Create command-line interface diff --git a/app/pyRewrap/pyrewrap.py b/app/pyRewrap/pyrewrap.py index 25e0f0b9..fb3584ac 100644 --- a/app/pyRewrap/pyrewrap.py +++ b/app/pyRewrap/pyrewrap.py @@ -71,7 +71,7 @@ # create transcoder transcoder = av.Transcoder( outputFile ) for streamIndex in range(0, inputFile.getProperties().getNbStreams()): - transcoder.add(av.InputStreamDesc(args.inputFileName, streamIndex)) + transcoder.addStream(av.InputStreamDesc(args.inputFileName, streamIndex)) # launch process progress = av.ConsoleProgress() diff --git a/app/pyThumbnail/pythumbnail.py b/app/pyThumbnail/pythumbnail.py index 63121660..36cd6924 100644 --- a/app/pyThumbnail/pythumbnail.py +++ b/app/pyThumbnail/pythumbnail.py @@ -97,7 +97,7 @@ # create transcoder transcoder = av.Transcoder( outputFile ) -transcoder.add( outputStream ) +transcoder.addStream( outputStream ) # launch process outputFile.beginWrap() diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 2588e488..72209676 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -35,7 +35,7 @@ Transcoder::~Transcoder() } } -void Transcoder::add(const InputStreamDesc& inputStreamDesc, +void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const std::string& profileName, const float offset) { // Check filename @@ -55,11 +55,11 @@ void Transcoder::add(const InputStreamDesc& inputStreamDesc, else { const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(profileName); - add(inputStreamDesc, encodingProfile, offset); + addStream(inputStreamDesc, encodingProfile, offset); } } -void Transcoder::add(const InputStreamDesc& inputStreamDesc, +void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset) { // Check filename @@ -87,7 +87,7 @@ void Transcoder::addGeneratedStream(const ProfileLoader::Profile& encodingProfil _streamTranscoders.push_back(_streamTranscodersAllocated.back()); } -void Transcoder::add(StreamTranscoder& stream) +void Transcoder::addStream(StreamTranscoder& stream) { _streamTranscoders.push_back(&stream); } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 4f065580..e6868b95 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -76,25 +76,25 @@ class AvExport Transcoder ~Transcoder(); /** - * @brief Create an output stream from the given input description to process. + * @brief Add a new stream to the output file, created from the given input description to process. * @param profileName: the encoding profile (rewrap if empty) * @param offset: in seconds * If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before * the stream to process. * If offset is negative, the transcoder will seek in the stream and start process at this specific time. */ - void add(const InputStreamDesc& inputStreamDesc, + void addStream(const InputStreamDesc& inputStreamDesc, const std::string& profileName = "", const float offset = 0); /** - * @brief Create an output stream from the given input description to process. + * @brief Add a new stream to the output file, created from the given input description to process. * @note Profile will be updated, be sure to pass unique profile name. */ - void add(const InputStreamDesc& inputStreamDesc, + void addStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); //@{ - // @brief Create an output generated stream. + // @brief Add a new generated stream to the output file, created from the given encoding profile. void addGeneratedStream(const std::string& encodingProfileName); void addGeneratedStream(const ProfileLoader::Profile& encodingProfile); //@} @@ -102,7 +102,7 @@ class AvExport Transcoder /** * @brief Add the stream */ - void add(StreamTranscoder& streamTranscoder); + void addStream(StreamTranscoder& streamTranscoder); /** * @brief Initialize all added streams, processing codec latency. diff --git a/test/pyTest/testEProcessMethod.py b/test/pyTest/testEProcessMethod.py index a091e307..588e0a74 100644 --- a/test/pyTest/testEProcessMethod.py +++ b/test/pyTest/testEProcessMethod.py @@ -27,8 +27,8 @@ def testEProcessMethodShortest(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodShortest ) - transcoder.add( av.InputStreamDesc(inputFileName_longest, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_shortest, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_longest, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_shortest, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -57,8 +57,8 @@ def testEProcessMethodLongest(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodLongest ) - transcoder.add( av.InputStreamDesc(inputFileName_longest, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_shortest, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_longest, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_shortest, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -88,9 +88,9 @@ def testEProcessMethodBasedOnStream(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodBasedOnStream, 1 ) - transcoder.add( av.InputStreamDesc(inputFileName_first, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_second, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_third, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_first, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_second, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_third, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -121,9 +121,9 @@ def testEProcessMethodBasedOnDuration(): transcoder = av.Transcoder( ouputFile ) transcoder.setProcessMethod( av.eProcessMethodBasedOnDuration, 0, outputDuration ) - transcoder.add( av.InputStreamDesc(inputFileName_first, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_second, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName_third, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_first, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_second, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName_third, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testFilter.py b/test/pyTest/testFilter.py index 52bd67c5..5c7e0770 100644 --- a/test/pyTest/testFilter.py +++ b/test/pyTest/testFilter.py @@ -65,7 +65,7 @@ def testVideoTranscodeWithFilter(): customProfile[av.avProfileType] = av.avProfileTypeVideo customProfile[av.avProfileCodec] = "mpeg2video" customProfile[av.avProfilePixelFormat] = "yuv420p" - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) # add yadif filter streamTranscoder = transcoder.getStreamTranscoder(0) @@ -104,7 +104,7 @@ def testAudioTranscodeWithFilter(): # transcode the video stream audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) # add volume filter (here +150% of current volume) streamTranscoder = transcoder.getStreamTranscoder(0) diff --git a/test/pyTest/testNbFrames.py b/test/pyTest/testNbFrames.py index cec20b0d..d97e349c 100644 --- a/test/pyTest/testNbFrames.py +++ b/test/pyTest/testNbFrames.py @@ -20,7 +20,7 @@ def testNbFramesVideoRewrap(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -47,7 +47,7 @@ def testNbFramesVideoTranscode(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "mpeg2" ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testNbSamples.py b/test/pyTest/testNbSamples.py index d419abb5..3dad11b9 100644 --- a/test/pyTest/testNbSamples.py +++ b/test/pyTest/testNbSamples.py @@ -20,7 +20,7 @@ def testNbSamplesAudioRewrap(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -54,7 +54,7 @@ def testNbSamplesAudioTranscode(): customProfile[av.avProfileType] = av.avProfileTypeAudio customProfile[av.avProfileCodec] = "pcm_s16le" - transcoder.add( av.InputStreamDesc(inputFileName, 0), customProfile ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), customProfile ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 58ce86e1..df9c9fc2 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -26,7 +26,7 @@ def testTranscodeAudioPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -56,7 +56,7 @@ def testTranscodeAudioNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "wave24b48kmono", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -86,7 +86,7 @@ def testRewrapAudioPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -117,7 +117,7 @@ def testRewrapAudioNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -148,7 +148,7 @@ def testTranscodeVideoPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -178,7 +178,7 @@ def testTranscodeVideoNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "mpeg2", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -208,7 +208,7 @@ def testRewrapVideoPositiveOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -239,7 +239,7 @@ def testRewrapVideoNegativeOffset(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -273,8 +273,8 @@ def testMultipleOffsetFromSameInputFile(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) - transcoder.add( av.InputStreamDesc(inputFileName, 1), "", offset_2 ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 1), "", offset_2 ) progress = av.ConsoleProgress() transcoder.process( progress ) @@ -310,8 +310,8 @@ def testMultipleOffsetFromSameStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) - transcoder.add( av.InputStreamDesc(inputFileName, 0), "", offset_2 ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset_1 ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset_2 ) progress = av.ConsoleProgress() transcoder.process( progress ) diff --git a/test/pyTest/testProcessStat.py b/test/pyTest/testProcessStat.py index ab9f5407..d8028d45 100644 --- a/test/pyTest/testProcessStat.py +++ b/test/pyTest/testProcessStat.py @@ -33,7 +33,7 @@ def testProcessWithStatistics(): src_properties = src_inputFile.getProperties() src_videoStream = src_properties.getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testProperties.py b/test/pyTest/testProperties.py index 35bf2e1c..3e29c8b5 100644 --- a/test/pyTest/testProperties.py +++ b/test/pyTest/testProperties.py @@ -28,7 +28,7 @@ def testAddPossibleMetadata(): transcoder = av.Transcoder( ouputFile ) # rewrap a stream - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) # add a set of metadata metadata_to_check = av.PropertyVector() @@ -57,7 +57,7 @@ def testAddImpossibleMetadata(): transcoder = av.Transcoder( ouputFile ) # rewrap a stream - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) # add one metadata metadata_to_check = ("undefinedMetadataKey", "undefinedMetadataValue") diff --git a/test/pyTest/testSetFrame.py b/test/pyTest/testSetFrame.py index 2ccd6cdc..2d5085e0 100644 --- a/test/pyTest/testSetFrame.py +++ b/test/pyTest/testSetFrame.py @@ -23,7 +23,7 @@ def testSetVideoFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.add( encodingProfile ) + transcoder.addStream( encodingProfile ) videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process @@ -69,7 +69,7 @@ def testSetAudioFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.add( "wave24b48kmono" ) + transcoder.addStream( "wave24b48kmono" ) audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process diff --git a/test/pyTest/testTranscoderAdd.py b/test/pyTest/testTranscoderAdd.py index 618568ed..6f3329b9 100644 --- a/test/pyTest/testTranscoderAdd.py +++ b/test/pyTest/testTranscoderAdd.py @@ -28,7 +28,7 @@ def testAddStreamTranscoder(): streamTranscoder = av.StreamTranscoder( inputFile.getStream( inputIndex ), ouputFile ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( streamTranscoder) + transcoder.addStream( streamTranscoder) # process progress = av.NoDisplayProgress() @@ -48,7 +48,7 @@ def testAddAllStreamsOfFileWhichDoesNotExist(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) # process progress = av.ConsoleProgress() diff --git a/test/pyTest/testTranscoderRewrap.py b/test/pyTest/testTranscoderRewrap.py index 1c1f62f4..cd4ae14a 100644 --- a/test/pyTest/testTranscoderRewrap.py +++ b/test/pyTest/testTranscoderRewrap.py @@ -72,7 +72,7 @@ def testRewrapAudioStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) processStat = transcoder.process() # check process stat returned @@ -106,7 +106,7 @@ def testRewrapAVIVideoStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) processStat = transcoder.process() # check process stat returned @@ -139,7 +139,7 @@ def testRewrapMOVVideoStream(): ouputFile = av.OutputFile( outputFileName ) transcoder = av.Transcoder( ouputFile ) - transcoder.add( av.InputStreamDesc(inputFileName, 1) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 1) ) processStat = transcoder.process() # check process stat returned @@ -172,7 +172,7 @@ def testRewrapRawVideoStream(): ouputFile = av.OutputFile(outputFileName) transcoder = av.Transcoder(ouputFile) - transcoder.add( av.InputStreamDesc(inputFileName, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) processStat = transcoder.process() # check process stat returned diff --git a/test/pyTest/testTranscoderTranscodeAudioMov.py b/test/pyTest/testTranscoderTranscodeAudioMov.py index c7f7349a..ba19f731 100644 --- a/test/pyTest/testTranscoderTranscodeAudioMov.py +++ b/test/pyTest/testTranscoderTranscodeAudioMov.py @@ -32,7 +32,7 @@ def testTranscodeMovVariableNbSamplesPerFrame(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), customProfile ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -64,8 +64,8 @@ def testTranscodeMovExtractChannels(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex, 0) ) - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex, 3) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex, 0) ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex, 3) ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeAudioWave.py b/test/pyTest/testTranscoderTranscodeAudioWave.py index e5a33eff..acc1c108 100644 --- a/test/pyTest/testTranscoderTranscodeAudioWave.py +++ b/test/pyTest/testTranscoderTranscodeAudioWave.py @@ -23,7 +23,7 @@ def testTranscodeWave24b48k5_1(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48k5_1" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48k5_1" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -57,7 +57,7 @@ def testTranscodeWave24b48kstereo(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kstereo" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kstereo" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -91,7 +91,7 @@ def testTranscodeWave24b48kmono(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -125,7 +125,7 @@ def testTranscodeWave16b48kmono(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -162,7 +162,7 @@ def testTranscodeWave16b48kmonoWithSilence(): inputFile = av.InputFile( inputFileName ) src_audioStream = inputFile.getProperties().getAudioProperties()[0] audioStreamIndex = src_audioStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeImage.py b/test/pyTest/testTranscoderTranscodeImage.py index fb272832..c80080f7 100644 --- a/test/pyTest/testTranscoderTranscodeImage.py +++ b/test/pyTest/testTranscoderTranscodeImage.py @@ -26,7 +26,7 @@ def testTranscodePngToMjpeg(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -57,7 +57,7 @@ def testTranscodeJpgToMjpeg(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "mjpeg" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscodeVideo.py b/test/pyTest/testTranscoderTranscodeVideo.py index 623afb94..1b8f6e95 100644 --- a/test/pyTest/testTranscoderTranscodeVideo.py +++ b/test/pyTest/testTranscoderTranscodeVideo.py @@ -23,7 +23,7 @@ def testTranscodeDnxhd120(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd120" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd120" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -61,7 +61,7 @@ def testTranscodeDnxhd185(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -99,7 +99,7 @@ def testTranscodeDnxhd185x(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185x" ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185x" ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) @@ -145,7 +145,7 @@ def testTranscodeYUV420(): inputFile = av.InputFile( inputFileName ) src_videoStream = inputFile.getProperties().getVideoProperties()[0] videoStreamIndex = src_videoStream.getStreamIndex() - transcoder.add( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) + transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile ) progress = av.ConsoleProgress() processStat = transcoder.process( progress ) From a4b6a2826988e18c1debdf33d32a975ca01e4232 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 13:42:01 +0200 Subject: [PATCH 09/31] AudioProperties: added doc --- src/AvTranscoder/properties/AudioProperties.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index 1c8c1834..a3928c43 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -15,9 +15,9 @@ class AvExport AudioProperties : public StreamProperties std::string getSampleFormatName() const; std::string getSampleFormatLongName() const; - std::string getChannelLayout() const; - std::string getChannelName() const; - std::string getChannelDescription() const; + std::string getChannelLayout() const; ///< Get a description of a channel layout (example: '5.1'). + std::string getChannelName() const; ///< Get the name of a given channel (example: 'LFE'). + std::string getChannelDescription() const; ///< Get the description of a given channel (example: 'low frequency'). size_t getBitRate() const; ///< in bits/s, 0 if unknown size_t getSampleRate() const; From 128e2ce67604ecd9dffc7572f435568dc3baaf7e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 13:45:00 +0200 Subject: [PATCH 10/31] AudioProperties: improved getChannelLayout method * According to some ffmpeg code, there is no need to allocate a buffer of 1024 characters to store the channel layout name. * See https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/tests/formats.c#L28 --- src/AvTranscoder/properties/AudioProperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/properties/AudioProperties.cpp b/src/AvTranscoder/properties/AudioProperties.cpp index d17cb7a0..5fbb9daf 100644 --- a/src/AvTranscoder/properties/AudioProperties.cpp +++ b/src/AvTranscoder/properties/AudioProperties.cpp @@ -72,7 +72,7 @@ std::string AudioProperties::getChannelLayout() const if(!_codecContext) throw std::runtime_error("unknown codec context"); - char buf1[1024]; + char buf1[512]; av_get_channel_layout_string(buf1, sizeof(buf1), -1, _codecContext->channel_layout); return std::string(buf1); } From b371beb2ecb94286ff64ae2af416eff7c8f026c2 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 13:47:43 +0200 Subject: [PATCH 11/31] AudioFrame: added getChannelLayoutDesc method Will be used in the next commit. --- src/AvTranscoder/data/decoded/AudioFrame.cpp | 7 +++++++ src/AvTranscoder/data/decoded/AudioFrame.hpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/AvTranscoder/data/decoded/AudioFrame.cpp b/src/AvTranscoder/data/decoded/AudioFrame.cpp index 00f9aaaf..baffbbee 100644 --- a/src/AvTranscoder/data/decoded/AudioFrame.cpp +++ b/src/AvTranscoder/data/decoded/AudioFrame.cpp @@ -50,6 +50,13 @@ AudioFrame::AudioFrame(const Frame& otherFrame) { } +std::string AudioFrame::getChannelLayoutDesc() const +{ + char buf[512]; + av_get_channel_layout_string(buf, sizeof(buf), getNbChannels(), getChannelLayout()); + return std::string(buf); +} + size_t AudioFrame::getSize() const { if(getSampleFormat() == AV_SAMPLE_FMT_NONE) diff --git a/src/AvTranscoder/data/decoded/AudioFrame.hpp b/src/AvTranscoder/data/decoded/AudioFrame.hpp index 132d8224..e0317e00 100644 --- a/src/AvTranscoder/data/decoded/AudioFrame.hpp +++ b/src/AvTranscoder/data/decoded/AudioFrame.hpp @@ -45,6 +45,7 @@ class AvExport AudioFrame : public Frame size_t getSampleRate() const { return av_frame_get_sample_rate(_frame); } size_t getNbChannels() const { return av_frame_get_channels(_frame); } size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); } + std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout. AVSampleFormat getSampleFormat() const { return static_cast(_frame->format); } size_t getNbSamplesPerChannel() const { return _frame->nb_samples; } AudioFrameDesc desc() const { return AudioFrameDesc(getSampleRate(), getNbChannels(), getSampleFormat()); } From ee5f73034343e9b4439e05ee3ec8d4b406e93217 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:14:30 +0200 Subject: [PATCH 12/31] Transcoder: can extract several channels in the same streams * Handle a vector of channel index instead of a single index (with -1 to get all of them). --- app/avProcessor/avProcessor.cpp | 8 ++- src/AvTranscoder/decoder/AudioDecoder.cpp | 55 ++++++++++++------- src/AvTranscoder/decoder/AudioDecoder.hpp | 2 +- src/AvTranscoder/decoder/AudioGenerator.cpp | 2 +- src/AvTranscoder/decoder/AudioGenerator.hpp | 2 +- src/AvTranscoder/decoder/IDecoder.hpp | 4 +- src/AvTranscoder/decoder/VideoDecoder.cpp | 2 +- src/AvTranscoder/decoder/VideoDecoder.hpp | 2 +- src/AvTranscoder/decoder/VideoGenerator.cpp | 2 +- src/AvTranscoder/decoder/VideoGenerator.hpp | 2 +- src/AvTranscoder/reader/IReader.cpp | 6 +- .../transcoder/StreamTranscoder.cpp | 27 ++++----- .../transcoder/StreamTranscoder.hpp | 10 ++-- src/AvTranscoder/transcoder/Transcoder.cpp | 40 ++++++++++---- src/AvTranscoder/transcoder/Transcoder.hpp | 26 +++++++-- 15 files changed, 124 insertions(+), 66 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 0841b1df..3f406173 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -29,18 +29,22 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder std::stringstream ss(streamId); size_t streamIndex = 0; char separator; - int subStreamIndex = -1; + std::vector channelIndexArray; ss >> streamIndex; ss >> separator; if(separator == '.') + { + int subStreamIndex = -1; ss >> subStreamIndex; + channelIndexArray.push_back(subStreamIndex); + } // generated stream if(!filename.length()) transcoder.addGeneratedStream(transcodeProfile); else { - avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, subStreamIndex); + avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, channelIndexArray); transcoder.addStream(inputDesc, transcodeProfile); } } diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index 3b20e8bc..862100f7 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -116,7 +116,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer) return decodeNextFrame; } -bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const size_t channelIndex) +bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) { AudioFrame& audioBuffer = static_cast(frameBuffer); @@ -136,37 +136,52 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const size_t channelIndex if(decodedSize == 0) return false; - // check if the expected channel exists - if(channelIndex > srcNbChannels - 1) + // check if each expected channel exists + for(std::vector::const_iterator channelIndex = channelsIndex.begin(); channelIndex != channelsIndex.end(); ++channelIndex) { - std::stringstream msg; - msg << "The channel at index "; - msg << channelIndex; - msg << " doesn't exist (srcNbChannels = "; - msg << srcNbChannels; - msg << ")."; - throw std::runtime_error(msg.str()); + if((*channelIndex) > srcNbChannels - 1) + { + std::stringstream msg; + msg << "The channel at index "; + msg << (*channelIndex); + msg << " doesn't exist (srcNbChannels = "; + msg << srcNbChannels; + msg << ")."; + throw std::runtime_error(msg.str()); + } } // copy frame properties of decoded frame audioBuffer.copyProperties(allDataOfNextFrame); - av_frame_set_channels(&audioBuffer.getAVFrame(), 1); - av_frame_set_channel_layout(&audioBuffer.getAVFrame(), AV_CH_LAYOUT_MONO); + av_frame_set_channels(&audioBuffer.getAVFrame(), channelsIndex.size()); + av_frame_set_channel_layout(&audioBuffer.getAVFrame(), av_get_default_channel_layout(channelsIndex.size())); audioBuffer.setNbSamplesPerChannel(allDataOfNextFrame.getNbSamplesPerChannel()); // @todo manage cases with data of frame not only on data[0] (use _frame.linesize) unsigned char* src = allDataOfNextFrame.getData()[0]; unsigned char* dst = audioBuffer.getData()[0]; - // offset - src += channelIndex * bytePerSample; - - // extract one channel - for(int sample = 0; sample < allDataOfNextFrame.getAVFrame().nb_samples; ++sample) + // extract one or more channels + for(size_t sample = 0; sample < allDataOfNextFrame.getNbSamplesPerChannel(); ++sample) { - memcpy(dst, src, bytePerSample); - dst += bytePerSample; - src += bytePerSample * srcNbChannels; + // offset in source buffer + src += channelsIndex.at(0) * bytePerSample; + + for(size_t i = 0; i < channelsIndex.size(); ++i) + { + memcpy(dst, src, bytePerSample); + dst += bytePerSample; + + // shift to the corresponding sample in the next channel of the current layout + if(i < channelsIndex.size() - 1) + src += (channelsIndex.at(i+1) - channelsIndex.at(i)) * bytePerSample; + // else shift to the next layout + else + { + src += (srcNbChannels - channelsIndex.at(i)) * bytePerSample; + break; + } + } } return true; diff --git a/src/AvTranscoder/decoder/AudioDecoder.hpp b/src/AvTranscoder/decoder/AudioDecoder.hpp index a2a6f2b8..204c1579 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.hpp +++ b/src/AvTranscoder/decoder/AudioDecoder.hpp @@ -17,7 +17,7 @@ class AvExport AudioDecoder : public IDecoder void setupDecoder(const ProfileLoader::Profile& profile = ProfileLoader::Profile()); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const size_t channelIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); void flushDecoder(); diff --git a/src/AvTranscoder/decoder/AudioGenerator.cpp b/src/AvTranscoder/decoder/AudioGenerator.cpp index 297ee009..75a1fdd6 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.cpp +++ b/src/AvTranscoder/decoder/AudioGenerator.cpp @@ -71,7 +71,7 @@ bool AudioGenerator::decodeNextFrame(Frame& frameBuffer) return true; } -bool AudioGenerator::decodeNextFrame(Frame& frameBuffer, const size_t subStreamIndex) +bool AudioGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) { return decodeNextFrame(frameBuffer); } diff --git a/src/AvTranscoder/decoder/AudioGenerator.hpp b/src/AvTranscoder/decoder/AudioGenerator.hpp index e12b2eba..9f8444f8 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.hpp +++ b/src/AvTranscoder/decoder/AudioGenerator.hpp @@ -19,7 +19,7 @@ class AvExport AudioGenerator : public IDecoder ~AudioGenerator(); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const size_t subStreamIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } diff --git a/src/AvTranscoder/decoder/IDecoder.hpp b/src/AvTranscoder/decoder/IDecoder.hpp index a373a9be..4f4dceb3 100644 --- a/src/AvTranscoder/decoder/IDecoder.hpp +++ b/src/AvTranscoder/decoder/IDecoder.hpp @@ -33,10 +33,10 @@ class AvExport IDecoder /** * @brief Decode substream of next frame * @param frameBuffer: the frame decoded - * @param channelIndex: index of channel to extract + * @param channelIndex: list of channels to extract * @return status of decoding */ - virtual bool decodeNextFrame(Frame& frameBuffer, const size_t channelIndex) = 0; + virtual bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) = 0; /** * @brief Set the next frame of the input stream (which bypass the work of decoding) diff --git a/src/AvTranscoder/decoder/VideoDecoder.cpp b/src/AvTranscoder/decoder/VideoDecoder.cpp index 51363466..ac4e9d89 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.cpp +++ b/src/AvTranscoder/decoder/VideoDecoder.cpp @@ -114,7 +114,7 @@ bool VideoDecoder::decodeNextFrame(Frame& frameBuffer) return decodeNextFrame; } -bool VideoDecoder::decodeNextFrame(Frame& frameBuffer, const size_t subStreamIndex) +bool VideoDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) { return false; } diff --git a/src/AvTranscoder/decoder/VideoDecoder.hpp b/src/AvTranscoder/decoder/VideoDecoder.hpp index 69b8419d..d7c8aedb 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.hpp +++ b/src/AvTranscoder/decoder/VideoDecoder.hpp @@ -17,7 +17,7 @@ class AvExport VideoDecoder : public IDecoder void setupDecoder(const ProfileLoader::Profile& profile = ProfileLoader::Profile()); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const size_t subStreamIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); void flushDecoder(); diff --git a/src/AvTranscoder/decoder/VideoGenerator.cpp b/src/AvTranscoder/decoder/VideoGenerator.cpp index 0d35df0e..712b5ee8 100644 --- a/src/AvTranscoder/decoder/VideoGenerator.cpp +++ b/src/AvTranscoder/decoder/VideoGenerator.cpp @@ -72,7 +72,7 @@ bool VideoGenerator::decodeNextFrame(Frame& frameBuffer) return true; } -bool VideoGenerator::decodeNextFrame(Frame& frameBuffer, const size_t channelIndex) +bool VideoGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) { return false; } diff --git a/src/AvTranscoder/decoder/VideoGenerator.hpp b/src/AvTranscoder/decoder/VideoGenerator.hpp index b6a7a556..dbde6216 100644 --- a/src/AvTranscoder/decoder/VideoGenerator.hpp +++ b/src/AvTranscoder/decoder/VideoGenerator.hpp @@ -19,7 +19,7 @@ class AvExport VideoGenerator : public IDecoder ~VideoGenerator(); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const size_t channelIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } diff --git a/src/AvTranscoder/reader/IReader.cpp b/src/AvTranscoder/reader/IReader.cpp index c950571e..61c0b761 100644 --- a/src/AvTranscoder/reader/IReader.cpp +++ b/src/AvTranscoder/reader/IReader.cpp @@ -73,7 +73,11 @@ Frame* IReader::readFrameAt(const size_t frame) // decode bool decodingStatus = false; if(_channelIndex != -1) - decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, _channelIndex); + { + std::vector channelsIndex; + channelsIndex.push_back(_channelIndex); + decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, channelsIndex); + } else decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame); // if decoding failed diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 7acfbfbb..7c4bdf65 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -31,7 +31,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _subStreamIndex(-1) + , _channelsIndex() , _offset(offset) , _needToSwitchToGenerator(false) { @@ -122,7 +122,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu } StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const int subStreamIndex, const float offset) + const std::vector channelsIndex, const float offset) : _inputStream(&inputStream) , _outputStream(NULL) , _sourceBuffer(NULL) @@ -133,7 +133,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _subStreamIndex(subStreamIndex) + , _channelsIndex(channelsIndex) , _offset(offset) , _needToSwitchToGenerator(false) { @@ -191,11 +191,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu AudioFrameDesc outputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); outputFrameDesc.setParameters(profile); - if(subStreamIndex > -1) - { - // @todo manage downmix ? - outputFrameDesc._nbChannels = 1; - } + if(!_channelsIndex.empty()) + outputFrameDesc._nbChannels = _channelsIndex.size(); outputAudio->setupAudioEncoder(outputFrameDesc, profile); // output stream @@ -203,8 +200,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu // buffers to process AudioFrameDesc inputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); - if(subStreamIndex > -1) - inputFrameDesc._nbChannels = 1; + if(!_channelsIndex.empty()) + inputFrameDesc._nbChannels = _channelsIndex.size(); _sourceBuffer = new AudioFrame(inputFrameDesc); _frameBuffer = new AudioFrame(outputAudio->getAudioCodec().getAudioFrameDesc()); @@ -237,7 +234,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader: , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _subStreamIndex(-1) + , _channelsIndex() , _offset(0) , _needToSwitchToGenerator(false) { @@ -419,7 +416,7 @@ bool StreamTranscoder::processFrame() if(processCase == eProcessCaseRewrap) return processRewrap(); - return processTranscode(_subStreamIndex); + return processTranscode(); } bool StreamTranscoder::processRewrap() @@ -462,7 +459,7 @@ bool StreamTranscoder::processRewrap() return true; } -bool StreamTranscoder::processTranscode(const int subStreamIndex) +bool StreamTranscoder::processTranscode() { assert(_outputStream != NULL); assert(_currentDecoder != NULL); @@ -475,10 +472,10 @@ bool StreamTranscoder::processTranscode(const int subStreamIndex) LOG_DEBUG("Decode next frame") bool decodingStatus = false; - if(subStreamIndex < 0) + if(_channelsIndex.empty()) decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer); else - decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, subStreamIndex); + decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, _channelsIndex); CodedData data; if(decodingStatus) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 4d2dfdc8..92ebbc41 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -26,16 +26,16 @@ class AvExport StreamTranscoder public: /** - * @brief rewrap stream + * @brief Rewrap the given stream. * @note offset feature when rewrap a stream is not supported **/ StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const float offset = 0); /** - * @brief transcode stream + * @brief Transcode the given stream. **/ StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const int subStreamIndex = -1, const float offset = 0); + const std::vector channelsIndex, const float offset = 0); /** * @brief encode from a generated stream @@ -118,7 +118,7 @@ class AvExport StreamTranscoder private: bool processRewrap(); - bool processTranscode(const int subStreamIndex = -1); ///< By default transcode all channels + bool processTranscode(); private: IInputStream* _inputStream; ///< Input stream to read next packet (has link, no ownership) @@ -136,7 +136,7 @@ class AvExport StreamTranscoder FilterGraph* _filterGraph; ///< Filter graph (has ownership) - int _subStreamIndex; ///< Index of channel that is processed from the input stream (<0 if no demultiplexing). + std::vector _channelsIndex; ///< List of channels that is processed from the input stream (empty if no demultiplexing). float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder. diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 72209676..883a8dfe 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -45,7 +45,7 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, if(profileName.length() == 0) { // Re-wrap - if(inputStreamDesc._channelIndex < 0) + if(! inputStreamDesc.demultiplexing()) addRewrapStream(inputStreamDesc, offset); // Transcode (transparent for the user) else @@ -205,7 +205,7 @@ void Transcoder::setProcessMethod(const EProcessMethod eProcessMethod, const siz void Transcoder::addRewrapStream(const InputStreamDesc& inputStreamDesc, const float offset) { - LOG_INFO("Add rewrap stream from file '" << inputStreamDesc._filename << "' / index=" << inputStreamDesc._streamIndex << " / offset=" << offset << "s") + LOG_INFO("Add rewrap stream from " << inputStreamDesc << " with offset=" << offset << "s") InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); @@ -220,10 +220,14 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, InputFile inputFile(inputStreamDesc._filename); ProfileLoader::Profile profile = getProfileFromFile(inputFile, inputStreamDesc._streamIndex); - // override channels parameter to manage demultiplexing - ProfileLoader::Profile::iterator it = profile.find(constants::avProfileChannel); - if(it != profile.end()) - it->second = "1"; + // override number of channels parameters to manage demultiplexing + if(inputStreamDesc.demultiplexing()) + { + // number of channels + std::stringstream ss; + ss << inputStreamDesc._channelsIndex.size(); + profile[constants::avProfileChannel] = ss.str(); + } addTranscodeStream(inputStreamDesc, profile, offset); } @@ -235,9 +239,8 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, if(!_profileLoader.hasProfile(profile)) _profileLoader.loadProfile(profile); - LOG_INFO("Add transcode stream from file '" - << inputStreamDesc._filename << "' / index=" << inputStreamDesc._streamIndex << " / channel=" << inputStreamDesc._channelIndex - << " / encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman) << " / offset=" << offset << "s") + LOG_INFO("Add transcode stream from " << inputStreamDesc + << "with encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman) << std::endl << "and offset=" << offset << "s") // Add input file InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); @@ -248,7 +251,7 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelIndex, offset)); + new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelsIndex, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } @@ -497,4 +500,21 @@ void Transcoder::fillProcessStat(ProcessStat& processStat) } } } + +std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc) +{ + flux << "input stream description: " << std::endl; + flux << "- filename: " << inputStreamDesc._filename << std::endl; + flux << "- stream index: " << inputStreamDesc._streamIndex << std::endl; + if(inputStreamDesc.demultiplexing()) + { + flux << "- channels index: "; + for(size_t c = 0; c < inputStreamDesc._channelsIndex.size(); ++c) + { + flux << inputStreamDesc._channelsIndex.at(c) << ", "; + } + flux << std::endl; + } + return flux; +} } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index e6868b95..6bbe4667 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -21,23 +21,41 @@ namespace avtranscoder */ struct InputStreamDesc { - InputStreamDesc(const std::string& filename, const size_t streamIndex, const int channelIndex) + InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelsIndex) : _filename(filename) , _streamIndex(streamIndex) - , _channelIndex(channelIndex) + , _channelsIndex(channelsIndex) {} + InputStreamDesc(const std::string& filename, const size_t streamIndex, const size_t channelIndex) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelsIndex() + { + _channelsIndex.push_back(channelIndex); + } + InputStreamDesc(const std::string& filename, const size_t streamIndex) : _filename(filename) , _streamIndex(streamIndex) - , _channelIndex(-1) + , _channelsIndex() {} + /** + * @return If a demultiplexing step will be done to extract the expected data. + */ + bool demultiplexing() const { return ! _channelsIndex.empty(); } + +public: std::string _filename; ///< Source file path. size_t _streamIndex; ///< Source stream to extract. - int _channelIndex; ///< Source channel to extract from the stream (no demultiplexing if -1) + std::vector _channelsIndex; ///< List of source channels to extract from the stream }; +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc); +#endif + /** * @brief Enum to set a policy of how we manage the process in case of several streams. * eProcessMethodShortest: stop the process at the end of the shortest stream. From 182409445c29976b5aa337d8d6ded967fce0e72b Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:14:40 +0200 Subject: [PATCH 13/31] AudioFrame: added doc --- src/AvTranscoder/data/decoded/AudioFrame.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/data/decoded/AudioFrame.hpp b/src/AvTranscoder/data/decoded/AudioFrame.hpp index e0317e00..895355db 100644 --- a/src/AvTranscoder/data/decoded/AudioFrame.hpp +++ b/src/AvTranscoder/data/decoded/AudioFrame.hpp @@ -45,7 +45,7 @@ class AvExport AudioFrame : public Frame size_t getSampleRate() const { return av_frame_get_sample_rate(_frame); } size_t getNbChannels() const { return av_frame_get_channels(_frame); } size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); } - std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout. + std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout (example: '5.1'). AVSampleFormat getSampleFormat() const { return static_cast(_frame->format); } size_t getNbSamplesPerChannel() const { return _frame->nb_samples; } AudioFrameDesc desc() const { return AudioFrameDesc(getSampleRate(), getNbChannels(), getSampleFormat()); } From 21506ac00b8d56541a1e8b30ea165a58ef112f26 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:17:56 +0200 Subject: [PATCH 14/31] AuAudioProperties: added doc --- src/AvTranscoder/properties/AudioProperties.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index a3928c43..1f9e4d17 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -22,7 +22,7 @@ class AvExport AudioProperties : public StreamProperties size_t getBitRate() const; ///< in bits/s, 0 if unknown size_t getSampleRate() const; size_t getNbChannels() const; - size_t getNbSamples() const; + size_t getNbSamples() const; ///< All the channels are included. size_t getTicksPerFrame() const; From 8642c80db40ba038557d4d8b02543cb7bd115cda Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:18:20 +0200 Subject: [PATCH 15/31] AudioTransform: added log to get the channel layout info --- src/AvTranscoder/transform/AudioTransform.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/transform/AudioTransform.cpp b/src/AvTranscoder/transform/AudioTransform.cpp index 593965ea..41194a06 100644 --- a/src/AvTranscoder/transform/AudioTransform.cpp +++ b/src/AvTranscoder/transform/AudioTransform.cpp @@ -55,8 +55,8 @@ bool AudioTransform::init(const Frame& srcFrame, const Frame& dstFrame) const AudioFrame& src = static_cast(srcFrame); const AudioFrame& dst = static_cast(dstFrame); - av_opt_set_int(_audioConvertContext, "in_channel_layout", av_get_default_channel_layout(src.getNbChannels()), 0); - av_opt_set_int(_audioConvertContext, "out_channel_layout", av_get_default_channel_layout(dst.getNbChannels()), 0); + av_opt_set_int(_audioConvertContext, "in_channel_layout", src.getChannelLayout(), 0); + av_opt_set_int(_audioConvertContext, "out_channel_layout", dst.getChannelLayout(), 0); av_opt_set_int(_audioConvertContext, "in_sample_rate", src.getSampleRate(), 0); av_opt_set_int(_audioConvertContext, "out_sample_rate", dst.getSampleRate(), 0); SetSampleFormat(_audioConvertContext, "in_sample_fmt", src.getSampleFormat(), 0); @@ -67,8 +67,8 @@ bool AudioTransform::init(const Frame& srcFrame, const Frame& dstFrame) FreeResampleContext(&_audioConvertContext); std::stringstream msg; msg << "Unable to open audio convert context:" << std::endl; - msg << "in_channel_layout " << av_get_default_channel_layout(src.getNbChannels()) << std::endl; - msg << "out_channel_layout " << av_get_default_channel_layout(dst.getNbChannels()) << std::endl; + msg << "in_channel_layout " << src.getChannelLayoutDesc() << std::endl; + msg << "out_channel_layout " << dst.getChannelLayoutDesc() << std::endl; msg << "in_sample_rate " << src.getSampleRate() << std::endl; msg << "out_sample_rate " << dst.getSampleRate() << std::endl; msg << "in_sample_fmt " << src.getSampleFormat() << std::endl; @@ -80,8 +80,10 @@ bool AudioTransform::init(const Frame& srcFrame, const Frame& dstFrame) msg << "Audio conversion from " << getSampleFormatName(src.getSampleFormat()) << " to " << getSampleFormatName(dst.getSampleFormat()) << std::endl; msg << "Source, number of channels = " << src.getNbChannels() << std::endl; + msg << "Source, channel layout = " << src.getChannelLayoutDesc() << std::endl; msg << "Source, sample rate = " << src.getSampleRate() << std::endl; msg << "Destination, number of channels = " << dst.getNbChannels() << std::endl; + msg << "Destination, channel layout = " << dst.getChannelLayoutDesc() << std::endl; msg << "Destination, sample rate = " << dst.getSampleRate() << std::endl; LOG_INFO(msg.str()) From 76f2b3fd05253c67459e46f0dffc5c85673b1af9 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:21:45 +0200 Subject: [PATCH 16/31] InputStreamDesc: renamed _channelsIndex attribute to _channelIndexArray --- src/AvTranscoder/decoder/AudioDecoder.cpp | 18 ++++++++--------- src/AvTranscoder/decoder/AudioDecoder.hpp | 2 +- src/AvTranscoder/decoder/AudioGenerator.cpp | 2 +- src/AvTranscoder/decoder/AudioGenerator.hpp | 2 +- src/AvTranscoder/decoder/IDecoder.hpp | 4 ++-- src/AvTranscoder/decoder/VideoDecoder.cpp | 2 +- src/AvTranscoder/decoder/VideoDecoder.hpp | 2 +- src/AvTranscoder/decoder/VideoGenerator.cpp | 2 +- src/AvTranscoder/decoder/VideoGenerator.hpp | 2 +- src/AvTranscoder/reader/IReader.cpp | 6 +++--- .../transcoder/StreamTranscoder.cpp | 20 +++++++++---------- .../transcoder/StreamTranscoder.hpp | 4 ++-- src/AvTranscoder/transcoder/Transcoder.cpp | 8 ++++---- src/AvTranscoder/transcoder/Transcoder.hpp | 14 ++++++------- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index 862100f7..2517d292 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -116,7 +116,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer) return decodeNextFrame; } -bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) +bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) { AudioFrame& audioBuffer = static_cast(frameBuffer); @@ -137,7 +137,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector return false; // check if each expected channel exists - for(std::vector::const_iterator channelIndex = channelsIndex.begin(); channelIndex != channelsIndex.end(); ++channelIndex) + for(std::vector::const_iterator channelIndex = channelIndexArray.begin(); channelIndex != channelIndexArray.end(); ++channelIndex) { if((*channelIndex) > srcNbChannels - 1) { @@ -153,8 +153,8 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector // copy frame properties of decoded frame audioBuffer.copyProperties(allDataOfNextFrame); - av_frame_set_channels(&audioBuffer.getAVFrame(), channelsIndex.size()); - av_frame_set_channel_layout(&audioBuffer.getAVFrame(), av_get_default_channel_layout(channelsIndex.size())); + av_frame_set_channels(&audioBuffer.getAVFrame(), channelIndexArray.size()); + av_frame_set_channel_layout(&audioBuffer.getAVFrame(), av_get_default_channel_layout(channelIndexArray.size())); audioBuffer.setNbSamplesPerChannel(allDataOfNextFrame.getNbSamplesPerChannel()); // @todo manage cases with data of frame not only on data[0] (use _frame.linesize) @@ -165,20 +165,20 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector for(size_t sample = 0; sample < allDataOfNextFrame.getNbSamplesPerChannel(); ++sample) { // offset in source buffer - src += channelsIndex.at(0) * bytePerSample; + src += channelIndexArray.at(0) * bytePerSample; - for(size_t i = 0; i < channelsIndex.size(); ++i) + for(size_t i = 0; i < channelIndexArray.size(); ++i) { memcpy(dst, src, bytePerSample); dst += bytePerSample; // shift to the corresponding sample in the next channel of the current layout - if(i < channelsIndex.size() - 1) - src += (channelsIndex.at(i+1) - channelsIndex.at(i)) * bytePerSample; + if(i < channelIndexArray.size() - 1) + src += (channelIndexArray.at(i+1) - channelIndexArray.at(i)) * bytePerSample; // else shift to the next layout else { - src += (srcNbChannels - channelsIndex.at(i)) * bytePerSample; + src += (srcNbChannels - channelIndexArray.at(i)) * bytePerSample; break; } } diff --git a/src/AvTranscoder/decoder/AudioDecoder.hpp b/src/AvTranscoder/decoder/AudioDecoder.hpp index 204c1579..b5e5ac57 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.hpp +++ b/src/AvTranscoder/decoder/AudioDecoder.hpp @@ -17,7 +17,7 @@ class AvExport AudioDecoder : public IDecoder void setupDecoder(const ProfileLoader::Profile& profile = ProfileLoader::Profile()); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray); void flushDecoder(); diff --git a/src/AvTranscoder/decoder/AudioGenerator.cpp b/src/AvTranscoder/decoder/AudioGenerator.cpp index 75a1fdd6..f6b61da0 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.cpp +++ b/src/AvTranscoder/decoder/AudioGenerator.cpp @@ -71,7 +71,7 @@ bool AudioGenerator::decodeNextFrame(Frame& frameBuffer) return true; } -bool AudioGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) +bool AudioGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) { return decodeNextFrame(frameBuffer); } diff --git a/src/AvTranscoder/decoder/AudioGenerator.hpp b/src/AvTranscoder/decoder/AudioGenerator.hpp index 9f8444f8..d2e3e8eb 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.hpp +++ b/src/AvTranscoder/decoder/AudioGenerator.hpp @@ -19,7 +19,7 @@ class AvExport AudioGenerator : public IDecoder ~AudioGenerator(); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray); void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } diff --git a/src/AvTranscoder/decoder/IDecoder.hpp b/src/AvTranscoder/decoder/IDecoder.hpp index 4f4dceb3..ca28bf15 100644 --- a/src/AvTranscoder/decoder/IDecoder.hpp +++ b/src/AvTranscoder/decoder/IDecoder.hpp @@ -33,10 +33,10 @@ class AvExport IDecoder /** * @brief Decode substream of next frame * @param frameBuffer: the frame decoded - * @param channelIndex: list of channels to extract + * @param channelIndexArray: list of channels to extract * @return status of decoding */ - virtual bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) = 0; + virtual bool decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) = 0; /** * @brief Set the next frame of the input stream (which bypass the work of decoding) diff --git a/src/AvTranscoder/decoder/VideoDecoder.cpp b/src/AvTranscoder/decoder/VideoDecoder.cpp index ac4e9d89..bfb42c95 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.cpp +++ b/src/AvTranscoder/decoder/VideoDecoder.cpp @@ -114,7 +114,7 @@ bool VideoDecoder::decodeNextFrame(Frame& frameBuffer) return decodeNextFrame; } -bool VideoDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) +bool VideoDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) { return false; } diff --git a/src/AvTranscoder/decoder/VideoDecoder.hpp b/src/AvTranscoder/decoder/VideoDecoder.hpp index d7c8aedb..3065f484 100644 --- a/src/AvTranscoder/decoder/VideoDecoder.hpp +++ b/src/AvTranscoder/decoder/VideoDecoder.hpp @@ -17,7 +17,7 @@ class AvExport VideoDecoder : public IDecoder void setupDecoder(const ProfileLoader::Profile& profile = ProfileLoader::Profile()); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray); void flushDecoder(); diff --git a/src/AvTranscoder/decoder/VideoGenerator.cpp b/src/AvTranscoder/decoder/VideoGenerator.cpp index 712b5ee8..bdaf645f 100644 --- a/src/AvTranscoder/decoder/VideoGenerator.cpp +++ b/src/AvTranscoder/decoder/VideoGenerator.cpp @@ -72,7 +72,7 @@ bool VideoGenerator::decodeNextFrame(Frame& frameBuffer) return true; } -bool VideoGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex) +bool VideoGenerator::decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) { return false; } diff --git a/src/AvTranscoder/decoder/VideoGenerator.hpp b/src/AvTranscoder/decoder/VideoGenerator.hpp index dbde6216..bb90217f 100644 --- a/src/AvTranscoder/decoder/VideoGenerator.hpp +++ b/src/AvTranscoder/decoder/VideoGenerator.hpp @@ -19,7 +19,7 @@ class AvExport VideoGenerator : public IDecoder ~VideoGenerator(); bool decodeNextFrame(Frame& frameBuffer); - bool decodeNextFrame(Frame& frameBuffer, const std::vector channelsIndex); + bool decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray); void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } diff --git a/src/AvTranscoder/reader/IReader.cpp b/src/AvTranscoder/reader/IReader.cpp index 61c0b761..3e40fd16 100644 --- a/src/AvTranscoder/reader/IReader.cpp +++ b/src/AvTranscoder/reader/IReader.cpp @@ -74,9 +74,9 @@ Frame* IReader::readFrameAt(const size_t frame) bool decodingStatus = false; if(_channelIndex != -1) { - std::vector channelsIndex; - channelsIndex.push_back(_channelIndex); - decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, channelsIndex); + std::vector channelIndexArray; + channelIndexArray.push_back(_channelIndex); + decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame, channelIndexArray); } else decodingStatus = _currentDecoder->decodeNextFrame(*_srcFrame); diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 7c4bdf65..de7a46f1 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -31,7 +31,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelsIndex() + , _channelIndexArray() , _offset(offset) , _needToSwitchToGenerator(false) { @@ -122,7 +122,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu } StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const std::vector channelsIndex, const float offset) + const std::vector channelIndexArray, const float offset) : _inputStream(&inputStream) , _outputStream(NULL) , _sourceBuffer(NULL) @@ -133,7 +133,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelsIndex(channelsIndex) + , _channelIndexArray(channelIndexArray) , _offset(offset) , _needToSwitchToGenerator(false) { @@ -191,8 +191,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu AudioFrameDesc outputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); outputFrameDesc.setParameters(profile); - if(!_channelsIndex.empty()) - outputFrameDesc._nbChannels = _channelsIndex.size(); + if(!_channelIndexArray.empty()) + outputFrameDesc._nbChannels = _channelIndexArray.size(); outputAudio->setupAudioEncoder(outputFrameDesc, profile); // output stream @@ -200,8 +200,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu // buffers to process AudioFrameDesc inputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); - if(!_channelsIndex.empty()) - inputFrameDesc._nbChannels = _channelsIndex.size(); + if(!_channelIndexArray.empty()) + inputFrameDesc._nbChannels = _channelIndexArray.size(); _sourceBuffer = new AudioFrame(inputFrameDesc); _frameBuffer = new AudioFrame(outputAudio->getAudioCodec().getAudioFrameDesc()); @@ -234,7 +234,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader: , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelsIndex() + , _channelIndexArray() , _offset(0) , _needToSwitchToGenerator(false) { @@ -472,10 +472,10 @@ bool StreamTranscoder::processTranscode() LOG_DEBUG("Decode next frame") bool decodingStatus = false; - if(_channelsIndex.empty()) + if(_channelIndexArray.empty()) decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer); else - decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, _channelsIndex); + decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, _channelIndexArray); CodedData data; if(decodingStatus) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 92ebbc41..381c779a 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -35,7 +35,7 @@ class AvExport StreamTranscoder * @brief Transcode the given stream. **/ StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const std::vector channelsIndex, const float offset = 0); + const std::vector channelIndexArray, const float offset = 0); /** * @brief encode from a generated stream @@ -136,7 +136,7 @@ class AvExport StreamTranscoder FilterGraph* _filterGraph; ///< Filter graph (has ownership) - std::vector _channelsIndex; ///< List of channels that is processed from the input stream (empty if no demultiplexing). + std::vector _channelIndexArray; ///< List of channels that is processed from the input stream (empty if no demultiplexing). float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder. diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 883a8dfe..064787eb 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -225,7 +225,7 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, { // number of channels std::stringstream ss; - ss << inputStreamDesc._channelsIndex.size(); + ss << inputStreamDesc._channelIndexArray.size(); profile[constants::avProfileChannel] = ss.str(); } @@ -251,7 +251,7 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelsIndex, offset)); + new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelIndexArray, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } @@ -509,9 +509,9 @@ std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamD if(inputStreamDesc.demultiplexing()) { flux << "- channels index: "; - for(size_t c = 0; c < inputStreamDesc._channelsIndex.size(); ++c) + for(size_t c = 0; c < inputStreamDesc._channelIndexArray.size(); ++c) { - flux << inputStreamDesc._channelsIndex.at(c) << ", "; + flux << inputStreamDesc._channelIndexArray.at(c) << ", "; } flux << std::endl; } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 6bbe4667..7d174cd0 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -21,35 +21,35 @@ namespace avtranscoder */ struct InputStreamDesc { - InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelsIndex) + InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelIndexArray) : _filename(filename) , _streamIndex(streamIndex) - , _channelsIndex(channelsIndex) + , _channelIndexArray(channelIndexArray) {} InputStreamDesc(const std::string& filename, const size_t streamIndex, const size_t channelIndex) : _filename(filename) , _streamIndex(streamIndex) - , _channelsIndex() + , _channelIndexArray() { - _channelsIndex.push_back(channelIndex); + _channelIndexArray.push_back(channelIndex); } InputStreamDesc(const std::string& filename, const size_t streamIndex) : _filename(filename) , _streamIndex(streamIndex) - , _channelsIndex() + , _channelIndexArray() {} /** * @return If a demultiplexing step will be done to extract the expected data. */ - bool demultiplexing() const { return ! _channelsIndex.empty(); } + bool demultiplexing() const { return ! _channelIndexArray.empty(); } public: std::string _filename; ///< Source file path. size_t _streamIndex; ///< Source stream to extract. - std::vector _channelsIndex; ///< List of source channels to extract from the stream + std::vector _channelIndexArray; ///< List of source channels to extract from the stream }; #ifndef SWIG From 98681670e0030ebbd4729847740c0d977b388390 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 18 Jul 2016 17:24:53 +0200 Subject: [PATCH 17/31] Format src files --- src/AvTranscoder/data/decoded/AudioFrame.hpp | 2 +- src/AvTranscoder/decoder/AudioDecoder.cpp | 5 ++-- src/AvTranscoder/decoder/AudioGenerator.cpp | 3 +- src/AvTranscoder/decoder/AudioGenerator.hpp | 4 +-- src/AvTranscoder/decoder/VideoGenerator.hpp | 4 +-- src/AvTranscoder/encoder/AudioEncoder.cpp | 1 - src/AvTranscoder/encoder/VideoEncoder.cpp | 1 - src/AvTranscoder/file/FormatContext.cpp | 2 +- src/AvTranscoder/file/FormatContext.hpp | 3 +- src/AvTranscoder/file/InputFile.cpp | 3 +- src/AvTranscoder/file/OutputFile.cpp | 7 +++-- .../properties/AudioProperties.hpp | 8 ++--- .../properties/FileProperties.cpp | 6 ++-- .../properties/FileProperties.hpp | 7 +++-- .../properties/StreamProperties.cpp | 3 +- .../properties/VideoProperties.cpp | 7 +++-- .../properties/VideoProperties.hpp | 4 +-- src/AvTranscoder/reader/IReader.hpp | 6 ++-- .../transcoder/StreamTranscoder.hpp | 3 +- src/AvTranscoder/transcoder/Transcoder.cpp | 26 ++++++++-------- src/AvTranscoder/transcoder/Transcoder.hpp | 30 +++++++++---------- 21 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/AvTranscoder/data/decoded/AudioFrame.hpp b/src/AvTranscoder/data/decoded/AudioFrame.hpp index 895355db..ea644498 100644 --- a/src/AvTranscoder/data/decoded/AudioFrame.hpp +++ b/src/AvTranscoder/data/decoded/AudioFrame.hpp @@ -45,7 +45,7 @@ class AvExport AudioFrame : public Frame size_t getSampleRate() const { return av_frame_get_sample_rate(_frame); } size_t getNbChannels() const { return av_frame_get_channels(_frame); } size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); } - std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout (example: '5.1'). + std::string getChannelLayoutDesc() const; ///< Get a description of a channel layout (example: '5.1'). AVSampleFormat getSampleFormat() const { return static_cast(_frame->format); } size_t getNbSamplesPerChannel() const { return _frame->nb_samples; } AudioFrameDesc desc() const { return AudioFrameDesc(getSampleRate(), getNbChannels(), getSampleFormat()); } diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index 2517d292..96e3b206 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -137,7 +137,8 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector return false; // check if each expected channel exists - for(std::vector::const_iterator channelIndex = channelIndexArray.begin(); channelIndex != channelIndexArray.end(); ++channelIndex) + for(std::vector::const_iterator channelIndex = channelIndexArray.begin(); + channelIndex != channelIndexArray.end(); ++channelIndex) { if((*channelIndex) > srcNbChannels - 1) { @@ -174,7 +175,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector // shift to the corresponding sample in the next channel of the current layout if(i < channelIndexArray.size() - 1) - src += (channelIndexArray.at(i+1) - channelIndexArray.at(i)) * bytePerSample; + src += (channelIndexArray.at(i + 1) - channelIndexArray.at(i)) * bytePerSample; // else shift to the next layout else { diff --git a/src/AvTranscoder/decoder/AudioGenerator.cpp b/src/AvTranscoder/decoder/AudioGenerator.cpp index f6b61da0..f13b880f 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.cpp +++ b/src/AvTranscoder/decoder/AudioGenerator.cpp @@ -34,7 +34,8 @@ bool AudioGenerator::decodeNextFrame(Frame& frameBuffer) if(frameBuffer.getAVFrame().channel_layout == 0) { const size_t channelLayout = av_get_default_channel_layout(frameBuffer.getAVFrame().channels); - LOG_WARN("Channel layout en the audio frame is not set. Set it to '" << channelLayout << "' to be able to copy silence data.") + LOG_WARN("Channel layout en the audio frame is not set. Set it to '" << channelLayout + << "' to be able to copy silence data.") av_frame_set_channel_layout(&frameBuffer.getAVFrame(), channelLayout); } diff --git a/src/AvTranscoder/decoder/AudioGenerator.hpp b/src/AvTranscoder/decoder/AudioGenerator.hpp index d2e3e8eb..ba80ab69 100644 --- a/src/AvTranscoder/decoder/AudioGenerator.hpp +++ b/src/AvTranscoder/decoder/AudioGenerator.hpp @@ -24,8 +24,8 @@ class AvExport AudioGenerator : public IDecoder void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } private: - Frame* _inputFrame; ///< Has link (no ownership) - AudioFrame* _silent; ///< The generated silent (has ownership) + Frame* _inputFrame; ///< Has link (no ownership) + AudioFrame* _silent; ///< The generated silent (has ownership) const AudioFrameDesc _frameDesc; ///< The description of the silence (sampleRate, channels...) }; } diff --git a/src/AvTranscoder/decoder/VideoGenerator.hpp b/src/AvTranscoder/decoder/VideoGenerator.hpp index bb90217f..c9053047 100644 --- a/src/AvTranscoder/decoder/VideoGenerator.hpp +++ b/src/AvTranscoder/decoder/VideoGenerator.hpp @@ -24,8 +24,8 @@ class AvExport VideoGenerator : public IDecoder void setNextFrame(Frame& inputFrame) { _inputFrame = &inputFrame; } private: - Frame* _inputFrame; ///< A frame given from outside (has link, no ownership) - VideoFrame* _blackImage; ///< The generated black image (has ownership) + Frame* _inputFrame; ///< A frame given from outside (has link, no ownership) + VideoFrame* _blackImage; ///< The generated black image (has ownership) const VideoFrameDesc _frameDesc; ///< The description of the black image (width, height...) }; } diff --git a/src/AvTranscoder/encoder/AudioEncoder.cpp b/src/AvTranscoder/encoder/AudioEncoder.cpp index 0e615466..66fa14e1 100644 --- a/src/AvTranscoder/encoder/AudioEncoder.cpp +++ b/src/AvTranscoder/encoder/AudioEncoder.cpp @@ -139,5 +139,4 @@ bool AudioEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData) return true; #endif } - } diff --git a/src/AvTranscoder/encoder/VideoEncoder.cpp b/src/AvTranscoder/encoder/VideoEncoder.cpp index a4dd7424..fef4ab37 100644 --- a/src/AvTranscoder/encoder/VideoEncoder.cpp +++ b/src/AvTranscoder/encoder/VideoEncoder.cpp @@ -152,5 +152,4 @@ bool VideoEncoder::encode(const AVFrame* decodedData, AVPacket& encodedData) return true; #endif } - } diff --git a/src/AvTranscoder/file/FormatContext.cpp b/src/AvTranscoder/file/FormatContext.cpp index cab0b3d7..efc56bfe 100644 --- a/src/AvTranscoder/file/FormatContext.cpp +++ b/src/AvTranscoder/file/FormatContext.cpp @@ -144,7 +144,7 @@ AVStream& FormatContext::addAVStream(const AVCodec& avCodec) bool FormatContext::seek(const uint64_t position, const int flag) { - LOG_INFO("Seek in '" << _avFormatContext->filename << "' at " << position << " with flag '"<< flag << "'") + LOG_INFO("Seek in '" << _avFormatContext->filename << "' at " << position << " with flag '" << flag << "'") const int err = av_seek_frame(_avFormatContext, -1, position, flag); if(err < 0) { diff --git a/src/AvTranscoder/file/FormatContext.hpp b/src/AvTranscoder/file/FormatContext.hpp index 3257ce2a..7e8cce88 100644 --- a/src/AvTranscoder/file/FormatContext.hpp +++ b/src/AvTranscoder/file/FormatContext.hpp @@ -78,7 +78,8 @@ class AvExport FormatContext * @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value * @param flag: seeking mode (AVSEEK_FLAG_xxx) * @return seek status - * @warn seeking on a raw bitstreams (without any container) could produce an error (because of a lack of timing information) + * @warn seeking on a raw bitstreams (without any container) could produce an error (because of a lack of timing + * information) * @see flushDecoder */ bool seek(const uint64_t position, const int flag); diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index f2210354..2dbaf379 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -61,7 +61,8 @@ bool InputFile::readNextPacket(CodedData& data, const size_t streamIndex) const int ret = av_read_frame(&_formatContext.getAVFormatContext(), &data.getAVPacket()); if(ret < 0) // error or end of file { - LOG_INFO("Stop reading the next frame of file '" << _filename << "', stream " << streamIndex << " (" << getDescriptionFromErrorCode(ret) << ")") + LOG_INFO("Stop reading the next frame of file '" << _filename << "', stream " << streamIndex << " (" + << getDescriptionFromErrorCode(ret) << ")") return false; } diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index 5a415050..ab838c37 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -319,12 +319,14 @@ void OutputFile::setupRemainingWrappingOptions() void OutputFile::setOutputStream(AVStream& avStream, const ICodec& codec) { // depending on the format, place global headers in extradata instead of every keyframe - if (_formatContext.getAVOutputFormat().flags & AVFMT_GLOBALHEADER) { + if(_formatContext.getAVOutputFormat().flags & AVFMT_GLOBALHEADER) + { avStream.codec->flags |= CODEC_FLAG_GLOBAL_HEADER; } // if the codec is experimental, allow it - if(codec.getAVCodec().capabilities & CODEC_CAP_EXPERIMENTAL) { + if(codec.getAVCodec().capabilities & CODEC_CAP_EXPERIMENTAL) + { LOG_WARN("This codec is considered experimental by libav/ffmpeg:" << codec.getCodecName()); avStream.codec->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; } @@ -337,5 +339,4 @@ void OutputFile::setOutputStream(AVStream& avStream, const ICodec& codec) memset(((uint8_t*)avStream.codec->extradata) + srcExtradataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE); avStream.codec->extradata_size = codec.getAVCodecContext().extradata_size; } - } diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index 1f9e4d17..a82f2462 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -15,14 +15,14 @@ class AvExport AudioProperties : public StreamProperties std::string getSampleFormatName() const; std::string getSampleFormatLongName() const; - std::string getChannelLayout() const; ///< Get a description of a channel layout (example: '5.1'). - std::string getChannelName() const; ///< Get the name of a given channel (example: 'LFE'). - std::string getChannelDescription() const; ///< Get the description of a given channel (example: 'low frequency'). + std::string getChannelLayout() const; ///< Get a description of a channel layout (example: '5.1'). + std::string getChannelName() const; ///< Get the name of a given channel (example: 'LFE'). + std::string getChannelDescription() const; ///< Get the description of a given channel (example: 'low frequency'). size_t getBitRate() const; ///< in bits/s, 0 if unknown size_t getSampleRate() const; size_t getNbChannels() const; - size_t getNbSamples() const; ///< All the channels are included. + size_t getNbSamples() const; ///< All the channels are included. size_t getTicksPerFrame() const; diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 4fcfd6f6..8d78d23c 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -31,7 +31,7 @@ FileProperties::FileProperties(const FormatContext& formatContext) void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyseLevel level) { // Returns at the beginning of the stream before any deep analysis - if(level > eAnalyseLevelHeader && ! isRawFormat()) + if(level > eAnalyseLevelHeader && !isRawFormat()) const_cast(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD); // clear properties @@ -123,7 +123,7 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse } // Returns at the beginning of the stream after any deep analysis - if(level > eAnalyseLevelHeader && ! isRawFormat()) + if(level > eAnalyseLevelHeader && !isRawFormat()) const_cast(_formatContext)->seek(0, AVSEEK_FLAG_BACKWARD); } @@ -203,7 +203,7 @@ size_t FileProperties::getBitRate() const size_t FileProperties::getFileSize() const { std::ifstream in(getFilename().c_str(), std::ios::binary | std::ios::ate); - return in.tellg(); + return in.tellg(); } size_t FileProperties::getPacketSize() const diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index 4bb9b96f..f873e3f8 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -40,14 +40,15 @@ class AvExport FileProperties 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. + 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) + 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) size_t getFileSize() const; ///< in bytes size_t getPacketSize() const; diff --git a/src/AvTranscoder/properties/StreamProperties.cpp b/src/AvTranscoder/properties/StreamProperties.cpp index ffc230ec..935af3b8 100644 --- a/src/AvTranscoder/properties/StreamProperties.cpp +++ b/src/AvTranscoder/properties/StreamProperties.cpp @@ -71,7 +71,8 @@ float StreamProperties::getDuration() const const size_t duration = _formatContext->streams[_streamIndex]->duration; if(duration == (size_t)AV_NOPTS_VALUE) { - LOG_WARN("The duration of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") + LOG_WARN("The duration of the stream '" << _streamIndex << "' of file '" << _formatContext->filename + << "' is unknown.") return 0; } return av_q2d(timeBase) * duration; diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index a171b4ae..533742df 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -339,7 +339,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 + // discard no frame type when decode _codecContext->skip_frame = AVDISCARD_NONE; Frame frame; @@ -421,7 +421,8 @@ size_t VideoProperties::getNbFrames() const size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; if(nbFrames == 0) { - LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") + LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename + << "' is unknown.") const float duration = getDuration(); if(duration != 0) { @@ -667,7 +668,7 @@ PropertyVector& VideoProperties::fillVector(PropertyVector& data) const { gop << _gopStructure.at(frameIndex).first; gop << "("; - gop << _gopStructure.at(frameIndex).second;; + gop << _gopStructure.at(frameIndex).second; gop << ")"; gop << " "; } diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index 433c8cd4..a83e9fdc 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -128,8 +128,8 @@ class AvExport VideoProperties : public StreamProperties bool _isInterlaced; bool _isTopFieldFirst; size_t _gopSize; - std::vector > _gopStructure; ///< picture type, encoded frame size in bytes - //@} + std::vector > _gopStructure; ///< picture type, encoded frame size in bytes + //@} /** * @brief GOP timecode of the first frame diff --git a/src/AvTranscoder/reader/IReader.hpp b/src/AvTranscoder/reader/IReader.hpp index 696e38d5..e73e3068 100644 --- a/src/AvTranscoder/reader/IReader.hpp +++ b/src/AvTranscoder/reader/IReader.hpp @@ -79,9 +79,9 @@ class AvExport IReader int _channelIndex; private: - int _currentFrame; ///< The current decoded frame. - bool _inputFileAllocated; ///< Does the InputFile is held by the class or not (depends on the constructor called) - bool _continueWithGenerator; ///< If there is no more data to decode, complete with generated data + int _currentFrame; ///< The current decoded frame. + bool _inputFileAllocated; ///< Does the InputFile is held by the class or not (depends on the constructor called) + bool _continueWithGenerator; ///< If there is no more data to decode, complete with generated data }; } diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 381c779a..715006a9 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -136,7 +136,8 @@ class AvExport StreamTranscoder FilterGraph* _filterGraph; ///< Filter graph (has ownership) - std::vector _channelIndexArray; ///< List of channels that is processed from the input stream (empty if no demultiplexing). + std::vector + _channelIndexArray; ///< List of channels that is processed from the input stream (empty if no demultiplexing). float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder. diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 064787eb..b76e6299 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -35,8 +35,7 @@ Transcoder::~Transcoder() } } -void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, - const std::string& profileName, const float offset) +void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const std::string& profileName, const float offset) { // Check filename if(inputStreamDesc._filename.length() == 0) @@ -45,7 +44,7 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, if(profileName.length() == 0) { // Re-wrap - if(! inputStreamDesc.demultiplexing()) + if(!inputStreamDesc.demultiplexing()) addRewrapStream(inputStreamDesc, offset); // Transcode (transparent for the user) else @@ -59,8 +58,7 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, } } -void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, - const ProfileLoader::Profile& profile, const float offset) +void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset) { // Check filename if(!inputStreamDesc._filename.length()) @@ -209,12 +207,12 @@ void Transcoder::addRewrapStream(const InputStreamDesc& inputStreamDesc, const f InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); - _streamTranscodersAllocated.push_back(new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, offset)); + _streamTranscodersAllocated.push_back( + new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); } -void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, - const float offset) +void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, const float offset) { // Get profile from input file InputFile inputFile(inputStreamDesc._filename); @@ -232,15 +230,16 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, addTranscodeStream(inputStreamDesc, profile, offset); } -void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, - const ProfileLoader::Profile& profile, const float offset) +void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, + const float offset) { // Add profile if(!_profileLoader.hasProfile(profile)) _profileLoader.loadProfile(profile); - LOG_INFO("Add transcode stream from " << inputStreamDesc - << "with encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman) << std::endl << "and offset=" << offset << "s") + LOG_INFO("Add transcode stream from " << inputStreamDesc << "with encodingProfile=" + << profile.at(constants::avProfileIdentificatorHuman) << std::endl + << "and offset=" << offset << "s") // Add input file InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); @@ -251,7 +250,8 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, inputStreamDesc._channelIndexArray, offset)); + new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, + inputStreamDesc._channelIndexArray, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 7d174cd0..38cc69b9 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -19,36 +19,39 @@ namespace avtranscoder /** * @brief Structure to describe the source data to extract. */ -struct InputStreamDesc { +struct InputStreamDesc +{ InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelIndexArray) : _filename(filename) , _streamIndex(streamIndex) , _channelIndexArray(channelIndexArray) - {} + { + } InputStreamDesc(const std::string& filename, const size_t streamIndex, const size_t channelIndex) : _filename(filename) , _streamIndex(streamIndex) , _channelIndexArray() { - _channelIndexArray.push_back(channelIndex); + _channelIndexArray.push_back(channelIndex); } InputStreamDesc(const std::string& filename, const size_t streamIndex) : _filename(filename) , _streamIndex(streamIndex) , _channelIndexArray() - {} + { + } /** * @return If a demultiplexing step will be done to extract the expected data. */ - bool demultiplexing() const { return ! _channelIndexArray.empty(); } + bool demultiplexing() const { return !_channelIndexArray.empty(); } public: - std::string _filename; ///< Source file path. - size_t _streamIndex; ///< Source stream to extract. + std::string _filename; ///< Source file path. + size_t _streamIndex; ///< Source stream to extract. std::vector _channelIndexArray; ///< List of source channels to extract from the stream }; @@ -101,15 +104,13 @@ class AvExport Transcoder * the stream to process. * If offset is negative, the transcoder will seek in the stream and start process at this specific time. */ - void addStream(const InputStreamDesc& inputStreamDesc, - const std::string& profileName = "", const float offset = 0); + void addStream(const InputStreamDesc& inputStreamDesc, const std::string& profileName = "", const float offset = 0); /** * @brief Add a new stream to the output file, created from the given input description to process. * @note Profile will be updated, be sure to pass unique profile name. */ - void addStream(const InputStreamDesc& inputStreamDesc, - const ProfileLoader::Profile& profile, const float offset = 0); + void addStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); //@{ // @brief Add a new generated stream to the output file, created from the given encoding profile. @@ -176,10 +177,9 @@ class AvExport Transcoder private: void addRewrapStream(const InputStreamDesc& inputStreamDesc, const float offset); - void addTranscodeStream(const InputStreamDesc& inputStreamDesc, - const float offset); - void addTranscodeStream(const InputStreamDesc& inputStreamDesc, - const ProfileLoader::Profile& profile, const float offset = 0); + void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const float offset); + void addTranscodeStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, + const float offset = 0); /** * @note If streamIndex is negative, activate all streams of the file. From b022bfbfaeaa046b221b5a89c8f8a5582b288b3f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:01:04 +0200 Subject: [PATCH 18/31] pyTest: added a test to check audio demux to one output --- .../pyTest/testTranscoderTranscodeAudioMov.py | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/pyTest/testTranscoderTranscodeAudioMov.py b/test/pyTest/testTranscoderTranscodeAudioMov.py index ba19f731..1d6a1953 100644 --- a/test/pyTest/testTranscoderTranscodeAudioMov.py +++ b/test/pyTest/testTranscoderTranscodeAudioMov.py @@ -52,7 +52,7 @@ def testTranscodeMovVariableNbSamplesPerFrame(): def testTranscodeMovExtractChannels(): """ Transcode the audio stream of a MOV file which contains a video stream. - Extract channel one and third of the audio stream (5.1). + Extract channel one and third of the audio stream (5.1), and create two output streams. The encoding profile will be found from from input. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] @@ -78,3 +78,35 @@ def testTranscodeMovExtractChannels(): dst_inputFile = av.InputFile( outputFileName ) for dst_audioStream in dst_inputFile.getProperties().getAudioProperties(): assert_equals( 1, dst_audioStream.getNbChannels() ) + + +def testTranscodeMovExtractChannelsToOneOutput(): + """ + Transcode the audio stream of a MOV file which contains a video stream. + Extract channel one, third and fifth of the audio stream (5.1), and create one output streams. + The encoding profile will be found from from input. + """ + inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] + outputFileName = "testTranscodeMovExtractChannelsToOneOutput.mov" + + ouputFile = av.OutputFile( outputFileName ) + transcoder = av.Transcoder( ouputFile ) + + inputFile = av.InputFile( inputFileName ) + src_audioStream = inputFile.getProperties().getAudioProperties()[0] + audioStreamIndex = src_audioStream.getStreamIndex() + audiochannelIndexArray = (0, 3, 5) + transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex, audiochannelIndexArray) ) + + progress = av.ConsoleProgress() + processStat = transcoder.process( progress ) + + # check process stat returned + audioStat = processStat.getAudioStat(0) + assert_equals(src_audioStream.getDuration(), audioStat.getDuration()) + + # check dst audio streams + dst_inputFile = av.InputFile( outputFileName ) + dst_audioProperties = dst_inputFile.getProperties().getAudioProperties() + assert_equals( 1, len(dst_audioProperties) ) + assert_equals( 3, dst_audioProperties[0].getNbChannels() ) From eb1e9af2bcfaa033af96ffdc0b3284b89bb09da3 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:09:26 +0200 Subject: [PATCH 19/31] AudioDecoder: improved perf if all channels of the stream are extracted This is the common case of the audio decoding. --- src/AvTranscoder/decoder/AudioDecoder.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/AvTranscoder/decoder/AudioDecoder.cpp b/src/AvTranscoder/decoder/AudioDecoder.cpp index 87ec9e8c..99d6a8a6 100644 --- a/src/AvTranscoder/decoder/AudioDecoder.cpp +++ b/src/AvTranscoder/decoder/AudioDecoder.cpp @@ -118,17 +118,19 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer) bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector channelIndexArray) { - AudioFrame& audioBuffer = static_cast(frameBuffer); - - // decode all data of the next frame - AudioFrame allDataOfNextFrame(audioBuffer); - if(!decodeNextFrame(allDataOfNextFrame)) - return false; - AVCodecContext& avCodecContext = _inputStream->getAudioCodec().getAVCodecContext(); const size_t srcNbChannels = avCodecContext.channels; const size_t bytePerSample = av_get_bytes_per_sample((AVSampleFormat)frameBuffer.getAVFrame().format); + // if all channels of the stream are extracted + if(srcNbChannels == channelIndexArray.size()) + return decodeNextFrame(frameBuffer); + + // else decode all data in an intermediate buffer + AudioFrame allDataOfNextFrame(frameBuffer); + if(!decodeNextFrame(allDataOfNextFrame)) + return false; + const int dstNbChannels = 1; const int noAlignment = 0; const size_t decodedSize = av_samples_get_buffer_size(NULL, dstNbChannels, frameBuffer.getAVFrame().nb_samples, @@ -153,6 +155,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer, const std::vector } // copy frame properties of decoded frame + AudioFrame& audioBuffer = static_cast(frameBuffer); audioBuffer.copyProperties(allDataOfNextFrame); av_frame_set_channels(&audioBuffer.getAVFrame(), channelIndexArray.size()); av_frame_set_channel_layout(&audioBuffer.getAVFrame(), av_get_default_channel_layout(channelIndexArray.size())); From 5ec2a730946b04337a8957f67ade259ccccd96c7 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:24:36 +0200 Subject: [PATCH 20/31] Transcoder: updated doc of addStream methods --- src/AvTranscoder/transcoder/Transcoder.hpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 2778f78f..1cce4e79 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -96,21 +96,16 @@ class AvExport Transcoder ~Transcoder(); - /** - * @brief Add a new stream to the output file, created from the given input description to process. - * @param profileName: the encoding profile (rewrap if empty) - * @param offset: in seconds - * If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before - * the stream to process. - * If offset is negative, the transcoder will seek in the stream and start process at this specific time. - */ + //@{ + // @brief Add a new stream to the output file, created from the given input description to process. + // @param profileName: the encoding profile (rewrap if empty) + // @param offset: in seconds + // If offset is positive, the transcoder will generate black images or silence (depending on the type of stream) before + // the stream to process. + // If offset is negative, the transcoder will seek in the stream and start process at this specific time. void addStream(const InputStreamDesc& inputStreamDesc, const std::string& profileName = "", const float offset = 0); - - /** - * @brief Add a new stream to the output file, created from the given input description to process. - * @note Profile will be updated, be sure to pass unique profile name. - */ void addStream(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile, const float offset = 0); + //@} //@{ // @brief Add a new generated stream to the output file, created from the given encoding profile. From 222c48fa58f849b253a483027f04ef02c4ed7828 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:24:45 +0200 Subject: [PATCH 21/31] StreamTranscoder: updated doc --- src/AvTranscoder/transcoder/StreamTranscoder.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index 3d0f0d4f..dfc73dbf 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -38,8 +38,7 @@ class AvExport StreamTranscoder const std::vector channelIndexArray, const float offset = 0); /** - * @brief encode from a generated stream - * @note offset feature has no sense here + * @brief Encode a generated stream **/ StreamTranscoder(IOutputFile& outputFile, const ProfileLoader::Profile& profile); From 1a512f9eca21652473a68f47a79f57567ebf8b0f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:25:38 +0200 Subject: [PATCH 22/31] Transcoder: refactored private method addTranscodeStream Added a local variable. --- src/AvTranscoder/transcoder/Transcoder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 6b2b5634..b5ffb74e 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -234,15 +234,15 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, cons // Add input file InputFile* referenceFile = addInputFile(inputStreamDesc._filename, inputStreamDesc._streamIndex, offset); + IInputStream& inputStream = referenceFile->getStream(inputStreamDesc._streamIndex); - switch(referenceFile->getStream(inputStreamDesc._streamIndex).getProperties().getStreamType()) + switch(inputStream.getProperties().getStreamType()) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(referenceFile->getStream(inputStreamDesc._streamIndex), _outputFile, profile, - inputStreamDesc._channelIndexArray, offset)); + new StreamTranscoder(inputStream, _outputFile, profile, inputStreamDesc._channelIndexArray, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } From 33723c818916479990ce0c674dfda52461a331af Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 10:55:36 +0200 Subject: [PATCH 23/31] StreamTranscoder: throw if a stream needs to switch to a generator but cannot * Updated doc of the method. * Added a python test. --- src/AvTranscoder/transcoder/StreamTranscoder.cpp | 7 +++---- src/AvTranscoder/transcoder/StreamTranscoder.hpp | 1 - test/pyTest/testOffset.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 788293e7..f3cef158 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -560,10 +560,9 @@ void StreamTranscoder::needToSwitchToGenerator(const bool needToSwitch) if(needToSwitch && !canSwitchToGenerator()) { std::stringstream os; - LOG_WARN("The stream " << _inputStream->getStreamIndex() << " has a duration of " << getDuration() - << "s. It needs to switch to a generator during the process, but it cannot. " - << "No generator will be used for this stream.") - return; + os << "The stream at index " << _inputStream->getStreamIndex() << " has a duration of " << getDuration() << "s."; + os << " It needs to switch to a generator during the process, but it cannot. "; + throw std::runtime_error(os.str()); } _needToSwitchToGenerator = needToSwitch; } diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index dfc73dbf..e0c854a5 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -27,7 +27,6 @@ class AvExport StreamTranscoder public: /** * @brief Rewrap the given stream. - * @note offset feature when rewrap a stream is not supported **/ StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const float offset = 0); diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 002cc39f..810cea3c 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -15,6 +15,22 @@ from pyAvTranscoder import avtranscoder as av +@raises(RuntimeError) +def testRewrapVideoPositiveOffsetWithoutGenerator(): + """ + Add a positive offset supposed to have a generator. + Depending on the codec and the given parameters, the generator could not be instanciate. + """ + inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE'] + outputFileName = "testPositiveOffsetWithoutGenerator.h264" + offset = 10 + + ouputFile = av.OutputFile( outputFileName ) + transcoder = av.Transcoder( ouputFile ) + + transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) + + def testTranscodeAudioPositiveOffset(): """ Transcode one audio stream (profile wave24b48kmono) with offset at the beginning of the process. From 8c95f639d53b23d3005cac7998c699253973cbb4 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 11:18:51 +0200 Subject: [PATCH 24/31] Moved InputStreamDesc struct to a separate file --- .../transcoder/InputStreamDesc.cpp | 23 +++++++ .../transcoder/InputStreamDesc.hpp | 64 +++++++++++++++++++ src/AvTranscoder/transcoder/Transcoder.cpp | 17 ----- src/AvTranscoder/transcoder/Transcoder.hpp | 46 +------------ src/AvTranscoder/transcoder/transcoder.i | 2 + 5 files changed, 91 insertions(+), 61 deletions(-) create mode 100644 src/AvTranscoder/transcoder/InputStreamDesc.cpp create mode 100644 src/AvTranscoder/transcoder/InputStreamDesc.hpp diff --git a/src/AvTranscoder/transcoder/InputStreamDesc.cpp b/src/AvTranscoder/transcoder/InputStreamDesc.cpp new file mode 100644 index 00000000..921425cc --- /dev/null +++ b/src/AvTranscoder/transcoder/InputStreamDesc.cpp @@ -0,0 +1,23 @@ +#include "InputStreamDesc.hpp" + +namespace avtranscoder +{ + +std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc) +{ + flux << "input stream description: " << std::endl; + flux << "- filename: " << inputStreamDesc._filename << std::endl; + flux << "- stream index: " << inputStreamDesc._streamIndex << std::endl; + if(inputStreamDesc.demultiplexing()) + { + flux << "- channels index: "; + for(size_t c = 0; c < inputStreamDesc._channelIndexArray.size(); ++c) + { + flux << inputStreamDesc._channelIndexArray.at(c) << ", "; + } + flux << std::endl; + } + return flux; +} + +} diff --git a/src/AvTranscoder/transcoder/InputStreamDesc.hpp b/src/AvTranscoder/transcoder/InputStreamDesc.hpp new file mode 100644 index 00000000..f9013880 --- /dev/null +++ b/src/AvTranscoder/transcoder/InputStreamDesc.hpp @@ -0,0 +1,64 @@ +#ifndef _AV_TRANSCODER_INPUT_STREAM_DESC_HPP_ +#define _AV_TRANSCODER_INPUT_STREAM_DESC_HPP_ + +#include + +#include +#include + +namespace avtranscoder +{ + +/** + * @brief Structure to describe the source data to extract. + */ +struct InputStreamDesc +{ + + InputStreamDesc() + : _filename() + , _streamIndex(0) + , _channelIndexArray() + { + } + + InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelIndexArray) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelIndexArray(channelIndexArray) + { + } + + InputStreamDesc(const std::string& filename, const size_t streamIndex, const size_t channelIndex) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelIndexArray() + { + _channelIndexArray.push_back(channelIndex); + } + + InputStreamDesc(const std::string& filename, const size_t streamIndex) + : _filename(filename) + , _streamIndex(streamIndex) + , _channelIndexArray() + { + } + + /** + * @return If a demultiplexing step will be done to extract the expected data. + */ + bool demultiplexing() const { return !_channelIndexArray.empty(); } + +public: + std::string _filename; ///< Source file path. + size_t _streamIndex; ///< Source stream to extract. + std::vector _channelIndexArray; ///< List of source channels to extract from the stream +}; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc); +#endif + +} + +#endif diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index b5ffb74e..07a50733 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -502,21 +502,4 @@ void Transcoder::fillProcessStat(ProcessStat& processStat) } } } - -std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc) -{ - flux << "input stream description: " << std::endl; - flux << "- filename: " << inputStreamDesc._filename << std::endl; - flux << "- stream index: " << inputStreamDesc._streamIndex << std::endl; - if(inputStreamDesc.demultiplexing()) - { - flux << "- channels index: "; - for(size_t c = 0; c < inputStreamDesc._channelIndexArray.size(); ++c) - { - flux << inputStreamDesc._channelIndexArray.at(c) << ", "; - } - flux << std::endl; - } - return flux; -} } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 1cce4e79..0fc94c92 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -8,7 +8,8 @@ #include #include -#include "StreamTranscoder.hpp" +#include +#include #include #include @@ -16,49 +17,6 @@ namespace avtranscoder { -/** - * @brief Structure to describe the source data to extract. - */ -struct InputStreamDesc -{ - - InputStreamDesc(const std::string& filename, const size_t streamIndex, const std::vector& channelIndexArray) - : _filename(filename) - , _streamIndex(streamIndex) - , _channelIndexArray(channelIndexArray) - { - } - - InputStreamDesc(const std::string& filename, const size_t streamIndex, const size_t channelIndex) - : _filename(filename) - , _streamIndex(streamIndex) - , _channelIndexArray() - { - _channelIndexArray.push_back(channelIndex); - } - - InputStreamDesc(const std::string& filename, const size_t streamIndex) - : _filename(filename) - , _streamIndex(streamIndex) - , _channelIndexArray() - { - } - - /** - * @return If a demultiplexing step will be done to extract the expected data. - */ - bool demultiplexing() const { return !_channelIndexArray.empty(); } - -public: - std::string _filename; ///< Source file path. - size_t _streamIndex; ///< Source stream to extract. - std::vector _channelIndexArray; ///< List of source channels to extract from the stream -}; - -#ifndef SWIG -AvExport std::ostream& operator<<(std::ostream& flux, const InputStreamDesc& inputStreamDesc); -#endif - /** * @brief Enum to set a policy of how we manage the process in case of several streams. * eProcessMethodShortest: stop the process at the end of the shortest stream. diff --git a/src/AvTranscoder/transcoder/transcoder.i b/src/AvTranscoder/transcoder/transcoder.i index ffb1eedd..229cd227 100644 --- a/src/AvTranscoder/transcoder/transcoder.i +++ b/src/AvTranscoder/transcoder/transcoder.i @@ -1,9 +1,11 @@ %{ +#include #include #include %} %template(StreamTranscoderVector) std::vector< avtranscoder::StreamTranscoder* >; +%include %include %include From bd012988001dfa81ab09d6821e598acc0ed40b58 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 11:22:47 +0200 Subject: [PATCH 25/31] StreamTranscoder: updated constructor parameters To get all inputStreamDesc instead of only the array of channel index. --- .../transcoder/StreamTranscoder.cpp | 25 +++++++++---------- .../transcoder/StreamTranscoder.hpp | 9 ++++--- src/AvTranscoder/transcoder/Transcoder.cpp | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index f3cef158..a6878bc3 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -1,4 +1,3 @@ - #include "StreamTranscoder.hpp" #include @@ -31,7 +30,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelIndexArray() + , _inputStreamDesc() , _offset(offset) , _needToSwitchToGenerator(false) { @@ -121,8 +120,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu setOffset(offset); } -StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const std::vector channelIndexArray, const float offset) +StreamTranscoder::StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInputStream& inputStream, IOutputFile& outputFile, + const ProfileLoader::Profile& profile, const float offset) : _inputStream(&inputStream) , _outputStream(NULL) , _sourceBuffer(NULL) @@ -133,7 +132,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelIndexArray(channelIndexArray) + , _inputStreamDesc(inputStreamDesc) , _offset(offset) , _needToSwitchToGenerator(false) { @@ -191,8 +190,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu AudioFrameDesc outputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); outputFrameDesc.setParameters(profile); - if(!_channelIndexArray.empty()) - outputFrameDesc._nbChannels = _channelIndexArray.size(); + if(_inputStreamDesc.demultiplexing()) + outputFrameDesc._nbChannels = _inputStreamDesc._channelIndexArray.size(); outputAudio->setupAudioEncoder(outputFrameDesc, profile); // output stream @@ -200,8 +199,8 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu // buffers to process AudioFrameDesc inputFrameDesc(_inputStream->getAudioCodec().getAudioFrameDesc()); - if(!_channelIndexArray.empty()) - inputFrameDesc._nbChannels = _channelIndexArray.size(); + if(_inputStreamDesc.demultiplexing()) + inputFrameDesc._nbChannels = _inputStreamDesc._channelIndexArray.size(); _sourceBuffer = new AudioFrame(inputFrameDesc); _frameBuffer = new AudioFrame(outputAudio->getAudioCodec().getAudioFrameDesc()); @@ -234,7 +233,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader: , _outputEncoder(NULL) , _transform(NULL) , _filterGraph(NULL) - , _channelIndexArray() + , _inputStreamDesc() , _offset(0) , _needToSwitchToGenerator(false) { @@ -466,10 +465,10 @@ bool StreamTranscoder::processTranscode() LOG_DEBUG("Decode next frame") bool decodingStatus = false; - if(_channelIndexArray.empty()) - decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer); + if(_inputStreamDesc.demultiplexing()) + decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, _inputStreamDesc._channelIndexArray); else - decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer, _channelIndexArray); + decodingStatus = _currentDecoder->decodeNextFrame(*_sourceBuffer); CodedData data; if(decodingStatus) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index e0c854a5..bfc1fad3 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -3,6 +3,8 @@ #include +#include + #include #include @@ -33,8 +35,8 @@ class AvExport StreamTranscoder /** * @brief Transcode the given stream. **/ - StreamTranscoder(IInputStream& inputStream, IOutputFile& outputFile, const ProfileLoader::Profile& profile, - const std::vector channelIndexArray, const float offset = 0); + StreamTranscoder(const InputStreamDesc& inputStreamDesc, IInputStream& inputStream, IOutputFile& outputFile, + const ProfileLoader::Profile& profile, const float offset = 0); /** * @brief Encode a generated stream @@ -135,8 +137,7 @@ class AvExport StreamTranscoder FilterGraph* _filterGraph; ///< Filter graph (has ownership) - std::vector - _channelIndexArray; ///< List of channels that is processed from the input stream (empty if no demultiplexing). + const InputStreamDesc _inputStreamDesc; ///< Description of the data to extract from the input stream. float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder. diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 07a50733..4e734f0a 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -242,7 +242,7 @@ void Transcoder::addTranscodeStream(const InputStreamDesc& inputStreamDesc, cons case AVMEDIA_TYPE_AUDIO: { _streamTranscodersAllocated.push_back( - new StreamTranscoder(inputStream, _outputFile, profile, inputStreamDesc._channelIndexArray, offset)); + new StreamTranscoder(inputStreamDesc, inputStream, _outputFile, profile, offset)); _streamTranscoders.push_back(_streamTranscodersAllocated.back()); break; } From 3dba20fe2b04c9e287643c199395dfcfa9a42418 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 11:23:14 +0200 Subject: [PATCH 26/31] pyTest: clean testTranscoderAdd --- test/pyTest/testTranscoderAdd.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/pyTest/testTranscoderAdd.py b/test/pyTest/testTranscoderAdd.py index 6f3329b9..2c359aa4 100644 --- a/test/pyTest/testTranscoderAdd.py +++ b/test/pyTest/testTranscoderAdd.py @@ -31,8 +31,7 @@ def testAddStreamTranscoder(): transcoder.addStream( streamTranscoder) # process - progress = av.NoDisplayProgress() - transcoder.process( progress ) + transcoder.process() @raises(IOError) @@ -51,5 +50,4 @@ def testAddAllStreamsOfFileWhichDoesNotExist(): transcoder.addStream( av.InputStreamDesc(inputFileName, 0) ) # process - progress = av.ConsoleProgress() - transcoder.process( progress ) + transcoder.process() From 1d84193f357504a8590027f5eadeaa74e08a5077 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 16:59:22 +0200 Subject: [PATCH 27/31] pyTest: fixed testSetFrame --- test/pyTest/testSetFrame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pyTest/testSetFrame.py b/test/pyTest/testSetFrame.py index 2d5085e0..c1d7008e 100644 --- a/test/pyTest/testSetFrame.py +++ b/test/pyTest/testSetFrame.py @@ -23,7 +23,7 @@ def testSetVideoFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.addStream( encodingProfile ) + transcoder.addGeneratedStream( encodingProfile ) videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process @@ -69,7 +69,7 @@ def testSetAudioFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.addStream( "wave24b48kmono" ) + transcoder.addGeneratedStream( "wave24b48kmono" ) audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process From 584f53020aeee5fe0d314433b64ea3577db0c20e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 18:27:41 +0200 Subject: [PATCH 28/31] Transcoder: renamed addGeneratedStream methods to addGenerateStream --- app/avProcessor/avProcessor.cpp | 2 +- src/AvTranscoder/transcoder/Transcoder.cpp | 6 +++--- src/AvTranscoder/transcoder/Transcoder.hpp | 4 ++-- test/pyTest/testSetFrame.py | 4 ++-- test/pyTest/testTranscoderGenerateStream.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/avProcessor/avProcessor.cpp b/app/avProcessor/avProcessor.cpp index 3f406173..2c367dcb 100644 --- a/app/avProcessor/avProcessor.cpp +++ b/app/avProcessor/avProcessor.cpp @@ -41,7 +41,7 @@ void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder // generated stream if(!filename.length()) - transcoder.addGeneratedStream(transcodeProfile); + transcoder.addGenerateStream(transcodeProfile); else { avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, channelIndexArray); diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 4e734f0a..f07ef225 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -67,13 +67,13 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const Profile addTranscodeStream(inputStreamDesc, profile, offset); } -void Transcoder::addGeneratedStream(const std::string& encodingProfileName) +void Transcoder::addGenerateStream(const std::string& encodingProfileName) { const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(encodingProfileName); - addGeneratedStream(encodingProfile); + addGenerateStream(encodingProfile); } -void Transcoder::addGeneratedStream(const ProfileLoader::Profile& encodingProfile) +void Transcoder::addGenerateStream(const ProfileLoader::Profile& encodingProfile) { // Add profile if(!_profileLoader.hasProfile(encodingProfile)) diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index 0fc94c92..9c4ee023 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -67,8 +67,8 @@ class AvExport Transcoder //@{ // @brief Add a new generated stream to the output file, created from the given encoding profile. - void addGeneratedStream(const std::string& encodingProfileName); - void addGeneratedStream(const ProfileLoader::Profile& encodingProfile); + void addGenerateStream(const std::string& encodingProfileName); + void addGenerateStream(const ProfileLoader::Profile& encodingProfile); //@} /** diff --git a/test/pyTest/testSetFrame.py b/test/pyTest/testSetFrame.py index c1d7008e..18d35df1 100644 --- a/test/pyTest/testSetFrame.py +++ b/test/pyTest/testSetFrame.py @@ -23,7 +23,7 @@ def testSetVideoFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.addGeneratedStream( encodingProfile ) + transcoder.addGenerateStream( encodingProfile ) videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process @@ -69,7 +69,7 @@ def testSetAudioFrame(): # create transcoder and add a video stream transcoder = av.Transcoder( ouputFile ) - transcoder.addGeneratedStream( "wave24b48kmono" ) + transcoder.addGenerateStream( "wave24b48kmono" ) audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder() # start process diff --git a/test/pyTest/testTranscoderGenerateStream.py b/test/pyTest/testTranscoderGenerateStream.py index 89edf87b..9f55f78c 100644 --- a/test/pyTest/testTranscoderGenerateStream.py +++ b/test/pyTest/testTranscoderGenerateStream.py @@ -36,7 +36,7 @@ def testGenerateVideoWithIncompleteProfile(): av.avProfileIdentificatorHuman : "New video preset", av.avProfileType : av.avProfileTypeVideo, } - transcoder.addGeneratedStream( encodingProfile ) + transcoder.addGenerateStream( encodingProfile ) transcoder.process() @@ -60,7 +60,7 @@ def testGenerateAudioWithIncompleteProfile(): av.avProfileIdentificatorHuman : "New audio preset", av.avProfileType : av.avProfileTypeAudio, } - transcoder.addGeneratedStream( encodingProfile ) + transcoder.addGenerateStream( encodingProfile ) transcoder.process() @@ -74,7 +74,7 @@ def testTranscodeDummyAudio(): transcoder = av.Transcoder( ouputFile ) # generate an audio stream - transcoder.addGeneratedStream( "wave24b48kmono" ) + transcoder.addGenerateStream( "wave24b48kmono" ) ouputFile.beginWrap() transcoder.processFrame() @@ -90,7 +90,7 @@ def testTranscodeDummyVideo(): transcoder = av.Transcoder( ouputFile ) # generate a video stream - transcoder.addGeneratedStream( "dnxhd120" ) + transcoder.addGenerateStream( "dnxhd120" ) ouputFile.beginWrap() transcoder.processFrame() From d01ccc8d1fea0df7527cc6ae093808bc106673e5 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jul 2016 18:29:49 +0200 Subject: [PATCH 29/31] pyTest: fixed doc of testTranscoderTranscodeAudioMov --- test/pyTest/testTranscoderTranscodeAudioMov.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pyTest/testTranscoderTranscodeAudioMov.py b/test/pyTest/testTranscoderTranscodeAudioMov.py index 1d6a1953..228d47cb 100644 --- a/test/pyTest/testTranscoderTranscodeAudioMov.py +++ b/test/pyTest/testTranscoderTranscodeAudioMov.py @@ -52,7 +52,7 @@ def testTranscodeMovVariableNbSamplesPerFrame(): def testTranscodeMovExtractChannels(): """ Transcode the audio stream of a MOV file which contains a video stream. - Extract channel one and third of the audio stream (5.1), and create two output streams. + Extract first and fourth channels of the audio stream (5.1), and create two output streams. The encoding profile will be found from from input. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] @@ -83,7 +83,7 @@ def testTranscodeMovExtractChannels(): def testTranscodeMovExtractChannelsToOneOutput(): """ Transcode the audio stream of a MOV file which contains a video stream. - Extract channel one, third and fifth of the audio stream (5.1), and create one output streams. + Extract first, third and last channels of the audio stream (5.1), and create one output streams. The encoding profile will be found from from input. """ inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'] From 58dbd6607e5357b00ef2f0cc65c051361ad25e11 Mon Sep 17 00:00:00 2001 From: Valentin Noel Date: Wed, 20 Jul 2016 16:49:39 +0200 Subject: [PATCH 30/31] pyTest: fixed testOffset * Removed ffmpeg dependent testRewrapVideoPositiveOffsetWithoutGenerator * The RuntimeError raising is not systematic --- test/pyTest/testOffset.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/pyTest/testOffset.py b/test/pyTest/testOffset.py index 810cea3c..002cc39f 100644 --- a/test/pyTest/testOffset.py +++ b/test/pyTest/testOffset.py @@ -15,22 +15,6 @@ from pyAvTranscoder import avtranscoder as av -@raises(RuntimeError) -def testRewrapVideoPositiveOffsetWithoutGenerator(): - """ - Add a positive offset supposed to have a generator. - Depending on the codec and the given parameters, the generator could not be instanciate. - """ - inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE'] - outputFileName = "testPositiveOffsetWithoutGenerator.h264" - offset = 10 - - ouputFile = av.OutputFile( outputFileName ) - transcoder = av.Transcoder( ouputFile ) - - transcoder.addStream( av.InputStreamDesc(inputFileName, 0), "", offset ) - - def testTranscodeAudioPositiveOffset(): """ Transcode one audio stream (profile wave24b48kmono) with offset at the beginning of the process. From a9959ccf8bb716f6ee1c90c3a5d73a5a37d4de9b Mon Sep 17 00:00:00 2001 From: Valentin Noel Date: Wed, 20 Jul 2016 16:52:51 +0200 Subject: [PATCH 31/31] .gitignore: added Python bytecode files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 2b20054b..427a1344 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ CMakeFiles Makefile cmake_install.cmake install_manifest.txt + +# Python +*.pyc +