fftools/ffmpeg_mux: simplify calling of_output_packet()

Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
This commit is contained in:
Anton Khirnov 2023-05-31 11:52:45 +02:00
parent 96e1325d91
commit f94957e8f4
4 changed files with 12 additions and 23 deletions

View File

@ -1112,7 +1112,7 @@ static int process_input(int file_index)
OutputStream *ost = ist->outputs[oidx];
OutputFile *of = output_files[ost->file_index];
close_output_stream(ost);
of_output_packet(of, ost->pkt, ost, 1);
of_output_packet(of, ost, NULL);
}
}

View File

@ -844,18 +844,7 @@ void of_close(OutputFile **pof);
void of_enc_stats_close(void);
/*
* Send a single packet to the output, applying any bitstream filters
* associated with the output stream. This may result in any number
* of packets actually being written, depending on what bitstream
* filters are applied. The supplied packet is consumed and will be
* blank (as if newly-allocated) when this function returns.
*
* If eof is set, instead indicate EOF to all bitstream filters and
* therefore flush any delayed packets to the output. A blank packet
* must be supplied in this case.
*/
void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof);
void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt);
/**
* @param dts predicted packet dts in AV_TIME_BASE_Q

View File

@ -531,7 +531,7 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
}
pkt->dts = pkt->pts;
of_output_packet(of, pkt, ost, 0);
of_output_packet(of, ost, pkt);
}
}
@ -718,7 +718,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
av_assert0(frame); // should never happen during flushing
return 0;
} else if (ret == AVERROR_EOF) {
of_output_packet(of, pkt, ost, 1);
of_output_packet(of, ost, NULL);
return ret;
} else if (ret < 0) {
av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc);
@ -752,7 +752,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
e->packets_encoded++;
of_output_packet(of, pkt, ost, 0);
of_output_packet(of, ost, pkt);
}
av_assert0(0);

View File

@ -324,18 +324,18 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost)
return 0;
}
void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
{
Muxer *mux = mux_from_of(of);
MuxStream *ms = ms_from_ost(ost);
const char *err_msg;
int ret = 0;
if (!eof && pkt->dts != AV_NOPTS_VALUE)
if (pkt && pkt->dts != AV_NOPTS_VALUE)
ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
/* rescale timestamps to the muxing timebase */
if (!eof) {
if (pkt) {
av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
pkt->time_base = ost->mux_timebase;
}
@ -344,7 +344,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
if (ms->bsf_ctx) {
int bsf_eof = 0;
ret = av_bsf_send_packet(ms->bsf_ctx, eof ? NULL : pkt);
ret = av_bsf_send_packet(ms->bsf_ctx, pkt);
if (ret < 0) {
err_msg = "submitting a packet for bitstream filtering";
goto fail;
@ -366,7 +366,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
goto mux_fail;
}
} else {
ret = submit_packet(mux, eof ? NULL : pkt, ost);
ret = submit_packet(mux, pkt, ost);
if (ret < 0)
goto mux_fail;
}
@ -399,7 +399,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
// EOF: flush output bitstream filters.
if (!pkt) {
of_output_packet(of, opkt, ost, 1);
of_output_packet(of, ost, NULL);
return;
}
@ -453,7 +453,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts)
}
}
of_output_packet(of, opkt, ost, 0);
of_output_packet(of, ost, opkt);
ms->streamcopy_started = 1;
}