AVPicture * picture = data;  unsigned char *src; unsigned char *dest = frame; int i, j;  int w = avctx->width; int h = avctx->height; int size = avpicture_get_size(avctx->pix_fmt, w, h);  if (size > buf_size) { return -1; }  switch(avctx->pix_fmt) { case PIX_FMT_YUV420P: for(i=0;i<3;i++) { if (i == 1) { w >>= 1; h >>= 1; } src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV422P: for(i=0;i<3;i++) { if (i == 1) { w >>= 1; } src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV444P: for(i=0;i<3;i++) { src = picture->data[i]; for(j=0;j<h;j++) { memcpy(dest, src, w); dest += w; src += picture->linesize[i]; } } break; case PIX_FMT_YUV422: src = picture->data[0]; for(j=0;j<h;j++) { memcpy(dest, src, w * 2); dest += w * 2; src += picture->linesize[0]; } break; case PIX_FMT_RGB24: case PIX_FMT_BGR24: src = picture->data[0]; for(j=0;j<h;j++) { memcpy(dest, src, w * 3); dest += w * 3; src += picture->linesize[0]; } break; default: return -1; }  return size;
return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width, avctx->height, frame, buf_size);
static int raw_encode(AVCodecContext *avctx,			    unsigned char *frame, int buf_size, void *data){	AVPicture * picture = data;    unsigned char *src;	unsigned char *dest = frame;    int i, j;	int w = avctx->width;	int h = avctx->height;	int size = avpicture_get_size(avctx->pix_fmt, w, h);    if (size > buf_size) {        return -1;    }    switch(avctx->pix_fmt) {    case PIX_FMT_YUV420P:        for(i=0;i<3;i++) {            if (i == 1) {                w >>= 1;                h >>= 1;            }            src = picture->data[i];            for(j=0;j<h;j++) {                memcpy(dest, src, w);                dest += w;                src += picture->linesize[i];            }        }        break;    case PIX_FMT_YUV422P:        for(i=0;i<3;i++) {            if (i == 1) {                w >>= 1;            }            src = picture->data[i];            for(j=0;j<h;j++) {                memcpy(dest, src, w);                dest += w;                src += picture->linesize[i];            }        }        break;    case PIX_FMT_YUV444P:        for(i=0;i<3;i++) {            src = picture->data[i];            for(j=0;j<h;j++) {                memcpy(dest, src, w);                dest += w;                src += picture->linesize[i];            }        }        break;    case PIX_FMT_YUV422:        src = picture->data[0];        for(j=0;j<h;j++) {            memcpy(dest, src, w * 2);            dest += w * 2;            src += picture->linesize[0];        }        break;    case PIX_FMT_RGB24:    case PIX_FMT_BGR24:        src = picture->data[0];        for(j=0;j<h;j++) {            memcpy(dest, src, w * 3);            dest += w * 3;            src += picture->linesize[0];        }        break;    default:        return -1;    }    return size;}