| 67 | } |
| 68 | |
| 69 | int main(int argc, char **argv) |
| 70 | { |
| 71 | const char *filename, *codec_name; |
| 72 | const AVCodec *codec; |
| 73 | AVCodecContext *c= NULL; |
| 74 | int i, ret, x, y; |
| 75 | FILE *f; |
| 76 | AVFrame *frame; |
| 77 | AVPacket *pkt; |
| 78 | uint8_t endcode[] = { 0, 0, 1, 0xb7 }; |
| 79 | |
| 80 | if (argc <= 2) { |
| 81 | fprintf(stderr, "Usage: %s <output file> <codec name>\n", argv[0]); |
| 82 | exit(0); |
| 83 | } |
| 84 | filename = argv[1]; |
| 85 | codec_name = argv[2]; |
| 86 | |
| 87 | /* find the mpeg1video encoder */ |
| 88 | codec = avcodec_find_encoder_by_name(codec_name); |
| 89 | if (!codec) { |
| 90 | fprintf(stderr, "Codec '%s' not found\n", codec_name); |
| 91 | exit(1); |
| 92 | } |
| 93 | |
| 94 | c = avcodec_alloc_context3(codec); |
| 95 | if (!c) { |
| 96 | fprintf(stderr, "Could not allocate video codec context\n"); |
| 97 | exit(1); |
| 98 | } |
| 99 | |
| 100 | pkt = av_packet_alloc(); |
| 101 | if (!pkt) |
| 102 | exit(1); |
| 103 | |
| 104 | /* put sample parameters */ |
| 105 | c->bit_rate = 400000; |
| 106 | /* resolution must be a multiple of two */ |
| 107 | c->width = 352; |
| 108 | c->height = 288; |
| 109 | /* frames per second */ |
| 110 | c->time_base = (AVRational){1, 25}; |
| 111 | c->framerate = (AVRational){25, 1}; |
| 112 | |
| 113 | /* emit one intra frame every ten frames |
| 114 | * check frame pict_type before passing frame |
| 115 | * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I |
| 116 | * then gop_size is ignored and the output of encoder |
| 117 | * will always be I frame irrespective to gop_size |
| 118 | */ |
| 119 | c->gop_size = 10; |
| 120 | c->max_b_frames = 1; |
| 121 | c->pix_fmt = AV_PIX_FMT_YUV420P; |
| 122 | |
| 123 | if (codec->id == AV_CODEC_ID_H264) |
| 124 | av_opt_set(c->priv_data, "preset", "slow", 0); |
| 125 | |
| 126 | /* open it */ |
nothing calls this directly
no test coverage detected