Skip to content

Commit 5dbb538

Browse files
committed
Merge pull request #484 from cchampet/dev_AudioVideoAvTranscoder0.5.10
AudioVideo: up to v4.4
2 parents f00df3f + be1553c commit 5dbb538

File tree

8 files changed

+64
-29
lines changed

8 files changed

+64
-29
lines changed
Submodule avTranscoder updated 78 files

plugins/image/io/AudioVideo/src/common/util.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ avtranscoder::ProfileLoader::Profile LibAVParams::getCorrespondingProfile( const
190190
if( libavOption.getDefaultInt() == paramInt->getValue() && libavOption.getName() != kOptionThreads )
191191
continue;
192192

193+
// FFmpeg threads option has a default value of 1.
194+
// Our threads parameter has a default value of 0.
195+
// If 0, do not use it to set the decoding/encoding profile:
196+
// avTranscoder will automatically set the number of threads according to the codec.
197+
if( libavOption.getName() == kOptionThreads && paramInt->getValue() == kOptionThreadsValue )
198+
continue;
199+
193200
libavOptionValue = boost::to_string( paramInt->getValue() );
194201
optionsNameAndValue.insert( std::make_pair( libavOptionName, libavOptionValue ) );
195202
continue;
@@ -462,7 +469,7 @@ void addOptionsToGroup( OFX::ImageEffectDescriptor& desc, OFX::GroupParamDescrip
462469
name == kPrefixAudio + kOptionThreads )
463470
{
464471
OFX::IntParamDescriptor* intParam = desc.defineIntParam( name );
465-
intParam->setDefault( 0 ); // autodetect a suitable number of threads to use
472+
intParam->setDefault( kOptionThreadsValue );
466473
intParam->setRange( 0, std::numeric_limits<int>::max() );
467474
intParam->setDisplayRange( 0, 64 );
468475
param = intParam;

plugins/image/io/AudioVideo/src/common/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const std::string kPrefixGroup = "g_";
2929
static const std::string kPrefixFlag = "_flag_";
3030

3131
static const std::string kOptionThreads = "threads";
32+
static const size_t kOptionThreadsValue = 0; ///< Autodetect a suitable number of threads to use
3233

3334
/**
3435
* @brief Use this class to get libav Options about format, video, and audio.

plugins/image/io/AudioVideo/src/mainEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define OFXPLUGIN_VERSION_MAJOR 4
2-
#define OFXPLUGIN_VERSION_MINOR 3
2+
#define OFXPLUGIN_VERSION_MINOR 4
33

44
#include <tuttle/plugin/Plugin.hpp>
55
#include "reader/AVReaderPluginFactory.hpp"

plugins/image/io/AudioVideo/src/reader/AVReaderPlugin.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ AVReaderPlugin::AVReaderPlugin( OfxImageEffectHandle handle )
2828
, _paramFormatDetailCustom( common::kPrefixFormat, AV_OPT_FLAG_DECODING_PARAM, true )
2929
, _paramVideoDetailCustom( common::kPrefixVideo, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM, true )
3030
, _inputFile( NULL )
31-
, _inputStreamVideo( NULL )
31+
, _inputStream( NULL )
32+
, _inputDecoder( NULL )
3233
, _sourceImage( NULL )
3334
, _imageToDecode( NULL )
3435
, _lastInputFilePath( "" )
3536
, _lastVideoStreamIndex( 0 )
3637
, _lastFrame( -1 )
3738
, _initVideo( false )
39+
, _isSetUp( false )
3840
{
3941
_clipDst = fetchClip( kOfxImageEffectOutputClipName );
4042

@@ -79,12 +81,14 @@ void AVReaderPlugin::ensureVideoIsOpen()
7981
{
8082
const std::string& filepath = _paramFilepath->getValue();
8183
const size_t videoStreamIndex = _paramVideoStreamIndex->getValue();
82-
83-
if( _lastInputFilePath == filepath && // already opened
84-
! _lastInputFilePath.empty() && // not the first time...
85-
_lastVideoStreamIndex == videoStreamIndex )
84+
85+
// if the given file is already opened
86+
if( _lastInputFilePath == filepath &&
87+
! _lastInputFilePath.empty() &&
88+
_lastVideoStreamIndex == videoStreamIndex )
8689
return;
87-
90+
91+
// if the given file does not exist
8892
if( filepath == "" || ! boost::filesystem::exists( filepath ) )
8993
{
9094
cleanInputFile();
@@ -97,21 +101,24 @@ void AVReaderPlugin::ensureVideoIsOpen()
97101
// set and analyse inputFile
98102
_inputFile.reset( new avtranscoder::InputFile( filepath ) );
99103
_lastInputFilePath = filepath;
104+
105+
// launch deep analyse to get info of first gop
100106
avtranscoder::NoDisplayProgress progress;
101107
_inputFile->analyse( progress, avtranscoder::eAnalyseLevelFirstGop );
102108

103-
// get streamId of the video stream
109+
// get index of the video stream
104110
if( videoStreamIndex >= _inputFile->getProperties().getVideoProperties().size() )
105111
{
106112
throw std::runtime_error( "the stream index doesn't exist in the input file" );
107113
}
108114
_lastVideoStreamIndex = videoStreamIndex;
109115

110-
// buffered video stream at _indexVideoStream
111-
_inputFile->activateStream( _paramVideoStreamIndex->getValue() );
116+
// buffered the selected video stream
117+
_inputStream = &_inputFile->getStream( _inputFile->getProperties().getVideoProperties().at(videoStreamIndex).getStreamIndex() );
118+
_inputStream->activate();
112119

113-
// set video stream
114-
_inputStreamVideo.reset( new avtranscoder::VideoDecoder( _inputFile->getStream( _paramVideoStreamIndex->getValue() ) ) );
120+
// set video decoder
121+
_inputDecoder.reset( new avtranscoder::VideoDecoder( *_inputStream ) );
115122
}
116123
catch( std::exception& e )
117124
{
@@ -126,7 +133,7 @@ void AVReaderPlugin::ensureVideoIsOpen()
126133
void AVReaderPlugin::cleanInputFile()
127134
{
128135
_inputFile.reset();
129-
_inputStreamVideo.reset();
136+
_inputDecoder.reset();
130137
_sourceImage.reset();
131138
_imageToDecode.reset();
132139
_lastInputFilePath = "";
@@ -291,7 +298,7 @@ void AVReaderPlugin::changedParam( const OFX::InstanceChangedArgs& args, const s
291298

292299
// update unknown of Metadata tab
293300
std::string unknownValue( "" );
294-
BOOST_FOREACH( const avtranscoder::UnknownProperties& unknownStream, params._inputProperties->getUnknownPropertiesProperties() )
301+
BOOST_FOREACH( const avtranscoder::UnknownProperties& unknownStream, params._inputProperties->getUnknownProperties() )
295302
{
296303
unknownValue += "::::: UNKNOWN STREAM ::::: \n";
297304
BOOST_FOREACH( const PropertyPair& pair, unknownStream.getPropertiesAsVector() )
@@ -477,6 +484,11 @@ void AVReaderPlugin::beginSequenceRender( const OFX::BeginSequenceRenderArgument
477484
{
478485
ReaderPlugin::beginSequenceRender( args );
479486

487+
// To be sure to execute the following code only once
488+
// Optimization in some hosts when rendering several frames (nuke...)
489+
if( _isSetUp )
490+
return;
491+
480492
ensureVideoIsOpen();
481493

482494
AVReaderParams params = getProcessParams();
@@ -486,34 +498,38 @@ void AVReaderPlugin::beginSequenceRender( const OFX::BeginSequenceRenderArgument
486498
formatProfile[ avtranscoder::constants::avProfileIdentificator ] = "customFormatPreset";
487499
formatProfile[ avtranscoder::constants::avProfileIdentificatorHuman ] = "Custom format preset";
488500
formatProfile[ avtranscoder::constants::avProfileType ] = avtranscoder::constants::avProfileTypeFormat;
501+
formatProfile[ avtranscoder::constants::avProfileFormat ] = params._inputFormatName;
489502
// format options
490503
const avtranscoder::ProfileLoader::Profile formatCommonProfile = _paramFormatCustom.getCorrespondingProfile();
491504
formatProfile.insert( formatCommonProfile.begin(), formatCommonProfile.end() );
492505
// format detail options
493506
const avtranscoder::ProfileLoader::Profile formatDetailProfile = _paramFormatDetailCustom.getCorrespondingProfile( params._inputFormatName );
494507
formatProfile.insert( formatDetailProfile.begin(), formatDetailProfile.end() );
495-
_inputFile->setProfile( formatProfile );
508+
_inputFile->setupUnwrapping( formatProfile );
496509

497510
// set video decoder
498511
avtranscoder::ProfileLoader::Profile videoProfile;
499512
videoProfile[ avtranscoder::constants::avProfileIdentificator ] = "customVideoPreset";
500513
videoProfile[ avtranscoder::constants::avProfileIdentificatorHuman ] = "Custom video preset";
501514
videoProfile[ avtranscoder::constants::avProfileType ] = avtranscoder::constants::avProfileTypeVideo;
515+
videoProfile[ avtranscoder::constants::avProfileCodec ] = params._inputVideoProperties->getCodecName();
502516
// video options
503517
const avtranscoder::ProfileLoader::Profile videoCommonProfile = _paramVideoCustom.getCorrespondingProfile();
504518
videoProfile.insert( videoCommonProfile.begin(), videoCommonProfile.end() );
505519
// video detail options
506520
const avtranscoder::ProfileLoader::Profile videoDetailProfile = _paramVideoDetailCustom.getCorrespondingProfile( params._inputVideoProperties->getCodecName() );
507521
videoProfile.insert( videoDetailProfile.begin(), videoDetailProfile.end() );
508-
_inputStreamVideo->setupDecoder( videoProfile );
522+
_inputDecoder->setupDecoder( videoProfile );
509523

510524
// get source image
511-
const avtranscoder::VideoFrameDesc sourceImageDesc( _inputFile->getStream( _paramVideoStreamIndex->getValue() ).getVideoCodec().getVideoFrameDesc() );
525+
const avtranscoder::VideoFrameDesc sourceImageDesc( _inputStream->getVideoCodec().getVideoFrameDesc() );
512526
_sourceImage.reset( new avtranscoder::VideoFrame( sourceImageDesc ) );
513527

514528
// get image to decode
515529
const avtranscoder::VideoFrameDesc imageToDecodeDesc( sourceImageDesc.getWidth(), sourceImageDesc.getHeight(), "rgb24" );
516530
_imageToDecode.reset( new avtranscoder::VideoFrame( imageToDecodeDesc ) );
531+
532+
_isSetUp = true;
517533
}
518534

519535
void AVReaderPlugin::render( const OFX::RenderArguments& args )

plugins/image/io/AudioVideo/src/reader/AVReaderPlugin.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ class AVReaderPlugin : public ReaderPlugin
3838
AVReaderPlugin( OfxImageEffectHandle handle );
3939

4040
public:
41+
/**
42+
* @brief Open and analyse the InputFile.
43+
* Create a Stream and its corresponding Decoder for the first video stream of the given file.
44+
* @note Do nothing if the InputFile and the videoStream are already set
45+
*/
4146
void ensureVideoIsOpen();
47+
48+
/**
49+
* @brief Clear all attributes related to unwrapping / decoding.
50+
*/
4251
void cleanInputFile();
4352

4453
AVReaderParams getProcessParams() const;
@@ -66,7 +75,7 @@ class AVReaderPlugin : public ReaderPlugin
6675
// do not need to delete these, the ImageEffect is managing them for us
6776
OFX::Clip* _clipDst; ///< Destination image clip
6877

69-
OFX::IntParam* _paramVideoStreamIndex; ///< video stream index
78+
OFX::IntParam* _paramVideoStreamIndex; ///< human readable video stream index (from 0 to x)
7079
OFX::BooleanParam* _paramUseCustomSAR; ///< Keep sample aspect ratio
7180
OFX::DoubleParam* _paramCustomSAR; ///< Custom SAR to use
7281

@@ -88,9 +97,10 @@ class AVReaderPlugin : public ReaderPlugin
8897
OFX::BooleanParam* _paramVerbose;
8998

9099
boost::scoped_ptr<avtranscoder::InputFile> _inputFile;
91-
boost::scoped_ptr<avtranscoder::VideoDecoder> _inputStreamVideo;
100+
boost::scoped_ptr<avtranscoder::VideoDecoder> _inputDecoder;
92101
boost::scoped_ptr<avtranscoder::VideoFrame> _sourceImage;
93102
boost::scoped_ptr<avtranscoder::VideoFrame> _imageToDecode;
103+
avtranscoder::InputStream* _inputStream; ///< Has link (InputFile has ownership)
94104

95105
avtranscoder::VideoTransform _colorTransform;
96106

@@ -99,7 +109,8 @@ class AVReaderPlugin : public ReaderPlugin
99109

100110
int _lastFrame;
101111

102-
bool _initVideo;
112+
bool _initVideo; ///< Is the video init
113+
bool _isSetUp; ///< Is the unwrapping and decoding setup
103114
};
104115

105116
}

plugins/image/io/AudioVideo/src/reader/AVReaderProcess.tcc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ void AVReaderProcess<View>::setup( const OFX::RenderArguments& args )
2626
if( ( _plugin._lastFrame + 1 ) != args.time )
2727
{
2828
_plugin._inputFile->seekAtFrame( args.time );
29-
_plugin._inputStreamVideo->flushDecoder();
29+
_plugin._inputDecoder->flushDecoder();
3030
}
3131

3232
_plugin._lastFrame = args.time;
3333

3434
// Fetch output image
35-
if( ! _plugin._inputStreamVideo->decodeNextFrame( *_plugin._sourceImage ) )
35+
if( ! _plugin._inputDecoder->decodeNextFrame( *_plugin._sourceImage ) )
3636
{
3737
BOOST_THROW_EXCEPTION( exception::Failed()
3838
<< exception::user() + "Can't open the frame at time " + args.time
@@ -113,10 +113,10 @@ View& AVReaderProcess<View>::readImage( View& dst, avtranscoder::VideoFrame& ima
113113
{
114114
typedef typename FileView::value_type Pixel;
115115

116-
size_t width = image.desc().getWidth();
117-
size_t height = image.desc().getHeight();
118-
avtranscoder::PixelProperties pixel = _plugin._inputFile->getProperties().getVideoProperties().at( _plugin._paramVideoStreamIndex->getValue() ).getPixelProperties();
119-
size_t rowSizeInBytes = pixel.getNbComponents() * width;
116+
const size_t width = image.desc().getWidth();
117+
const size_t height = image.desc().getHeight();
118+
const avtranscoder::PixelProperties pixel = _plugin._inputFile->getProperties().getVideoProperties().at( _plugin._paramVideoStreamIndex->getValue() ).getPixelProperties();
119+
const size_t rowSizeInBytes = pixel.getNbComponents() * width;
120120

121121
FileView avSrcView = interleaved_view(
122122
width, height,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ void AVWriterPlugin::render( const OFX::RenderArguments& args )
10191019
cleanProfile( profile, common::kPrefixFormat );
10201020

10211021
// set format profile (need to be done after beginWrap when muxing)
1022-
_outputFile->setProfile( profile );
1022+
_outputFile->setupWrapping( profile );
10231023

10241024
// manage codec lantancy
10251025
_transcoder->preProcessCodecLatency();

0 commit comments

Comments
 (0)