sizeof(frame), NULL);
av_frame_free(&frame);
}
- av_fifo_free(fg->inputs[j]->frame_queue);
+ av_fifo_freep(&fg->inputs[j]->frame_queue);
if (fg->inputs[j]->ist->sub2video.sub_queue) {
while (av_fifo_size(fg->inputs[j]->ist->sub2video.sub_queue)) {
AVSubtitle sub;
&sub, sizeof(sub), NULL);
avsubtitle_free(&sub);
}
- av_fifo_free(fg->inputs[j]->ist->sub2video.sub_queue);
+ av_fifo_freep(&fg->inputs[j]->ist->sub2video.sub_queue);
}
av_buffer_unref(&fg->inputs[j]->hw_frames_ctx);
av_freep(&fg->inputs[j]->name);
}
}
-static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
{
AVFormatContext *s = of->ctx;
AVStream *st = ost->st;
int ret;
+ /*
+ * Audio encoders may split the packets -- #frames in != #packets out.
+ * But there is no reordering, so we can limit the number of output packets
+ * by simply dropping them here.
+ * Counting encoded video frames needs to be done separately because of
+ * reordering, see do_video_out().
+ * Do not count the packet when unqueued because it has been counted when queued.
+ */
+ if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) {
+ if (ost->frame_number >= ost->max_frames) {
+ av_packet_unref(pkt);
+ return;
+ }
+ ost->frame_number++;
+ }
+
if (!of->header_written) {
AVPacket tmp_pkt = {0};
/* the muxer is not initialized yet, buffer the packet */
(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
pkt->pts = pkt->dts = AV_NOPTS_VALUE;
- /*
- * Audio encoders may split the packets -- #frames in != #packets out.
- * But there is no reordering, so we can limit the number of output packets
- * by simply dropping them here.
- * Counting encoded video frames needs to be done separately because of
- * reordering, see do_video_out()
- */
- if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {
- if (ost->frame_number >= ost->max_frames) {
- av_packet_unref(pkt);
- return;
- }
- ost->frame_number++;
- }
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
int i;
uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
goto finish;
idx++;
} else
- write_packet(of, pkt, ost);
+ write_packet(of, pkt, ost, 0);
}
} else
- write_packet(of, pkt, ost);
+ write_packet(of, pkt, ost, 0);
finish:
if (ret < 0 && ret != AVERROR_EOF) {
!ost->filters &&
next_picture &&
ist &&
- lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) {
- duration = lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base));
+ lrintf(next_picture->pkt_duration * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) {
+ duration = lrintf(next_picture->pkt_duration * av_q2d(ist->st->time_base) / av_q2d(enc->time_base));
}
if (!next_picture) {
break;
case AVMEDIA_TYPE_AUDIO:
if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
- enc->channels != av_frame_get_channels(filtered_frame)) {
+ enc->channels != filtered_frame->channels) {
av_log(NULL, AV_LOG_ERROR,
"Audio filter graph output is not normalized and encoder does not support parameter changes\n");
break;
if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
continue;
- avcodec_send_frame(enc, NULL);
-
for (;;) {
const char *desc = NULL;
AVPacket pkt;
pkt.size = 0;
update_benchmark(NULL);
- ret = avcodec_receive_packet(enc, &pkt);
+
+ while ((ret = avcodec_receive_packet(enc, &pkt)) == AVERROR(EAGAIN)) {
+ ret = avcodec_send_frame(enc, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
+ desc,
+ av_err2str(ret));
+ exit_program(1);
+ }
+ }
+
update_benchmark("flush_%s %d.%d", desc, ost->file_index, ost->index);
if (ret < 0 && ret != AVERROR_EOF) {
av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n",
exit_program(1);
if (exit_on_error && *got_output && ist) {
- if (av_frame_get_decode_error_flags(ist->decoded_frame) || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
+ if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
av_log(NULL, AV_LOG_FATAL, "%s: corrupt decoded frame in stream %d\n", input_files[ist->file_index]->ctx->filename, ist->st->index);
exit_program(1);
}
ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, AV_BUFFERSRC_FLAG_PUSH);
if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error while filtering\n");
+ if (ret != AVERROR_EOF)
+ av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret));
return ret;
}
}
ist->hwaccel_retrieved_pix_fmt = decoded_frame->format;
- best_effort_timestamp= av_frame_get_best_effort_timestamp(decoded_frame);
+ best_effort_timestamp= decoded_frame->best_effort_timestamp;
if (ist->framerate.num)
best_effort_timestamp = ist->cfr_next_pts++;
while (av_fifo_size(ost->muxing_queue)) {
AVPacket pkt;
av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
- write_packet(of, &pkt, ost);
+ write_packet(of, &pkt, ost, 1);
}
}