[gegl] Replace {first, cur}_dts + Remove no-op functions & unused vars



commit 717c67bd5945598ffdd36233a0bf21e7430f1fb8
Author: Behnam Momeni <sbmomeni gmail com>
Date:   Fri Mar 4 20:34:36 2022 +0330

    Replace {first,cur}_dts + Remove no-op functions & unused vars
    
    The cur_dts and first_dts fields are moved to internal.h and the
    avformat library is supposed to use them exclusively. The cur_dts
    is the last seen packet dts, so it can be replaced by pkt.dts and
    the first_dts is the first seen packet dts, so it can be kept in
    a new p->first_dts variable after the first decoding (in video stream).
    
    The av_register_all and avcodec_register_all functions have no effect
    in the new version.
    
    The coded_frame is removed and it was used for reporting more
    information to the caller (which is not required in gegl).
    For details, check https://github.com/FFmpeg/FFmpeg/commit/11bc79089378a5ec00547d0f85bc152afdf30dfa
    
    Finally, the filename is replaced by url which is allocated dynamically
    with no size limit.

 operations/external/ff-load.c | 11 +++++++++--
 operations/external/ff-save.c | 16 +++++++++-------
 2 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
index 2f658dd8f..32d3fce91 100644
--- a/operations/external/ff-load.c
+++ b/operations/external/ff-load.c
@@ -76,11 +76,12 @@ typedef struct
   gint             height;
   gdouble          fps;
   gint             codec_delay;
+  int64_t          first_dts;
 
   gchar           *loadedfilename; /* to remember which file is "cached"     */
 
   AVFormatContext *audio_fcontext;
-  AVCodec         *audio_codec;
+  const AVCodec   *audio_codec;
   int              audio_index;
   GList           *audio_track;
   long             audio_cursor_pos;
@@ -95,7 +96,7 @@ typedef struct
   AVCodecContext  *video_ctx;
   AVStream        *audio_stream;
   AVCodecContext  *audio_ctx;
-  AVCodec         *video_codec;
+  const AVCodec   *video_codec;
   AVFrame         *lavc_frame;
   AVFrame         *rgb_frame;
   glong            prevframe;      /* previously decoded frame number */
@@ -381,6 +382,8 @@ decode_frame (GeglOperation *operation,
             }
           while (ret == 0)
             {
+              if (!p->first_dts)
+                p->first_dts = pkt.dts;
               ret = avcodec_receive_frame (p->video_ctx, p->lavc_frame);
               if (ret == AVERROR(EAGAIN))
                 {
@@ -397,8 +400,12 @@ decode_frame (GeglOperation *operation,
               got_picture = 1;
               if ((pkt.dts == pkt.pts) || (p->lavc_frame->key_frame!=0))
                 {
+                  // cur_dts and first_dts are moved to libavformat/internal.h
+                  /*
                   p->lavc_frame->pts = (p->video_stream->cur_dts -
                                         p->video_stream->first_dts);
+                  */
+                  p->lavc_frame->pts = pkt.dts - p->first_dts;
                   p->prevpts =  av_rescale_q (p->lavc_frame->pts,
                                               p->video_stream->time_base,
                                               AV_TIME_BASE_Q) * 1.0 / AV_TIME_BASE;
diff --git a/operations/external/ff-save.c b/operations/external/ff-save.c
index a34f9fac9..f6edd3921 100644
--- a/operations/external/ff-save.c
+++ b/operations/external/ff-save.c
@@ -251,8 +251,6 @@ init (GeglProperties *o)
 
   if (!inited)
     {
-      av_register_all ();
-      avcodec_register_all ();
       inited = 1;
     }
 
@@ -877,7 +875,7 @@ write_video_frame (GeglProperties *o,
   else
 #endif
     {
-      int got_packet = 0;
+      // int got_packet = 0;
       int key_frame = 0;
       ret = avcodec_send_frame (c, picture_ptr);
       while (ret == 0)
@@ -901,8 +899,10 @@ write_video_frame (GeglProperties *o,
               break;
             }
           // out_size = 0;
-          got_packet = 1;
+          // got_packet = 1;
           key_frame = !!(pkt2.flags & AV_PKT_FLAG_KEY);
+      // coded_frame is removed by 
https://github.com/FFmpeg/FFmpeg/commit/11bc79089378a5ec00547d0f85bc152afdf30dfa
+      /*
       if (!out_size && got_packet && c->coded_frame)
         {
           c->coded_frame->pts       = pkt2.pts;
@@ -910,6 +910,7 @@ write_video_frame (GeglProperties *o,
           if (c->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY)
               c->coded_frame->pict_type = AV_PICTURE_TYPE_I;
         }
+      */
           if (pkt2.side_data_elems > 0)
             {
               int i;
@@ -971,14 +972,15 @@ tfile (GeglProperties *o)
 
   p->oc->oformat = p->fmt;
 
-  snprintf (p->oc->filename, sizeof (p->oc->filename), "%s", o->path);
+  // The "avio_open" below fills "url" field instead of the "filename"
+  // snprintf (p->oc->filename, sizeof (p->oc->filename), "%s", o->path);
 
   p->video_st = NULL;
   p->audio_st = NULL;
 
   if (strcmp (o->video_codec, "auto"))
   {
-    AVCodec *codec = avcodec_find_encoder_by_name (o->video_codec);
+    const AVCodec *codec = avcodec_find_encoder_by_name (o->video_codec);
     p->fmt->video_codec = AV_CODEC_ID_NONE;
     if (codec)
       p->fmt->video_codec = codec->id;
@@ -995,7 +997,7 @@ tfile (GeglProperties *o)
   }
   if (strcmp (o->audio_codec, "auto"))
   {
-    AVCodec *codec = avcodec_find_encoder_by_name (o->audio_codec);
+    const AVCodec *codec = avcodec_find_encoder_by_name (o->audio_codec);
     p->fmt->audio_codec = AV_CODEC_ID_NONE;
     if (codec)
       p->fmt->audio_codec = codec->id;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]