From 1c46ef380103ff05ab48467a7050079b0e1751a5 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 25 Aug 2016 11:40:12 +0200 Subject: [PATCH 1/7] AudioVideo: up avtranscoder submodule to v0.10.4 --- plugins/image/io/AudioVideo/avTranscoder | 2 +- .../AudioVideo/src/writer/AVWriterPlugin.cpp | 76 ++++++++----------- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/plugins/image/io/AudioVideo/avTranscoder b/plugins/image/io/AudioVideo/avTranscoder index 94c3b736a..103c33f91 160000 --- a/plugins/image/io/AudioVideo/avTranscoder +++ b/plugins/image/io/AudioVideo/avTranscoder @@ -1 +1 @@ -Subproject commit 94c3b736ab86d64fda5bd7343bcffe6304aab538 +Subproject commit 103c33f918f78f45d99166a746e21662eeb94cfb diff --git a/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp b/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp index 50a9e7592..5702a9167 100644 --- a/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp +++ b/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp @@ -2,8 +2,8 @@ #include "AVWriterProcess.hpp" #include "AVWriterDefinitions.hpp" +#include #include -#include #include #include @@ -286,10 +286,8 @@ void AVWriterPlugin::updateAudioSelectStream(size_t indexAudioOutput) const std::string inputFilePath = _paramAudioFilePath.at(indexAudioOutput)->getValue(); if(boost::filesystem::exists(inputFilePath)) { - avtranscoder::NoDisplayProgress progress; - const avtranscoder::FileProperties fileProperties = - avtranscoder::InputFile::analyseFile(inputFilePath, progress, avtranscoder::eAnalyseLevelHeader); - const size_t nbAudioStream = fileProperties.getAudioProperties().size(); + const avtranscoder::InputFile inputFile(inputFilePath); + const size_t nbAudioStream = inputFile.getProperties().getNbAudioStreams(); _paramAudioStreamIndex.at(indexAudioOutput)->setRange(0, nbAudioStream); _paramAudioStreamIndex.at(indexAudioOutput)->setDisplayRange(0, nbAudioStream); } @@ -330,17 +328,15 @@ void AVWriterPlugin::updateAudioFileInfo(size_t indexAudioOutput) std::string inputFilePath = _paramAudioFilePath.at(indexAudioOutput)->getValue(); if(boost::filesystem::exists(inputFilePath)) { - avtranscoder::NoDisplayProgress progress; - const avtranscoder::FileProperties fileProperties = - avtranscoder::InputFile::analyseFile(inputFilePath, progress, avtranscoder::eAnalyseLevelHeader); - const size_t nbAudioStream = fileProperties.getAudioProperties().size(); + const avtranscoder::InputFile inputFile(inputFilePath); + const std::vector& audioPropertiesArray = inputFile.getProperties().getAudioProperties(); + const size_t nbAudioStream = audioPropertiesArray.size(); std::string audioInfo = "Audio streams: "; audioInfo += boost::lexical_cast(nbAudioStream); audioInfo += "\n"; for(size_t audioStreamIndex = 0; audioStreamIndex < nbAudioStream; ++audioStreamIndex) { - const avtranscoder::AudioProperties& audioProperties = - fileProperties.getAudioProperties().at(audioStreamIndex); + const avtranscoder::AudioProperties& audioProperties = audioPropertiesArray.at(audioStreamIndex); // stream audioInfo += "Stream "; @@ -564,6 +560,14 @@ void AVWriterPlugin::initVideo(const OFX::RenderArguments& args) try { + // get rod + const OfxRectI bounds = _clipSrc->getPixelRod(args.time, args.renderScale); + const int width = bounds.x2 - bounds.x1; + const int height = bounds.y2 - bounds.y1; + + // set description of the frame set by the plugin + _videoDesc.reset(new avtranscoder::VideoFrameDesc(width, height, "rgb24")); + // Get custom video profile avtranscoder::ProfileLoader::Profile profile; profile[avtranscoder::constants::avProfileIdentificator] = "customVideoPreset"; @@ -586,6 +590,11 @@ void AVWriterPlugin::initVideo(const OFX::RenderArguments& args) profile[avtranscoder::constants::avProfileWidth] = boost::to_string(_paramCustomSize->getValue().x); profile[avtranscoder::constants::avProfileHeight] = boost::to_string(_paramCustomSize->getValue().y); } + else + { + profile[avtranscoder::constants::avProfileWidth] = boost::to_string(width); + profile[avtranscoder::constants::avProfileHeight] = boost::to_string(height); + } // video options const avtranscoder::ProfileLoader::Profile videoProfile = _paramVideoCustom.getCorrespondingProfile(); @@ -598,19 +607,8 @@ void AVWriterPlugin::initVideo(const OFX::RenderArguments& args) cleanProfile(profile, common::kPrefixVideo); - // get rod - const OfxRectI bounds = _clipSrc->getPixelRod(args.time, args.renderScale); - const int width = bounds.x2 - bounds.x1; - const int height = bounds.y2 - bounds.y1; - - // describe input frame and codec of transcode - avtranscoder::VideoCodec videoCodec(avtranscoder::eCodecTypeEncoder, - profile[avtranscoder::constants::avProfileCodec]); - _videoDesc.reset(new avtranscoder::VideoFrameDesc(width, height, "rgb24")); - videoCodec.setImageParameters(*_videoDesc); - - // add video stream - _transcoder->add("", 0, profile, videoCodec); + // add video stream (the frames to encode will be set by the plugin) + _transcoder->addGenerateStream(profile); } catch(std::exception& e) { @@ -702,18 +700,8 @@ void AVWriterPlugin::initAudio() { try { - avtranscoder::AudioCodec audioCodec(avtranscoder::eCodecTypeEncoder, - profile.at(avtranscoder::constants::avProfileCodec)); - const size_t sampleRate = - boost::lexical_cast(profile.at(avtranscoder::constants::avProfileSampleRate)); - const size_t channels = - boost::lexical_cast(profile.at(avtranscoder::constants::avProfileChannel)); - avtranscoder::AudioFrameDesc audioDesc(sampleRate, channels, - profile.at(avtranscoder::constants::avProfileSampleFormat)); - audioCodec.setAudioParameters(audioDesc); - // add silent stream - _transcoder->add("", 1, profile, audioCodec); + _transcoder->addGenerateStream(profile); } catch(std::out_of_range& e) { @@ -729,10 +717,8 @@ void AVWriterPlugin::initAudio() std::vector indexAudioStreams; if(inputStreamIndex == -1) { - avtranscoder::NoDisplayProgress progress; - const avtranscoder::FileProperties fileProperties = - avtranscoder::InputFile::analyseFile(inputFileName, progress, avtranscoder::eAnalyseLevelHeader); - const std::vector audioProperties = fileProperties.getAudioProperties(); + const avtranscoder::InputFile inputFile(inputFileName); + const std::vector audioProperties = inputFile.getProperties().getAudioProperties(); for(size_t propertiesIndex = 0; propertiesIndex < audioProperties.size(); ++propertiesIndex) { indexAudioStreams.push_back(audioProperties.at(propertiesIndex).getStreamIndex()); @@ -744,14 +730,14 @@ void AVWriterPlugin::initAudio() { if(inputStreamIndex != -1) { - _transcoder->add(inputFileName, inputStreamIndex, presetName); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, inputStreamIndex), presetName); } else { for(std::vector::iterator itStreamIndex = indexAudioStreams.begin(); itStreamIndex != indexAudioStreams.end(); ++itStreamIndex) { - _transcoder->add(inputFileName, *itStreamIndex, presetName); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, *itStreamIndex), presetName); } } } @@ -767,14 +753,14 @@ void AVWriterPlugin::initAudio() { if(inputStreamIndex != -1) { - _transcoder->add(inputFileName, inputStreamIndex, subStream, profile, offset); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, inputStreamIndex, subStream), profile, offset); } else { for(std::vector::iterator itStreamIndex = indexAudioStreams.begin(); itStreamIndex != indexAudioStreams.end(); ++itStreamIndex) { - _transcoder->add(inputFileName, *itStreamIndex, subStream, profile, offset); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, *itStreamIndex, subStream), profile, offset); } } } @@ -783,14 +769,14 @@ void AVWriterPlugin::initAudio() { if(inputStreamIndex != -1) { - _transcoder->add(inputFileName, inputStreamIndex, subStream, presetName, offset); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, inputStreamIndex, subStream), presetName, offset); } else { for(std::vector::iterator itStreamIndex = indexAudioStreams.begin(); itStreamIndex != indexAudioStreams.end(); ++itStreamIndex) { - _transcoder->add(inputFileName, *itStreamIndex, subStream, presetName, offset); + _transcoder->addStream(avtranscoder::InputStreamDesc(inputFileName, *itStreamIndex, subStream), presetName, offset); } } } From c90379c772f32f9f083de01977dd22d2c42ab341 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 25 Aug 2016 12:35:33 +0200 Subject: [PATCH 2/7] AudioVideo writer: fixed warning logged when updating the parameters from a video profile "width" and "height" are custom avtranscoder parameters, and a specific process is done for them. --- plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp b/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp index 5702a9167..7e8ca286e 100644 --- a/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp +++ b/plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp @@ -879,7 +879,9 @@ void AVWriterPlugin::updateVideoFromExistingProfile() option.first == avtranscoder::constants::avProfileType || option.first == avtranscoder::constants::avProfileCodec || option.first == avtranscoder::constants::avProfilePixelFormat || - option.first == avtranscoder::constants::avProfileFrameRate) + option.first == avtranscoder::constants::avProfileFrameRate || + option.first == avtranscoder::constants::avProfileWidth || + option.first == avtranscoder::constants::avProfileHeight) continue; if(!_paramVideoCustom.setOption(option.first, option.second)) From 083d44e3e1a6908459a4429744d116bf706ee791 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 25 Aug 2016 12:50:38 +0200 Subject: [PATCH 3/7] AudioVideo: fixed default value of some OFX Choice parameters * For some options, we need to translate the libav option default value to a value compliant with OpenFX. * This commit removed most of the warnings raised by Nuke when copying the reader/writer nodes. --- .../io/AudioVideo/src/common/LibAVParams.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp index 3563c7d38..36478468e 100644 --- a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp +++ b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp @@ -499,7 +499,20 @@ void addOptionsToGroup(OFX::ImageEffectDescriptor& desc, OFX::GroupParamDescript } OFX::ChoiceParamDescriptor* choiceParam = desc.defineChoiceParam(name); - choiceParam->setDefault(option.getDefaultInt()); + + // Translate the libav option default value to a value compliant with OpenFX + int ofxDefaultValue = 0; + const int libavDefaultValue = option.getDefaultInt(); + if(libavDefaultValue >= 0 && libavDefaultValue < option.getChilds().size()) + ofxDefaultValue = libavDefaultValue; + else if(option.getMin() > std::numeric_limits::min()) + { + const int computedDefaultValue = libavDefaultValue - option.getMin(); + if(computedDefaultValue < option.getChilds().size()) + ofxDefaultValue = computedDefaultValue; + } + choiceParam->setDefault(ofxDefaultValue); + BOOST_FOREACH(const avtranscoder::Option& child, option.getChilds()) { choiceParam->appendOption(child.getName() + " " + child.getHelp()); From 52c460e80a9b10f6aef8c019c578320779b78b4b Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 29 Aug 2016 16:46:09 +0200 Subject: [PATCH 4/7] AudioVideo writer: refactored how to set the default video codec No need to create a local variable here. --- .../image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp b/plugins/image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp index be889c8c0..3c8439102 100644 --- a/plugins/image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp +++ b/plugins/image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp @@ -226,13 +226,12 @@ void AVWriterPluginFactory::describeInContext(OFX::ImageEffectDescriptor& desc, customWidth->setParent(videoCustomGroupParam); int default_codec = 0; - std::string defaultVideoCodec("mpeg4"); OFX::ChoiceParamDescriptor* videoCodec = desc.defineChoiceParam(kParamVideoCodec); avtranscoder::NamesMap videoCodecsNames(avtranscoder::getAvailableVideoCodecsNames()); for(avtranscoder::NamesMap::const_iterator itName = videoCodecsNames.begin(); itName != videoCodecsNames.end(); ++itName) { videoCodec->appendOption(itName->first + " " + itName->second); - if(itName->first == defaultVideoCodec) + if(itName->first == "mpeg4") default_codec = videoCodec->getNOptions() - 1; } videoCodec->setLabel(kParamVideoCodecLabel); From ecf7b81b2d0d435f31559f50097c10f31daa0be6 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 29 Aug 2016 17:48:14 +0200 Subject: [PATCH 5/7] AudioVideo: fixed warning message in some host about OFX Choice parameters * When an OFX Choice parameter has no child options. * Solution: manually adding an child option called "unknown". --- plugins/image/io/AudioVideo/src/common/LibAVParams.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp index 36478468e..c9f95bda3 100644 --- a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp +++ b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp @@ -513,10 +513,17 @@ void addOptionsToGroup(OFX::ImageEffectDescriptor& desc, OFX::GroupParamDescript } choiceParam->setDefault(ofxDefaultValue); + // Added child options BOOST_FOREACH(const avtranscoder::Option& child, option.getChilds()) { choiceParam->appendOption(child.getName() + " " + child.getHelp()); } + + // Fixed warning message in some host (ie. Nuke), about OFX Choice parameters without child options + if(option.getChilds().empty()) + { + choiceParam->appendOption("unknown"); + } param = choiceParam; break; } From 25c06ca964392d5022f90787c603c9b52d019f2c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 29 Aug 2016 17:49:27 +0200 Subject: [PATCH 6/7] AudioVideo: hide the OFX Choice parameters which have only one option Not useful in the interface. --- plugins/image/io/AudioVideo/src/common/LibAVParams.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp index c9f95bda3..3d383ea12 100644 --- a/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp +++ b/plugins/image/io/AudioVideo/src/common/LibAVParams.cpp @@ -524,6 +524,11 @@ void addOptionsToGroup(OFX::ImageEffectDescriptor& desc, OFX::GroupParamDescript { choiceParam->appendOption("unknown"); } + + // Hide the OFX Choice parameter if it has only one option (not useful in the interface) + if(choiceParam->getNOptions() < 2) + choiceParam->setIsSecret(true); + param = choiceParam; break; } From 4eec6d286a9e99836478a752fa0b67895c747d22 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 29 Aug 2016 17:50:01 +0200 Subject: [PATCH 7/7] AudioVideo: up to v4.9 --- plugins/image/io/AudioVideo/src/mainEntry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/image/io/AudioVideo/src/mainEntry.cpp b/plugins/image/io/AudioVideo/src/mainEntry.cpp index 0c315d7b9..2369e2729 100644 --- a/plugins/image/io/AudioVideo/src/mainEntry.cpp +++ b/plugins/image/io/AudioVideo/src/mainEntry.cpp @@ -1,5 +1,5 @@ #define OFXPLUGIN_VERSION_MAJOR 4 -#define OFXPLUGIN_VERSION_MINOR 8 +#define OFXPLUGIN_VERSION_MINOR 9 #include #include "reader/AVReaderPluginFactory.hpp"