mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-25 00:32:31 +00:00
examples/encoding.c: use av_image_alloc() for allocating an image buffer
Simplify.
This commit is contained in:
parent
2420763638
commit
2e5a9e580c
@ -205,7 +205,7 @@ static void video_encode_example(const char *filename)
|
|||||||
int i, out_size, size, x, y, outbuf_size;
|
int i, out_size, size, x, y, outbuf_size;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
AVFrame *picture;
|
AVFrame *picture;
|
||||||
uint8_t *outbuf, *picture_buf;
|
uint8_t *outbuf;
|
||||||
|
|
||||||
printf("Video encoding\n");
|
printf("Video encoding\n");
|
||||||
|
|
||||||
@ -245,15 +245,11 @@ static void video_encode_example(const char *filename)
|
|||||||
/* alloc image and output buffer */
|
/* alloc image and output buffer */
|
||||||
outbuf_size = 100000;
|
outbuf_size = 100000;
|
||||||
outbuf = malloc(outbuf_size);
|
outbuf = malloc(outbuf_size);
|
||||||
size = c->width * c->height;
|
|
||||||
picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
|
|
||||||
|
|
||||||
picture->data[0] = picture_buf;
|
/* the image can be allocated by any means and av_image_alloc() is
|
||||||
picture->data[1] = picture->data[0] + size;
|
* just the most convenient way if av_malloc() is to be used */
|
||||||
picture->data[2] = picture->data[1] + size / 4;
|
av_image_alloc(picture->data, picture->linesize,
|
||||||
picture->linesize[0] = c->width;
|
c->width, c->height, c->pix_fmt, 1);
|
||||||
picture->linesize[1] = c->width / 2;
|
|
||||||
picture->linesize[2] = c->width / 2;
|
|
||||||
|
|
||||||
/* encode 1 second of video */
|
/* encode 1 second of video */
|
||||||
for(i=0;i<25;i++) {
|
for(i=0;i<25;i++) {
|
||||||
@ -296,11 +292,11 @@ static void video_encode_example(const char *filename)
|
|||||||
outbuf[3] = 0xb7;
|
outbuf[3] = 0xb7;
|
||||||
fwrite(outbuf, 1, 4, f);
|
fwrite(outbuf, 1, 4, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(picture_buf);
|
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
|
|
||||||
avcodec_close(c);
|
avcodec_close(c);
|
||||||
av_free(c);
|
av_free(c);
|
||||||
|
av_free(picture->data[0]);
|
||||||
av_free(picture);
|
av_free(picture);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user