MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode

Function encode

doc/examples/encode_video.c:39–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37#include <libavutil/imgutils.h>
38
39static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
40 FILE *outfile)
41{
42 int ret;
43
44 /* send the frame to the encoder */
45 if (frame)
46 printf("Send frame %3"PRId64"\n", frame->pts);
47
48 ret = avcodec_send_frame(enc_ctx, frame);
49 if (ret < 0) {
50 fprintf(stderr, "Error sending a frame for encoding\n");
51 exit(1);
52 }
53
54 while (ret >= 0) {
55 ret = avcodec_receive_packet(enc_ctx, pkt);
56 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
57 return;
58 else if (ret < 0) {
59 fprintf(stderr, "Error during encoding\n");
60 exit(1);
61 }
62
63 printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
64 fwrite(pkt->data, 1, pkt->size, outfile);
65 av_packet_unref(pkt);
66 }
67}
68
69int main(int argc, char **argv)
70{

Callers 1

mainFunction · 0.70

Calls 3

avcodec_send_frameFunction · 0.85
avcodec_receive_packetFunction · 0.85
av_packet_unrefFunction · 0.85

Tested by

no test coverage detected