Beispiel #1
0
/*
 * deshake_configure:  Configure this instance of the module.  See
 * tcmodule-data.h for function details.
 */
static int deshake_configure(TCModuleInstance *self,
			     const char *options, vob_t *vob)
{
  DeshakeData *sd = NULL;
  TC_MODULE_SELF_CHECK(self, "configure");
  char* filenamecopy, *filebasename;

  sd = self->userdata;

  /*    sd->framesize = sd->vob->im_v_width * MAX_PLANES *
	sizeof(char) * 2 * sd->vob->im_v_height * 2;     */

  MotionDetect* md = &(sd->md);
  TransformData* td = &(sd->td);

  // init MotionDetect part
  VSFrameInfo fi;
  initFrameInfo(&fi, sd->vob->ex_v_width, sd->vob->ex_v_height,
                transcode2ourPF(sd->vob->im_v_codec));

  if(initMotionDetect(md, &fi, MOD_NAME) != VS_OK){
    tc_log_error(MOD_NAME, "initialization of Motion Detection failed");
    return TC_ERROR;
  }

  sd->result = tc_malloc(TC_BUF_LINE);
  filenamecopy = tc_strdup(sd->vob->video_in_file);
  filebasename = basename(filenamecopy);
  if (strlen(filebasename) < TC_BUF_LINE - 4) {
    tc_snprintf(sd->result, 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(sd->result, TC_BUF_LINE, DEFAULT_TRANS_FILE_NAME);
  }

  // init trasform part
  VSFrameInfo fi_dest;
  initFrameInfo(&fi_dest, sd->vob->ex_v_width, sd->vob->ex_v_height,
                transcode2ourPF(sd->vob->im_v_codec));

  if(initTransformData(td, &fi, &fi_dest, MOD_NAME) != VS_OK){
    tc_log_error(MOD_NAME, "initialization of TransformData failed");
    return TC_ERROR;
  }
  td->verbose=verbose;


  if (options != NULL) {
    // for some reason this plugin is called in the old fashion
    //  (not with inspect). Anyway we support both ways of getting help.
    if(optstr_lookup(options, "help")) {
      tc_log_info(MOD_NAME,deshake_help);
      return(TC_IMPORT_ERROR);
    }

    optstr_get(options, "result",     "%[^:]", sd->result);
    optstr_get(options, "shakiness",  "%d", &md->shakiness);
    optstr_get(options, "accuracy",   "%d", &md->accuracy);
    optstr_get(options, "stepsize",   "%d", &md->stepSize);
    optstr_get(options, "algo",       "%d", &md->algo);
    optstr_get(options, "mincontrast","%lf",&md->contrastThreshold);
    md->show = 0;

    optstr_get(options, "maxshift",  "%d", &td->maxShift);
    optstr_get(options, "maxangle",  "%lf", &td->maxAngle);
    optstr_get(options, "smoothing", "%d", &td->smoothing);
    optstr_get(options, "crop"     , "%d", (int*)&td->crop);
    optstr_get(options, "zoom"     , "%lf",&td->zoom);
    optstr_get(options, "optzoom"  , "%d", &td->optZoom);
    optstr_get(options, "interpol" , "%d", (int*)(&td->interpolType));
    optstr_get(options, "sharpen"  , "%lf",&td->sharpen);
    td->relative=1;
    td->invert=0;
  }

  if(configureMotionDetect(md)!= VS_OK){
    tc_log_error(MOD_NAME, "configuration of Motion Detection failed");
    return TC_ERROR;
  }
  if(configureTransformData(td)!= VS_OK){
    tc_log_error(MOD_NAME, "configuration of Tranform failed");
    return TC_ERROR;
  }

  if (verbose) {
    tc_log_info(MOD_NAME, "Video Deshake  Settings:");
    tc_log_info(MOD_NAME, "    smoothing = %d", td->smoothing);
    tc_log_info(MOD_NAME, "    shakiness = %d", md->shakiness);
    tc_log_info(MOD_NAME, "     accuracy = %d", md->accuracy);
    tc_log_info(MOD_NAME, "     stepsize = %d", md->stepSize);
    tc_log_info(MOD_NAME, "         algo = %d", md->algo);
    tc_log_info(MOD_NAME, "  mincontrast = %f", md->contrastThreshold);
    tc_log_info(MOD_NAME, "         show = %d", md->show);
    tc_log_info(MOD_NAME, "       result = %s", sd->result);
    tc_log_info(MOD_NAME, "    maxshift  = %d", td->maxShift);
    tc_log_info(MOD_NAME, "    maxangle  = %f", td->maxAngle);
    tc_log_info(MOD_NAME, "         crop = %s",
		td->crop ? "Black" : "Keep");
    tc_log_info(MOD_NAME, "         zoom = %f", td->zoom);
    tc_log_info(MOD_NAME, "      optzoom = %s",
		td->optZoom ? "On" : "Off");
    tc_log_info(MOD_NAME, "     interpol = %s",
		interpolTypes[td->interpolType]);
    tc_log_info(MOD_NAME, "      sharpen = %f", td->sharpen);

  }

  sd->avg.initialized=0;

  sd->f = fopen(sd->result, "w");
  if (sd->f == NULL) {
    tc_log_error(MOD_NAME, "cannot open result file %s!\n", sd->result);
    return TC_ERROR;
  }

  return TC_OK;
}
Beispiel #2
0
static int config_input(AVFilterLink *inlink)
{
    AVFilterContext *ctx = inlink->dst;
    FilterData *fd = ctx->priv;
    FILE* f;
//    char* filenamecopy, *filebasename;

    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format];

    TransformData* td = &(fd->td);

    VSFrameInfo fi_src;
    VSFrameInfo fi_dest;
    if(!initFrameInfo(&fi_src, inlink->w, inlink->h,
                      AV2OurPixelFormat(ctx,inlink->format)) ||
       !initFrameInfo(&fi_dest, inlink->w, inlink->h,
                      AV2OurPixelFormat(ctx, inlink->format))){
        av_log(ctx, AV_LOG_ERROR, "unknown pixel format: %i (%s)",
               inlink->format, desc->name);
        return AVERROR(EINVAL);
    }

    // check
    if(fi_src.bytesPerPixel != av_get_bits_per_pixel(desc)/8 ||
       fi_src.log2ChromaW != desc->log2_chroma_w ||
       fi_src.log2ChromaH != desc->log2_chroma_h){
        av_log(ctx, AV_LOG_ERROR, "pixel-format error: bpp %i<>%i  ",
               fi_src.bytesPerPixel, av_get_bits_per_pixel(desc)/8);
        av_log(ctx, AV_LOG_ERROR, "chroma_subsampl: w: %i<>%i  h: %i<>%i\n",
               fi_src.log2ChromaW, desc->log2_chroma_w,
               fi_src.log2ChromaH, desc->log2_chroma_h);
        return AVERROR(EINVAL);
    }

    if(initTransformData(td, &fi_src, &fi_dest, "transform") != VS_OK){
        av_log(ctx, AV_LOG_ERROR, "initialization of TransformData failed\n");
        return AVERROR(EINVAL);
    }
    td->verbose=1; // TODO: get from somewhere


    /// TODO: find out input name
//    fd->input = (char*)av_malloc(VS_INPUT_MAXLEN);

//    filenamecopy = strndup(fd->vob->video_in_file);
//    filebasename = basename(filenamecopy);
//    if (strlen(filebasename) < VS_INPUT_MAXLEN - 4) {
//        snprintf(fd->result, VS_INPUT_MAXLEN, "%s.trf", filebasename);
//} else {
//    av_log(ctx, AV_LOG_WARN, "input name too long, using default `%s'",
//                    DEFAULT_TRANS_FILE_NAME);
    snprintf(fd->input, VS_INPUT_MAXLEN, DEFAULT_TRANS_FILE_NAME);
//    }

    if (fd->options != NULL) {
        if(optstr_lookup(fd->options, "help")) {
            av_log(ctx, AV_LOG_INFO, transform_help);
            return AVERROR(EINVAL);
        }

        optstr_get(fd->options, "input",     "%[^:]", fd->input);
        optstr_get(fd->options, "maxshift",  "%d", &td->maxShift);
        optstr_get(fd->options, "maxangle",  "%lf", &td->maxAngle);
        optstr_get(fd->options, "smoothing", "%d", &td->smoothing);
        optstr_get(fd->options, "crop"     , "%d", &td->crop);
        optstr_get(fd->options, "invert"   , "%d", &td->invert);
        optstr_get(fd->options, "relative" , "%d", &td->relative);
        optstr_get(fd->options, "zoom"     , "%lf",&td->zoom);
        optstr_get(fd->options, "optzoom"  , "%d", &td->optZoom);
        optstr_get(fd->options, "interpol" , "%d", (int*)(&td->interpolType));
        optstr_get(fd->options, "sharpen"  , "%lf",&td->sharpen);
        if(optstr_lookup(fd->options, "tripod")){
            av_log(ctx,AV_LOG_INFO, "Virtual tripod mode: relative=False, smoothing=0");
            td->relative=0;
            td->smoothing=0;
        }
    }

    if(configureTransformData(td)!= VS_OK){
    	av_log(ctx, AV_LOG_ERROR, "configuration of Tranform failed\n");
        return AVERROR(EINVAL);
    }

    av_log(ctx, AV_LOG_INFO, "Image Transformation/Stabilization Settings:\n");
    av_log(ctx, AV_LOG_INFO, "    input     = %s\n", fd->input);
    av_log(ctx, AV_LOG_INFO, "    smoothing = %d\n", td->smoothing);
    av_log(ctx, AV_LOG_INFO, "    maxshift  = %d\n", td->maxShift);
    av_log(ctx, AV_LOG_INFO, "    maxangle  = %f\n", td->maxAngle);
    av_log(ctx, AV_LOG_INFO, "    crop      = %s\n", td->crop ? "Black" : "Keep");
    av_log(ctx, AV_LOG_INFO, "    relative  = %s\n", td->relative ? "True": "False");
    av_log(ctx, AV_LOG_INFO, "    invert    = %s\n", td->invert ? "True" : "False");
    av_log(ctx, AV_LOG_INFO, "    zoom      = %f\n", td->zoom);
    av_log(ctx, AV_LOG_INFO, "    optzoom   = %s\n", td->optZoom ? "On" : "Off");
    av_log(ctx, AV_LOG_INFO, "    interpol  = %s\n", interpolTypes[td->interpolType]);
    av_log(ctx, AV_LOG_INFO, "    sharpen   = %f\n", td->sharpen);

    f = fopen(fd->input, "r");
    if (f == NULL) {
        av_log(ctx, AV_LOG_ERROR, "cannot open input file %s!\n", fd->input);
    } else {
        ManyLocalMotions mlms;
        if(readLocalMotionsFile(f,&mlms)==VS_OK){
            // calculate the actual transforms from the localmotions
            if(localmotions2TransformsSimple(td, &mlms,&fd->trans)!=VS_OK)
                av_log(ctx, AV_LOG_ERROR, "calculating transformations failed!\n");
        }else{ // try to read old format
            if (!readOldTransforms(td, f, &fd->trans)) { /* read input file */
                av_log(ctx, AV_LOG_ERROR, "error parsing input file %s!\n", fd->input);
            }
        }
    }
    fclose(f);

    if (preprocessTransforms(td, &fd->trans)!= VS_OK ) {
        av_log(ctx, AV_LOG_ERROR, "error while preprocessing transforms\n");
        return AVERROR(EINVAL);
    }

    // TODO: add sharpening
    return 0;
}