Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: pal@sandflow.com
To: ffmpeg-devel@ffmpeg.org
Cc: Pierre-Anthony Lemieux <pal@palemieux.com>
Subject: [FFmpeg-devel] [PATCH v3 4/7] avformat/seek: add ff_rescale_interval() function
Date: Mon,  7 Mar 2022 14:15:39 -0800
Message-ID: <20220307221542.3265-4-pal@sandflow.com> (raw)
In-Reply-To: <20220307221542.3265-1-pal@sandflow.com>

From: Pierre-Anthony Lemieux <pal@palemieux.com>

Refactors a function used by avformat/concat and avformat/imf.

---
 libavformat/avio_internal.h | 21 +++++++++++++++++++++
 libavformat/seek.c          | 10 ++++++++++
 2 files changed, 31 insertions(+)

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 1f5e3d474b..ef2ec7864f 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -23,6 +23,7 @@
 #include "url.h"
 
 #include "libavutil/log.h"
+#include "libavutil/rational.h"
 
 extern const AVClass ff_avio_class;
 
@@ -281,4 +282,24 @@ int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp);
 int64_t ff_read_string_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp,
                                            int64_t max_len);
 
+/**
+ * Rescales a timestamp and the endpoints of an interval to which the temstamp
+ * belongs, from a timebase `tb_in` to a timebase `tb_out`.
+ *
+ * The upper (lower) bound of the output interval is rounded up (down) such that
+ * the output interval always falls within the intput interval. The timestamp is
+ * rounded to the nearest integer and halfway cases away from zero, and can
+ * therefore fall outside of the output interval.
+ * 
+ * Useful to simplify the rescaling of the arguments of AVInputFormat::read_seek2()
+ *
+ * @param[in] tb_in      Timebase of the input `min_ts`, `ts` and `max_ts`
+ * @param[in] tb_out     Timebase of the ouput `min_ts`, `ts` and `max_ts`
+ * @param[in,out] min_ts Lower bound of the interval
+ * @param[in,out] ts     Timestamp
+ * @param[in,out] max_ts Upper bound of the interval
+ */
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+                         int64_t *min_ts, int64_t *ts, int64_t *max_ts);
+
 #endif /* AVFORMAT_AVIO_INTERNAL_H */
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 405ca316b3..890aea7f8a 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -751,3 +751,13 @@ int avformat_flush(AVFormatContext *s)
     ff_read_frame_flush(s);
     return 0;
 }
+
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+                         int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+    *ts     = av_rescale_q    (*    ts, tb_in, tb_out);
+    *min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
+                               AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
+    *max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
+                               AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
+}
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-03-07 22:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 22:15 [FFmpeg-devel] [PATCH v3 1/7] avformat/imf: relocate static function imf_time_to_ts() pal
2022-03-07 22:15 ` [FFmpeg-devel] [PATCH v3 2/7] avformat/imf: add support for input seeking pal
2022-03-07 22:15 ` [FFmpeg-devel] [PATCH v3 3/7] avformat/imf: clean-up and reduce logging pal
2022-03-07 22:15 ` pal [this message]
2022-03-07 22:15 ` [FFmpeg-devel] [PATCH v3 5/7] avformat/tests: add test for ff_rescale_interval() pal
2022-03-07 22:15 ` [FFmpeg-devel] [PATCH v3 6/7] avformat/imf: refactor to use ff_rescale_interval() pal
2022-03-07 22:15 ` [FFmpeg-devel] [PATCH v3 7/7] avformat/concat: " pal
2022-03-08 13:39   ` Nicolas George

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220307221542.3265-4-pal@sandflow.com \
    --to=pal@sandflow.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=pal@palemieux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git