[01/10] avconv: Flush output BSFs when stream copy reaches EOF

Message ID 20170507223519.11880-2-sw@jkqxz.net
State Superseded
Headers show

Commit Message

Mark Thompson May 7, 2017, 10:35 p.m.
Same as f64d1100a54d12c78ce436181bb64229c56da6b3, for stream copy
rather than encode.
---
 avtools/avconv.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Luca Barbato May 7, 2017, 10:59 p.m. | #1
On 5/8/17 12:35 AM, Mark Thompson wrote:
> Same as f64d1100a54d12c78ce436181bb64229c56da6b3, for stream copy
> rather than encode.
> ---
>  avtools/avconv.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/avtools/avconv.c b/avtools/avconv.c
> index 2e218e96c..719d289ff 100644
> --- a/avtools/avconv.c
> +++ b/avtools/avconv.c
> @@ -1127,6 +1127,12 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
>      int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
>      AVPacket opkt;
>  
> +    // EOF: flush output bitstream filters.
> +    if (!pkt) {
> +        output_packet(of, &opkt, ost, 1);
> +        return;
> +    }
> +
>      av_init_packet(&opkt);
>  
>      if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
> @@ -1590,7 +1596,7 @@ static void process_input_packet(InputStream *ist, const AVPacket *pkt, int no_e
>              break;
>          }
>      }
> -    for (i = 0; pkt && i < nb_output_streams; i++) {
> +    for (i = 0; i < nb_output_streams; i++) {
>          OutputStream *ost = output_streams[i];
>  
>          if (!check_output_constraints(ist, ost) || ost->encoding_needed)
> @@ -2779,7 +2785,7 @@ static int transcode(void)
>      /* at the end of stream, we must flush the decoder buffers */
>      for (i = 0; i < nb_input_streams; i++) {
>          ist = input_streams[i];
> -        if (!input_files[ist->file_index]->eof_reached && ist->decoding_needed) {
> +        if (!input_files[ist->file_index]->eof_reached) {
>              process_input_packet(ist, NULL, 0);
>          }
>      }
> 

This should get in w/out much controversy I guess.

Patch

diff --git a/avtools/avconv.c b/avtools/avconv.c
index 2e218e96c..719d289ff 100644
--- a/avtools/avconv.c
+++ b/avtools/avconv.c
@@ -1127,6 +1127,12 @@  static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
     int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
     AVPacket opkt;
 
+    // EOF: flush output bitstream filters.
+    if (!pkt) {
+        output_packet(of, &opkt, ost, 1);
+        return;
+    }
+
     av_init_packet(&opkt);
 
     if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
@@ -1590,7 +1596,7 @@  static void process_input_packet(InputStream *ist, const AVPacket *pkt, int no_e
             break;
         }
     }
-    for (i = 0; pkt && i < nb_output_streams; i++) {
+    for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
 
         if (!check_output_constraints(ist, ost) || ost->encoding_needed)
@@ -2779,7 +2785,7 @@  static int transcode(void)
     /* at the end of stream, we must flush the decoder buffers */
     for (i = 0; i < nb_input_streams; i++) {
         ist = input_streams[i];
-        if (!input_files[ist->file_index]->eof_reached && ist->decoding_needed) {
+        if (!input_files[ist->file_index]->eof_reached) {
             process_input_packet(ist, NULL, 0);
         }
     }