[FFmpeg-cvslog] fftools/ffmpeg_mux: simplify calling of_output_packet()

Anton Khirnov git at videolan.org
Mon Jun 5 17:31:25 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed May 31 11:52:45 2023 +0200| [f94957e8f4416e09e9530ef071929edb598a7d78] | committer: Anton Khirnov

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f94957e8f4416e09e9530ef071929edb598a7d78
---

 fftools/ffmpeg.c     |  2 +-
 fftools/ffmpeg.h     | 13 +------------
 fftools/ffmpeg_enc.c |  6 +++---
 fftools/ffmpeg_mux.c | 14 +++++++-------
 4 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9997881572..d62ccc56c9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -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);
             }
         }
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 49c07ede95..890081edb4 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -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
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1515ca971f..8dd8104cea 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -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);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 485f499971..879a291ba9 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -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;
 }



More information about the ffmpeg-cvslog mailing list