Skip to content

Commit

Permalink
Temp fix for #34 seeking to timestamp can fail
Browse files Browse the repository at this point in the history
  • Loading branch information
glenne committed Jul 13, 2024
1 parent bebd670 commit 2a18cae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
17 changes: 15 additions & 2 deletions native/ffreader/src/FFReaderAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Napi::Object nativeVideoExecutor(const Napi::CallbackInfo &info) {
}
auto file = args.Get("file").As<Napi::String>().Utf8Value();
auto frameNum = args.Get("frameNum").As<Napi::Number>().DoubleValue();
auto tsMilli = args.Get("tsMilli").As<Napi::Number>().DoubleValue();
auto tsMilli = args.Get("tsMilli").As<Napi::Number>().Int64Value();
auto ffreader = videoReaders.find(file);
if (ffreader == videoReaders.end()) {
std::cerr << "File not open opening " << file << std::endl;
Expand Down Expand Up @@ -226,8 +226,18 @@ Napi::Object nativeVideoExecutor(const Napi::CallbackInfo &info) {
if (tsMilli) {
// refine the fractional part now that we know the exact frame times
// involved.
fractionalPart = (tsMilli * 1000.0 - frameA->tsMicro) /
fractionalPart = double(tsMilli * 1000 - frameA->tsMicro) /
(frameB->tsMicro - frameA->tsMicro);
// std::cout << "tsMilli=" << tsMilli << " A ts=" << frameA->tsMicro
// << " B ts=" << frameB->tsMicro
// << " frac=" << fractionalPart << std::endl;
// std::cout << tsMilli << std::endl
// << frameA->tsMicro << std::endl
// << frameB->tsMicro << std::endl;
if (std::abs(fractionalPart) >= 1.0) {
std::cout << "Restricting fractional part to 1.0" << std::endl;
fractionalPart = 0;
}
}
if (!hasZoom || roi.width < 50) {
// std::cout << "restricting roi"
Expand All @@ -236,6 +246,9 @@ Napi::Object nativeVideoExecutor(const Napi::CallbackInfo &info) {
auto width = std::min(frameA->width, 256);
roi = {frameA->width / 2 - width / 2, 0, width, frameA->height};
}
// std::cout << "A framenum=" << frameA->frameNum
// << " B framenum=" << frameB->frameNum
// << " frac=" << fractionalPart << std::endl;
frameInfo = generateInterpolatedFrame(frameA, frameB, fractionalPart,
roi, hasZoom);
frameA->motion = frameInfo->motion;
Expand Down
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crewtimer-video-review",
"version": "1.0.3",
"version": "1.0.4",
"description": "Review finish line video and post timing data to CrewTimer.",
"license": "MIT",
"author": {
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/video/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ const VideoImage: React.FC<{ width: number; height: number }> = ({
[image, destHeight, destWidth]
);
console.log(
`frame: ${getVideoFrameNum()}, motion: ${JSON.stringify(image.motion)}`
`frame: ${getVideoFrameNum()}, motion: ${JSON.stringify(image.motion)} ${
image.width
}x${image.height}`
);

useEffect(() => {
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/video/VideoFileUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { showErrorDialog } from 'renderer/util/ErrorDialog';
import { useInitializing } from 'renderer/util/UseSettings';
import { timeToMilli } from 'renderer/util/Util';
import {
getHyperZoomFactor,
getImage,
getTimezoneOffset,
getVideoFile,
Expand Down Expand Up @@ -187,10 +188,14 @@ const doRequestVideoFrame = async ({
const startTime =
(openFileStatus.startTime + offset * 60 * 1000000) %
(24 * 60 * 60 * 1000000);
const frameNum =

let frameNum =
1 +
((tsMilli * 1000 - startTime) / delta) * (openFileStatus.numFrames - 1);

if (getHyperZoomFactor() <= 1) {
frameNum = Math.round(frameNum);
}
console.log('seeking to ' + frameNum);
seekPos = frameNum;
}
Expand Down

0 comments on commit 2a18cae

Please sign in to comment.