- out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture);
- /* if zero size, it means the image was buffered */
- if (out_size > 0) {
- AVPacket pkt;
- av_init_packet(&pkt);
-
- if (c->coded_frame->pts != AV_NOPTS_VALUE)
- pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
- if(c->coded_frame->key_frame)
- pkt.flags |= PKT_FLAG_KEY;
- pkt.stream_index= st->index;
- pkt.data= video_outbuf;
- pkt.size= out_size;
-
- /* write the compressed frame in the media file */
+ ret = avcodec_encode_video2(c, &pkt, picture, &got_packet);
+ /* If size is zero, it means the image was buffered. */
+ if (!ret && got_packet && pkt.size) {
+ if (pkt.pts != AV_NOPTS_VALUE) {
+ pkt.pts = av_rescale_q(pkt.pts,
+ c->time_base, st->time_base);
+ }
+ if (pkt.dts != AV_NOPTS_VALUE) {
+ pkt.dts = av_rescale_q(pkt.dts,
+ c->time_base, st->time_base);
+ }
+ pkt.stream_index = st->index;
+
+ /* Write the compressed frame to the media file. */