ffmpeg | branch: master | Clément Bœsch <cboe...@gopro.com> | Tue Apr 4 11:48:23 2017 +0200| [6db36a0227656057b43ab562dcabc2aa3fb8686f] | committer: Clément Bœsch
Merge commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802' * commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802': examples/encode_video: allocate the packet dynamically Merged-by: Clément Bœsch <cboe...@gopro.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6db36a0227656057b43ab562dcabc2aa3fb8686f --- doc/examples/encode_video.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c index f29e9fb..d2075c1 100644 --- a/doc/examples/encode_video.c +++ b/doc/examples/encode_video.c @@ -71,7 +71,7 @@ int main(int argc, char **argv) int i, ret, x, y; FILE *f; AVFrame *frame; - AVPacket pkt; + AVPacket *pkt; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; if (argc <= 2) { @@ -96,6 +96,10 @@ int main(int argc, char **argv) exit(1); } + pkt = av_packet_alloc(); + if (!pkt) + exit(1); + /* put sample parameters */ c->bit_rate = 400000; /* resolution must be a multiple of two */ @@ -147,10 +151,6 @@ int main(int argc, char **argv) /* encode 1 second of video */ for (i = 0; i < 25; i++) { - av_init_packet(&pkt); - pkt.data = NULL; // packet data will be allocated by the encoder - pkt.size = 0; - fflush(stdout); /* make sure the frame data is writable */ @@ -177,11 +177,11 @@ int main(int argc, char **argv) frame->pts = i; /* encode the image */ - encode(c, frame, &pkt, f); + encode(c, frame, pkt, f); } /* flush the encoder */ - encode(c, NULL, &pkt, f); + encode(c, NULL, pkt, f); /* add sequence end code to have a real MPEG file */ fwrite(endcode, 1, sizeof(endcode), f); @@ -189,6 +189,7 @@ int main(int argc, char **argv) avcodec_free_context(&c); av_frame_free(&frame); + av_packet_free(&pkt); return 0; } ====================================================================== diff --cc doc/examples/encode_video.c index f29e9fb,cb12836..d2075c1 --- a/doc/examples/encode_video.c +++ b/doc/examples/encode_video.c @@@ -70,12 -68,12 +70,12 @@@ int main(int argc, char **argv AVCodecContext *c= NULL; int i, ret, x, y; FILE *f; - AVFrame *picture; + AVFrame *frame; - AVPacket pkt; + AVPacket *pkt; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; - if (argc <= 1) { - fprintf(stderr, "Usage: %s <output file>\n", argv[0]); + if (argc <= 2) { + fprintf(stderr, "Usage: %s <output file> <codec name>\n", argv[0]); exit(0); } filename = argv[1]; @@@ -91,11 -88,12 +91,15 @@@ } c = avcodec_alloc_context3(codec); - picture = av_frame_alloc(); + if (!c) { + fprintf(stderr, "Could not allocate video codec context\n"); + exit(1); + } + pkt = av_packet_alloc(); + if (!pkt) + exit(1); + /* put sample parameters */ c->bit_rate = 400000; /* resolution must be a multiple of two */ @@@ -146,11 -130,7 +150,7 @@@ } /* encode 1 second of video */ - for(i=0;i<25;i++) { + for (i = 0; i < 25; i++) { - av_init_packet(&pkt); - pkt.data = NULL; // packet data will be allocated by the encoder - pkt.size = 0; - fflush(stdout); /* make sure the frame data is writable */ @@@ -174,10 -154,10 +174,10 @@@ } } - picture->pts = i; + frame->pts = i; /* encode the image */ - encode(c, frame, &pkt, f); - encode(c, picture, pkt, f); ++ encode(c, frame, pkt, f); } /* flush the encoder */ @@@ -188,7 -168,8 +188,8 @@@ fclose(f); avcodec_free_context(&c); - av_frame_free(&picture); + av_frame_free(&frame); + av_packet_free(&pkt); return 0; } _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog