Beispiel #1
0
void printProperties( const tth::ofx::property::OfxhSet properties, std::string context="" )
{
	if( context.size() == 0 )
	{
		TUTTLE_COUT( _color._red << "Number of properties : " << properties.getSize() << _color._std );
	}
	else
	{
		TUTTLE_COUT( _color._red << "Number of properties for \"" << context << "\": " << properties.getSize() << _color._std );
	}

	TUTTLE_COUT( _color._red << "RW" << _color._std << " " << _color._red << "ModifiedBy" << _color._std << "\t" << _color._red << "Type" << _color._std << "\t" << _color._red << "Size" << _color._std << "\t" << _color._red <<std::setw (50)  << std::left << "Property Name" << _color._std << "\t" << _color._red << "Default Values" << _color._std );
	tth::ofx::property::PropertyMap propMap = properties.getMap();
	for( tth::ofx::property::PropertyMap::const_iterator itProperty = propMap.begin(); itProperty != propMap.end(); ++itProperty )
	{
		const tth::ofx::property::OfxhProperty& prop = *( itProperty->second );
		TUTTLE_COUT(
			_color._green <<
			( prop.getPluginReadOnly() ? (_color._green + "r-" + _color._std + " ") : (_color._green + "rw" + _color._std + " " ) ) <<
			( prop.getModifiedBy() == tth::ofx::property::eModifiedByHost ? ( _color._green + "host" + _color._std + "  \t" ) : ( _color._green + "plugin" + _color._std + "\t" ) ) <<
			_color._green << ( tth::ofx::property::mapTypeEnumToString( prop.getType() ) ) << _color._std << "\t" << _color._green << "[" <<
			prop.getDimension() << "]" << _color._std << "\t" <<
			_color._blue <<
			std::setw (50)  << std::left <<
			itProperty->first << _color._std << "\t" << _color._green << "{ " <<
			getDefaultValues(prop) << " }" << _color._std
		);
	}
}
Beispiel #2
0
void WriterPlugin::render( const OFX::RenderArguments& args )
{
	_oneRender = false;

	TUTTLE_COUT( "        --> " << getAbsoluteFilenameAt( args.time ) );

	boost::scoped_ptr<OFX::Image> src( _clipSrc->fetchImage( args.time ) );
	boost::scoped_ptr<OFX::Image> dst( _clipDst->fetchImage( args.time ) );
	
	// Copy buffer
	const OfxRectI bounds = dst->getBounds();
	TUTTLE_TCOUT_VAR( bounds );
	if( src->isLinearBuffer() && dst->isLinearBuffer() )
	{
		TUTTLE_TCOUT( "isLinearBuffer" );
		const std::size_t imageDataBytes = dst->getBoundsImageDataBytes();
		TUTTLE_TCOUT_VAR( imageDataBytes );
		if( imageDataBytes )
		{
			void* dataSrcPtr = src->getPixelAddress( bounds.x1, bounds.y1 );
			void* dataDstPtr = dst->getPixelAddress( bounds.x1, bounds.y1 );
			memcpy( dataDstPtr, dataSrcPtr, imageDataBytes );
		}
	}
	else
	{
		const std::size_t rowBytesToCopy = dst->getBoundsRowDataBytes();
		for( int y = bounds.y1; y < bounds.y2; ++y )
		{
			void* dataSrcPtr = src->getPixelAddress( bounds.x1, y );
			void* dataDstPtr = dst->getPixelAddress( bounds.x1, y );
			memcpy( dataDstPtr, dataSrcPtr, rowBytesToCopy );
		}
	}
}
ConvolutionProcessParams ConvolutionPlugin::getProcessParams() const
{
	ConvolutionProcessParams params;

	OfxPointI size = _paramSize->getValue();

	params._size.x = boost::numeric_cast<unsigned int>( size.x );
	params._size.y = boost::numeric_cast<unsigned int>( size.y );

	params._convMatrix.resize( params._size.x, params._size.y );
	for( unsigned int y = 0; y < params._size.y; ++y )
	{
//		unsigned int yy = y * params._size.x;
		for( unsigned int x = 0; x < params._size.x; ++x )
		{
			params._convMatrix(x, y) = _paramCoef[y][x]->getValue();
			TUTTLE_COUT( "coef[" << y << "][" << x << "] = " << params._convMatrix(x, y) );
		}
	}
	return params;
}
void OfxhPluginCache::scanDirectory( std::set<std::string>& foundBinFiles, const std::string& dir, bool recurse )
{
	#ifdef CACHE_DEBUG
	TUTTLE_TCOUT( "looking in " << dir << " for plugins" );
	#endif

	#if defined ( WINDOWS )
	WIN32_FIND_DATA findData;
	HANDLE findHandle;
	#else
	DIR* d = opendir( dir.c_str() );
	if( !d )
	{
		return;
	}
	#endif

	_pluginDirs.push_back( dir.c_str() );

	#if defined ( UNIX )
	while( dirent * de = readdir( d ) )
	#elif defined ( WINDOWS )
	findHandle = FindFirstFile( ( dir + "\\*" ).c_str(), &findData );

	if( findHandle == INVALID_HANDLE_VALUE )
	{
		return;
	}

	while( 1 )
	#endif
	{
		#if defined ( UNIX )
		std::string name = de->d_name;
		bool isdir       = true;
		#else
		std::string name = findData.cFileName;
		bool isdir       = ( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0;
		#endif
		if( name.find( ".ofx.bundle" ) != std::string::npos )
		{
			std::string barename   = name.substr( 0, name.length() - strlen( ".bundle" ) );
			std::string bundlepath = dir + DIRSEP + name;
			std::string binpath    = bundlepath + DIRSEP "Contents" DIRSEP + ARCHSTR + DIRSEP + barename;

			foundBinFiles.insert( binpath );

			if( _knownBinFiles.find( binpath ) == _knownBinFiles.end() )
			{
				#ifdef CACHE_DEBUG
				TUTTLE_TCOUT( "found non-cached binary " << binpath );
				#endif
				setDirty();
				try
				{
					// the binary was not in the cache
					OfxhPluginBinary* pb = new OfxhPluginBinary( binpath, bundlepath, this );
					_binaries.push_back( pb );
					_knownBinFiles.insert( binpath );

					for( int j = 0; j < pb->getNPlugins(); ++j )
					{
						OfxhPlugin& plug                   = pb->getPlugin( j );
						APICache::OfxhPluginAPICacheI& api = plug.getApiHandler();
						api.loadFromPlugin( plug );
					}
				}
				catch(... )
				{
					TUTTLE_COUT( tuttle::common::kColorError << "warning: can't load " << binpath << tuttle::common::kColorStd );
					TUTTLE_COUT_CURRENT_EXCEPTION;
				}
			}
			else
			{
				#ifdef CACHE_DEBUG
				TUTTLE_TCOUT( "found cached binary " << binpath );
				#endif
			}
		}
		else
		{
			if( isdir && ( recurse && name[0] != '@' && name != "." && name != ".." ) )
			{
				scanDirectory( foundBinFiles, dir + DIRSEP + name, recurse );
			}
		}
		#if defined( WINDOWS )
		int rval = FindNextFile( findHandle, &findData );

		if( rval == 0 )
		{
			break;
		}
		#endif
	}

	#if defined( UNIX )
	closedir( d );
	#else
	FindClose( findHandle );
	#endif
}
Beispiel #5
0
void foundAssociateSpecificDummyNode( std::string& inputNode, const std::string& dummyNodeName, const std::string& dummyNodeFullName, const std::string& dummyNodeShortName, const std::vector<ttl::ofx::imageEffect::OfxhImageEffectPlugin*>& nodeList, const std::vector<std::string>& nodeArgs )
{
	if( !std::strcmp( inputNode.c_str(), dummyNodeFullName.c_str() ) || !std::strcmp( inputNode.c_str(), dummyNodeName.c_str() ) || !std::strcmp( inputNode.c_str(), dummyNodeShortName.c_str() ) )
	{
		if( nodeArgs.size() == 0 )
		{
			BOOST_THROW_EXCEPTION( tuttle::exception::Value()
								   << tuttle::exception::user() + "specify and input name (file or sequence)." );
		}
		boost::filesystem::path p( nodeArgs.at( 0 ) );
		std::string inputExtension = p.extension().string();
		boost::algorithm::to_lower( inputExtension );
		if( inputExtension.size() == 0 )
		{
			BOOST_THROW_EXCEPTION( tuttle::exception::Value()
								   << tuttle::exception::user() + "invalid extension of input file/sequence." );
		}
		inputExtension = inputExtension.substr( 1 ); // remove '.' at begining
		unsigned int numberOfSupportedExtension = std::numeric_limits<unsigned int>::max();
		BOOST_FOREACH( ttl::ofx::imageEffect::OfxhImageEffectPlugin* node, nodeList )
		{
			const std::string pluginName = node->getRawIdentifier();
			if( boost::algorithm::find_first( pluginName, dummyNodeName ) )
			{
				tuttle::host::ofx::imageEffect::OfxhImageEffectPlugin* plugin = tuttle::host::Core::instance().getImageEffectPluginById( pluginName );
				plugin->loadAndDescribeActions();
				const tuttle::host::ofx::imageEffect::OfxhImageEffectPlugin::ContextSet contexts = plugin->getContexts();
				const tuttle::host::ofx::property::OfxhSet& properties = plugin->getDescriptorInContext( *contexts.begin() ).getProperties();
				if( properties.hasProperty( kTuttleOfxImageEffectPropSupportedExtensions ) )
				{
					const tuttle::host::ofx::property::OfxhProperty& prop = properties.fetchProperty( kTuttleOfxImageEffectPropSupportedExtensions );
					const std::vector<std::string> supportedExtensions = getStringValues( prop );
					BOOST_FOREACH( const std::string& ext, supportedExtensions )
					{
//						TUTTLE_TCOUT_VAR2( ext, inputExtension );
						if( ext == inputExtension )
						{
//							TUTTLE_TCOUT( pluginName << " [" << supportedExtensions.size() << "] can read " << ext );
							if( supportedExtensions.size() < numberOfSupportedExtension )
							{
								// Arbitrary solution...
								// If we found multiple plugins that support the requested format,
								// we select the plugin which supports the lowest number of formats.
								// So by defaut, we select specialized plugin before
								// plugin using generic libraries with all formats.
								numberOfSupportedExtension = supportedExtensions.size();
								inputNode = pluginName;
							}
						}
					}
				}
			}
		}
		if( numberOfSupportedExtension == std::numeric_limits<unsigned int>::max() )
		{
			BOOST_THROW_EXCEPTION( tuttle::exception::Value()
								   << tuttle::exception::user() + "Unsupported extension \"" + inputExtension + "\"." );
		}
		TUTTLE_COUT( _color._yellow << "Replace " << dummyNodeName << " with: " << inputNode << _color._std );
	}
}
Beispiel #6
0
void getPluginProperties( const std::string& plugName )
{
	tth::ofx::imageEffect::OfxhImageEffectPlugin* plug = tth::Core::instance().getImageEffectPluginById( plugName );
	
	if( !plug )
	{
		TUTTLE_COUT( _color._red << "no plugin match to: " << plugName << _color._std );
		return;
	}

	plug->loadAndDescribeActions();
	TUTTLE_COUT("Identifier:\t\t"		<< plug->getIdentifier() );
	TUTTLE_COUT("Raw identifier:\t\t"	<< plug->getRawIdentifier() );
	TUTTLE_COUT("Minor version:\t\t"	<< plug->getVersionMinor() );
	TUTTLE_COUT("Major version:\t\t" 	<< plug->getVersionMajor() );
	TUTTLE_COUT("API version:\t\t"		<< plug->getApiVersion() );

	// list contexts of plugin
	TUTTLE_COUT( _color._green << "Contexts:" << _color._std );

	tth::ofx::imageEffect::OfxhImageEffectPlugin::ContextSet contexts = plug->getContexts();
	tth::ofx::imageEffect::OfxhImageEffectPlugin::ContextSet::iterator itContext;
	std::string strContexts;
	for( itContext = contexts.begin(); itContext != contexts.end(); ++itContext )
	{
		strContexts += *itContext + ", ";
	}
	strContexts.erase(strContexts.size()-2, 2);
	TUTTLE_COUT( "[ " << strContexts << " ]" );
	itContext = contexts.begin();

	// list properties of plugin for the first context
	if( properties )
	{
		TUTTLE_COUT( std::endl << _color._red << "Properties" << _color._std );

		const tth::ofx::property::OfxhSet properties = plug->getDescriptorInContext( *itContext ).getProperties();
		printProperties( properties );
	}
	tth::ofx::imageEffect::OfxhImageEffectNode* plugInst = NULL;
	if( clips | parameters )
	{
		if( plug->supportsContext( kOfxImageEffectContextReader ) )
		{
			plugInst = plug->createInstance( kOfxImageEffectContextReader );
		}
		else if( plug->supportsContext( kOfxImageEffectContextWriter ) )
		{
			plugInst = plug->createInstance( kOfxImageEffectContextWriter );
		}
		else if( plug->supportsContext( kOfxImageEffectContextGenerator ) )
		{
			plugInst = plug->createInstance( kOfxImageEffectContextGenerator );
		}
		else if( plug->supportsContext( kOfxImageEffectContextFilter ) )
		{
			plugInst = plug->createInstance( kOfxImageEffectContextFilter );
		}
		else if( plug->supportsContext( kOfxImageEffectContextGeneral ) )
		{
			plugInst = plug->createInstance( kOfxImageEffectContextGeneral );
		}
		else
		{
			TUTTLE_CERR( _color._error << "Plugin contexts not supported by the host. (" + plugName + ")" << _color._std );
			return;
		}
	}
	if( clips )
	{
		TUTTLE_COUT( std::endl << _color._red << "Clips" << _color._std );

		typedef std::map<std::string, tth::ofx::attribute::OfxhClipImageDescriptor*> ContextMap;

		// get contexts
		ContextMap::const_iterator it = plugInst->getDescriptor( ).getClips().begin();
		std::string strClipContexts;
		for( ; it != plugInst->getDescriptor( ).getClips().end(); ++it )
		{
			strClipContexts += (*it).first + ", " ;
		}
		strClipContexts.erase( strClipContexts.size()-2, 2 );

		TUTTLE_COUT( _color._green << "[ " << strClipContexts << " ]" << _color._std );


		// get propeties in each context
		ContextMap::const_iterator it2 = plugInst->getDescriptor( ).getClips().begin();
		for( ; it2 != plugInst->getDescriptor().getClips().end(); ++it2 )
		{
			printProperties( (*it2).second->getProperties(), (*it2).first );
		}
	}
	
	if( parameters )
	{
		TUTTLE_COUT( std::endl << _color._red << "Parameters" << _color._std );

		typedef std::map<std::string, tth::ofx::attribute::OfxhParamDescriptor*> ParamDescriptorMap;

		// get contexts
		ParamDescriptorMap::const_iterator it = plugInst->getDescriptor( ).getParams().begin();
		std::string strParamsContexts;
		for( ; it != plugInst->getDescriptor( ).getParams().end(); ++it )
		{
			strParamsContexts += (*it).first + ", ";
		}
		strParamsContexts.erase( strParamsContexts.size()-2, 2 );

		TUTTLE_COUT( _color._green << "[ " << strParamsContexts << " ]" << _color._std );

		// get propeties in each context
		ParamDescriptorMap::const_iterator it2 = plugInst->getDescriptor( ).getParams().begin();
		for( ; it2 != plugInst->getDescriptor().getParams().end(); it2++ )
		{
			printProperties( (*it2).second->getProperties(), (*it2).first );
		}
		/*
		const tth::ofx::property::OfxhSet paramProperties = plugInst->getDescriptor( ).getParamList().front().getProperties();
		printProperties( paramProperties, "" );
		*/
	}
}
Beispiel #7
0
int main( int argc, char** argv )
{
	bool				verbose			= false;
	std::vector<std::string>	plugins;
	std::vector<std::string>	foundPlugins;
	std::vector<std::string>	filters;
	
	// Declare the supported options.
	bpo::options_description mainOptions;
	mainOptions.add_options()
		("help,h"     , "show this help")
		("all,a"      , "show list of all plugins available")
		("filter,f"   , bpo::value<std::string>(), "filtering the output for research a plugin. ex: -f \"*blur,*tuttle*\"")
		("color"      , "color the output")
		("verbose,v"  , "explain what is being done")
		("properties" , "list properties of the OpenFX plugin")
		("clips"      , "list clips of the OpenFX plugin")
		("parameters" , "list parameters of the OpenFX plugin")
		("brief"            , "brief summary of the tool")
	;
	
	// describe hidden options
	bpo::options_description hidden;
	hidden.add_options()
		("plugin", bpo::value< std::vector<std::string> >(), "input directories")
	;
	
	// define default options 
	bpo::positional_options_description pod;
	pod.add("plugin", -1);
	
	bpo::options_description cmdline_options;
	cmdline_options.add(mainOptions).add(hidden);

	//parse the command line, and put the result in vm
	bpo::variables_map vm;
	try
	{
		bpo::store(bpo::command_line_parser(argc, argv).options(cmdline_options).positional(pod).run(), vm);

		// get environnement options and parse them
		if( const char* env_plugins_options = std::getenv("SAM_PLUGINS_OPTIONS") )
		{
			const std::vector<std::string> vecOptions = bpo::split_unix( env_plugins_options, " " );
			bpo::store(bpo::command_line_parser(vecOptions).options(cmdline_options).positional(pod).run(), vm);
		}
		if( const char* env_options = std::getenv("SAM_OPTIONS") )
		{
			const std::vector<std::string> vecOptions = bpo::split_unix( env_options, " " );
			bpo::store(bpo::command_line_parser(vecOptions).options(cmdline_options).positional(pod).run(), vm);
		}
		bpo::notify(vm);
	}
	catch( const bpo::error& e)
	{
		TUTTLE_COUT( "sam-plugins: command line error: " << e.what() );
		exit( -2 );
	}
	catch(...)
	{
		TUTTLE_COUT( "sam-plugins: unknown error in command line.");
		exit( -2 );
	}

	if (vm.count("color"))
	{
		color = true;
		_color.enable();
	}

	if( vm.count("help") )
	{
		TUTTLE_COUT( _color._blue  << "TuttleOFX project [http://sites.google.com/site/tuttleofx]" << _color._std << std::endl );
		TUTTLE_COUT( _color._blue  << "NAME" << _color._std );
		TUTTLE_COUT( _color._green << "\tsam-plugins - show informations about OpenFX plugins" << _color._std << std::endl );
		TUTTLE_COUT( _color._blue  << "SYNOPSIS" << _color._std );
		TUTTLE_COUT( _color._green << "\tsam-plugins [options] [specific_OpenFX_plugin]" << _color._std << std::endl );
		TUTTLE_COUT( _color._blue  << "DESCRIPTION" << _color._std );
		TUTTLE_COUT( "List OpenFX in OFX_PLUGIN_PATH by default.");
		TUTTLE_COUT( "And could print properties, parameters and clips for each plugins" << std::endl );
		TUTTLE_COUT( _color._blue  << "OPTIONS" << _color._std );
		TUTTLE_COUT( mainOptions );
		return 0;
	}
	
	if ( vm.count("brief") )
	{
		TUTTLE_COUT( _color._green << "show informations about OpenFX plugins" << _color._std );
		return 0;
	}

	// defines plugins
	if( vm.count("plugin") )
	{
		plugins = vm["plugin"].as< std::vector<std::string> >();
	}
	
	if( vm.count("filter") )
	{
		bal::split( filters, vm["filter"].as<std::string>(), bal::is_any_of(","));
	}
	
	if( vm.count("all") | (plugins.size() == 0) )
	{
		tth::Core::instance().preload();
		const std::vector<tth::ofx::imageEffect::OfxhImageEffectPlugin*> plugs = tth::Core::instance().getImageEffectPluginCache().getPlugins();
		
		for( std::size_t i = 0; i < plugs.size(); ++i )
		{
			const std::string plugName = plugs.at(i)->getRawIdentifier();
			if( isNotFiltered( plugName, filters) )
			{
				TUTTLE_COUT( plugName );
			}
		}
		return 0;
	}

	if (vm.count("verbose"))
	{
		verbose = true;
	}

	if (vm.count("properties"))
	{
		properties = true;
	}

	if (vm.count("clips"))
	{
		clips = true;
	}

	if (vm.count("parameters"))
	{
		parameters = true;
	}
//	for(unsigned int i=0; i< plugins.size(); i++)
//		TUTTLE_COUT( plugins.at(i) );
	
	try
	{
		tth::Core::instance().preload();
		// get the plugins names for research partials names (rawreader need to make reference to the plug tuttle.reader)
		const std::vector<tth::ofx::imageEffect::OfxhImageEffectPlugin*> plugs = tth::Core::instance().getImageEffectPluginCache().getPlugins();

		unsigned int founded;
		BOOST_FOREACH( const std::string& plugin, plugins )
		{
			std::vector< std::string > termsPlugin;
			bal::split( termsPlugin, plugin, bal::is_any_of("."));

			for( std::size_t i=0; i<plugs.size(); i++ )
			{
				founded = 0;
				for( std::size_t t=0; t<termsPlugin.size(); t++ )
				{
					std::size_t found1 = plugs.at(i)->getRawIdentifier().find( "."+termsPlugin.at(t) );
					std::size_t found2 = plugs.at(i)->getRawIdentifier().find( termsPlugin.at(t)+"." );
					if( ( found1 == std::string::npos ) && ( found2 == std::string::npos ) )
					{
						break;
					}
					++founded;
					if( founded == termsPlugin.size() )
					{
						/*TUTTLE_COUT("plug is " << plugs.at(i)->getRawIdentifier() );*/
						foundPlugins.push_back( plugs.at(i)->getRawIdentifier() );
					}
				}
			}
		}

		TUTTLE_COUT( _color._red << "################################################################################" << _color._std );

		BOOST_FOREACH( const std::string& plugin, foundPlugins )
		{
			TUTTLE_COUT(_color._blue << "PLUGIN DESCRIPTION" << _color._std );
			getPluginProperties( plugin );
			TUTTLE_COUT( _color._red << "################################################################################" << _color._std );
		}
int VideoFFmpegWriter::execute( boost::uint8_t* in_buffer, int in_width, int in_height, PixelFormat in_pixelFormat )
{
	_error = IGNORE_FINISH;

	if( !_avformatOptions )
	{
		// TODO avformat_alloc_context2 can guess format from filename
		// if format name is NULL, find a way to expose the feature
		if (avformat_alloc_output_context2(&_avformatOptions, NULL, _formatName.c_str(), filename().c_str()) < 0)
		{
			TUTTLE_CERR( "ffmpegWriter: output context allocation failed" );
			return false;
		}
		_ofmt = _avformatOptions->oformat;
		TUTTLE_CERR( "ffmpegWriter: " << std::string(_ofmt->name) << " format selected" );
	}

	if( !_stream )
	{
		_codec = avcodec_find_encoder_by_name( _codecName.c_str() );
		if (!_codec)
		{
			TUTTLE_CERR( "ffmpegWriter: codec not found" );
			return false;
		}
		TUTTLE_CERR( "ffmpegWriter: " << std::string(_codec->name) << " codec selected" );

		_stream = avformat_new_stream( _avformatOptions, _codec );
		if( !_stream )
		{
			TUTTLE_CERR( "ffmpegWriter: out of memory." );
			return false;
		}
		avcodec_get_context_defaults3(_stream->codec, _codec);

		if( _videoPresetName.length() !=0 )
		{
			TUTTLE_COUT( "ffmpegWriter: " << _videoPresetName << " preset selected" );
			std::string presetFilename = getFilename( std::string(_codec->name), _videoPresetName );
			
			PresetsOptions opts = getOptionsForPresetFilename( presetFilename );
			PresetsOptions::iterator itOpt;
			for ( itOpt = opts.begin() ; itOpt != opts.end(); itOpt++ )
			{
				int ret = av_opt_set( (void*)_stream->codec, (*itOpt).first.c_str(), (*itOpt).second.c_str(), 0);
				switch( ret )
				{
					case AVERROR_OPTION_NOT_FOUND: TUTTLE_CERR( "ffmpegPreset: unable to find " << (*itOpt).first ); break;
					case AVERROR(EINVAL): TUTTLE_CERR( "ffmpegPreset: invalid value " << (*itOpt).second.c_str() << " for option " << (*itOpt).first ); break;
					case AVERROR(ERANGE): TUTTLE_CERR( "ffmpegPreset: invalid range for parameter " << (*itOpt).first << " : " << (*itOpt).second.c_str() ); break;
				}
			}
		}
		
		_stream->codec->bit_rate           = _bitRate;
		_stream->codec->bit_rate_tolerance = _bitRateTolerance;
		_stream->codec->width              = width();
		_stream->codec->height             = height();
		_stream->codec->time_base          = av_d2q( 1.0 / _fps, 100 );
		_stream->codec->gop_size           = _gopSize;
		_stream->codec->sample_rate        = 48000; ///< samples per second
		_stream->codec->channels           = 0;     ///< number of audio channels
		if( _bFrames )
		{
			_stream->codec->max_b_frames     = _bFrames;
			_stream->codec->b_frame_strategy = 0;
			_stream->codec->b_quant_factor   = 2.0;
		}
		_stream->codec->mb_decision = _mbDecision;

		int pixfmt_allowed = 0, k;
		if ( _codec->pix_fmts )
		{
			for ( k = 0; _codec->pix_fmts[k] != PIX_FMT_NONE; k++ )
			{
				if ( _codec->pix_fmts[k] == _out_pixelFormat )
				{
					pixfmt_allowed = 1;
					break;
				}
			}
		}
		else
		{
			// If a codec does not contain a list of supported pixel
			// formats, just assume that _out_PixelFormat is valid
			pixfmt_allowed = 1;
		}

		if ( !pixfmt_allowed )
		{
			// av_get_pix_fmt_name requires lavu 51.3.0 or higher
			TUTTLE_CERR( "ffmpegWriter: pixel format " << av_get_pix_fmt_name(_out_pixelFormat) << " not available in codec" );
			_out_pixelFormat = _codec->pix_fmts[0];
			TUTTLE_CERR( "ffmpegWriter: auto-selecting " << av_get_pix_fmt_name(_out_pixelFormat) );
		}
		_stream->codec->pix_fmt     = _out_pixelFormat;

		if( !strcmp( _avformatOptions->oformat->name, "mp4" ) || !strcmp( _avformatOptions->oformat->name, "mov" ) || !strcmp( _avformatOptions->oformat->name, "3gp" ) || !strcmp( _avformatOptions->oformat->name, "flv" ) )
			_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;

		av_dump_format( _avformatOptions, 0, filename().c_str(), 1 );

		if( avcodec_open2( _stream->codec, _codec, NULL ) < 0 )
		{
			TUTTLE_CERR( "ffmpegWriter: unable to open codec." );
			freeFormat();
			return false;
		}

		if( !( _ofmt->flags & AVFMT_NOFILE ) )
		{
			if( avio_open2( &_avformatOptions->pb, filename().c_str(),
                                        AVIO_FLAG_WRITE, NULL, NULL ) < 0 )
			{
				TUTTLE_CERR( "ffmpegWriter: unable to open file." );
				freeFormat();
				return false;
			}
		}

		avformat_write_header( _avformatOptions, NULL );
	}

	_error = CLEANUP;

	AVFrame* in_frame = avcodec_alloc_frame();
	avcodec_get_frame_defaults( in_frame );
	avpicture_fill( (AVPicture*)in_frame, in_buffer, in_pixelFormat, in_width, in_height );

	AVFrame* out_frame = avcodec_alloc_frame();
	avcodec_get_frame_defaults( out_frame );
	int out_picSize            = avpicture_get_size( _out_pixelFormat, width(), height() );
	boost::uint8_t* out_buffer = (boost::uint8_t*) av_malloc( out_picSize );
	avpicture_fill( (AVPicture*) out_frame, out_buffer, _out_pixelFormat, width(), height() );

	_sws_context = sws_getCachedContext( _sws_context, in_width, in_height, in_pixelFormat, width(), height(), _out_pixelFormat, SWS_BICUBIC, NULL, NULL, NULL );

	TUTTLE_COUT( "ffmpegWriter: input format: " << av_get_pix_fmt_name( in_pixelFormat ) );
	TUTTLE_COUT( "ffmpegWriter: output format: " << av_get_pix_fmt_name( _out_pixelFormat ) );

	if( !_sws_context )
	{
		TUTTLE_CERR( "ffmpeg-conversion failed (" << in_pixelFormat << "->" << _out_pixelFormat << ")." );
		return false;
	}
	int error = sws_scale( _sws_context, in_frame->data, in_frame->linesize, 0, height(), out_frame->data, out_frame->linesize );
	if( error < 0 )
	{
		TUTTLE_CERR( "ffmpeg-conversion failed (" << in_pixelFormat << "->" << _out_pixelFormat << ")." );
		return false;
	}

	int ret = 0;
	if( ( _avformatOptions->oformat->flags & AVFMT_RAWPICTURE ) != 0 )
	{
		AVPacket pkt;
		av_init_packet( &pkt );
		pkt.flags       |= AV_PKT_FLAG_KEY;
		pkt.stream_index = _stream->index;
		pkt.data         = (boost::uint8_t*) out_frame;
		pkt.size         = sizeof( AVPicture );
		ret              = av_interleaved_write_frame( _avformatOptions, &pkt );
	}
	else
	{
		AVPacket pkt;
		int hasFrame = 0;
		av_init_packet( &pkt );
		pkt.size = 0;
		pkt.data = NULL;
		pkt.stream_index = _stream->index;

		if( _stream->codec->coded_frame && _stream->codec->coded_frame->pts != static_cast<boost::int64_t>( AV_NOPTS_VALUE ) ) // static_cast<unsigned long> (
			pkt.pts = av_rescale_q( _stream->codec->coded_frame->pts, _stream->codec->time_base, _stream->time_base );

		if( _stream->codec->coded_frame && _stream->codec->coded_frame->key_frame )
			pkt.flags |= AV_PKT_FLAG_KEY;

		out_frame->pts = pts++;
		ret = avcodec_encode_video2( _stream->codec, &pkt, out_frame,  &hasFrame );
		if ( ret < 0 )
			return false;

		if ( hasFrame )
		{
			ret = av_interleaved_write_frame( _avformatOptions, &pkt );
			if ( ret < 0 )
			{
				TUTTLE_CERR( "ffmpegWriter: error writing packet to file" );
				return false;
			}
		}
	}

	av_free( out_buffer );
	av_free( out_frame );
	av_free( in_frame );
	// in_buffer not free (function parameter)

	if( ret )
	{
		TUTTLE_CERR( "ffmpegWriter: error writing frame to file." );
		return false;
	}

	_error = SUCCESS;
	return true;
}
Beispiel #9
0
void printImageProperties( std::string path )
{
	try
	{

		Image         *image;
		ImageInfo     *image_info;
		
		// Read a file into image object
		image_info = AcquireImageInfo();
		GetImageInfo( image_info );

		strcpy( image_info -> filename, path.c_str() );

		ExceptionInfo* exceptionsInfo = AcquireExceptionInfo();
		GetExceptionInfo( exceptionsInfo );
		
		image = ReadImage( image_info, exceptionsInfo );
		
		std::string imageType;
		switch( image->type )
		{
			case UndefinedType             : imageType = "Undefined type of image"; break;
			case BilevelType               : imageType = "Bilevel image"; break;
			case GrayscaleType             : imageType = "Grayscale image"; break;
			case GrayscaleMatteType        : imageType = "Grayscale image with opacity"; break;
			case PaletteType               : imageType = "Indexed color image"; break;
			case PaletteMatteType          : imageType = "Indexed color image with opacity"; break;
			case TrueColorType             : imageType = "Truecolor image"; break;
			case TrueColorMatteType        : imageType = "Truecolor image with opacity"; break;
			case ColorSeparationType       : imageType = "Cyan/Yellow/Magenta/Black (CYMK) image"; break;
			case ColorSeparationMatteType  : imageType = "Cyan/Yellow/Magenta/Black (CYMK) image with opacity"; break;
			case OptimizeType              : imageType = "Optimize image"; break;
			case 11                        : imageType = "Indexed bilevel image with opacity"; break; // PaletteBilevelMatteType
		}

		std::string resolutionType;
		switch( image->units )
		{
			case UndefinedResolution            : resolutionType = " [unknown units]"; break;
			case PixelsPerInchResolution        : resolutionType = " [dpi]"; break;
			case PixelsPerCentimeterResolution  : resolutionType = " [pixels/cm]"; break;
		}

		std::string colorSpaceType;
		switch( image->colorspace )
		{
			case UndefinedColorspace      : colorSpaceType = "unknown color space"; break;
			case RGBColorspace            : colorSpaceType = "RGB"; break;
			case GRAYColorspace           : colorSpaceType = "Gray"; break;
			case TransparentColorspace    : colorSpaceType = "Transparent"; break;
			case OHTAColorspace           : colorSpaceType = "OHTA"; break;
			case XYZColorspace            : colorSpaceType = "XYZ"; break;
			case YCbCrColorspace          : colorSpaceType = "Y Cb Cr"; break;
			case YCCColorspace            : colorSpaceType = "YCC"; break;
			case YIQColorspace            : colorSpaceType = "YIQ"; break;
			case YPbPrColorspace          : colorSpaceType = "Y Pb Pr"; break;
			case YUVColorspace            : colorSpaceType = "YUV"; break;
			case CMYKColorspace           : colorSpaceType = "CMYK"; break;
			case sRGBColorspace           : colorSpaceType = "sRGB"; break;
			case LabColorspace            : colorSpaceType = "Lab"; break;
			case 14                       : colorSpaceType = "HSB"; break; // HSBColorspace
			case HSLColorspace            : colorSpaceType = "HSL"; break;
			case HWBColorspace            : colorSpaceType = "HWB"; break;
			case Rec601LumaColorspace     : colorSpaceType = "Rec601 Luma"; break;
			case 18                       : colorSpaceType = "Rec601 Y Cb Cr"; break; // Rec601YCbCrColorspace
			case Rec709LumaColorspace     : colorSpaceType = "Rec709 Luma"; break;
			case 20                       : colorSpaceType = "Rec709 Y Cb Cr"; break; //  Rec709YCbCrColorspace
			case LogColorspace            : colorSpaceType = "Log"; break;
			case 22                       : colorSpaceType = "CMY"; break; // CMYColorspace
		}

		std::string interlaceType;
		switch( image->interlace )
		{
			case UndefinedInterlace    : interlaceType = "undefined"; break;
			case NoInterlace           : interlaceType = "no interlacing"; break;
			case LineInterlace         : interlaceType = "line interlacing"; break;
			case PlaneInterlace        : interlaceType = "plane interlacing"; break;
			case PartitionInterlace    : interlaceType = "partition interlacing"; break;
			case 5                     : interlaceType = "GIF interlacing"; break; // GIFInterlace
			case 6                     : interlaceType = "Jpeg interlacing"; break; // JPEGInterlace
			case 7                     : interlaceType = "PNG interlacing"; break; // PNGInterlace
		}

		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "width"                 << image->columns                                                                         );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "height"                << image->rows                                                                            );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "bit-depth"             << image->depth  << " bits"                                                               );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "compression quality"   << image->quality                                                                         );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "image type"            << imageType                                                                              );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "" );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "x resolution"          << image->x_resolution  << resolutionType                                                 );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "y resolution"          << image->y_resolution  << resolutionType                                                 );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "interlacing"           << interlaceType                                                                          );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "" );
		//TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "format"                << image->format()                                                                        );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "channels"              << colorSpaceType << ( GetImageAlphaChannel(image)==MagickTrue ? std::string("A") : "" )  );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "color space"           << colorSpaceType                                                                         );
		TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "gamma"                 << image->gamma                                                                           );

		TUTTLE_COUT( "" );
	}
	catch( ... )
	{
		TUTTLE_COUT( "Caught exception" << "\n" );
	}
	
}
Beispiel #10
0
void dumpImageProperties( const ttl::Sequence& s )
{
	TUTTLE_COUT(s);
	printImageProperties( s.getAbsoluteFirstFilename() );
	sam::wasSthgDumped = true;
}