diff mbox series

[FFmpeg-devel,22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding

Message ID 20230531145453.20994-22-anton@khirnov.net
State Accepted
Commit 730a2221afa6384d753fb4f22b7734efc0bef07f
Headers show
Series [FFmpeg-devel,01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 31, 2023, 2:54 p.m. UTC
The code currently uses OutputStream.pkt, which complicates its
ownership semantics.
---
 fftools/ffmpeg_enc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 8dd8104cea..2bf4782a9f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -57,6 +57,9 @@  struct Encoder {
 
     AVFrame *sq_frame;
 
+    // packet for receiving encoded output
+    AVPacket *pkt;
+
     // combined size of all the packets received from the encoder
     uint64_t data_size;
 
@@ -78,6 +81,8 @@  void enc_free(Encoder **penc)
     av_frame_free(&enc->last_frame);
     av_frame_free(&enc->sq_frame);
 
+    av_packet_free(&enc->pkt);
+
     av_freep(penc);
 }
 
@@ -97,6 +102,10 @@  int enc_alloc(Encoder **penc, const AVCodec *codec)
             goto fail;
     }
 
+    enc->pkt = av_packet_alloc();
+    if (!enc->pkt)
+        goto fail;
+
     *penc = enc;
 
     return 0;
@@ -454,10 +463,11 @@  static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb)
 
 void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
 {
+    Encoder *e = ost->enc;
     int subtitle_out_max_size = 1024 * 1024;
     int subtitle_out_size, nb, i, ret;
     AVCodecContext *enc;
-    AVPacket *pkt = ost->pkt;
+    AVPacket *pkt = e->pkt;
     int64_t pts;
 
     if (sub->pts == AV_NOPTS_VALUE) {
@@ -669,7 +679,7 @@  static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
 {
     Encoder            *e = ost->enc;
     AVCodecContext   *enc = ost->enc_ctx;
-    AVPacket         *pkt = ost->pkt;
+    AVPacket         *pkt = e->pkt;
     const char *type_desc = av_get_media_type_string(enc->codec_type);
     const char    *action = frame ? "encode" : "flush";
     int ret;