Skip to content

Commit

Permalink
Make CFR mode actually force CFR even when the reported fps is unchanged
Browse files Browse the repository at this point in the history
Fix duration calculation for CFR mode
  • Loading branch information
myrsloik committed May 25, 2024
1 parent 76ecdd2 commit ddaac8d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
9 changes: 2 additions & 7 deletions src/avisynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,8 @@ class AvisynthVideoSource : public IClip {

if (FPSNum > 0) {
vsh::reduceRational(&FPSNum, &FPSDen);
if (VP.FPS.Den != FPSDen || VP.FPS.Num != FPSNum) {
VI.SetFPS(static_cast<int>(FPSNum), static_cast<int>(FPSDen));
VI.num_frames = std::max(1, static_cast<int>((VP.Duration * VI.fps_numerator) / VI.fps_denominator));
} else {
FPSNum = -1;
FPSDen = 1;
}
VI.SetFPS(static_cast<int>(FPSNum), static_cast<int>(FPSDen));
VI.num_frames = std::max(1, static_cast<int>((VP.Duration * VI.fps_numerator) * VP.TimeBase.ToDouble() / VI.fps_denominator + 0.5));
} else if (RFF) {
VI.num_frames = vsh::int64ToIntS(VP.NumRFFFrames);
}
Expand Down
11 changes: 3 additions & 8 deletions src/vapoursynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,9 @@ static void VS_CC CreateBestVideoSource(const VSMap *In, VSMap *Out, void *, VSC

if (D->FPSNum > 0) {
vsh::reduceRational(&D->FPSNum, &D->FPSDen);
if (VP.FPS.Den != D->FPSDen || VP.FPS.Num != D->FPSNum) {
D->VI.fpsDen = D->FPSDen;
D->VI.fpsNum = D->FPSNum;
D->VI.numFrames = std::max(1, static_cast<int>((VP.Duration * D->VI.fpsNum) / D->VI.fpsDen));
} else {
D->FPSNum = -1;
D->FPSDen = 1;
}
D->VI.fpsDen = D->FPSDen;
D->VI.fpsNum = D->FPSNum;
D->VI.numFrames = std::max(1, static_cast<int>((VP.Duration * D->VI.fpsNum) * VP.TimeBase.ToDouble() / D->VI.fpsDen + 0.5));
} else if (D->RFF) {
D->VI.numFrames = vsh::int64ToIntS(VP.NumRFFFrames);
}
Expand Down
8 changes: 6 additions & 2 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <thread>
#include <cassert>
#include <iterator>
#include <charconv>

#include "../libp2p/p2p_api.h"

Expand Down Expand Up @@ -1657,8 +1658,11 @@ void BestVideoSource::WriteTimecodes(const std::filesystem::path &TimecodeFile)
throw BestSourceException("Couldn't open timecode file for writing");

fprintf(F.get(), "# timecode format v2\n");
for (const auto &Iter : TrackIndex.Frames)
fprintf(F.get(), "%.02f\n", (Iter.PTS * VP.TimeBase.Num) / (double)VP.TimeBase.Den);
for (const auto &Iter : TrackIndex.Frames) {
char buffer[100];
auto res = std::to_chars(buffer, buffer + sizeof(buffer), (Iter.PTS * VP.TimeBase.Num) / (double)VP.TimeBase.Den, std::chars_format::fixed, 2);
fprintf(F.get(), "%s\n", std::string(buffer, res.ptr - buffer).c_str());
}
}

const BestVideoSource::FrameInfo &BestVideoSource::GetFrameInfo(int64_t N) const {
Expand Down

0 comments on commit ddaac8d

Please sign in to comment.