* Video encoding example */
| 198 | * Video encoding example |
| 199 | */ |
| 200 | static void video_encode_example(const char *filename) |
| 201 | { |
| 202 | AVCodec *codec; |
| 203 | AVCodecContext *c= NULL; |
| 204 | int i, out_size, size, x, y, outbuf_size; |
| 205 | FILE *f; |
| 206 | AVFrame *picture; |
| 207 | uint8_t *outbuf, *picture_buf; |
| 208 | |
| 209 | printf("Video encoding\n"); |
| 210 | |
| 211 | /* find the mpeg1 video encoder */ |
| 212 | codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); |
| 213 | if (!codec) { |
| 214 | fprintf(stderr, "codec not found\n"); |
| 215 | exit(1); |
| 216 | } |
| 217 | |
| 218 | c= avcodec_alloc_context(); |
| 219 | picture= avcodec_alloc_frame(); |
| 220 | |
| 221 | /* put sample parameters */ |
| 222 | c->bit_rate = 400000; |
| 223 | /* resolution must be a multiple of two */ |
| 224 | c->width = 352; |
| 225 | c->height = 288; |
| 226 | /* frames per second */ |
| 227 | c->time_base= (AVRational){1,25}; |
| 228 | c->gop_size = 10; /* emit one intra frame every ten frames */ |
| 229 | c->max_b_frames=1; |
| 230 | c->pix_fmt = PIX_FMT_YUV420P; |
| 231 | |
| 232 | /* open it */ |
| 233 | if (avcodec_open(c, codec) < 0) { |
| 234 | fprintf(stderr, "could not open codec\n"); |
| 235 | exit(1); |
| 236 | } |
| 237 | |
| 238 | f = fopen(filename, "wb"); |
| 239 | if (!f) { |
| 240 | fprintf(stderr, "could not open %s\n", filename); |
| 241 | exit(1); |
| 242 | } |
| 243 | |
| 244 | /* alloc image and output buffer */ |
| 245 | outbuf_size = 100000; |
| 246 | outbuf = malloc(outbuf_size); |
| 247 | size = c->width * c->height; |
| 248 | picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */ |
| 249 | |
| 250 | picture->data[0] = picture_buf; |
| 251 | picture->data[1] = picture->data[0] + size; |
| 252 | picture->data[2] = picture->data[1] + size / 4; |
| 253 | picture->linesize[0] = c->width; |
| 254 | picture->linesize[1] = c->width / 2; |
| 255 | picture->linesize[2] = c->width / 2; |
| 256 | |
| 257 | /* encode 1 second of video */ |
no test coverage detected