处理时,无法使用电影库听到视频的声音

时间:2016-12-26 15:35:40

标签: java video processing video-processing

Hy Guys, 当我想使用处理来播放电影时,我遇到了问题,因为当我抓住一个帧来应用卷积蒙版的滤镜时,我会失去声音。一切都很好,但是我听不懂,只听到第二声,然后剩下的就响了。 这是我的代码:

import processing.video.*;
//DECLARATION OF OBJECT MOVIE
Movie myMovie;

//DECLARATION OF IMAGE SOURCE AND IMAGE FILTERED
PImage imgOriginal, imgFilterContornos;

// CONVOLUTION MASK TO DETECT EDGES
float[][] matrixContorno = { 
{ -1, -1, -1 }, 
{ -1, 8, -1 }, 
{ -1, -1, -1 } };

// DIMENSION OF CONVOLUTION MASK
int matrixsizeContorno = 3;

// OFFSET
int offsetContorno = 128;

final int RED=0, GREEN=1, BLUE=2;

void setup() {
  //LOAD THE VIDEO
  myMovie = new Movie(this, "cartell_cine.mov");
  myMovie.noLoop();
  size(1280, 720);

  myMovie.play();
  frameRate(30);
}

void draw() {

}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
    m.read();
    //GET THE FRAME
    imgOriginal=m; 
    // I CREATE A NEW IMAGE WITH SAME DIMENSIONS AS ORIGINAL
    imgFilterContornos = createImage(imgOriginal.width, imgOriginal.height, RGB);

    // LOADING PIXELES TO ALLOW ACCESS TO ARRAY pixels[]
    imgOriginal.loadPixels();
    imgFilterContornos.loadPixels();

    for (int x = 0; x < m.width; x++) {
      for (int y = 0; y < m.height; y++) {

        // CALCULATING CONVOLUTION
        int r = convolution(x, y, matrixContorno, matrixsizeContorno, offsetContorno, imgOriginal,RED);
        int g = convolution(x, y, matrixContorno, matrixsizeContorno, offsetContorno, imgOriginal,GREEN);
        int b = convolution(x, y, matrixContorno, matrixsizeContorno, offsetContorno, imgOriginal,BLUE);
        // I GET THE NEW PIXEL
        int loc = x + y * imgOriginal.width;
        imgFilterContornos.pixels[loc] = color(r,g,b);

      }
    } 

    imgFilterContornos.updatePixels();
    set(0,0,imgFilterContornos);


}

// METHOD TO CALCULATE DE SPACIAL CONVOLUTION
int convolution(int x, int y, float[][] matrix, int matrixsize, int offset, PImage img, int canal) {
      float result = 0.0;
      int half = matrixsize / 2;

      // Recorremos la matriz de convolución
      for (int i = 0; i < matrixsize; i++) {
        for (int j = 0; j < matrixsize; j++) {
        // Cálculo del píxel sobre el que estamos trabajando
        int xloc = x + i - half;
        int yloc = y + j - half;
        int loc = xloc + img.width * yloc;

        // We make sure that we take a pixel within the valid range. In this case we are
        // applying replication of nearby pixel values ​​to pixel locations
        // coming out of the image
        loc = constrain(loc, 0, img.pixels.length-1);

        // Calculation of the convolution operation
        // Check the value of the corresponding channel
        if (canal==RED)
          result += ((imgOriginal.pixels[loc] >> 16 & 0xFF) * matrix[i][j]);
        else if (canal==GREEN)
          result += ((imgOriginal.pixels[loc] >> 8 & 0xFF) * matrix[i][j]);
          else if (canal==BLUE)
            result += ((imgOriginal.pixels[loc] & 0xFF) * matrix[i][j]);
        }
      }

      // OFFSET
      result += offset;


      result = constrain(result, 0, 255);


      return (int)result;
}

提前谢谢!

0 个答案:

没有答案