Before this, output bitstream filters would never see EOF and
therefore would not be able to flush any delayed packets.
---
On 14/03/17 15:51, wm4 wrote:
> I haven't looked at the avconv code, but is it really necessary to
> (I assume) duplicate all the BSF filter data flow code just for
> draining?
How about this?
avtools/avconv.c | 71 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 43 insertions(+), 28 deletions(-)
diff --git a/avtools/avconv.c b/avtools/avconv.c
index 5c36761c1..1d29f0886 100644
--- a/avtools/avconv.c
+++ b/avtools/avconv.c
@@ -359,40 +359,42 @@ static void write_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost)
}
}
-static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+static void apply_bsf(OutputFile *of, AVPacket *input_pkt,
+ OutputStream *ost, int input_idx)
{
- int ret = 0;
+ AVPacket pkt;
+ int ret, idx;
- /* apply the output bitstream filters, if any */
- if (ost->nb_bitstream_filters) {
- int idx;
+ av_init_packet(&pkt);
+ pkt.data = NULL;
+ pkt.size = 0;
- ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);
- if (ret < 0)
+ ret = av_bsf_send_packet(ost->bsf_ctx[input_idx], input_pkt);
+ if (ret < 0)
+ goto finish;
+
+ idx = input_idx + 1;
+ while (idx > input_idx) {
+ /* get a packet from the previous filter up the chain */
+ ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], &pkt);
+ if (ret == AVERROR(EAGAIN)) {
+ ret = 0;
+ idx--;
+ continue;
+ } else if (ret == AVERROR(EOF) && idx - 1 == input_idx) {
+ break;
+ } else if (ret < 0)
goto finish;
- idx = 1;
- while (idx) {
- /* get a packet from the previous filter up the chain */
- ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
- if (ret == AVERROR(EAGAIN)) {
- ret = 0;
- idx--;
- continue;
- } else if (ret < 0)
+ /* send it to the next filter down the chain or to the muxer */
+ if (idx < ost->nb_bitstream_filters) {
+ ret = av_bsf_send_packet(ost->bsf_ctx[idx], &pkt);
+ if (ret < 0)
goto finish;
-
- /* send it to the next filter down the chain or to the muxer */
- if (idx < ost->nb_bitstream_filters) {
- ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);
- if (ret < 0)
- goto finish;
- idx++;
- } else
- write_packet(of, pkt, ost);
- }
- } else
- write_packet(of, pkt, ost);
+ idx++;
+ } else
+ write_packet(of, &pkt, ost);
+ }
finish:
if (ret < 0 && ret != AVERROR_EOF) {
@@ -402,6 +404,15 @@ finish:
}
}
+static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+{
+ /* apply the output bitstream filters, if any */
+ if (ost->nb_bitstream_filters)
+ apply_bsf(of, pkt, ost, 0);
+ else
+ write_packet(of, pkt, ost);
+}
+
static int check_recording_time(OutputStream *ost)
{
OutputFile *of = output_files[ost->file_index];
@@ -1083,6 +1094,10 @@ static void flush_encoders(void)
fprintf(ost->logfile, "%s", enc->stats_out);
}
if (ret == AVERROR_EOF) {
+ int idx;
+ for (idx = 0; idx < ost->nb_bitstream_filters; idx++)
+ apply_bsf(of, NULL, ost, idx);
+
stop_encoding = 1;
break;
}
--
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel