1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-06-04 05:57:49 +02:00

Merge commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802'

* commit '59ab9e8ba1df7e3347a4cd2bd56c32e74aede802':
  examples/encode_video: allocate the packet dynamically

Merged-by: Clément Bœsch <cboesch@gopro.com>
This commit is contained in:
Clément Bœsch 2017-04-04 11:48:23 +02:00
commit 6db36a0227

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv)
int i, ret, x, y; int i, ret, x, y;
FILE *f; FILE *f;
AVFrame *frame; AVFrame *frame;
AVPacket pkt; AVPacket *pkt;
uint8_t endcode[] = { 0, 0, 1, 0xb7 }; uint8_t endcode[] = { 0, 0, 1, 0xb7 };
if (argc <= 2) { if (argc <= 2) {
@ -96,6 +96,10 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
pkt = av_packet_alloc();
if (!pkt)
exit(1);
/* put sample parameters */ /* put sample parameters */
c->bit_rate = 400000; c->bit_rate = 400000;
/* resolution must be a multiple of two */ /* resolution must be a multiple of two */
@ -147,10 +151,6 @@ int main(int argc, char **argv)
/* 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);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
fflush(stdout); fflush(stdout);
/* make sure the frame data is writable */ /* make sure the frame data is writable */
@ -177,11 +177,11 @@ int main(int argc, char **argv)
frame->pts = i; frame->pts = i;
/* encode the image */ /* encode the image */
encode(c, frame, &pkt, f); encode(c, frame, pkt, f);
} }
/* flush the encoder */ /* flush the encoder */
encode(c, NULL, &pkt, f); encode(c, NULL, pkt, f);
/* add sequence end code to have a real MPEG file */ /* add sequence end code to have a real MPEG file */
fwrite(endcode, 1, sizeof(endcode), f); fwrite(endcode, 1, sizeof(endcode), f);
@ -189,6 +189,7 @@ int main(int argc, char **argv)
avcodec_free_context(&c); avcodec_free_context(&c);
av_frame_free(&frame); av_frame_free(&frame);
av_packet_free(&pkt);
return 0; return 0;
} }