Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- codec = avcodec_find_encoder(CODEC_ID_MSMPEG4V1);
- if (!codec)
- {
- NSLog("Couldn't init codec");
- abort();
- }
- codecContext = avcodec_alloc_context();
- codecContext->bit_rate = 384000;
- codecContext->width = FRAME_WIDTH;
- codecContext->height = FRAME_HEIGHT;
- codecContext->time_base = (AVRational) {
- 1,
- FPS
- };
- codecContext->pix_fmt = PIX_FMT_YUV420P;
- int codec_open_result = avcodec_open(codecContext, codec);
- if (codec_open_result < 0)
- {
- NSLog(@"Couldn't open codec");
- abort();
- }
- /* previously defined
- #define FRAME_WIDTH 320
- #define FRAME_HEIGHT 480
- */
- 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 *src[4] = {
- scaleBuffer,
- scaleBuffer + FRAME_WIDTH * FRAME_HEIGHT,
- scaleBuffer + ( FRAME_WIDTH * FRAME_HEIGHT ) + ( FRAME_WIDTH * FRAME_HEIGHT / 4 ),
- NULL
- };
- int stride[4] = {
- FRAME_WIDTH,
- FRAME_WIDTH / 2,
- FRAME_WIDTH / 2,
- 0
- };
- struct SwsContext *sws;
- 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);
- // the "sliceHeight" variable evaluates to 480 in GDB at this point, which seems correct
- 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];
- int out_size = avcodec_encode_video(codecContext, encodeBuffer, frameSize, currentPicture);
- // the "out_size" variable evaluates to 4 in GDB, which seems incorrect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement