| 92 | } |
| 93 | |
| 94 | static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, |
| 95 | FILE *output) |
| 96 | { |
| 97 | int ret; |
| 98 | |
| 99 | /* send the frame for encoding */ |
| 100 | ret = avcodec_send_frame(ctx, frame); |
| 101 | if (ret < 0) { |
| 102 | fprintf(stderr, "Error sending the frame to the encoder\n"); |
| 103 | exit(1); |
| 104 | } |
| 105 | |
| 106 | /* read all the available output packets (in general there may be any |
| 107 | * number of them */ |
| 108 | while (ret >= 0) { |
| 109 | ret = avcodec_receive_packet(ctx, pkt); |
| 110 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) |
| 111 | return; |
| 112 | else if (ret < 0) { |
| 113 | fprintf(stderr, "Error encoding audio frame\n"); |
| 114 | exit(1); |
| 115 | } |
| 116 | |
| 117 | fwrite(pkt->data, 1, pkt->size, output); |
| 118 | av_packet_unref(pkt); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | int main(int argc, char **argv) |
| 123 | { |
no test coverage detected