예제 #1
0
  void PipelineStabDetect::init(Magick::Image img) {
    width = img.columns();
    height = img.rows();

    if (!vsFrameInfoInit(&fi, width, height, PF_RGB24)) {
      throw runtime_error("Failed to initialize frame info");
    }
    fi.planes = 1; // I don't understand vs frame info... But later is assert for planes == 1

    if (vsMotionDetectInit(&md, &stabConf->mdConf, &fi) != VS_OK) {
      throw runtime_error("Initialization of Motion Detection failed, please report a BUG");
    }
    vsMotionDetectGetConfig(&stabConf->mdConf, &md);

    *verboseOutput << "Video stabilization settings (pass 1/2):" << endl;
    *verboseOutput << "     shakiness = " << stabConf->mdConf.shakiness << endl;
    *verboseOutput << "      accuracy = " << stabConf->mdConf.accuracy << endl;
    *verboseOutput << "      stepsize = " << stabConf->mdConf.stepSize << endl;
    *verboseOutput << "   mincontrast = " << stabConf->mdConf.contrastThreshold << endl;
    *verboseOutput << "        tripod = " << stabConf->mdConf.virtualTripod << endl;
    *verboseOutput << "          show = " << stabConf->mdConf.show << endl;
    *verboseOutput << "        result = " << stabConf->stabStateFile->fileName() << endl;


    //f = fopen(stabStateFile->fileName().toStdString(), "w");
    f = stabConf->openStabStateFile("w");
    if (vsPrepareFile(&md, f) != VS_OK) {
      throw runtime_error(QString("cannot write to transform file %1").arg(stabConf->stabStateFile->fileName()).toStdString());
    }

    initialized = true;
  }
예제 #2
0
int main(int argc, char *argv[])
{
    VSFrameInfo fi;
    VSMotionDetect md;
    VSMotionDetectConfig conf;

    (void)argc;
    (void)argv;

    conf.algo              = 1;
    conf.modName           = "vidstabtest";
    conf.shakiness         = 5;
    conf.accuracy          = 15;
    conf.stepSize          = 6;
    conf.contrastThreshold = 0.25;
    conf.show              = 0;
    conf.virtualTripod     = 0;

    vsFrameInfoInit(&fi, 320, 240, PF_YUV420P);

    if (vsMotionDetectInit(&md, &conf, &fi) != VS_OK)
        return 1;
    
    vsMotionDetectionCleanup(&md);

    return 0;
}
예제 #3
0
static StabData* init_detect(mlt_properties properties, mlt_image_format *format, int *width, int *height)
{
	StabData *data = new StabData;
	memset(data, 0, sizeof(StabData));
	data->animation = mlt_animation_new();

	VSPixelFormat pf = convertImageFormat(*format);
	VSFrameInfo fi;
	vsFrameInfoInit(&fi, *width, *height, pf);

	const char* filterName = mlt_properties_get(properties, "mlt_service");

	VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig(filterName);
	conf.shakiness = mlt_properties_get_int(properties, "shakiness");
	conf.accuracy = mlt_properties_get_int(properties, "accuracy");
	conf.stepSize = mlt_properties_get_int(properties, "stepsize");
	conf.algo = mlt_properties_get_int(properties, "algo");
	conf.contrastThreshold = mlt_properties_get_double(properties, "mincontrast");
	conf.show = mlt_properties_get_int(properties, "show");
	conf.virtualTripod = mlt_properties_get_int(properties, "tripod");
	vsMotionDetectInit(&data->md, &conf, &fi);

	// add vectors to properties
	mlt_properties_set_data(properties, "vectors", data->animation, 1, (mlt_destructor) mlt_animation_close,
					(mlt_serialiser) vectors_serializer);
	return data;
}
예제 #4
0
  void PipelineStabTransform::init(Magick::Image img) {
    width = img.columns();
    height = img.rows();


    if (!vsFrameInfoInit(&fi, width, height, PF_RGB24)) {
      throw runtime_error("Failed to initialize frame format");
    }
    fi.planes = 1; // I don't understand vs frame info... But later is assert for planes == 1

    if (vsTransformDataInit(&td, &stabConf->tsConf, &fi, &fi) != VS_OK) {
      throw runtime_error("initialization of vid.stab transform failed, please report a BUG");
    }
    vsTransformGetConfig(&stabConf->tsConf, &td);

    *verboseOutput << "Video transformation/stabilization settings (pass 2/2):" << endl;
    *verboseOutput << "    input     = " << stabConf->stabStateFile->fileName() << endl;
    *verboseOutput << "    smoothing = " << stabConf->tsConf.smoothing << endl;
    *verboseOutput << "    optalgo   = " <<
      (stabConf->tsConf.camPathAlgo == VSOptimalL1 ? "opt" :
      (stabConf->tsConf.camPathAlgo == VSGaussian ? "gauss" : "avg")) << endl;
    *verboseOutput << "    maxshift  = " << stabConf->tsConf.maxShift << endl;
    *verboseOutput << "    maxangle  = " << stabConf->tsConf.maxAngle << endl;
    *verboseOutput << "    crop      = " << (stabConf->tsConf.crop ? "Black" : "Keep") << endl;
    *verboseOutput << "    relative  = " << (stabConf->tsConf.relative ? "True" : "False") << endl;
    *verboseOutput << "    invert    = " << (stabConf->tsConf.invert ? "True" : "False") << endl;
    *verboseOutput << "    zoom      = " << (stabConf->tsConf.zoom) << endl;
    *verboseOutput << "    optzoom   = " << (
      stabConf->tsConf.optZoom == 1 ? "Static (1)" : (stabConf->tsConf.optZoom == 2 ? "Dynamic (2)" : "Off (0)")) << endl;
    if (stabConf->tsConf.optZoom == 2)
      *verboseOutput << "    zoomspeed = " << stabConf->tsConf.zoomSpeed << endl;
    *verboseOutput << "    interpol  = " << getInterpolationTypeName(stabConf->tsConf.interpolType) << endl;

    //f = fopen(stabStateFile->fileName().toStdString(), "r");
    f = stabConf->openStabStateFile("r");
    VSManyLocalMotions mlms;
    if (vsReadLocalMotionsFile(f, &mlms) == VS_OK) {
      // calculate the actual transforms from the local motions
      if (vsLocalmotions2Transforms(&td, &mlms, &trans) != VS_OK) {
        throw runtime_error("calculating transformations failed");
      }
    } else { // try to read old format
      if (!vsReadOldTransforms(&td, f, &trans)) { /* read input file */
        throw runtime_error(QString("error parsing input file %1").arg(stabConf->stabStateFile->fileName()).toStdString());
      }
    }

    fclose(f);
    f = NULL;

    if (vsPreprocessTransforms(&td, &trans) != VS_OK) {
      throw runtime_error("error while preprocessing transforms");
    }
    initialized = true;
  }
예제 #5
0
int init_deshake(DeshakeData *data, mlt_properties properties,
		mlt_image_format *format, int *width, int *height, char* interps)
{
	VSPixelFormat pf = convertImageFormat(*format);
	VSFrameInfo fiIn, fiOut;
	vsFrameInfoInit(&fiIn, *width, *height, pf);
	vsFrameInfoInit(&fiOut, *width, *height, pf);

	VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig(FILTER_NAME);
	conf.shakiness = mlt_properties_get_int(properties, "shakiness");
	conf.accuracy = mlt_properties_get_int(properties, "accuracy");
	conf.stepSize = mlt_properties_get_int(properties, "stepsize");
	conf.algo = mlt_properties_get_int(properties, "algo");
	conf.contrastThreshold = mlt_properties_get_double(properties, "mincontrast");
	conf.show = 0;

	vsMotionDetectInit(&data->md, &conf, &fiIn);

	VSTransformConfig tdconf = vsTransformGetDefaultConfig(FILTER_NAME);
	tdconf.smoothing = mlt_properties_get_int(properties, "smoothing");
	tdconf.maxShift = mlt_properties_get_int(properties, "maxshift");
	tdconf.maxAngle = mlt_properties_get_double(properties, "maxangle");
	tdconf.crop = (VSBorderType) mlt_properties_get_int(properties, "crop");
	tdconf.zoom = mlt_properties_get_int(properties, "zoom");
	tdconf.optZoom = mlt_properties_get_int(properties, "optzoom");
	tdconf.zoomSpeed = mlt_properties_get_double(properties, "zoomspeed");
	tdconf.relative = 1;
	tdconf.invert = 0;

	// by default a bilinear interpolation is selected
	tdconf.interpolType = VS_BiLinear;
	if (strcmp(interps, "nearest") == 0 || strcmp(interps, "neighbor") == 0)
		tdconf.interpolType = VS_Zero;
	else if (strcmp(interps, "tiles") == 0 || strcmp(interps, "fast_bilinear") == 0)
		tdconf.interpolType = VS_Linear;

	vsTransformDataInit(&data->td, &tdconf, &fiIn, &fiOut);

	data->avg.initialized = 0;
	return 0;
}
예제 #6
0
static void init_analyze_data( mlt_filter filter, mlt_frame frame, VSPixelFormat vs_format, int width, int height )
{
	mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
	vs_data* data = (vs_data*)filter->child;
	vs_analyze* analyze_data = (vs_analyze*)calloc( 1, sizeof(vs_analyze) );
	memset( analyze_data, 0, sizeof(vs_analyze) );

	// Initialize a VSMotionDetectConfig
	const char* filterName = mlt_properties_get( properties, "mlt_service" );
	VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig( filterName );
	conf.shakiness = mlt_properties_get_int( properties, "shakiness" );
	conf.accuracy = mlt_properties_get_int( properties, "accuracy" );
	conf.stepSize = mlt_properties_get_int( properties, "stepsize" );
	conf.contrastThreshold = mlt_properties_get_double( properties, "mincontrast" );
	conf.show = mlt_properties_get_int( properties, "show" );
	conf.virtualTripod = mlt_properties_get_int( properties, "tripod" );

	// Initialize a VSFrameInfo
	VSFrameInfo fi;
	vsFrameInfoInit( &fi, width, height, vs_format );

	// Initialize the saved VSMotionDetect
	vsMotionDetectInit( &analyze_data->md, &conf, &fi );

	// Initialize the file to save results to
	char* filename = mlt_properties_get( properties, "filename" );
	analyze_data->results = fopen( filename, "w" );
	if ( vsPrepareFile( &analyze_data->md, analyze_data->results ) != VS_OK )
	{
		mlt_log_error( MLT_FILTER_SERVICE(filter), "Can not write to results file: %s\n", filename );
		destory_analyze_data( analyze_data );
		data->analyze_data = NULL;
	}
	else
	{
		data->analyze_data = analyze_data;
	}
}
예제 #7
0
/**
 * transform_configure:  Configure this instance of the module.  See
 * tcmodule-data.h for function details.
 */
static int transform_configure(TCModuleInstance *self,
             const char *options, vob_t *vob)
{
    FilterData *fd = NULL;
    char* filenamecopy, *filebasename;
    FILE* f;
    TC_MODULE_SELF_CHECK(self, "configure");

    fd = self->userdata;
    VSTransformData* td = &(fd->td);

    fd->vob = vob;
    if (!fd->vob)
        return TC_ERROR; /* cannot happen */

    /**** Initialise private data structure */

    VSFrameInfo fi_src;
    VSFrameInfo fi_dest;
    vsFrameInfoInit(&fi_src, fd->vob->ex_v_width, fd->vob->ex_v_height,
                  transcode2ourPF(fd->vob->im_v_codec));
    vsFrameInfoInit(&fi_dest, fd->vob->ex_v_width, fd->vob->ex_v_height,
                  transcode2ourPF(fd->vob->im_v_codec));

    VSTransformConfig conf = vsTransformGetDefaultConfig(MOD_NAME);
    conf.verbose = verbose;
    fd->sharpen  = 0.8;


    vsTransformationsInit(&fd->trans);

    filenamecopy = tc_strdup(fd->vob->video_in_file);
    filebasename = basename(filenamecopy);
    if (strlen(filebasename) < TC_BUF_LINE - 4) {
        tc_snprintf(fd->input, TC_BUF_LINE, "%s.trf", filebasename);
    } else {
        tc_log_warn(MOD_NAME, "input name too long, using default `%s'",
                    DEFAULT_TRANS_FILE_NAME);
        tc_snprintf(fd->input, TC_BUF_LINE, DEFAULT_TRANS_FILE_NAME);
    }



    /* process remaining options */
    if (options != NULL) {
        // We support also the help option.
        if(optstr_lookup(options, "help")) {
            tc_log_info(MOD_NAME,vs_transform_help);
            return(TC_IMPORT_ERROR);
        }
        optstr_get(options, "input",  "%[^:]", (char*)&fd->input);
        optstr_get(options, "maxshift",  "%d", &conf.maxShift);
        optstr_get(options, "maxangle", "%lf", &conf.maxAngle);
        optstr_get(options, "smoothing", "%d", &conf.smoothing);
        optstr_get(options, "invert"   , "%d", &conf.invert);
        optstr_get(options, "relative" , "%d", &conf.relative);
        optstr_get(options, "zoom"     ,"%lf", &conf.zoom);
        optstr_get(options, "optzoom"  , "%d", &conf.optZoom);
        optstr_get(options, "zoomspeed", "%lf",&conf.zoomSpeed);
        optstr_get(options, "interpol" , "%d", (int*)(&conf.interpolType));
        optstr_get(options, "sharpen"  ,"%lf", &fd->sharpen);
        if(optstr_lookup(options, "tripod")){
            tc_log_info(MOD_NAME,"Virtual tripod mode: relative=False, smoothing=0");
            conf.relative=0;
            conf.smoothing=0;
        }
    }

    if(vsTransformDataInit(td, &conf, &fi_src, &fi_dest) != VS_OK){
        tc_log_error(MOD_NAME, "initialization of VSTransformData failed");
        return TC_ERROR;
    }
    vsTransformGetConfig(&conf,td);

    if (verbose) {
        tc_log_info(MOD_NAME, "Image Transformation/Stabilization Settings:");
        tc_log_info(MOD_NAME, "    input     = %s", fd->input);
        tc_log_info(MOD_NAME, "    smoothing = %d", conf.smoothing);
        tc_log_info(MOD_NAME, "    maxshift  = %d", conf.maxShift);
        tc_log_info(MOD_NAME, "    maxangle  = %f", conf.maxAngle);
        tc_log_info(MOD_NAME, "    crop      = %s",
                        conf.crop ? "Black" : "Keep");
        tc_log_info(MOD_NAME, "    relative  = %s",
                    conf.relative ? "True": "False");
        tc_log_info(MOD_NAME, "    invert    = %s",
                    conf.invert ? "True" : "False");
        tc_log_info(MOD_NAME, "    zoom      = %f", conf.zoom);
        tc_log_info(MOD_NAME, "    optzoom   = %d", conf.optZoom);
        if(conf.optZoom==2){
            tc_log_info(MOD_NAME, "    zoomspeed = %f", conf.zoomSpeed);
        }
        tc_log_info(MOD_NAME, "    interpol  = %s",
                    getInterpolationTypeName(conf.interpolType));
        tc_log_info(MOD_NAME, "    sharpen   = %f", fd->sharpen);
    }

    f = fopen(fd->input, "r");
    if (f == NULL) {
        tc_log_error(MOD_NAME, "cannot open input file %s!\n", fd->input);
        /* return (-1); when called using tcmodinfo this will fail */
    } else {
        VSManyLocalMotions mlms;
        if(vsReadLocalMotionsFile(f,&mlms)==VS_OK){
            // calculate the actual transforms from the localmotions
            if(vsLocalmotions2Transforms(td, &mlms,&fd->trans)!=VS_OK)
                tc_log_error(MOD_NAME, "calculating transformations failed!\n");
        }else{ // try to read old format
            if (!vsReadOldTransforms(td, f, &fd->trans)) { /* read input file */
                tc_log_error(MOD_NAME, "error parsing input file %s!\n", fd->input);
            }
        }
    }
    fclose(f);

    if (vsPreprocessTransforms(td, &fd->trans)!= VS_OK ) {
        tc_log_error(MOD_NAME, "error while preprocessing transforms!");
        return TC_ERROR;
    }

    // sharpen is still in transcode...
    /* Is this the right point to add the filter? Seems to be the case.*/
    if(fd->sharpen>0){
        /* load unsharp filter */
        char unsharp_param[256];
        sprintf(unsharp_param,"luma=%f:%s:chroma=%f:%s",
                fd->sharpen, "luma_matrix=5x5",
                fd->sharpen/2, "chroma_matrix=5x5");
        if (!tc_filter_add("unsharp", unsharp_param)) {
            tc_log_warn(MOD_NAME, "cannot load unsharp filter!");
        }
    }

    return TC_OK;
}
예제 #8
0
static void init_apply_data( mlt_filter filter, mlt_frame frame, VSPixelFormat vs_format, int width, int height )
{
	mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
	vs_data* data = (vs_data*)filter->child;
	vs_apply* apply_data = (vs_apply*)calloc( 1, sizeof(vs_apply) );
	char* filename = mlt_properties_get( properties, "results" );
	memset( apply_data, 0, sizeof( vs_apply ) );

	mlt_log_info( MLT_FILTER_SERVICE(filter), "Load results from %s\n", filename );

	// Initialize the VSTransformConfig
	get_transform_config( &apply_data->conf, filter, frame );

	// Initialize VSTransformData
	VSFrameInfo fi_src, fi_dst;
	vsFrameInfoInit( &fi_src, width, height, vs_format );
	vsFrameInfoInit( &fi_dst, width, height, vs_format );
	vsTransformDataInit( &apply_data->td, &apply_data->conf, &fi_src, &fi_dst );

	// Initialize VSTransformations
	vsTransformationsInit( &apply_data->trans );

	// Convert file name string encoding.
	mlt_properties_from_utf8( properties, "results", "_results" );
	filename = mlt_properties_get( properties, "_results" );

	// Load the motions from the analyze step and convert them to VSTransformations
	FILE* f = fopen( filename, "r" );
	VSManyLocalMotions mlms;

	if( vsReadLocalMotionsFile( f, &mlms ) == VS_OK )
	{
		int i = 0;
		mlt_log_info( MLT_FILTER_SERVICE(filter), "Successfully loaded %d motions\n", vs_vector_size( &mlms ) );
		vsLocalmotions2Transforms( &apply_data->td, &mlms, &apply_data->trans );
		vsPreprocessTransforms( &apply_data->td, &apply_data->trans );

		// Free the MultipleLocalMotions
		for( i = 0; i < vs_vector_size( &mlms ); i++ )
		{
			LocalMotions* lms = (LocalMotions*)vs_vector_get( &mlms, i );
			if( lms )
			{
				vs_vector_del( lms );
			}
		}
		vs_vector_del( &mlms );

		data->apply_data = apply_data;
	}
	else
	{
		mlt_log_error( MLT_FILTER_SERVICE(filter), "Can not read results file: %s\n", filename );
		destory_apply_data( apply_data );
		data->apply_data = NULL;
	}

	if( f )
	{
		fclose( f );
	}
}