Exemplo n.º 1
0
void ofApp::setup(){
    ofDisableArbTex();
    _video.initGrabber(640, 480);
    _currentFilter = 0;
    
    
    _filters.push_back(new KuwaharaFilter());
    _filters.push_back(new SketchFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new PerlinPixellationFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new XYDerivativeFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new ZoomBlurFilter());
    _filters.push_back(new EmbossFilter(_video.getWidth(), _video.getHeight(), 2.f));
    _filters.push_back(new BilateralFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new SobelEdgeDetectionFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new TiltShiftFilter(_video.getTextureReference()));
    _filters.push_back(new VoronoiFilter(_video.getTextureReference()));    
    _filters.push_back(new CGAColorspaceFilter());
    _filters.push_back(new ErosionFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new LookupFilter(_video.getWidth(), _video.getHeight(), "img/lookup_amatorka.png"));
    _filters.push_back(new LookupFilter(_video.getWidth(), _video.getHeight(), "img/lookup_miss_etikate.png"));
    _filters.push_back(new LookupFilter(_video.getWidth(), _video.getHeight(), "img/lookup_soft_elegance_1.png"));
    _filters.push_back(new VignetteFilter());
    _filters.push_back(new ToonFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new PixelateFilter(_video.getWidth(), _video.getHeight()));
    _filters.push_back(new HarrisCornerDetectionFilter(_video.getTextureReference()));
    _filters.push_back(new MotionDetectionFilter(_video.getTextureReference()));
    _filters.push_back(new LowPassFilter(_video.getWidth(), _video.getHeight(), 0.9));
    _filters.push_back(new PinchDistortionFilter(ofGetWidth(), ofGetHeight(), 2.0, 0.5));
    _filters.push_back(new SwirlFilter(ofGetWidth(), ofGetHeight(), 1.0, 1.0));

        // and here's how you might daisy-chain a bunch of filters
    
    FilterChain * foggyTexturedGlassChain = new FilterChain(_video.getWidth(), _video.getHeight(), "Weird Glass");
    foggyTexturedGlassChain->addFilter(new PerlinPixellationFilter(_video.getWidth(), _video.getHeight(), 13.f));
    foggyTexturedGlassChain->addFilter(new EmbossFilter(_video.getWidth(), _video.getHeight(), 0.5));
    foggyTexturedGlassChain->addFilter(new GaussianBlurFilter(_video.getWidth(), _video.getHeight(), 3.f));
    _filters.push_back(foggyTexturedGlassChain);
    
        // here's another unimaginative filter chain
    
    FilterChain * watercolorChain = new FilterChain(_video.getWidth(), _video.getHeight(), "Monet");
    watercolorChain->addFilter(new KuwaharaFilter(9));
    watercolorChain->addFilter(new LookupFilter(_video.getWidth(), _video.getHeight(), "img/lookup_miss_etikate.png"));
    watercolorChain->addFilter(new BilateralFilter(_video.getWidth(), _video.getHeight()));
    watercolorChain->addFilter(new VignetteFilter());
    _filters.push_back(watercolorChain);
    
    
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    printf(
"AC3 Encoder\n"
"===========\n"
"This utility is a part of AC3Filter project (http://ac3filter.net)\n"
"Copyright (c) 2007-2009 by Alexander Vigovsky\n"
"\n"
"Usage:\n"
"  ac3enc input.wav output.ac3 [-br:bitrate]\n"
    );
    return 1;
  }

  /////////////////////////////////////////////////////////
  // Parse arguments
  /////////////////////////////////////////////////////////

  const char *input_filename = argv[1];
  const char *output_filename = argv[2];
  int bitrate = 448000;

  for (int iarg = 3; iarg < argc; iarg++)
  {
    if (is_arg(argv[iarg], "br", argt_num))
    {
       bitrate = (int)arg_num(argv[iarg]);
       continue;
    }

    printf("Error: unknown option: %s\n", argv[iarg]);
    return 1;
  }

  /////////////////////////////////////////////////////////
  // Open files
  /////////////////////////////////////////////////////////

  WAVSource src;
  if (!src.open(input_filename, 65536))
  {
    printf("Cannot open file %s (not a PCM file?)\n", input_filename);
    return 1;
  }

  RAWSink sink;
  if (!sink.open(output_filename))
  {
    printf("Cannot open file %s for writing!\n", argv[2]);
    return 1;
  }

  /////////////////////////////////////////////////////////
  // Setup everything
  /////////////////////////////////////////////////////////

  Converter   conv(2048);
  AC3Enc      enc;
  FilterChain chain;

  chain.add_back(&conv, "Converter");
  chain.add_back(&enc,  "Encoder");

  conv.set_format(FORMAT_LINEAR);
  conv.set_order(win_order);

  if (!enc.set_bitrate(bitrate))
  {
    printf("Wrong bitrate (%i)!\n", bitrate);
    return 1;
  }

  Speakers spk = src.get_output();
  spk.format = FORMAT_LINEAR;
  if (!enc.set_input(spk))
  {
    printf("Cannot encode this file (%s %iHz)!\n", spk.sample_rate);
    return 1;
  }

  /////////////////////////////////////////////////////////
  // Process
  /////////////////////////////////////////////////////////

  Chunk raw_chunk;
  Chunk ac3_chunk;

  CPUMeter cpu_usage;
  CPUMeter cpu_total;

  double ms = 0;
  double old_ms = 0;

  cpu_usage.start();
  cpu_total.start();

  fprintf(stderr, "0.0%% Frs/err: 0/0\tTime: 0:00.000i\tFPS: 0 CPU: 0%%\r");
  int frames = 0;
  while (!src.is_empty())
  {
    if (!src.get_chunk(&raw_chunk))
    {
      printf("Data load error!\n");
      return 1;
    }

    if (!chain.process(&raw_chunk))
    {
      printf("Encoding error!\n");
      return 1;
    }

    while (!chain.is_empty())
    {
      if (!chain.get_chunk(&ac3_chunk))
      {
        printf("Encoding error!\n");
        return 1;
      }

      sink.process(&ac3_chunk);
      frames++;

      /////////////////////////////////////////////////////
      // Statistics

      ms = double(cpu_total.get_system_time() * 1000);
      if (ms > old_ms + 100)
      {
        old_ms = ms;

        // Statistics
        fprintf(stderr, "%2.1f%% Frames: %i\tTime: %i:%02i.%03i\tFPS: %i CPU: %.1f%%  \r",
          double(src.pos()) * 100.0 / src.size(),
          frames,
          int(ms/60000), int(ms) % 60000/1000, int(ms) % 1000,
          int(frames * 1000 / (ms+1)),
          cpu_usage.usage() * 100);
      } // if (ms > old_ms + 100)
    }
  }

  fprintf(stderr, "%2.1f%% Frames: %i\tTime: %i:%02i.%03i\tFPS: %i CPU: %.1f%%  \n",
    double(src.pos()) * 100.0 / src.size(),
    frames,
    int(ms/60000), int(ms) % 60000/1000, int(ms) % 1000,
    int(frames * 1000 / (ms+1)),
    cpu_usage.usage() * 100);

  cpu_usage.stop();
  cpu_total.stop();

  printf("System time: %ims\n", int(cpu_total.get_system_time() / 10000));
  printf("Process time: %ims\n", int(cpu_total.get_thread_time() / 10000));

  return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  if (argc < 3)
  {
    printf(

"Gain\n"
"====\n"
"Simple gain tool to amplify or attenuate an audio file.\n"
"This utility is a part of AC3Filter project (http://ac3filter.net)\n"
"Copyright (c) 2008-2009 by Alexander Vigovsky\n"
"\n"
"Usage:\n"
"  > gain input.wav output.wav [-g[ain]:n]\n"
"\n"
"Options:\n"
"  input.wav  - file to process\n"
"  output.wav - file to write the result to\n"
"  -gain - gain to apply\n"
"\n"
"Example:\n"
" > gain a.wav b.wav -gain:-10\n"
" Attenuate by 10dB\n"
    );
    return 0;
  }

  const char *input_filename = argv[1];
  const char *output_filename = argv[2];
  double gain = 1.0;

  /////////////////////////////////////////////////////////////////////////////
  // Parse arguments

  for (int iarg = 3; iarg < argc; iarg++)
  {
    // -gain
    if (is_arg(argv[iarg], "gain", argt_num))
    {
      gain = db2value(arg_num(argv[iarg]));
      continue;
    }

    printf("Error: unknown option: %s\n", argv[iarg]);
    return -1;
  }

  /////////////////////////////////////////////////////////////////////////////
  // Open files

  WAVSource src(input_filename, block_size);
  if (!src.is_open())
  {
    printf("Error: cannot open file: %s\n", input_filename);
    return -1;
  }

  WAVSink sink(output_filename);
  if (!sink.is_open())
  {
    printf("Error: cannot open file: %s\n", output_filename);
    return -1;
  }

  Speakers spk = src.get_output();

  /////////////////////////////////////////////////////////////////////////////
  // Build the chain

  Converter iconv(block_size);
  Converter oconv(block_size);
  iconv.set_format(FORMAT_LINEAR);
  oconv.set_format(src.get_output().format);
  Gain gain_filter;
  AGC agc(1024);

  gain_filter.gain = gain;

  FilterChain chain;
  chain.add_back(&iconv, "Input converter");
  chain.add_back(&gain_filter, "Gain");
  chain.add_back(&agc, "AGC");
  chain.add_back(&oconv, "Output converter");

  if (!chain.set_input(spk))
  {
    printf("Error: cannot start processing\n");
    return -1;
  }

  /////////////////////////////////////////////////////////////////////////////
  // Do the job

  Chunk chunk;
  printf("0%%\r");

  vtime_t t = local_time() + 0.1;
  while (!src.is_empty())
  {
    src.get_chunk(&chunk);
    if (!chain.process_to(&chunk, &sink))
    {
      char buf[1024];
      chain.chain_text(buf, array_size(buf));
      printf("Processing error. Chain dump: %s\n", buf);
      return -1;
    }

    if (local_time() > t)
    {
      t += 0.1;
      double pos = double(src.pos()) * 100 / src.size();
      printf("%i%%\r", (int)pos);
    }
  }
  printf("100%%\n");
  return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
  if (argc < 3)
  {
    printf(
"Resample\n"
"========\n"
"Sample rate conversion utility\n"
"This utility is a part of AC3Filter project (http://ac3filter.net)\n"
"Copyright (c) 2008-2011 by Alexander Vigovsky\n"
"\n"
"Usage:\n"
"  > resample input.wav output.wav [-r[ate]:n] [-q[uality]:n] [-a[ttenuation]:n] [-d[ither]]\n"
"\n"
"Options:\n"
"  input.wav  - file to convert\n"
"  output.wav - file to write the result to\n"
"  rate - new sample rate (deafult: 48000)\n"
"  quality - passband width (default: 0.99)\n"
"  attenuation - stopband attenuation in dB (default: 100)\n"
"  dither - dither the result\n"
"\n"
"Example:\n"
"  > resample input.wav output.wav -r:44100 -q:0.999 -a:150\n"
"  Passband width in this example is 0.999. This means that only uppper 22Hz\n"
"  of the destination bandwidth (22028Hz - 22050Hz) will be distorted.\n"
"  Note, that attenuation is large here. Such attenuation is only sensible for\n"
"  at least 24bit files.\n");
    return 0;
  }

  const char *input_filename = argv[1];
  const char *output_filename = argv[2];
  int sample_rate = 48000;
  double q = 0.99;
  double a = 100;
  bool do_dither = false;

  for (int iarg = 3; iarg < argc; iarg++)
  {
    // -r[ate]
    if (is_arg(argv[iarg], "r", argt_num) || 
        is_arg(argv[iarg], "rate", argt_num))
    {
      sample_rate = (int)arg_num(argv[iarg]);
      continue;
    }

    // -q[uality]
    if (is_arg(argv[iarg], "q", argt_num) || 
        is_arg(argv[iarg], "quality", argt_num))
    {
      q = arg_num(argv[iarg]);
      continue;
    }

    // -a[ttenuation]
    if (is_arg(argv[iarg], "a", argt_num) || 
        is_arg(argv[iarg], "attenuation", argt_num))
    {
      a = arg_num(argv[iarg]);
      continue;
    }

    // -d[ither]
    if (is_arg(argv[iarg], "d", argt_bool) || 
        is_arg(argv[iarg], "dither", argt_bool))
    {
      do_dither = arg_bool(argv[iarg]);
      continue;
    }

    printf("Error: unknown option: %s\n", argv[iarg]);
    return 1;
  }

  if (sample_rate == 0)
  {
    printf("Error: incorrect sample rate\n");
    return -1;
  }

  WAVSource src(input_filename, block_size);
  if (!src.is_open())
  {
    printf("Error: cannot open file: %s\n", input_filename);
    return -1;
  }

  WAVSink sink(output_filename);
  if (!sink.is_open())
  {
    printf("Error: cannot open file: %s\n", output_filename);
    return -1;
  }

  Speakers spk = src.get_output();

  Converter iconv(block_size);
  Converter oconv(block_size);
  Resample resample;
  AGC agc(1024);
  Dither dither;

  iconv.set_format(FORMAT_LINEAR);
  oconv.set_format(src.get_output().format);
  if (!resample.set(sample_rate, a, q))
  {
    printf("Error: cannot do sample rate conversion with given parameters\n", output_filename);
    return -1;
  }

  FilterChain chain;
  chain.add_back(&iconv, "Input converter");
  chain.add_back(&resample, "Resample");
  if (do_dither && !spk.is_floating_point())
  {
    chain.add_back(&dither, "Dither");
    dither.level = 0.5 / spk.level;
  }
  chain.add_back(&agc, "AGC");
  chain.add_back(&oconv, "Output converter");

  Chunk chunk;
  printf("Conversion %i -> %i\n", src.get_output().sample_rate, sample_rate);
  printf("0%%\r");

  vtime_t t = local_time() + 0.1;
  while (!src.is_empty())
  {
    src.get_chunk(&chunk);
    if (!chain.process_to(&chunk, &sink))
    {
      char buf[1024];
      chain.chain_text(buf, array_size(buf));
      printf("Processing error. Chain dump: %s\n", buf);
      return -1;
    }

    if (local_time() > t)
    {
      t += 0.1;
      double pos = double(src.pos()) * 100 / src.size();
      printf("%i%%\r", (int)pos);
    }
  }
  printf("100%%\n");
  return 0;
}
Exemplo n.º 5
0
FilterChain *FilterManager::LoadFilters(QString Filters,
                                        VideoFrameType &inpixfmt,
                                        VideoFrameType &outpixfmt, int &width,
                                        int &height, int &bufsize,
                                        int max_threads)
{
    if (Filters.toLower() == "none")
        return nullptr;

    vector<const FilterInfo*> FiltInfoChain;
    FilterChain *FiltChain = new FilterChain;
    vector<FmtConv*> FmtList;
    const FilterInfo *FI;
    const FilterInfo *FI2;
    QString Opts;
    const FilterInfo *Convert = GetFilterInfo("convert");
    QStringList OptsList;
    QStringList FilterList = Filters.split(",", QString::SkipEmptyParts);
    VideoFilter *NewFilt = nullptr;
    FmtConv *FC, *FC2, *S1, *S2, *S3;
    VideoFrameType ifmt;
    int nbufsize;
    int cbufsize;
    int postfilt_width = width;
    int postfilt_height = height;

    for (auto i = FilterList.begin(); i != FilterList.end(); ++i)
    {
        QString FiltName = (*i).section('=', 0, 0);
        QString FiltOpts = (*i).section('=', 1);

        if (FiltName.contains("opengl", Qt::CaseInsensitive) ||
            FiltName.contains("vdpau",  Qt::CaseInsensitive))
            continue;

        FI = GetFilterInfo(FiltName);

        if (FI)
        {
            FiltInfoChain.push_back(FI);
            OptsList.push_back(FiltOpts);
        }
        else
        {
            LOG(VB_GENERAL, LOG_ERR, LOC +
                QString("Failed to load filter '%1', "
                        "no such filter exists").arg(FiltName));
            FiltInfoChain.clear();
            break;
        }
    }

    ifmt = inpixfmt;
    for (uint i = 0; i < FiltInfoChain.size(); i++)
    {
        S1 = S2 = S3 = nullptr;
        FI = FiltInfoChain[i];
        if (FiltInfoChain.size() - i == 1)
        {
            for (FC = FI->formats; FC->in != FMT_NONE; FC++)
            {
                if (FC->out == outpixfmt && FC->in == ifmt)
                {
                    S1 = FC;
                    break;
                }
                if (FC->in == ifmt && !S2)
                    S2 = FC;
                if (FC->out == outpixfmt && !S3)
                    S3 = FC;
            }
        }
        else
        {
            FI2 = FiltInfoChain[i+1];
            for (FC = FI->formats; FC->in != FMT_NONE; FC++)
            {
                for (FC2 = FI2->formats; FC2->in != FMT_NONE; FC2++)
                {
                    if (FC->in == ifmt && FC->out == FC2->in)
                    {
                        S1 = FC;
                        break;
                    }
                    if (FC->out == FC2->in && !S3)
                        S3 = FC;
                }
                if (S1)
                    break;
                if (FC->in == ifmt && !S2)
                    S2 = FC;
            }
        }

        if (S1)
            FC = S1;
        else if (S2)
            FC = S2;
        else if (S3)
            FC = S3;
        else
            FC = FI->formats;

        if (FC->in != ifmt && (i > 0 || ifmt != FMT_NONE))
        {
            if (!Convert)
            {
                LOG(VB_GENERAL, LOG_ERR, "FilterManager: format conversion "
                                         "needed but convert filter not found");
                FiltInfoChain.clear();
                break;
            }
            FiltInfoChain.insert(FiltInfoChain.begin() + i, Convert);
            OptsList.insert(i, QString ());
            FmtList.push_back(new FmtConv);
            if (FmtList.back())
            {
                FmtList.back()->in = ifmt;
                FmtList.back()->out = FC->in;
                i++;
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR,
                    "FilterManager: memory allocation "
                    "failure, returning empty filter chain");
                FiltInfoChain.clear();
                break;
            }
        }
        FmtList.push_back(new FmtConv);
        if (FmtList.back())
        {
            FmtList.back()->in = FC->in;
            FmtList.back()->out = FC->out;
        }
        else
        {
            LOG(VB_GENERAL, LOG_ERR,
                "FilterManager: memory allocation failure, "
                "returning empty filter chain");
            FiltInfoChain.clear();
            break;
        }
        ifmt = FC->out;
    }

    if (ifmt != outpixfmt && outpixfmt != FMT_NONE &&
        (FiltInfoChain.size() || inpixfmt != FMT_NONE))
    {
        if (!Convert)
        {
            LOG(VB_GENERAL, LOG_ERR, "FilterManager: format conversion "
                                     "needed but convert filter not found");
            FiltInfoChain.clear();
        }
        else
        {
            FiltInfoChain.push_back(Convert);
            OptsList.push_back( QString ());
            FmtList.push_back(new FmtConv);
            if (FmtList.back())
            {
                FmtList.back()->in = ifmt;
                FmtList.back()->out = outpixfmt;
            }
            else
            {
                LOG(VB_GENERAL, LOG_ERR,
                    "FilterManager: memory allocation "
                    "failure, returning empty filter chain");
                FiltInfoChain.clear();
            }
        }
    }

    nbufsize = -1;

    if (FiltInfoChain.empty())
    {
        delete FiltChain;
        FiltChain = nullptr;
    }

    for (uint i = 0; i < FiltInfoChain.size(); i++)
    {
        QByteArray tmp = OptsList[i].toLocal8Bit();
        NewFilt = LoadFilter(FiltInfoChain[i], FmtList[i]->in,
                             FmtList[i]->out, postfilt_width,
                             postfilt_height, tmp.constData(),
                             max_threads);

        if (!NewFilt)
        {
            delete FiltChain;
            LOG(VB_GENERAL, LOG_ERR, QString("FilterManager: failed to load "
                                             "filter %1 %2->%3 with args %4")
                    .arg(FiltInfoChain[i]->name)
                    .arg(FmtToString(FmtList[i]->in))
                    .arg(FmtToString(FmtList[i]->out))
                    .arg(OptsList[i]));
            FiltChain = nullptr;
            nbufsize = -1;
            break;
        }

        if (NewFilt->filter && FiltChain)
        {
            FiltChain->Append(NewFilt);
        }
        else
        {
            if (NewFilt->opts)
                free(NewFilt->opts);
            if (NewFilt->cleanup)
                NewFilt->cleanup(NewFilt);
            dlclose(NewFilt->handle);
            free(NewFilt);
        }

        switch (FmtList[i]->out)
        {
            case FMT_YV12:
                cbufsize = postfilt_width * postfilt_height * 3 / 2;
                break;
            case FMT_YUV422P:
                cbufsize = postfilt_width * postfilt_height * 2;
                break;
            case FMT_RGB24:
                cbufsize = postfilt_width * postfilt_height * 3;
                break;
            case FMT_ARGB32:
                cbufsize = postfilt_width * postfilt_height * 4;
                break;
            default:
                cbufsize = 0;
        }

        if (cbufsize > nbufsize)
            nbufsize = cbufsize;
    }

    if (FiltChain)
    {
        if (inpixfmt == FMT_NONE)
            inpixfmt = FmtList.front()->in;
        if (outpixfmt == FMT_NONE)
            outpixfmt = FmtList.back()->out;
        width = postfilt_width;
        height = postfilt_height;
    }
    else
    {
        if (inpixfmt == FMT_NONE && outpixfmt == FMT_NONE)
            inpixfmt = outpixfmt = FMT_YV12;
        else if (inpixfmt == FMT_NONE)
            inpixfmt = outpixfmt;
        else if (outpixfmt == FMT_NONE)
            outpixfmt = inpixfmt;
    }

    switch (inpixfmt)
    {
        case FMT_YV12:
            cbufsize = postfilt_width * postfilt_height * 3 / 2;
            break;
        case FMT_YUV422P:
            cbufsize = postfilt_width * postfilt_height * 2;
            break;
        case FMT_RGB24:
            cbufsize = postfilt_width * postfilt_height * 3;
            break;
        case FMT_ARGB32:
            cbufsize = postfilt_width * postfilt_height * 4;
            break;
        default:
            cbufsize = 0;
    }

    if (cbufsize > nbufsize)
        nbufsize = cbufsize;

    bufsize = nbufsize;

    vector<FmtConv*>::iterator it = FmtList.begin();
    for (; it != FmtList.end(); ++it)
        delete *it;
    FmtList.clear();

    return FiltChain;
}