1

目前,我正在研究热、单声道等视频效果。为此,我正在使用带有画布内容的预览回调。

谁能告诉我如何保存这个视频?

下面我有我的回调代码:

mCamera.setPreviewCallback(new PreviewCallback() {
                public void onPreviewFrame(byte[] data1, Camera _camera) 
                {
                    Camera.Parameters parameters = _camera.getParameters();
                    parameters.setColorEffect(Camera.Parameters.EFFECT_NONE);
                    previewSize = parameters.getPreviewSize();
                    int frameSize = previewSize.width * previewSize.height;
                    int height = previewSize.height;
                    int width = previewSize.width;
                    int pixel;  
                    int A, R, G, B;
                    final double GS_RED = 0.299;
                    final double GS_GREEN = 0.587;
                    final double GS_BLUE = 0.114;
                    int[] rgba = new int[frameSize+1];

                    data = data1;

                         for (int i = 0; i < height; i++) 
                             for(int j = 0; j < width; j++) 
                             { 
                                 int y = (0xff & ((int) data[i * previewSize.width + j])); 
                                 int u = (0xff & ((int) data[frameSize + (i >> 1) * previewSize.width + (j & ~1) + 0])); 
                                 int v = (0xff & ((int) data[frameSize + (i >> 1) * previewSize.width + (j & ~1) + 1])); 

                                 y = y < 16 ? 16 : y;

                                 int r = Math.round(1.164f * (y - 16) + 1.596f * (v - 128)); 
                                 int g = Math.round(1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128)); 
                                 int b = Math.round(1.164f * (y - 16) + 2.018f * (u - 128));

                                 r = r < 0 ? 0 : (r > 255 ? 255 : r); 
                                 g = g < 0 ? 0 : (g > 255 ? 255 : g); 
                                 b = b < 0 ? 0 : (b > 255 ? 255 : b);

                                rgba[i * previewSize.width + j] = 0xff000000 + (b << 16) + (g<< 8) + r;
                         }

                      Bitmap bmp = Bitmap.createBitmap(width, height,
                      Bitmap.Config.RGB_565);
                      bmp.setPixels(rgba, 0 , width , 0, 0, width, height);


                    // scan through every single pixel
                        for(int x = 0; x < width; ++x) {
                            for(int y = 0; y < height; ++y) {
                                // get one pixel color
                                pixel = bmp.getPixel(x, y);
                                // retrieve color of all channels
                                A = Color.alpha(pixel);
                                R = Color.red(pixel);
                                G = Color.green(pixel);
                                B = Color.blue(pixel);
                                // take conversion up to one single value
                                R = G = B = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);
                                // set new pixel color to output bitmap
                                bmp.setPixel(x, y, Color.argb(A, R, G, B));
                            }
                        }

                      canvas = mHolder.lockCanvas(); 
                      if (canvas != null) 
                      {
                          canvas.drawBitmap(bmp, (canvas.getWidth() - width) / 4, (canvas.getHeight() - height) / 4, null);
                          mHolder.unlockCanvasAndPost(canvas); 
                      } 
                      bmp.recycle();
                }
            });
4

1 回答 1

0

您可以保存每个帧,然后可以将它们与 ffmpeg 合并以进行编码,以创建视频文件。

于 2012-11-17T11:38:24.590 回答