Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)ffmpegProcessFrames
- {
- // get a pointer sitting at the most recent image data
- // - we're doing "totalCaptured - 1" because at this point we've already captured the frame, so totalCaptured will reflect
- // the index after the last frame has been captured. we want a pointer at the beginning of this data
- // - % BUFFER_FRAME_MAX_COUNT : since our data buffer is circular - meaning once it gets to the end of the allocated memory,
- // it starts filling up at the beginning again, we want to compensate for each time we reach the end of the buffer
- // - * frameSize : frameSize represents the number of bytes per image
- // - buffer + : we want to get a pointer that sits at the head of the image we want to process, so take the buffer and add
- // the appropriate number of bytes to get to the current image
- uint8_t *rgb_data = buffer + (frameSize * ((*totalCaptured - 1) % BUFFER_FRAME_MAX_COUNT));
- uint8_t *rgb_src[3] = {
- rgb_data,
- NULL,
- NULL
- };
- int rgb_stride[3] = {
- 4 * FRAME_WIDTH,
- 0,
- 0
- };
- uint8_t *origDataPtr;
- uint8_t *data = av_malloc(4 * FRAME_WIDTH * FRAME_HEIGHT);
- origDataPtr = &(*data);
- // i believe this is for planar image representation
- uint8_t *src[4] = {
- data,
- data + FRAME_WIDTH * FRAME_HEIGHT,
- data + FRAME_WIDTH * FRAME_HEIGHT * 2,
- data + FRAME_WIDTH * FRAME_HEIGHT * 3
- };
- int stride[4] = {
- FRAME_WIDTH,
- FRAME_WIDTH,
- FRAME_WIDTH,
- FRAME_WIDTH
- };
- struct SwsContext *sws;
- // get the scale context
- sws = sws_getContext(FRAME_WIDTH, // src width
- FRAME_HEIGHT, // src height
- PIX_FMT_RGB32, // src pixel format ,
- FRAME_WIDTH, // dest width
- FRAME_HEIGHT, // dest height
- PIX_FMT_YUVA420P, // dest pix format
- SWS_BILINEAR, // FLAGS
- NULL,
- NULL,
- NULL);
- int sliceHeight = sws_scale(sws,
- rgb_src,
- rgb_stride,
- 0,
- FRAME_HEIGHT,
- src,
- stride);
- sws_freeContext(sws);
- x264_image_t img;
- img.i_csp = X264_CSP_I420;
- img.i_plane = 4;
- for (int i = 0; i < 4; i++)
- {
- img.i_stride[i] = stride[i];
- img.plane[i] = src[i];
- }
- x264_picture_t picvar;
- x264_picture_t *pic = &picvar;
- x264_picture_alloc(pic, X264_CSP_I420, FRAME_WIDTH, FRAME_HEIGHT);
- pic->img = img;
- // encode
- x264_picture_t pic_out;
- x264_nal_t *nal;
- int i_nal;
- int i_frame_size = 0;
- i_frame_size = x264_encoder_encode( encoderHandle, &nal, &i_nal, pic, &pic_out );
- for (int i = 0; i < 4; i++)
- src[i] = NULL;
- /*
- the following line logs this message:
- ProjectName(532,0x854600) malloc: *** error for object 0x615f5f5e: Non-aligned pointer being freed
- *** set a breakpoint in malloc_error_break to debug
- */
- av_freep(origDataPtr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement