[FFmpeg-devel] [PATCH 04/44] avformat/mux: Move ff_choose_timebase to nutenc, its only user

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat May 7 14:27:50 EEST 2022


(This function does not seem to abide by its documentation.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavformat/internal.h |  9 ---------
 libavformat/mux.c      | 15 ---------------
 libavformat/nutenc.c   | 22 +++++++++++++++++++++-
 3 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 5ffc26600a..715e3ce33f 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -765,15 +765,6 @@ int ff_is_intra_only(enum AVCodecID id);
  */
 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
 
-/**
- * Chooses a timebase for muxing the specified stream.
- *
- * The chosen timebase allows sample accurate timestamps based
- * on the framerate or sample rate for audio streams. It also is
- * at least as precise as 1/min_precision would be.
- */
-AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision);
-
 /**
  * Chooses a timebase for muxing the specified stream.
  */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index f1ae1c874e..cfcfa600df 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -89,21 +89,6 @@ static void frac_add(FFFrac *f, int64_t incr)
     f->num = num;
 }
 
-AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision)
-{
-    AVRational q;
-
-    q = st->time_base;
-
-    for (int j = 2; j < 14; j += 1 + (j > 2))
-        while (q.den / q.num < min_precision && q.num % j == 0)
-            q.num /= j;
-    while (q.den / q.num < min_precision && q.den < (1<<24))
-        q.den <<= 1;
-
-    return q;
-}
-
 enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st)
 {
     AVCodecParameters *par = st->codecpar;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index d8c35783ae..0cea1fabb3 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -36,6 +36,26 @@
 #include "riff.h"
 #include "version.h"
 
+/**
+ * Chooses a timebase for muxing the specified stream.
+ *
+ * The chosen timebase allows sample accurate timestamps based
+ * on the framerate or sample rate for audio streams. It also is
+ * at least as precise as 1/min_precision would be.
+ */
+static AVRational choose_timebase(AVFormatContext *s, AVStream *st, int min_precision)
+{
+    AVRational q = st->time_base;
+
+    for (int j = 2; j < 14; j += 1 + (j > 2))
+        while (q.den / q.num < min_precision && q.num % j == 0)
+            q.num /= j;
+    while (q.den / q.num < min_precision && q.den < (1<<24))
+        q.den <<= 1;
+
+    return q;
+}
+
 static int find_expected_header(AVCodecParameters *p, int size, int key_frame,
                                 uint8_t out[64])
 {
@@ -728,7 +748,7 @@ static int nut_write_header(AVFormatContext *s)
         if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) {
             time_base = (AVRational) {1, st->codecpar->sample_rate};
         } else {
-            time_base = ff_choose_timebase(s, st, 48000);
+            time_base = choose_timebase(s, st, 48000);
         }
 
         avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
-- 
2.32.0



More information about the ffmpeg-devel mailing list