[Libav-user] Encoding a screenshot into a video using FFMPEG

phuze koj phuze9 at gmail.com
Mon Apr 15 03:45:38 CEST 2013


I've made some progress, here is the new code that sort-of works:

for(i=0;i<77;i++) {
        fflush(stdout);

uint8_t *pPixels = new uint8_t[screenWidth*screenHeight*(32 >> 3)];
pPixels = screenCap(); //getting the screenshot by the same method posted
earlier

int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height);
uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes*sizeof(uint8_t));

outpic->pts = (int64_t)((float)i * (1000.0/((float)(c->time_base.den))) *
90);
avpicture_fill((AVPicture*)inpic, pPixels, PIX_FMT_RGB32, c->width,
c->height); // Fill picture with image
 avpicture_fill((AVPicture*)outpic, outbuffer, PIX_FMT_YUV420P, c->width,
c->height);
av_image_alloc(outpic->data,outpic->linesize,c->width,c->height,c->pix_fmt,1);

inpic->data[0] += inpic->linesize[0]*(screenHeight-1); // Flipping frame
inpic->linesize[0] = -inpic->linesize[0]; // Flipping frame
struct SwsContext* fooContext = sws_getContext(c->width, c->height,
PIX_FMT_RGB32, c->width, c->height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR,
NULL, NULL, NULL);
sws_scale(fooContext, inpic->data, inpic->linesize, 0, c->height,
outpic->data, outpic->linesize);
printf("Image scaled\n");

        // encode the image
        out_size = avcodec_encode_video(c, outbuf, outbuf_size, outpic);
        printf("Encoding frame %3d (size=%5d)\n", i, out_size);
        fwrite(outbuf, 1, out_size, f);
delete [] pPixels;
}

This is giving me *some *output, but not quite usable still. Here is a
picture <http://i.imgur.com/Hqgta3L.png> of the new code's output video,
which shows the console (and should have visual studio behind it). Does
this gray background indicate that I'm using the wrong input pixel format
for the screenshot?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130414/5829f371/attachment.html>


More information about the Libav-user mailing list