aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-05-07 05:46:40 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-05-10 07:46:53 +0200
commit217f2bfb493e3546c3de9e267dd538d8c09f4174 (patch)
tree7612f4ee60296646d0575a0de0fd2a6ccd80954d
parentb516302cfe8bf6ca6983a1b36f24c8f2487f718a (diff)
downloadffmpeg-217f2bfb493e3546c3de9e267dd538d8c09f4174.tar.gz
avformat/utils: Move internal stream timebase stuff to avformat.c
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavformat/avformat.c66
-rw-r--r--libavformat/utils.c65
2 files changed, 66 insertions, 65 deletions
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 0b86ff025c..ac0e28a6a9 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -20,6 +20,8 @@
*/
#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
@@ -254,3 +256,67 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
return;
}
}
+
+int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
+ AVStream *ost, const AVStream *ist,
+ enum AVTimebaseSource copy_tb)
+{
+ const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
+ AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
+
+ enc_ctx->time_base = ist->time_base;
+ /*
+ * Avi is a special case here because it supports variable fps but
+ * having the fps and timebase differe significantly adds quite some
+ * overhead
+ */
+ if (!strcmp(ofmt->name, "avi")) {
+#if FF_API_R_FRAME_RATE
+ if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
+ && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
+ && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
+ && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
+ && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
+ || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
+ enc_ctx->time_base.num = ist->r_frame_rate.den;
+ enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
+ enc_ctx->ticks_per_frame = 2;
+ } else
+#endif
+ if (copy_tb == AVFMT_TBCF_AUTO && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->time_base)
+ && av_q2d(ist->time_base) < 1.0/500
+ || copy_tb == AVFMT_TBCF_DECODER) {
+ enc_ctx->time_base = dec_ctx->time_base;
+ enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
+ enc_ctx->time_base.den *= 2;
+ enc_ctx->ticks_per_frame = 2;
+ }
+ } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
+ && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
+ if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->time_base.den
+ && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > av_q2d(ist->time_base)
+ && av_q2d(ist->time_base) < 1.0/500
+ || copy_tb == AVFMT_TBCF_DECODER) {
+ enc_ctx->time_base = dec_ctx->time_base;
+ enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
+ }
+ }
+
+ if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
+ && dec_ctx->time_base.num < dec_ctx->time_base.den
+ && dec_ctx->time_base.num > 0
+ && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
+ enc_ctx->time_base = dec_ctx->time_base;
+ }
+
+ av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
+ enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
+
+ return 0;
+}
+
+AVRational av_stream_get_codec_timebase(const AVStream *st)
+{
+ // See avformat_transfer_internal_stream_timing_info() TODO.
+ return cffstream(st)->avctx->time_base;
+}
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3267db432e..f5d24e7a3a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -28,7 +28,6 @@
#include "libavutil/bprint.h"
#include "libavutil/dict.h"
#include "libavutil/internal.h"
-#include "libavutil/intreadwrite.h"
#include "libavutil/pixfmt.h"
#include "libavutil/thread.h"
#include "libavutil/time.h"
@@ -1079,70 +1078,6 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf
return 0;
}
-int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
- AVStream *ost, const AVStream *ist,
- enum AVTimebaseSource copy_tb)
-{
- const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
- AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
-
- enc_ctx->time_base = ist->time_base;
- /*
- * Avi is a special case here because it supports variable fps but
- * having the fps and timebase differe significantly adds quite some
- * overhead
- */
- if (!strcmp(ofmt->name, "avi")) {
-#if FF_API_R_FRAME_RATE
- if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
- && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
- && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
- && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
- && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
- || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
- enc_ctx->time_base.num = ist->r_frame_rate.den;
- enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
- enc_ctx->ticks_per_frame = 2;
- } else
-#endif
- if (copy_tb == AVFMT_TBCF_AUTO && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->time_base)
- && av_q2d(ist->time_base) < 1.0/500
- || copy_tb == AVFMT_TBCF_DECODER) {
- enc_ctx->time_base = dec_ctx->time_base;
- enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
- enc_ctx->time_base.den *= 2;
- enc_ctx->ticks_per_frame = 2;
- }
- } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
- && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
- if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->time_base.den
- && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > av_q2d(ist->time_base)
- && av_q2d(ist->time_base) < 1.0/500
- || copy_tb == AVFMT_TBCF_DECODER) {
- enc_ctx->time_base = dec_ctx->time_base;
- enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
- }
- }
-
- if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
- && dec_ctx->time_base.num < dec_ctx->time_base.den
- && dec_ctx->time_base.num > 0
- && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
- enc_ctx->time_base = dec_ctx->time_base;
- }
-
- av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
- enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
-
- return 0;
-}
-
-AVRational av_stream_get_codec_timebase(const AVStream *st)
-{
- // See avformat_transfer_internal_stream_timing_info() TODO.
- return cffstream(st)->avctx->time_base;
-}
-
void ff_format_set_url(AVFormatContext *s, char *url)
{
av_assert0(url);