reverted some of the video stuff. will do it myself soon
This commit is contained in:
@@ -9,12 +9,10 @@
|
|||||||
#include "../util/output/aviwriter.hpp"
|
#include "../util/output/aviwriter.hpp"
|
||||||
#include "../util/output/bmpwriter.hpp"
|
#include "../util/output/bmpwriter.hpp"
|
||||||
#include "../util/timing_decorator.cpp"
|
#include "../util/timing_decorator.cpp"
|
||||||
#include "../util/output/frame.hpp"
|
|
||||||
#include "../util/output/video.hpp"
|
|
||||||
|
|
||||||
struct AnimationConfig {
|
struct AnimationConfig {
|
||||||
int width = 1024;
|
int width = 256;
|
||||||
int height = 1024;
|
int height = 256;
|
||||||
int totalFrames = 480;
|
int totalFrames = 480;
|
||||||
float fps = 30.0f;
|
float fps = 30.0f;
|
||||||
int numSeeds = 8;
|
int numSeeds = 8;
|
||||||
@@ -72,6 +70,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector<std::tuple<siz
|
|||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
std::vector<std::tuple<size_t, Vec2, Vec4>> newseeds;
|
std::vector<std::tuple<size_t, Vec2, Vec4>> newseeds;
|
||||||
|
|
||||||
|
|
||||||
std::unordered_set<size_t> visitedThisFrame;
|
std::unordered_set<size_t> visitedThisFrame;
|
||||||
for (const auto& seed : seeds) {
|
for (const auto& seed : seeds) {
|
||||||
visitedThisFrame.insert(std::get<0>(seed));
|
visitedThisFrame.insert(std::get<0>(seed));
|
||||||
@@ -89,6 +88,7 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector<std::tuple<siz
|
|||||||
}
|
}
|
||||||
visitedThisFrame.insert(neighbor);
|
visitedThisFrame.insert(neighbor);
|
||||||
|
|
||||||
|
|
||||||
Vec2 neipos = grid.getPositionID(neighbor);
|
Vec2 neipos = grid.getPositionID(neighbor);
|
||||||
Vec4 neighborColor = grid.getColor(neighbor);
|
Vec4 neighborColor = grid.getColor(neighbor);
|
||||||
float distance = seedPOS.distance(neipos);
|
float distance = seedPOS.distance(neipos);
|
||||||
@@ -115,56 +115,56 @@ void expandPixel(Grid2& grid, AnimationConfig config, std::vector<std::tuple<siz
|
|||||||
seeds = std::move(newseeds);
|
seeds = std::move(newseeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
bool exportavi(std::vector<std::vector<uint8_t>> frames, AnimationConfig config) {
|
||||||
AnimationConfig config;
|
TIME_FUNCTION;
|
||||||
|
std::string filename = "output/chromatic_transformation.avi";
|
||||||
|
|
||||||
Grid2 grid = setup(config);
|
std::cout << "Frame count: " << frames.size() << std::endl;
|
||||||
Preview(grid);
|
std::cout << "Frame size: " << (frames.empty() ? 0 : frames[0].size()) << std::endl;
|
||||||
std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid,config);
|
std::cout << "Width: " << config.width << ", Height: " << config.height << std::endl;
|
||||||
|
|
||||||
// Create video object with BGR channels and configured FPS
|
std::filesystem::path dir = "output";
|
||||||
video vid(config.width+1, config.height+1, {'B', 'G', 'R'}, config.fps, true);
|
if (!std::filesystem::exists(dir)) {
|
||||||
|
if (!std::filesystem::create_directories(dir)) {
|
||||||
for (int i = 0; i < config.totalFrames; ++i){
|
std::cout << "Failed to create output directory!" << std::endl;
|
||||||
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
return false;
|
||||||
expandPixel(grid,config,seeds);
|
}
|
||||||
|
|
||||||
frame outputFrame;
|
|
||||||
grid.getGridAsFrame(outputFrame, {'B', 'G', 'R'});
|
|
||||||
|
|
||||||
// Add frame to video (this will compress it using RLE + differential encoding)
|
|
||||||
vid.add_frame(outputFrame);
|
|
||||||
|
|
||||||
// Optional: Print compression stats every 50 frames
|
|
||||||
// if ((i + 1) % 50 == 0) {
|
|
||||||
// auto stats = vid.get_compression_stats();
|
|
||||||
// std::cout << "Frame " << (i + 1) << " - Compression ratio: " << stats.overall_ratio
|
|
||||||
// << ", Total compressed: " << stats.total_compressed_bytes << " bytes" << std::endl;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the video-based AVIWriter overload
|
bool success = AVIWriter::saveAVI(filename, frames, config.width+1, config.height+1, config.fps);
|
||||||
bool success = AVIWriter::saveAVI("output/chromatic_transformation.avi", vid, config.fps);
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// Print final compression statistics
|
// Check if file actually exists
|
||||||
auto final_stats = vid.get_compression_stats();
|
if (std::filesystem::exists(filename)) {
|
||||||
std::cout << "Successfully saved AVI with " << vid.frame_count() << " frames" << std::endl;
|
auto file_size = std::filesystem::file_size(filename);
|
||||||
std::cout << "Final compression statistics:" << std::endl;
|
}
|
||||||
std::cout << " Total frames: " << final_stats.total_frames << std::endl;
|
|
||||||
std::cout << " Video duration: " << final_stats.video_duration << " seconds" << std::endl;
|
|
||||||
std::cout << " Uncompressed size: " << final_stats.total_uncompressed_bytes << " bytes" << std::endl;
|
|
||||||
std::cout << " Compressed size: " << final_stats.total_compressed_bytes << " bytes" << std::endl;
|
|
||||||
std::cout << " Overall compression ratio: " << final_stats.overall_ratio << std::endl;
|
|
||||||
std::cout << " Average frame compression ratio: " << final_stats.average_frame_ratio << std::endl;
|
|
||||||
|
|
||||||
// Optional: Save compressed video data for later use
|
|
||||||
auto serialized_data = vid.serialize();
|
|
||||||
std::cout << "Serialized video data size: " << serialized_data.size() << " bytes" << std::endl;
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Failed to save AVI file!" << std::endl;
|
std::cout << "Failed to save AVI file!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
AnimationConfig config;
|
||||||
|
|
||||||
|
Grid2 grid = setup(config);
|
||||||
|
//grid.updateNeighborMap();
|
||||||
|
Preview(grid);
|
||||||
|
std::vector<std::tuple<size_t, Vec2, Vec4>> seeds = pickSeeds(grid,config);
|
||||||
|
std::vector<std::vector<uint8_t>> frames;
|
||||||
|
|
||||||
|
for (int i = 0; i < config.totalFrames; ++i){
|
||||||
|
std::cout << "Processing frame " << i + 1 << "/" << config.totalFrames << std::endl;
|
||||||
|
expandPixel(grid,config,seeds);
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
std::vector<uint8_t> frame;
|
||||||
|
grid.getGridAsBGR(width,height,frame);
|
||||||
|
frames.push_back(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
exportavi(frames,config);
|
||||||
FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED);
|
FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user