b)流程
//查找编码器
codec = avcodec_find_encoder(codec_id);
//分配编码器结构体
c = avcodec_alloc_context3(codec);
/设置编码器参数
c->bit_rate = 400000;
c->width = 352;
c->height = 288;
c->time_base= (AVRational){1,25};
c->gop_size = 10;
c->max_b_frames=1;
c->pix_fmt = AV_PIX_FMT_YUV420P;
av_opt_set(c->priv_data, "preset", "slow", 0);
avcodec_open2(c, codec, NULL)
f = fopen(filename, "wb");
frame = avcodec_alloc_frame();
frame->format = c->pix_fmt;
frame->width = c->width;
frame->height = c->height;
ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,c->pix_fmt, 32);
av_init_packet(&pkt);
fflush(stdout);
ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
fwrite(endcode, 1, sizeof(endcode), f);
fclose(f);
avcodec_close(c);
av_free(c);
av_freep(&frame->data[0]);
avcodec_free_frame(&frame);