Advertisement
Guest User

Untitled

a guest
Mar 31st, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. int resizeFrame(int colorspace, int width, int height, AVFrame *frame) {
  2.   AVFrame *newFrame = NULL;
  3.   newFrame = avcodec_alloc_frame();
  4.   if(frame == NULL)
  5.     return -1;
  6.  
  7.   int numBytes = avpicture_get_size(colorspace, width, height);
  8.   uint8_t *buffer = NULL;
  9.   buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
  10.   avpicture_fill((AVPicture *)newFrame, buffer, colorspace, width, height);
  11.  
  12.   newFrame->width = width;
  13.   newFrame->height = height;
  14.   newFrame->format = colorspace;
  15.  
  16.   struct SwsContext *resizeContext = NULL;
  17.   resizeContext = sws_getContext (
  18.     frame->width,
  19.     frame->height,
  20.     frame->format,
  21.     newFrame->width,
  22.     newFrame->height,
  23.     newFrame->format,
  24.     SWS_SPLINE,
  25.     NULL,
  26.     NULL,
  27.     NULL
  28.   );
  29.  
  30.   int linesWritten = sws_scale (
  31.     resizeContext,
  32.     (uint8_t const * const *)frame->data,
  33.     frame->linesize,
  34.     0,
  35.     newFrame->height,
  36.     newFrame->data,
  37.     newFrame->linesize
  38.   );
  39.  
  40.   printf("Lines Written: %i\n", linesWritten);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement