Skip to content

Commit 2de4464

Browse files
updated framerate to be the time between ProcessFrame calls instead of within a call
1 parent d964e5e commit 2de4464

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Samples/StyleTransfer/VideoEffect/StyleTransferEffectCpp/StyleTransferEffect.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ namespace winrt::StyleTransferEffectCpp::implementation
3333
outputTransformed.Close();
3434
}
3535

36+
3637
void StyleTransferEffect::ProcessFrame(ProcessVideoFrameContext context) {
37-
// Play around with dropping frames so as to not overwhelm when processing slowly
38-
if ((frameNum + 1) % 5 == 0) {
39-
frameNum = 0;
40-
OutputDebugString(L"Drop");
41-
return;
38+
auto now = std::chrono::high_resolution_clock::now();
39+
std::chrono::milliseconds timePassed;
40+
// If the first time calling ProcessFrame, just start the timer
41+
if (firstProcessFrameCall) {
42+
m_StartTime = now;
43+
firstProcessFrameCall = false;
4244
}
45+
// On the second and any proceding process,
46+
else {
47+
timePassed = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_StartTime);
48+
m_StartTime = now;
49+
Notifier.SetFrameRate(1000.f / timePassed.count()); // Convert to FPS: milli to seconds, invert
50+
}
51+
4352
OutputDebugString(L"PF Start | ");
44-
auto startSync = std::chrono::high_resolution_clock::now();
4553

4654
VideoFrame inputFrame = context.InputFrame();
4755
VideoFrame outputFrame = context.OutputFrame();
@@ -55,10 +63,7 @@ namespace winrt::StyleTransferEffectCpp::implementation
5563
Session.Evaluate(Binding, L"test");
5664
outputTransformed.CopyToAsync(outputFrame).get();
5765

58-
auto syncTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startSync);
59-
Notifier.SetFrameRate(1000.f / syncTime.count()); // Convert to FPS: milli to seconds, invert
6066
OutputDebugString(L"PF End\n ");
61-
frameNum++;
6267
}
6368

6469
void StyleTransferEffect::SetEncodingProperties(VideoEncodingProperties props, IDirect3DDevice device) {

Samples/StyleTransfer/VideoEffect/StyleTransferEffectCpp/StyleTransferEffect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace winrt::StyleTransferEffectCpp::implementation
3636
VideoEncodingProperties encodingProperties;
3737
std::mutex Processing;
3838
StyleTransferEffectNotifier Notifier;
39-
int frameNum = 0;
39+
std::chrono::time_point<std::chrono::steady_clock> m_StartTime;
40+
bool firstProcessFrameCall = true;
4041
};
4142
}
4243

0 commit comments

Comments
 (0)