if (got_packet) {
if (pkt.pts != AV_NOPTS_VALUE)
pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
if (pkt.duration > 0)
pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
}
}
-static int bit_buffer_size = 1024 * 256;
-static uint8_t *bit_buffer = NULL;
-
#if !CONFIG_AVFILTER
static void do_video_resample(OutputStream *ost,
InputStream *ist,
for (i = 0; i < nb_frames; i++) {
AVPacket pkt;
av_init_packet(&pkt);
+ pkt.data = NULL;
+ pkt.size = 0;
if (!check_recording_time(ost))
return;
write_frame(s, &pkt, ost);
} else {
+ int got_packet;
AVFrame big_picture;
big_picture = *final_picture;
big_picture.pict_type = AV_PICTURE_TYPE_I;
ost->forced_kf_index++;
}
- ret = avcodec_encode_video(enc,
- bit_buffer, bit_buffer_size,
- &big_picture);
+ ret = avcodec_encode_video2(enc, &pkt, &big_picture, &got_packet);
if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
exit_program(1);
}
- if (ret > 0) {
- pkt.data = bit_buffer;
- pkt.size = ret;
- if (enc->coded_frame->pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ if (got_packet) {
+ if (pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
- if (enc->coded_frame->key_frame)
- pkt.flags |= AV_PKT_FLAG_KEY;
write_frame(s, &pkt, ost);
*frame_size = ret;
video_size += ret;
for (;;) {
AVPacket pkt;
- int fifo_bytes;
+ int fifo_bytes, got_packet;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
}
break;
case AVMEDIA_TYPE_VIDEO:
- ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
+ ret = avcodec_encode_video2(enc, &pkt, NULL, &got_packet);
if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
exit_program(1);
}
video_size += ret;
- if (enc->coded_frame && enc->coded_frame->key_frame)
- pkt.flags |= AV_PKT_FLAG_KEY;
if (ost->logfile && enc->stats_out) {
fprintf(ost->logfile, "%s", enc->stats_out);
}
- if (ret <= 0) {
+ if (!got_packet) {
stop_encoding = 1;
break;
}
- pkt.data = bit_buffer;
- pkt.size = ret;
- if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
+ if (pkt.pts != AV_NOPTS_VALUE)
+ pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
+ if (pkt.dts != AV_NOPTS_VALUE)
+ pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
write_frame(os, &pkt, ost);
break;
default:
}
}
}
- if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
- int size = codec->width * codec->height;
- bit_buffer_size = FFMAX(bit_buffer_size, 6 * size + 200);
- }
- }
-
- if (!bit_buffer)
- bit_buffer = av_malloc(bit_buffer_size);
- if (!bit_buffer) {
- av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n",
- bit_buffer_size);
- return AVERROR(ENOMEM);
}
/* open each encoder */
ret = 0;
fail:
- av_freep(&bit_buffer);
av_freep(&no_packet);
if (output_streams) {