Beispiel #1
0
Datei: hello.c Projekt: rayl/MLT
mlt_producer create_tracks( int argc, char **argv )
{
	// Create the field
	mlt_field field = mlt_field_init( );

	// Obtain the multitrack
	mlt_multitrack multitrack = mlt_field_multitrack( field );

	// Obtain the tractor
	mlt_tractor tractor = mlt_field_tractor( field );

	// Obtain a composite transition
	mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" );

	// Create track 0
	mlt_producer track0 = create_playlist( argc, argv );

	// Get the length of track0
	mlt_position length = mlt_producer_get_playtime( track0 );

	// Create the watermark track
	mlt_producer track1 = mlt_factory_producer( NULL, "pango:" );

	// Get the properties of track1
	mlt_properties properties = mlt_producer_properties( track1 );

	// Set the properties
	mlt_properties_set( properties, "text", "Hello\nWorld" );
	mlt_properties_set_position( properties, "in", 0 );
	mlt_properties_set_position( properties, "out", length - 1 );
	mlt_properties_set_position( properties, "length", length );

	// Now set the properties on the transition
	properties = mlt_transition_properties( transition );
	mlt_properties_set_position( properties, "in", 0 );
	mlt_properties_set_position( properties, "out", length - 1 );

	// Add our tracks to the multitrack
	mlt_multitrack_connect( multitrack, track0, 0 );
	mlt_multitrack_connect( multitrack, track1, 1 );

	// Now plant the transition
	mlt_field_plant_transition( field, transition, 0, 1 );

	// Now set the properties on the transition
	properties = mlt_tractor_properties( tractor );

	// Ensure clean up and set properties correctly
	mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
	mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
	mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL );
	mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL );
	mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
	mlt_properties_set_position( properties, "length", length );
	mlt_properties_set_position( properties, "out", length - 1 );

	// Return the tractor
	return mlt_tractor_producer( tractor );
}
Beispiel #2
0
void transport( mlt_producer producer )
{
	mlt_properties properties = mlt_producer_properties( producer );

	term_init( );
	fprintf( stderr, "Press 'q' to continue\n" );
	while( mlt_properties_get_int( properties, "done" ) == 0 )
	{
		int value = term_read( );
		if ( value != -1 )
			transport_action( producer, ( char * )&value );
	}
}
Beispiel #3
0
void transport_action( mlt_producer producer, char *value )
{
	mlt_properties properties = mlt_producer_properties( producer );

	switch( value[ 0 ] )
	{
		case 'q':
			mlt_properties_set_int( properties, "done", 1 );
			break;
		case '0':
			mlt_producer_set_speed( producer, 1 );
			mlt_producer_seek( producer, 0 );
			break;
		case '1':
			mlt_producer_set_speed( producer, -5 );
			break;
		case '2':
			mlt_producer_set_speed( producer, -2.5 );
			break;
		case '3':
			mlt_producer_set_speed( producer, -1 );
			break;
		case '4':
			mlt_producer_set_speed( producer, -0.5 );
			break;
		case '5':
			mlt_producer_set_speed( producer, 0 );
			break;
		case '6':
			mlt_producer_set_speed( producer, 0.5 );
			break;
		case '7':
			mlt_producer_set_speed( producer, 1 );
			break;
		case '8':
			mlt_producer_set_speed( producer, 2.5 );
			break;
		case '9':
			mlt_producer_set_speed( producer, 5 );
			break;
	}
}
Beispiel #4
0
void VideoScript::pre_judge() throw (Exception)
{
    const ScriptParam* inparam = get_param_info("in");
    const ScriptParam* outparam = get_param_info("out");
    const ScriptParam* resparam = get_param_info("resource");

    if ( !inparam || inparam->param_style != ScriptParams::PosParam ||
            !outparam || outparam->param_style != ScriptParams::PosParam) {
        throw_error_v(ErrorScriptArgInvalid, "in/out position param is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    if ( !resparam || resparam->param_style != ScriptParams::ScalarParam ) {
        throw_error_v(ErrorScriptArgInvalid, "resource scalar param is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    json_t* res_arg = get_arg_value("resource");
    json_t* in = get_arg_value("in");
    json_t* out = get_arg_value("out");

    if (!res_arg || !json_is_string(res_arg) || !strlen(json_string_value(res_arg))) {
        throw_error_v(ErrorScriptArgInvalid, "resource arg is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    if ( !in || !json_is_integer(in) ) {
        throw_error_v(ErrorScriptArgInvalid, "in arg is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    if ( !out || !json_is_integer(out) ) {
        throw_error_v(ErrorScriptArgInvalid, "out arg is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    string path(json_string_value(res_arg));

    mlt_profile profile = mlt_profile_clone(MltLoader::global_profile);
    mlt_producer prod = mlt_factory_producer(profile, "loader", path.c_str());

    if  ( prod == NULL ) {
        throw_error_v(ErrorScriptArgInvalid, "out arg is required for %s script",
                      Vm::proc_type_names[VIDEO_RESOURCE_SCRIPT]);
    }

    uuid = Vm::uuid();
    MltLoader::push_mlt_registry(mlt_producer_service(prod), uuid.c_str());

    //mlt_producer prod = Vm::get_stream_resource(path);
    int length = mlt_producer_get_length(prod);
    int inframe = json_integer_value(in), outframe = json_integer_value(out);

    json_decref(in);
    json_decref(out);

    switch (inparam->pos_type) {
    case ScriptParams::FramePos:
        if ( inframe == -1  || inframe >= length) {
            inframe = length - 1;
        }
        else if ( inframe < 0 ) {
            inframe = length + inframe;
            if (inframe < 0)inframe = 0;
        }
        break;
    case ScriptParams::TimePos: {
        int total_time = length * 40;
        if ( inframe == -1 ) {
            inframe = length - 1;
        }
        else if ( inframe >= 0  ) {
            if ( inframe > total_time) {
                inframe = length -1;
            }
            else {
                inframe = (double)inframe / 40 ;
            }
        }
        else {
            inframe = total_time + inframe;
            if ( inframe < 0 ) {
                inframe = length - 1;
            }
            else {
                inframe = (double)inframe/40;
            }
        }
    }
    break;
    }


    switch (outparam->pos_type) {
    case ScriptParams::FramePos:
        if ( outframe == -1  || outframe >= length) {
            outframe = length - 1;
        }
        else if ( outframe < 0 ) {
            outframe = length + outframe;
            if (outframe < 0)outframe = 0;
        }
        break;
    case ScriptParams::TimePos: {
        int total_time = length * 40;
        if ( outframe == -1 ) {
            outframe = length - 1;
        }
        else if ( outframe >= 0  ) {
            if ( outframe > total_time) {
                outframe = length -1;
            }
            else {
                outframe = (double)outframe / 40 ;
            }
        }
        else {
            outframe = total_time + outframe;
            if ( outframe < 0 ) {
                outframe = length - 1;
            }
            else {
                outframe = (double)outframe/40;
            }
        }
    }
    break;
    }

    if ( inframe > outframe ) {
        inframe ^= outframe ^= inframe ^= outframe;
    }

    set_frame_range(inframe,outframe);

    if ( !type_spec_props.get() ) {
        type_spec_props.reset(new ScriptProps(*this, NULL));
    }

    type_spec_props->add_property("resource", res_arg);
    json_decref(res_arg);

    type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h);
    if ( !mlt_props.get()) {
        mlt_props.reset(new ScriptProps(*this, NULL));
    }
    json_t* jv = json_integer(inframe);
    mlt_props->add_property("in", jv);
    json_decref(jv);

    jv = json_integer(outframe);
    mlt_props->add_property("out", jv);
    json_decref(jv);

    //mlt_producer_set_in_and_out(prod, inframe, outframe);
#ifdef DEBUG
    std::cout << mlt_producer_properties(prod);
#endif

    this->path  = path;
    //todo: check format info
    return;
}
Beispiel #5
0
void AsisScript::pre_judge() throw (Exception)
{
    ScriptProps::Property& service_prop = type_spec_props->get_property("service");
    if (!service_prop.Evaluable::finished())
        throw_error_v(ErrorScriptFmtError,"asis producer script service should be determinated");

    ScriptProps::Property& resource_prop = type_spec_props->get_property("resource");
    if (!resource_prop.Evaluable::finished())
        throw_error_v(ErrorScriptFmtError,"asis producer script resource should be determinated");

    json_t* svc_value = service_prop.compile();
    json_t* res_value = resource_prop.compile();
    JsonWrap svc_wrap(svc_value,1);
    JsonWrap res_wrap(res_value,1);

    if ( !svc_value || !json_is_string(svc_value) || !strlen(json_string_value(svc_value)))
        throw_error_v(ErrorScriptFmtError,"asis producer script service should be string value");
    if ( !res_value || !json_is_string(res_value) || !strlen(json_string_value(res_value)))
        throw_error_v(ErrorScriptFmtError,"asis producer script resource should be string value");

    mlt_profile prof = mlt_profile_clone(MltLoader::global_profile);
    mlt_producer tmp_prod = mlt_factory_producer(prof, json_string_value(svc_value), json_string_value(res_value));
    MltSvcWrap prod_wrap(mlt_producer_service(tmp_prod), 1);

    if (tmp_prod == NULL) {
        throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed", json_string_value(svc_value));
    }

    if ( mlt_props ) {
        ScriptProps::PropIter it = mlt_props->begin();
        for ( ; it!=mlt_props->end(); it++) {
            if ( it->second->Evaluable::finished() ) {
                json_t* prop_v = it->second->compile();
                JsonWrap prop_wrap(prop_v, 1);

                switch(prop_v->type) {
                case JSON_INTEGER:
                    mlt_properties_set_int64(mlt_producer_properties(tmp_prod),
                                             it->first.c_str(), json_integer_value(prop_v));
                    break;
                case JSON_REAL:
                    mlt_properties_set_double(mlt_producer_properties(tmp_prod),
                                              it->first.c_str(), json_real_value(prop_v));
                    break;
                case JSON_STRING:
                    mlt_properties_set(mlt_producer_properties(tmp_prod),
                                       it->first.c_str(), json_string_value(prop_v));
                    break;
                case JSON_TRUE:
                    mlt_properties_set_int(mlt_producer_properties(tmp_prod),
                                           it->first.c_str(), 1);
                    break;
                case JSON_FALSE:
                    mlt_properties_set_int(mlt_producer_properties(tmp_prod),
                                           it->first.c_str(), 0);
                    break;
                default:
                    throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed. %s prop invalid",
                                  json_string_value(svc_value), it->first.c_str());
                }
            }
        }
    }

    int in = mlt_producer_get_in(tmp_prod);
    int out = mlt_producer_get_out(tmp_prod);
    set_frame_range(in, out);

    if ( !mlt_props.get()) {
        mlt_props.reset(new ScriptProps(*this, NULL));
    }
    json_t* jv = json_integer(in);
    mlt_props->add_property("in", jv);
    json_decref(jv);

    jv = json_integer(out);
    mlt_props->add_property("out", jv);
    json_decref(jv);

    string uuid = Vm::uuid();
    type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h);
    prod_wrap.obj = NULL;
    MltLoader::push_mlt_registry(mlt_producer_service(tmp_prod), uuid.c_str());
}
Beispiel #6
0
mlt_service SingleResourceLoader::get_asis_producer(JsonWrap js)
throw (Exception)
{
    json_t* defines = js.h;

    defines_tmp=js;

    json_t* je = json_object_get(defines, "resource");
    json_t* uuid_je = json_object_get(defines, "uuid");
    json_t* svc_je = json_object_get(defines, "service");

    assert( je && json_is_string(je) && strlen(json_string_value(je)));
    assert( svc_je && json_is_string(svc_je) && strlen(json_string_value(svc_je)));
    assert( uuid_je && json_is_string(uuid_je) && strlen(json_string_value(uuid_je)));

    mlt_producer obj = MLT_PRODUCER(MltLoader::pop_mlt_registry(json_string_value(uuid_je)));
    if (obj == NULL) {
        mlt_profile profile = mlt_profile_clone(global_profile);
        obj = mlt_factory_producer(profile, json_string_value(svc_je), json_string_value(je));
#ifdef DEBUG
        std::cout << mlt_producer_properties(obj);
#endif
    }

    if ( !obj ) {
        throw_error_v(ErrorRuntimeLoadFailed, "video producer load failed:%s", json_string_value(je));
    }

    mlt_properties props = mlt_producer_properties(obj);

    je = json_object_get(defines, "props");
    if (je && json_is_object(je) && json_object_size(je)) {

        json_t* inj = json_object_get(je,"in"), *outj = json_object_get(je,"out");
        assert(inj && outj && json_is_integer(inj) && json_is_integer(outj));

        mlt_producer_set_in_and_out(obj,json_integer_value(inj), json_integer_value(outj));

        void* it = json_object_iter(je);
        while(it) {
            const char* k = json_object_iter_key(it);
            json_t* prop_je = json_object_iter_value(it);
            it = json_object_iter_next(je, it);

            if ( json_is_object(prop_je) || json_is_array(prop_je))
                continue;

            if ( !strcmp(k,"in") || !strcmp(k,"out"))
                continue;

            switch(prop_je->type) {
            case JSON_INTEGER:
                mlt_properties_set_int64(props, k, json_integer_value(prop_je));
                break;
            case JSON_REAL:
                mlt_properties_set_double(props, k, json_real_value(prop_je));
                break;
            case JSON_STRING:
                mlt_properties_set(props, k, json_string_value(prop_je));
                break;
            case JSON_TRUE:
                mlt_properties_set_int(props,k, 1);
                break;
            case JSON_FALSE:
                mlt_properties_set_int(props,k, 0);
                break;
            default:
                break;
            }
        }
    }

    MltSvcWrap wrap(mlt_producer_service(obj), 1);
    producer_tmp  = obj;

    parse_filters();


    wrap.obj = NULL;
    return mlt_producer_service(obj);
}
Beispiel #7
0
Datei: pango.c Projekt: Enlik/mlt
int main( int argc, char **argv )
{
	char temp[ 132 ];
	char *file1 = NULL;
	char *text = NULL;

	mlt_factory_init( "../modules" );

	if ( argc < 3 )
	{
		fprintf( stderr, "usage: pango file.mpeg  text_to_display\n" );
		return 1;
	}
	else
	{
		file1 = argv[ 1 ];
		text = argv[ 2 ];
	}

	// Start the consumer...
	mlt_consumer consumer = mlt_factory_consumer( "bluefish", "NTSC" );

	// Create the producer(s)
	mlt_playlist pl1 = mlt_playlist_init();
	mlt_producer dv1 = mlt_factory_producer( "mcmpeg", file1 );
	mlt_playlist_append( pl1, dv1 );

	mlt_playlist pl2 = mlt_playlist_init();
	mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
	mlt_playlist_append( pl2, title );
	mlt_properties_set( mlt_producer_properties( title ), "family", "Sans" );
	mlt_properties_set( mlt_producer_properties( title ), "size", "36" );
	mlt_properties_set( mlt_producer_properties( title ), "weight", "700" );
	mlt_properties_set( mlt_producer_properties( title ), "text", text );
	mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f );
	mlt_properties_set_int( mlt_producer_properties( title ), "pad", 8 );
	mlt_properties_set_int( mlt_producer_properties( title ), "align", 1 );
	mlt_properties_set_int( mlt_producer_properties( title ), "x", 200 );
	mlt_properties_set_int( mlt_producer_properties( title ), "y", 40 );
	mlt_properties_set_double( mlt_producer_properties( title ), "mix", 0.8 );

	// Register producers(s) with a multitrack object
	mlt_multitrack multitrack = mlt_multitrack_init( );
	mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl1 ), 0 );
	mlt_multitrack_connect( multitrack, mlt_playlist_producer( pl2 ), 1 );

	// Define a transition
	mlt_transition transition = mlt_factory_transition( "composite", NULL );
	mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 );
	mlt_transition_set_in_and_out( transition, 0.0, 9999.0 );

	// Buy a tractor and connect it to the filter
	mlt_tractor tractor = mlt_tractor_init( );
	mlt_tractor_connect( tractor, mlt_transition_service( transition ) );

	// Connect the tractor to the consumer
	mlt_consumer_connect( consumer, mlt_tractor_service( tractor ) );

	// Do stuff until we're told otherwise...
	fprintf( stderr, "Press return to continue\n" );
	fgets( temp, 132, stdin );

	// Close everything...
	mlt_consumer_close( consumer );
	mlt_tractor_close( tractor );
	mlt_transition_close( transition );
	mlt_multitrack_close( multitrack );
	mlt_playlist_close( pl1 );
	mlt_playlist_close( pl2 );
	mlt_producer_close( dv1 );
	mlt_producer_close( title );

	return 0;
}