You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-11 14:30:22 +02:00
examples/encode_video: use the AVFrame API for allocating the frame
It is more efficient and so preferred over allocating the buffers manually.
This commit is contained in:
@ -88,16 +88,16 @@ int main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height,
|
|
||||||
c->pix_fmt, 32);
|
|
||||||
if (ret < 0) {
|
|
||||||
fprintf(stderr, "could not alloc raw picture buffer\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
picture->format = c->pix_fmt;
|
picture->format = c->pix_fmt;
|
||||||
picture->width = c->width;
|
picture->width = c->width;
|
||||||
picture->height = c->height;
|
picture->height = c->height;
|
||||||
|
|
||||||
|
ret = av_frame_get_buffer(picture, 32);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "could not alloc the frame data\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* encode 1 second of video */
|
/* encode 1 second of video */
|
||||||
for(i=0;i<25;i++) {
|
for(i=0;i<25;i++) {
|
||||||
av_init_packet(&pkt);
|
av_init_packet(&pkt);
|
||||||
@ -105,6 +105,12 @@ int main(int argc, char **argv)
|
|||||||
pkt.size = 0;
|
pkt.size = 0;
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
/* make sure the frame data is writable */
|
||||||
|
ret = av_frame_make_writable(picture);
|
||||||
|
if (ret < 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
/* prepare a dummy image */
|
/* prepare a dummy image */
|
||||||
/* Y */
|
/* Y */
|
||||||
for(y=0;y<c->height;y++) {
|
for(y=0;y<c->height;y++) {
|
||||||
@ -159,7 +165,6 @@ int main(int argc, char **argv)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
avcodec_free_context(&c);
|
avcodec_free_context(&c);
|
||||||
av_freep(&picture->data[0]);
|
|
||||||
av_frame_free(&picture);
|
av_frame_free(&picture);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user