5

OpenGLフレームのCMSampleBufferを取得する必要があります。私はこれを使用しています:

int s = 1;
        UIScreen * screen = [UIScreen mainScreen];
        if ([screen respondsToSelector:@selector(scale)]){
            s = (int)[screen scale];
        }
        const int w = viewController.view.frame.size.width/2;
        const int h = viewController.view.frame.size.height/2;
        const NSInteger my_data_length = 4*w*h*s*s;
        // allocate array and read pixels into it.
        GLubyte * buffer = malloc(my_data_length);
        glReadPixels(0, 0, w*s, h*s, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
        // gl renders "upside down" so swap top to bottom into new array.
        GLubyte * buffer2 = malloc(my_data_length);
        for(int y = 0; y < h*s; y++){
            memcpy(buffer2 + (h*s - 1 - y)*4*w*s, buffer + (4*y*w*s), 4*w*s);
        }
        free(buffer);
        CMBlockBufferRef * cm_block_buffer_ref;
        CMBlockBufferAccessDataBytes(cm_block_buffer_ref,0,my_data_length,buffer2,*buffer2);
        CMSampleBufferRef * cm_buffer;
        CMSampleBufferCreate (kCFAllocatorDefault,cm_block_buffer_ref,true,NULL,NULL,NULL,1,1,NULL,0,NULL,cm_buffer);

CMSampleBufferCreateのEXEC_BAD_ACCESSを取得します。

どんな助けでもありがたいです、ありがとう。

4

3 に答える 3

6

解決策は、AVAssetWriterInputPixelBufferAdaptorクラスを使用することでした。

int s = 1;
        UIScreen * screen = [UIScreen mainScreen];
        if ([screen respondsToSelector:@selector(scale)]){
            s = (int)[screen scale];
        }
        const int w = viewController.view.frame.size.width/2;
        const int h = viewController.view.frame.size.height/2;
        const NSInteger my_data_length = 4*w*h*s*s;
        // allocate array and read pixels into it.
        GLubyte * buffer = malloc(my_data_length);
        glReadPixels(0, 0, w*s, h*s, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
        // gl renders "upside down" so swap top to bottom into new array.
        GLubyte * buffer2 = malloc(my_data_length);
        for(int y = 0; y < h*s; y++){
            memcpy(buffer2 + (h*s - 1 - y)*4*w*s, buffer + (4*y*w*s), 4*w*s);
        }
        free(buffer);
        CVPixelBufferRef pixel_buffer = NULL;
        CVPixelBufferCreateWithBytes (NULL,w*2,h*2,kCVPixelFormatType_32BGRA,buffer2,4*w*s,NULL,0,NULL,&pixel_buffer);
        [av_adaptor appendPixelBuffer: pixel_buffer withPresentationTime:CMTimeMakeWithSeconds([[NSDate date] timeIntervalSinceDate: start_time],30)];
于 2011-01-28T18:14:18.903 に答える
1

コードで3 番目のパラメーターがCMSampleBufferCreate()true になっているのはなぜですか? ドキュメントによると:

パラメーター

アロケーター

CMSampleBuffer オブジェクトにメモリを割り当てるために使用するアロケーター。現在のデフォルト アロケータを使用するには、kCFAllocatorDefault を渡します。

データバッファ

これは、NULL、バッキング メモリのない CMBlockBuffer、バッキング メモリはあるがデータがまだない CMBlockBuffer、またはメディア データが既に含まれている CMBlockBuffer のいずれかです。最後のケース (または NULL で numSamples が 0 の場合) のみ、dataReady を true にする必要があります。

データレディ

dataBuffer に既にメディア データが含まれているかどうかを示します。

cm_block_buffer_refバッファとして渡されているものにはデータが含まれていないため(安全のためにNULLにする必要があります。コンパイラがデフォルトでそうするとは思いません)、ここで使用する必要がありfalseます。

これには他にも問題があるかもしれませんが、それが最初に飛び出す項目です。

于 2011-01-28T14:13:00.683 に答える
0

なぜ double malloc なのか、一時バッファーを介してスワップインしないのはなぜですか?

このようなもの:

    GLubyte * raw = (GLubyte *) wyMalloc(size);
    LOGD("raw address %p", raw);
    glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, raw);
    const size_t end = h/2;
    const size_t W = 4*w;
    GLubyte row[4*w];
    for (int i=0; i <= end; i++) {
        void * top = raw + (h - i - 1)*W;
        void * bottom = raw + i*W;
        memcpy(row, top, W);
        memcpy(top, bottom, W);
        memcpy(bottom, row, W);
    }
于 2012-10-03T03:30:13.157 に答える