Before this, output bitstream filters would never see EOF and
therefore would not be able to flush any delayed packets.
---
No longer has the packet on the stack.
avtools/avconv.c | 75 +++++++++++++++++++++++++++++++++++---------------------
1 file changed, 47 insertions(+), 28 deletions(-)
diff --git a/avtools/avconv.c b/avtools/avconv.c
index 5c36761c1..50498b2f3 100644
--- a/avtools/avconv.c
+++ b/avtools/avconv.c
@@ -359,40 +359,44 @@ static void write_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost)
}
}
-static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+static void apply_bsfs(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;
+ pkt = av_packet_alloc();
+ if (!pkt) {
+ ret = AVERROR(ENOMEM);
+ goto finish;
+ }
- 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) {
@@ -400,6 +404,17 @@ finish:
"packet for stream #%d:%d.\n", ost->file_index, ost->index);
exit_program(1);
}
+
+ av_packet_free(&pkt);
+}
+
+static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+{
+ /* apply the output bitstream filters, if any */
+ if (ost->nb_bitstream_filters)
+ apply_bsfs(of, pkt, ost, 0);
+ else
+ write_packet(of, pkt, ost);
}
static int check_recording_time(OutputStream *ost)
@@ -1083,6 +1098,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_bsfs(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