Advertisement
Guest User

Untitled

a guest
May 10th, 2010
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. codec = avcodec_find_encoder(CODEC_ID_MSMPEG4V1);
  2.  
  3. if (!codec)
  4. {
  5.     NSLog("Couldn't init codec");
  6.     abort();
  7. }
  8.  
  9. codecContext = avcodec_alloc_context();
  10. codecContext->bit_rate = 384000;
  11. codecContext->width = FRAME_WIDTH;
  12. codecContext->height = FRAME_HEIGHT;
  13. codecContext->time_base = (AVRational) {
  14.     1,
  15.     FPS
  16. };
  17.  
  18. codecContext->pix_fmt = PIX_FMT_YUV420P;
  19.  
  20. int codec_open_result = avcodec_open(codecContext, codec);
  21.  
  22. if (codec_open_result < 0)
  23. {
  24.     NSLog(@"Couldn't open codec");
  25.     abort();
  26. }
  27.  
  28. /* previously defined
  29. #define FRAME_WIDTH  320
  30. #define FRAME_HEIGHT 480
  31. */
  32.  
  33. uint8_t *rgb_data = buffer + (frameSize * ((*totalCaptured - 1) % BUFFER_FRAME_MAX_COUNT));
  34.  
  35. uint8_t *rgb_src[3] = {
  36.     rgb_data,
  37.     NULL,
  38.     NULL
  39. };
  40.  
  41. int rgb_stride[3] = {
  42.     4 * FRAME_WIDTH,
  43.     0,
  44.     0
  45. };
  46.  
  47. uint8_t *src[4] = {
  48.     scaleBuffer,
  49.     scaleBuffer + FRAME_WIDTH * FRAME_HEIGHT,
  50.     scaleBuffer + ( FRAME_WIDTH * FRAME_HEIGHT ) + ( FRAME_WIDTH * FRAME_HEIGHT / 4 ),
  51.     NULL
  52. };
  53.  
  54. int stride[4] = {
  55.     FRAME_WIDTH,
  56.     FRAME_WIDTH / 2,
  57.     FRAME_WIDTH / 2,
  58.     0
  59. };
  60.  
  61. struct SwsContext *sws;
  62.  
  63. sws = sws_getContext(FRAME_WIDTH,       // src width
  64.                      FRAME_HEIGHT,      // src height
  65.                      PIX_FMT_RGB32,     // src pixel format ,
  66.                      FRAME_WIDTH,       // dest width
  67.                      FRAME_HEIGHT,      // dest height
  68.                      PIX_FMT_YUV420P,   // dest pix format
  69.                      SWS_BILINEAR,      // FLAGS
  70.                      NULL,  
  71.                      NULL,
  72.                      NULL);
  73.  
  74.  
  75. int sliceHeight = sws_scale(sws,
  76.                             rgb_src,
  77.                             rgb_stride,
  78.                             0,
  79.                             FRAME_HEIGHT,
  80.                             src,
  81.                             stride);
  82.                            
  83. // the "sliceHeight" variable evaluates to 480 in GDB at this point, which seems correct
  84.  
  85. if (sliceHeight <= 0)
  86. {
  87.     NSLog(@"couldn't scale");
  88.     abort();
  89. }
  90.  
  91. sws_freeContext(sws);
  92.  
  93. currentPicture->data[0] = src[0];
  94. currentPicture->data[1] = src[1];
  95. currentPicture->data[2] = src[2];
  96. currentPicture->data[3] = src[3];
  97.  
  98. currentPicture->linesize[0] = stride[0];
  99. currentPicture->linesize[1] = stride[1];
  100. currentPicture->linesize[2] = stride[2];
  101. currentPicture->linesize[3] = stride[3];
  102.  
  103. int out_size = avcodec_encode_video(codecContext, encodeBuffer, frameSize, currentPicture);
  104.  
  105. // the "out_size" variable evaluates to 4 in GDB, which seems incorrect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement