+ const AVOption *opt = NULL;
+
+ // For each AVOption on the AVClass object
+#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(12<<8)+0)
+ while ( ( opt = av_opt_next( object, opt ) ) )
+#else
+ while ( ( opt = av_next_option( object, opt ) ) )
+#endif
+ {
+ // If matches flags and not a binary option (not supported by Mlt)
+ if ( !( opt->flags & req_flags ) || ( opt->type == FF_OPT_TYPE_BINARY ) )
+ continue;
+
+ // Ignore constants (keyword values)
+ if ( !unit && opt->type == FF_OPT_TYPE_CONST )
+ continue;
+ // When processing a groups of options (unit)...
+ // ...ignore non-constants
+ else if ( unit && opt->type != FF_OPT_TYPE_CONST )
+ continue;
+ // ...ignore constants not in this group
+ else if ( unit && opt->type == FF_OPT_TYPE_CONST && strcmp( unit, opt->unit ) )
+ continue;
+ // ..add constants to the 'values' sequence
+ else if ( unit && opt->type == FF_OPT_TYPE_CONST )
+ {
+ char key[20];
+ snprintf( key, 20, "%d", mlt_properties_count( params ) );
+ mlt_properties_set( params, key, opt->name );
+ continue;
+ }
+
+ // Create a map for this option.
+ mlt_properties p = mlt_properties_new();
+ char key[20];
+ snprintf( key, 20, "%d", mlt_properties_count( params ) );
+ // Add the map to the 'parameters' sequence.
+ mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
+
+ // Add the parameter metadata for this AVOption.
+ mlt_properties_set( p, "identifier", opt->name );
+ if ( opt->help )
+ {
+ if ( subclass )
+ {
+ char *s = malloc( strlen( opt->help ) + strlen( subclass ) + 4 );
+ strcpy( s, opt->help );
+ strcat( s, " (" );
+ strcat( s, subclass );
+ strcat( s, ")" );
+ mlt_properties_set( p, "description", s );
+ free( s );
+ }
+ else
+ mlt_properties_set( p, "description", opt->help );
+ }
+
+ switch ( opt->type )
+ {
+ case FF_OPT_TYPE_FLAGS:
+ mlt_properties_set( p, "type", "string" );
+ mlt_properties_set( p, "format", "flags" );
+ break;
+ case FF_OPT_TYPE_INT:
+ if ( !opt->unit )
+ {
+ mlt_properties_set( p, "type", "integer" );
+ if ( opt->min != INT_MIN )
+ mlt_properties_set_int( p, "minimum", (int) opt->min );
+ if ( opt->max != INT_MAX )
+ mlt_properties_set_int( p, "maximum", (int) opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+ mlt_properties_set_int( p, "default", (int) opt->default_val.dbl );
+#endif
+ }
+ else
+ {
+ mlt_properties_set( p, "type", "string" );
+ mlt_properties_set( p, "format", "integer or keyword" );
+ }
+ break;
+ case FF_OPT_TYPE_INT64:
+ mlt_properties_set( p, "type", "integer" );
+ mlt_properties_set( p, "format", "64-bit" );
+ if ( opt->min != INT64_MIN )
+ mlt_properties_set_int64( p, "minimum", (int64_t) opt->min );
+ if ( opt->max != INT64_MAX )
+ mlt_properties_set_int64( p, "maximum", (int64_t) opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+ mlt_properties_set_int64( p, "default", (int64_t) opt->default_val.dbl );
+#endif
+ break;
+ case FF_OPT_TYPE_FLOAT:
+ mlt_properties_set( p, "type", "float" );
+ if ( opt->min != FLT_MIN && opt->min != -340282346638528859811704183484516925440.0 )
+ mlt_properties_set_double( p, "minimum", opt->min );
+ if ( opt->max != FLT_MAX )
+ mlt_properties_set_double( p, "maximum", opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+ mlt_properties_set_double( p, "default", opt->default_val.dbl );
+#endif
+ break;
+ case FF_OPT_TYPE_DOUBLE:
+ mlt_properties_set( p, "type", "float" );
+ mlt_properties_set( p, "format", "double" );
+ if ( opt->min != DBL_MIN )
+ mlt_properties_set_double( p, "minimum", opt->min );
+ if ( opt->max != DBL_MAX )
+ mlt_properties_set_double( p, "maximum", opt->max );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+ mlt_properties_set_double( p, "default", opt->default_val.dbl );
+#endif
+ break;
+ case FF_OPT_TYPE_STRING:
+ mlt_properties_set( p, "type", "string" );
+#if LIBAVUTIL_VERSION_MAJOR > 50
+ mlt_properties_set( p, "default", opt->default_val.str );
+#endif
+ break;
+ case FF_OPT_TYPE_RATIONAL:
+ mlt_properties_set( p, "type", "string" );
+ mlt_properties_set( p, "format", "numerator:denominator" );
+ break;
+ case FF_OPT_TYPE_CONST:
+ default:
+ mlt_properties_set( p, "type", "integer" );
+ mlt_properties_set( p, "format", "constant" );
+ break;
+ }
+ // If the option belongs to a group (unit) and is not a constant (keyword value)
+ if ( opt->unit && opt->type != FF_OPT_TYPE_CONST )
+ {
+ // Create a 'values' sequence.
+ mlt_properties values = mlt_properties_new();
+
+ // Recurse to add constants in this group to the 'values' sequence.
+ add_parameters( values, object, req_flags, opt->unit, NULL );
+ if ( mlt_properties_count( values ) )
+ mlt_properties_set_data( p, "values", values, 0, (mlt_destructor) mlt_properties_close, NULL );
+ else
+ mlt_properties_close( values );
+ }
+ }