Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- };
- /*
- * Our array should look like this, according to the Y'UV spec:
- * [ ======================= Y' =======================, =========== U ===========, =========== V =========== ]
- *
- * where
- * the length of Y' == frame_width * frame_height
- * and
- * the length of U == frame_width * frame_height / 4
- * and
- * the length of V == frame_width * frame_height / 4 (same as U)
- *
- *
- * For reference, an RGB array looks like this:
- *
- * [pixel] [pixel] [pixel] [pixel]
- * [ A,B,G,R, A,G,B,R, A,G,B,R, A,B,G,R...(cont'd)]
- *
- * (four bytes per pixel, packed)
- */
- uint8_t *src[4] = {
- /*
- * First pointer should point to a section of data that starts
- * at zero and should be as many bytes as there are pixels. The
- * Y' value in Y'UV needs one byte per pixel.
- */
- scaleBuffer,
- /*
- * Second pointer should start at 1byte * frame_width * frame_height
- * and should be long enough to contain one fourth the amount of data as
- * the Y' value, since one U component of Y'UV contains data for four Y' components
- */
- scaleBuffer + FRAME_WIDTH * FRAME_HEIGHT,
- /*
- * Third pointer should be same as previous. both the U and V components in Y'UV
- * contain one forth the amount of data as the Y' component.
- */
- scaleBuffer + ( FRAME_WIDTH * FRAME_HEIGHT ) + ( FRAME_WIDTH * FRAME_HEIGHT / 4 ),
- /*
- * No data needed for the fourth row since we're all accounted for in the first three
- */
- NULL
- };
- int stride[4] = {
- FRAME_WIDTH,
- FRAME_WIDTH / 2,
- FRAME_WIDTH / 2,
- 0
- };
- 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_YUV420P, // dest pix format
- SWS_BILINEAR, // FLAGS
- NULL,
- NULL,
- NULL);
- int sliceHeight = sws_scale(sws,
- rgb_src,
- rgb_stride,
- 0,
- FRAME_HEIGHT,
- src,
- stride);
- if (sliceHeight <= 0)
- {
- NSLog(@"couldn't scale");
- abort();
- }
- sws_freeContext(sws);
- currentPicture->data[0] = src[0];
- currentPicture->data[1] = src[1];
- currentPicture->data[2] = src[2];
- currentPicture->data[3] = src[3];
- currentPicture->linesize[0] = stride[0];
- currentPicture->linesize[1] = stride[1];
- currentPicture->linesize[2] = stride[2];
- currentPicture->linesize[3] = stride[3];
- out_size = avcodec_encode_video(codecContext, encodeBuffer, frameSize, currentPicture);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement