added some extra logging

This commit is contained in:
Yggdrasil75
2025-11-14 13:43:33 -05:00
parent ff622ec0d8
commit b6828e4582
3 changed files with 27 additions and 3 deletions

View File

@@ -114,6 +114,7 @@ private:
// Helper function to convert frame to RGB format
static std::vector<uint8_t> frameToRGB(const frame& frm) {
TIME_FUNCTION;
if (frm.empty()) {
return {};
}
@@ -179,9 +180,8 @@ private:
public:
// New method for video objects
static bool saveAVI(const std::string& filename,
const video& vid,
float fps = 0.0f) {
static bool saveAVI(const std::string& filename,const video& vid,float fps = 0.0f) {
TIME_FUNCTION;
if (vid.empty()) {
return false;
}
@@ -204,6 +204,7 @@ public:
static bool saveAVI(const std::string& filename,
const std::vector<std::vector<uint8_t>>& frames,
int width, int height, float fps = 30.0f) {
TIME_FUNCTION;
if (frames.empty() || width <= 0 || height <= 0 || fps <= 0) {
return false;
}
@@ -382,6 +383,7 @@ public:
static bool saveAVI(const std::string& filename,
const std::vector<frame>& frames,
float fps = 30.0f) {
TIME_FUNCTION;
if (frames.empty() || fps <= 0) {
return false;
}
@@ -414,6 +416,7 @@ public:
const std::vector<std::string>& frameFiles,
int width, int height,
float fps = 30.0f) {
TIME_FUNCTION;
std::vector<std::vector<uint8_t>> frames;
frames.reserve(frameFiles.size());

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <algorithm>
#include <iostream>
#include "../timing_decorator.hpp"
class video {
private:
@@ -21,6 +22,7 @@ private:
// Compress frame using differential encoding
std::vector<std::pair<uint8_t, uint32_t>> compress_with_differential(
const frame& current_frame, const frame* previous_frame = nullptr) const {
TIME_FUNCTION;
if (previous_frame == nullptr) {
// First frame - compress normally
@@ -49,6 +51,7 @@ private:
// Decompress differential frame
frame decompress_differential(const std::vector<std::pair<uint8_t, uint32_t>>& compressed_diff,
const frame& previous_frame) const {
TIME_FUNCTION;
frame diff_frame;
diff_frame.decompress_rle(compressed_diff);
@@ -108,6 +111,7 @@ public:
// Add a frame to the video sequence
void add_frame(const frame& new_frame) {
TIME_FUNCTION;
// Validate frame dimensions and channels
if (new_frame.width() != width_ || new_frame.height() != height_) {
throw std::invalid_argument("Frame dimensions must match video dimensions");
@@ -133,6 +137,7 @@ public:
// Get a specific frame
frame get_frame(size_t index) const {
TIME_FUNCTION;
if (index >= compressed_frames_.size()) {
throw std::out_of_range("Frame index out of range");
}
@@ -154,6 +159,7 @@ public:
// Get multiple frames as a sequence
std::vector<frame> get_frames(size_t start_index, size_t count) const {
TIME_FUNCTION;
if (start_index >= compressed_frames_.size()) {
throw std::out_of_range("Start index out of range");
}
@@ -189,6 +195,7 @@ public:
// Replace a frame
void replace_frame(size_t index, const frame& new_frame) {
TIME_FUNCTION;
if (index >= compressed_frames_.size()) {
throw std::out_of_range("Frame index out of range");
}
@@ -226,6 +233,7 @@ public:
// Enable/disable differential encoding
void set_differential_encoding(bool enabled) {
TIME_FUNCTION;
if (use_differential_encoding_ == enabled) {
return; // No change needed
}
@@ -246,11 +254,13 @@ public:
// Get video duration in seconds
double duration() const noexcept {
TIME_FUNCTION;
return compressed_frames_.size() / fps_;
}
// Calculate total compressed size in bytes
size_t total_compressed_size() const noexcept {
TIME_FUNCTION;
size_t total = 0;
for (const auto& compressed_frame : compressed_frames_) {
total += compressed_frame.size() * sizeof(std::pair<uint8_t, uint32_t>);
@@ -260,11 +270,13 @@ public:
// Calculate total uncompressed size in bytes
size_t total_uncompressed_size() const noexcept {
TIME_FUNCTION;
return compressed_frames_.size() * width_ * height_ * channels_.size();
}
// Calculate overall compression ratio
double overall_compression_ratio() const noexcept {
TIME_FUNCTION;
if (empty()) {
return 1.0;
}
@@ -277,6 +289,7 @@ public:
// Calculate average frame compression ratio
double average_frame_compression_ratio() const {
TIME_FUNCTION;
if (empty()) {
return 1.0;
}
@@ -292,6 +305,7 @@ public:
// Get compression statistics
struct compression_stats {
TIME_FUNCTION;
size_t total_frames;
size_t total_compressed_bytes;
size_t total_uncompressed_bytes;
@@ -301,6 +315,7 @@ public:
};
compression_stats get_compression_stats() const {
TIME_FUNCTION;
compression_stats stats;
stats.total_frames = compressed_frames_.size();
stats.total_compressed_bytes = total_compressed_size();
@@ -313,6 +328,7 @@ public:
// Extract a sub-video
video subvideo(size_t start_frame, size_t frame_count) const {
TIME_FUNCTION;
if (start_frame >= compressed_frames_.size()) {
throw std::out_of_range("Start frame out of range");
}
@@ -329,6 +345,7 @@ public:
// Append another video (must have same dimensions and channels)
void append_video(const video& other) {
TIME_FUNCTION;
if (other.width_ != width_ || other.height_ != height_ || other.channels_ != channels_) {
throw std::invalid_argument("Videos must have same dimensions and channels");
}
@@ -349,6 +366,7 @@ public:
// Save/Load functionality (basic serialization)
std::vector<uint8_t> serialize() const {
TIME_FUNCTION;
// Simple serialization format:
// [header][compressed_frame_data...]
// Header: width(4), height(4), channels_count(1), channels_data(n), fps(8), frame_count(4)
@@ -394,6 +412,7 @@ public:
// Deserialize from byte data
static video deserialize(const std::vector<uint8_t>& data) {
TIME_FUNCTION;
if (data.size() < 4 + 4 + 1 + 8 + 1 + 4) { // Minimum header size
throw std::invalid_argument("Invalid video data: too short");
}