fftools/ffmpeg_mux: use a dedicated packet for BSF output

Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
This commit is contained in:
Anton Khirnov 2023-05-31 11:45:13 +02:00
parent c803b36b8f
commit 96e1325d91
2 changed files with 8 additions and 2 deletions

View File

@ -351,7 +351,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
} }
while (!bsf_eof) { while (!bsf_eof) {
ret = av_bsf_receive_packet(ms->bsf_ctx, pkt); ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
if (ret == AVERROR(EAGAIN)) if (ret == AVERROR(EAGAIN))
return; return;
else if (ret == AVERROR_EOF) else if (ret == AVERROR_EOF)
@ -361,7 +361,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
goto fail; goto fail;
} }
ret = submit_packet(mux, bsf_eof ? NULL : pkt, ost); ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost);
if (ret < 0) if (ret < 0)
goto mux_fail; goto mux_fail;
} }
@ -656,6 +656,10 @@ static int bsf_init(MuxStream *ms)
return ret; return ret;
ost->st->time_base = ctx->time_base_out; ost->st->time_base = ctx->time_base_out;
ms->bsf_pkt = av_packet_alloc();
if (!ms->bsf_pkt)
return AVERROR(ENOMEM);
return 0; return 0;
} }
@ -856,6 +860,7 @@ static void ost_free(OutputStream **post)
avcodec_parameters_free(&ost->par_in); avcodec_parameters_free(&ost->par_in);
av_bsf_free(&ms->bsf_ctx); av_bsf_free(&ms->bsf_ctx);
av_packet_free(&ms->bsf_pkt);
av_packet_free(&ost->pkt); av_packet_free(&ost->pkt);
av_dict_free(&ost->encoder_opts); av_dict_free(&ost->encoder_opts);

View File

@ -44,6 +44,7 @@ typedef struct MuxStream {
AVFifo *muxing_queue; AVFifo *muxing_queue;
AVBSFContext *bsf_ctx; AVBSFContext *bsf_ctx;
AVPacket *bsf_pkt;
EncStats stats; EncStats stats;