Hi,
I'm developing an application which tries to convert array of uiimages to video
format. As uiimages are in RGBA format and I have to convert it into YUV420P
format. So for that i'm using the following code:-
img_convert_ctx = sws_getContext(c->width, c->height,PIX_FMT_RGB32,
c->width, c->height,
c->pix_fmt,
sws_flags, NULL, NULL, NULL);
if (img_convert_ctx == NULL) {
fprintf(stderr, "Cannot initialize the conversion
context\n");
exit(1);
}
UIImage *image = [UIImage imageWithData:[frames
objectAtIndex:frame_count]];
CGImageRef imageRef = image.CGImage;
NSData *data = (NSData *)
CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
uint8_t *pixels = (uint8_t *)[data bytes];
uint8_t *pixelsR = (uint8_t *)malloc([data length]/4);
uint8_t *pixelsG = (uint8_t *)malloc([data length]/4);
uint8_t *pixelsB = (uint8_t *)malloc([data length]/4);
uint8_t *pixelsA = (uint8_t *)malloc([data length]/4);
int p = 0;
for(int i = 0; i < [data length]; i += 4)
{
int r = i ; int g = i+1; int b = i+2; int a = i+3;
pixelsR[p] = pixels[r];
pixelsG[p] = pixels[g];
pixelsB[p] = pixels[b];
pixelsA[p] = pixels[a];
p++;
}
rgbFrame->data[0] = pixelsR;
rgbFrame->data[1] = pixelsG;
rgbFrame->data[2] = pixelsB;
rgbFrame->linesize[0] = c->width;
//rgbFrame->linesize[1] = c->width;
//rgbFrame->linesize[2] = c->width;
sws_scale(img_convert_ctx, rgbFrame->data, rgbFrame->linesize,
0, c->height, picture->data,
picture->linesize);
I'm getting the video but not clear with some different colors.
I think I'm not initializing the data[0],data[1],data[2],data[3], linesize[0],
linesize[1], linesize[2], linesize[3].
Can I get the help that where i'm going wrong by rectifying me. As it is little
bit tricky.
Thanks in Advance.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user