Converted all logs in main to JSON. Added framerate readout in logs

This commit is contained in:
mattmcw 2026-04-04 13:11:06 -04:00
parent 5f46252011
commit 10af93d77f
3 changed files with 15 additions and 13 deletions

View File

@ -121,7 +121,7 @@ bool FrameExtractor::open()
// Framerate in fps
AVRational fps = stream->avg_frame_rate;
d->framerate = static_cast<double>(fps.num);
d->framerate = static_cast<double>((double)fps.num / fps.den);
return true;
}
@ -244,3 +244,4 @@ void FrameExtractor::forEachFrame(FrameCallback cb)
int FrameExtractor::width() const { return d->width; }
int FrameExtractor::height() const { return d->height; }
double FrameExtractor::durationSeconds() const { return d->duration; }
double FrameExtractor::framerate() const { return d->framerate; }

View File

@ -41,7 +41,7 @@ public:
int width() const;
int height() const;
double durationSeconds() const;
double framreate() const;
double framerate() const;
private:
struct Impl;

View File

@ -40,13 +40,13 @@ int main(int argc, char* argv[])
std::cerr << "{ \"error\" : \"Output directory does not exist: " << outputDir << "\" }\n";
return 1;
}
std::cout << "{ \"Output\" : \"" << outputDir << "\" }\n";
std::cout << "{ \"output\" : \"" << outputDir << "\" }\n";
} else {
if (!platform::createTempDirectory("vfe_frames_", outputDir)) {
std::cerr << "{ \"error\" : \"Failed to create temporary directory.\" }\n";
return 1;
}
std::cout << "{ \"Output\" : \"" << outputDir << "\", \"Temporary\" : true }\n";
std::cout << "{ \"output\" : \"" << outputDir << "\", \"temporary\" : true }\n";
}
// Open video
@ -56,10 +56,11 @@ int main(int argc, char* argv[])
return 1;
}
std::cout << "{ \"Video\" : \"" << inputPath << "\" }\n"
<< "Stream duration: " << extractor.durationSeconds() << "s | "
<< "Resolution: " << extractor.width() << "x" << extractor.height() << "\n"
<< "Extracting frames...\n";
std::cout << "{ \"video\" : \"" << inputPath << "\" }\n"
<< "{ \"duration\" : " << extractor.durationSeconds() << " }\n"
<< "{ \"framerate\" : " << extractor.framerate() << " } \n"
<< "{ \"resolution\" : { \"w\" :" << extractor.width() << ", \"h\" : " << extractor.height() << " } }\n"
<< "{ \"started\" : true, \"video\" : \"" << inputPath << "\" }\n";
TiffWriter writer(outputDir);
uint64_t frameCount = 0;
@ -67,16 +68,16 @@ int main(int argc, char* argv[])
extractor.forEachFrame([&](const FrameData& frame) {
const std::string filename = writer.write(frame, frameCount);
if (filename.empty()) {
std::cerr << "Warning: failed to write frame " << frameCount << "\n";
std::cerr << "{ \"warning\" : \"Failed to write frame " << frameCount << "\" }\n";
} else if (frameCount % 100 == 0) {
std::cout << " Written frame " << frameCount
<< " -> " << filename << "\n";
std::cout << "{ \"progress\" : " << frameCount
<< ", \"file\" : " << filename << "\" }\n";
}
++frameCount;
return true; // return false to stop early
});
std::cout << "Done. Extracted " << frameCount << " frame(s) to:\n"
<< " " << outputDir << "\n";
std::cout << "{ \"completed\" : true, \"frames\" : " << frameCount << ", \"output\" : \""
<< outputDir << "\", \"video\" : \"" << inputPath << "\" }\n";
return 0;
}