Skip to content

Commit 170fc00

Browse files
author
Clement Champetier
committed
AudioVideo writer: fix plugin instanciation
* AvTranscoder returns an array of pair<name, long name> for format and codecs (instead of two arrays which can have a different size). * Update Vatranscoder submodule (up to v0.5.4).
1 parent fe41702 commit 170fc00

File tree

4 files changed

+104
-86
lines changed

4 files changed

+104
-86
lines changed
Submodule avTranscoder updated 71 files

plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.cpp

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ AVWriterPlugin::AVWriterPlugin( OfxImageEffectHandle handle )
129129

130130
avtranscoder::OptionArrayMap optionsFormatDetailMap = avtranscoder::getOutputFormatOptions();
131131
_paramFormatDetailCustom.fetchLibAVParams( *this, optionsFormatDetailMap, common::kPrefixFormat );
132-
const std::string formatName = avtranscoder::getFormatsShortNames().at( _paramFormat->getValue() );
132+
const std::string formatName = avtranscoder::getFormatsNames().at( _paramFormat->getValue() ).first;
133133
common::disableOFXParamsForFormatOrCodec( *this, optionsFormatDetailMap, formatName, common::kPrefixFormat );
134134

135135
avtranscoder::OptionArrayMap optionsVideoCodecMap = avtranscoder::getVideoCodecOptions();
136136
_paramVideoDetailCustom.fetchLibAVParams( *this, optionsVideoCodecMap, common::kPrefixVideo );
137-
const std::string videoCodecName = avtranscoder::getVideoCodecsShortNames().at( _paramVideoCodec->getValue() );
137+
const std::string videoCodecName = avtranscoder::getVideoCodecsNames().at( _paramVideoCodec->getValue() ).first;
138138
common::disableOFXParamsForFormatOrCodec( *this, optionsVideoCodecMap, videoCodecName, common::kPrefixVideo );
139139

140140
avtranscoder::OptionArrayMap optionsAudioCodecMap = avtranscoder::getAudioCodecOptions();
141141
_paramAudioDetailCustom.fetchLibAVParams( *this, optionsAudioCodecMap, common::kPrefixAudio );
142-
const std::string audioCodecName = avtranscoder::getAudioCodecsShortNames().at( _paramAudioCodec->getValue() );
142+
const std::string audioCodecName = avtranscoder::getAudioCodecsNames().at( _paramAudioCodec->getValue() ).first;
143143
common::disableOFXParamsForFormatOrCodec( *this, optionsAudioCodecMap, audioCodecName, common::kPrefixAudio );
144144

145145
updatePixelFormats( videoCodecName );
@@ -386,15 +386,12 @@ void AVWriterPlugin::changedParam( const OFX::InstanceChangedArgs& args, const s
386386
// filename
387387
if( paramName == kTuttlePluginFilename )
388388
{
389-
const std::string& extension = avtranscoder::getFormat( _paramFilepath->getValue() );
390-
391-
std::vector<std::string> formats( avtranscoder::getFormatsShortNames() );
392-
std::vector<std::string>::iterator itFormat = std::find( formats.begin(), formats.end(), extension );
393-
if( itFormat != formats.end() )
389+
const std::string extension = avtranscoder::getFormat( _paramFilepath->getValue() );
390+
if( ! extension.empty() )
394391
{
395-
size_t indexFormat = std::distance( formats.begin(), itFormat );
396-
_paramFormat->setValue( indexFormat );
392+
setFormatParam( extension );
397393
}
394+
398395
cleanVideoAndAudio();
399396
}
400397
// format
@@ -571,13 +568,7 @@ void AVWriterPlugin::initOutput()
571568
std::string formatFromFile = avtranscoder::getFormat( path.filename().string() );
572569
if( ! formatFromFile.empty() )
573570
{
574-
std::vector<std::string> formats( avtranscoder::getFormatsShortNames() );
575-
std::vector<std::string>::iterator iterFormat = std::find( formats.begin(), formats.end(), formatFromFile );
576-
size_t formatIndex = std::distance( formats.begin(), iterFormat);
577-
if( formatIndex != formats.size() )
578-
{
579-
_paramFormat->setValue( formatIndex );
580-
}
571+
setFormatParam( formatFromFile );
581572
}
582573

583574
// update format
@@ -898,13 +889,7 @@ void AVWriterPlugin::updateFormatFromExistingProfile()
898889
avtranscoder::ProfileLoader::Profile existingProfile = _presetLoader.getFormatProfiles().at( presetIndex - 1 );
899890

900891
// format
901-
std::vector<std::string> formats = avtranscoder::getFormatsShortNames();
902-
std::vector<std::string>::iterator iterFormat = std::find( formats.begin(), formats.end(), existingProfile[ avtranscoder::constants::avProfileFormat ] );
903-
size_t fomatIndex = std::distance( formats.begin(), iterFormat );
904-
if( fomatIndex < formats.size() )
905-
{
906-
_paramFormat->setValue( fomatIndex );
907-
}
892+
setFormatParam( existingProfile[ avtranscoder::constants::avProfileFormat ] );
908893

909894
// other options
910895
BOOST_FOREACH( avtranscoder::ProfileLoader::Profile::value_type& option, existingProfile )
@@ -930,18 +915,12 @@ void AVWriterPlugin::updateVideoFromExistingProfile()
930915
avtranscoder::ProfileLoader::Profile existingProfile = _presetLoader.getVideoProfiles().at( presetIndex - 1 );
931916

932917
// video codec
933-
std::vector<std::string> codecs = avtranscoder::getVideoCodecsShortNames();
934-
std::vector<std::string>::iterator iterCodec = std::find( codecs.begin(), codecs.end(), existingProfile[ avtranscoder::constants::avProfileCodec ] );
935-
size_t codecIndex = std::distance( codecs.begin(), iterCodec);
936-
if( codecIndex < codecs.size() )
937-
{
938-
_paramVideoCodec->setValue( codecIndex );
939-
}
918+
setVideoCodecParam( existingProfile[ avtranscoder::constants::avProfileCodec ] );
940919

941920
// pixel format
942921
if( existingProfile.find( avtranscoder::constants::avProfilePixelFormat ) != existingProfile.end() )
943922
{
944-
std::vector<std::string> pixelFormats( avtranscoder::getPixelFormats( *iterCodec ) );
923+
std::vector<std::string> pixelFormats( avtranscoder::getPixelFormats( existingProfile[ avtranscoder::constants::avProfileCodec ] ) );
945924
std::vector<std::string>::iterator iterPixelFormat = std::find( pixelFormats.begin(), pixelFormats.end(), existingProfile[ avtranscoder::constants::avProfilePixelFormat ] );
946925
size_t pixelFomatIndex = std::distance( pixelFormats.begin(), iterPixelFormat);
947926
if( pixelFomatIndex < pixelFormats.size() )
@@ -989,18 +968,12 @@ void AVWriterPlugin::updateAudioFromExistingProfile()
989968
avtranscoder::ProfileLoader::Profile existingProfile = _presetLoader.getAudioProfiles().at( presetIndex - 2 );
990969

991970
// audio codec
992-
std::vector<std::string> codecs = avtranscoder::getAudioCodecsShortNames();
993-
std::vector<std::string>::iterator iterCodec = std::find( codecs.begin(), codecs.end(), existingProfile[ avtranscoder::constants::avProfileCodec ] );
994-
size_t codecIndex = std::distance( codecs.begin(), iterCodec);
995-
if( codecIndex < codecs.size() )
996-
{
997-
_paramAudioCodec->setValue( codecIndex );
998-
}
971+
setAudioCodecParam( existingProfile[ avtranscoder::constants::avProfileCodec ] );
999972

1000973
// sample format
1001974
if( existingProfile.find( avtranscoder::constants::avProfileSampleFormat ) != existingProfile.end() )
1002975
{
1003-
std::vector<std::string> sampleFormats( avtranscoder::getSampleFormats( *iterCodec ) );
976+
std::vector<std::string> sampleFormats( avtranscoder::getSampleFormats( existingProfile[ avtranscoder::constants::avProfileCodec ] ) );
1004977
std::vector<std::string>::iterator iterSampleFormat = std::find( sampleFormats.begin(), sampleFormats.end(), existingProfile[ avtranscoder::constants::avProfileSampleFormat ] );
1005978
size_t sampleFomatIndex = std::distance( sampleFormats.begin(), iterSampleFormat);
1006979
if( sampleFomatIndex < sampleFormats.size() )
@@ -1084,42 +1057,42 @@ void AVWriterPlugin::endSequenceRender( const OFX::EndSequenceRenderArguments& a
10841057
_outputFile->endWrap();
10851058
}
10861059

1087-
std::string AVWriterPlugin::getFormatName( const int format ) const
1060+
std::string AVWriterPlugin::getFormatName( const size_t formatIndex ) const
10881061
{
10891062
try
10901063
{
1091-
return avtranscoder::getFormatsShortNames().at( format );
1064+
return avtranscoder::getFormatsNames().at( formatIndex ).first;
10921065
}
10931066
catch( std::exception& e )
10941067
{
10951068
BOOST_THROW_EXCEPTION( exception::Failed()
1096-
<< exception::user() + "unable to get format " + format + " - " + e.what() );
1069+
<< exception::user() + "unable to get format " + formatIndex + " - " + e.what() );
10971070
}
10981071
}
10991072

1100-
std::string AVWriterPlugin::getVideoCodecName( const int codec ) const
1073+
std::string AVWriterPlugin::getVideoCodecName( const size_t codecIndex ) const
11011074
{
11021075
try
11031076
{
1104-
return avtranscoder::getVideoCodecsShortNames().at( codec );
1077+
return avtranscoder::getVideoCodecsNames().at( codecIndex ).first;
11051078
}
11061079
catch( std::exception& e )
11071080
{
11081081
BOOST_THROW_EXCEPTION( exception::Failed()
1109-
<< exception::user() + "unable to get video codec " + codec + " - " + e.what() );
1082+
<< exception::user() + "unable to get video codec " + codecIndex + " - " + e.what() );
11101083
}
11111084
}
11121085

1113-
std::string AVWriterPlugin::getAudioCodecName( const int codec ) const
1086+
std::string AVWriterPlugin::getAudioCodecName( const size_t codecIndex ) const
11141087
{
11151088
try
11161089
{
1117-
return avtranscoder::getAudioCodecsShortNames().at( codec );
1090+
return avtranscoder::getAudioCodecsNames().at( codecIndex ).first;
11181091
}
11191092
catch( std::exception& e )
11201093
{
11211094
BOOST_THROW_EXCEPTION( exception::Failed()
1122-
<< exception::user() + "unable to get audio codec " + codec + " - " + e.what() );
1095+
<< exception::user() + "unable to get audio codec " + codecIndex + " - " + e.what() );
11231096
}
11241097
}
11251098

@@ -1175,6 +1148,57 @@ std::string AVWriterPlugin::getSampleFormatName( const std::string& audioCodecNa
11751148
}
11761149
}
11771150

1151+
void AVWriterPlugin::setFormatParam( const std::string& formatShortName )
1152+
{
1153+
avtranscoder::NamesArray formats( avtranscoder::getFormatsNames() );
1154+
for( avtranscoder::NamesArray::iterator itFormat = formats.begin();
1155+
itFormat != formats.end();
1156+
++itFormat )
1157+
{
1158+
if( itFormat->first == formatShortName )
1159+
{
1160+
const size_t indexFormat = std::distance( formats.begin(), itFormat );
1161+
if( indexFormat < formats.size() )
1162+
_paramFormat->setValue( indexFormat );
1163+
break;
1164+
}
1165+
}
1166+
}
1167+
1168+
void AVWriterPlugin::setVideoCodecParam( const std::string& videoCodecShortName )
1169+
{
1170+
avtranscoder::NamesArray codecs( avtranscoder::getVideoCodecsNames() );
1171+
for( avtranscoder::NamesArray::iterator itCodec = codecs.begin();
1172+
itCodec != codecs.end();
1173+
++itCodec )
1174+
{
1175+
if( itCodec->first == videoCodecShortName )
1176+
{
1177+
const size_t indexCodec = std::distance( codecs.begin(), itCodec );
1178+
if( indexCodec < codecs.size() )
1179+
_paramVideoCodec->setValue( indexCodec );
1180+
break;
1181+
}
1182+
}
1183+
}
1184+
1185+
void AVWriterPlugin::setAudioCodecParam( const std::string& audioCodecShortName )
1186+
{
1187+
avtranscoder::NamesArray codecs( avtranscoder::getAudioCodecsNames() );
1188+
for( avtranscoder::NamesArray::iterator itCodec = codecs.begin();
1189+
itCodec != codecs.end();
1190+
++itCodec )
1191+
{
1192+
if( itCodec->first == audioCodecShortName )
1193+
{
1194+
const size_t indexCodec = std::distance( codecs.begin(), itCodec );
1195+
if( indexCodec < codecs.size() )
1196+
_paramAudioCodec->setValue( indexCodec );
1197+
break;
1198+
}
1199+
}
1200+
}
1201+
11781202
}
11791203
}
11801204
}

plugins/image/io/AudioVideo/src/writer/AVWriterPlugin.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class AVWriterPlugin : public WriterPlugin
4747
public:
4848
AVWriterPlugin( OfxImageEffectHandle handle );
4949

50-
private:
51-
void updateVisibleTools();
52-
5350
public:
5451
AVProcessParams getProcessParams();
5552

@@ -96,15 +93,24 @@ class AVWriterPlugin : public WriterPlugin
9693
void render( const OFX::RenderArguments& args );
9794
void endSequenceRender( const OFX::EndSequenceRenderArguments& args );
9895

96+
private:
97+
void updateVisibleTools();
98+
9999
//@{
100100
/** Getters which throw exception if format or codec are not found. */
101-
std::string getFormatName( const int format ) const;
102-
std::string getVideoCodecName( const int codec ) const;
103-
std::string getAudioCodecName( const int codec ) const;
101+
std::string getFormatName( const size_t formatIndex ) const;
102+
std::string getVideoCodecName( const size_t codecIndex ) const;
103+
std::string getAudioCodecName( const size_t codecIndex ) const;
104104
std::string getPixelFormatName( const std::string& videoCodecName ) const;
105105
std::string getSampleFormatName( const std::string& audioCodecName ) const;
106106
//@}
107107

108+
//@{
109+
void setFormatParam( const std::string& formatShortName );
110+
void setVideoCodecParam( const std::string& videoCodecShortName );
111+
void setAudioCodecParam( const std::string& audioCodecShortName );
112+
//@}
113+
108114
public:
109115
// format
110116
OFX::GroupParam* _paramFormatCustomGroup;

plugins/image/io/AudioVideo/src/writer/AVWriterPluginFactory.cpp

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,13 @@ void AVWriterPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
156156
/// FORMAT PARAMETERS
157157
int default_format = 0;
158158
OFX::ChoiceParamDescriptor* format = desc.defineChoiceParam( kParamFormat );
159-
std::vector<std::string> formatsShortNames( avtranscoder::getFormatsShortNames() );
160-
std::vector<std::string> formatsLongNames( avtranscoder::getFormatsLongNames() );
161-
for( std::vector<std::string>::const_iterator itShort = formatsShortNames.begin(),
162-
itLong = formatsLongNames.begin(),
163-
itEnd = formatsShortNames.end();
164-
itShort != itEnd;
165-
++itShort,
166-
++itLong )
159+
avtranscoder::NamesArray formatsNames( avtranscoder::getFormatsNames() );
160+
for( avtranscoder::NamesArray::const_iterator itName = formatsNames.begin();
161+
itName != formatsNames.end();
162+
++itName )
167163
{
168-
format->appendOption( *itShort + ": " + *itLong );
169-
if( (*itShort) == "mp4" )
164+
format->appendOption( itName->first + " " + itName->second );
165+
if( itName->first == "mp4" )
170166
default_format = format->getNOptions() - 1;
171167
}
172168
format->setLabel( kParamFormatLabel );
@@ -239,17 +235,13 @@ void AVWriterPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
239235
int default_codec = 0;
240236
std::string defaultVideoCodec( "mpeg4" );
241237
OFX::ChoiceParamDescriptor* videoCodec = desc.defineChoiceParam( kParamVideoCodec );
242-
std::vector<std::string> videoCodecsShortNames( avtranscoder::getVideoCodecsShortNames() );
243-
std::vector<std::string> videoCodecsLongNames( avtranscoder::getVideoCodecsLongNames() );
244-
for( std::vector<std::string>::const_iterator itShort = videoCodecsShortNames.begin(),
245-
itLong = videoCodecsLongNames.begin(),
246-
itEnd = videoCodecsShortNames.end();
247-
itShort != itEnd;
248-
++itShort,
249-
++itLong )
238+
avtranscoder::NamesArray videoCodecsNames( avtranscoder::getVideoCodecsNames() );
239+
for( avtranscoder::NamesArray::const_iterator itName = videoCodecsNames.begin();
240+
itName != videoCodecsNames.end();
241+
++itName )
250242
{
251-
videoCodec->appendOption( *itShort + ": " + *itLong );
252-
if( (*itShort) == defaultVideoCodec )
243+
videoCodec->appendOption( itName->first + " " + itName->second );
244+
if( itName->first == defaultVideoCodec )
253245
default_codec = videoCodec->getNOptions() - 1;
254246
}
255247
videoCodec->setLabel( kParamVideoCodecLabel );
@@ -307,17 +299,13 @@ void AVWriterPluginFactory::describeInContext( OFX::ImageEffectDescriptor& desc,
307299
int default_audio_codec = 0;
308300
std::string defaultAudioCodec( "pcm_s16le" );
309301
OFX::ChoiceParamDescriptor* audioCodecParam = desc.defineChoiceParam( kParamAudioCodec );
310-
std::vector<std::string> audioCodecsShortNames( avtranscoder::getAudioCodecsShortNames() );
311-
std::vector<std::string> audioCodecsLongNames( avtranscoder::getAudioCodecsLongNames() );
312-
for( std::vector<std::string>::const_iterator itShort = audioCodecsShortNames.begin(),
313-
itLong = audioCodecsLongNames.begin(),
314-
itEnd = audioCodecsShortNames.end();
315-
itShort != itEnd;
316-
++itShort,
317-
++itLong )
302+
avtranscoder::NamesArray audioCodecsNames( avtranscoder::getAudioCodecsNames() );
303+
for( avtranscoder::NamesArray::const_iterator itName = audioCodecsNames.begin();
304+
itName != audioCodecsNames.end();
305+
++itName )
318306
{
319-
audioCodecParam->appendOption( *itShort + ": " + *itLong );
320-
if( (*itShort) == defaultAudioCodec )
307+
audioCodecParam->appendOption( itName->first + " " + itName->second );
308+
if( itName->first == defaultAudioCodec )
321309
default_audio_codec = audioCodecParam->getNOptions() - 1;
322310
}
323311
audioCodecParam->setLabel( kParamAudioCodecLabel );

0 commit comments

Comments
 (0)