22
33ImageReader::ImageReader () {}
44void ImageReader::start () {
5- std::filesystem::remove_all (cachePath);
6- std::filesystem::create_directory (cachePath);
7- std::string command = " ffmpeg -y -i " + inputVideo
8- + " -vf \" select=not(mod(n\\ ,30))\" -vsync vfr -q:v 2 "
9- + cachePath + " /img_%05d.png" ;
5+ try {
6+ if (std::filesystem::exists (cachePath))
7+ std::filesystem::remove_all (cachePath);
8+ std::filesystem::create_directory (cachePath);
9+ } catch (const std::exception &e) {
10+ std::cout << e.what () << " \n " ;
11+ }
12+
13+ std::filesystem::path fullPath = cachePath / " img_%05d.png" ;
14+
15+ std::string command = ffmpegName + " -y -i \" " + inputVideo.string ()
16+ + " \" -vf \" fps=1\" -q:v 2 \" " + fullPath.string ()
17+ + " \" " ;
1018 CommandRunner runner;
1119 runner.runCommand (command);
1220 while (runner.readable ()) {
@@ -16,7 +24,7 @@ void ImageReader::start() {
1624
1725 outFile.open (outputPath, std::ios::binary | std::ios::out);
1826
19- std::vector<std::string > paths;
27+ std::vector<std::filesystem::path > paths;
2028 for (const auto &p : std::filesystem::directory_iterator (cachePath)) {
2129 if (p.path ().extension () == " .png" ) {
2230 paths.push_back (p.path ());
@@ -32,9 +40,9 @@ void ImageReader::start() {
3240 outFile.close ();
3341}
3442
35- void ImageReader::readImage (const std::string &path) {
43+ void ImageReader::readImage (const std::filesystem::path &path) {
3644 int w, h, n;
37- unsigned char *data = stbi_load (path.c_str (), &w, &h, &n, 1 );
45+ unsigned char *data = stbi_load (path.string (). c_str (), &w, &h, &n, 1 );
3846
3947 auto getPixel = [&data, w](size_t x, size_t y) {
4048 size_t i = y * w + x;
@@ -64,6 +72,9 @@ void ImageReader::readImage(const std::string &path) {
6472 free (data);
6573}
6674
67- void ImageReader::setInputFile (const std::string &path) { inputVideo = path; }
68- void ImageReader::setOutputFile (const std::string &path) { outputPath = path; }
69-
75+ void ImageReader::setInputFile (const std::filesystem::path &path) {
76+ inputVideo = path;
77+ }
78+ void ImageReader::setOutputFile (const std::filesystem::path &path) {
79+ outputPath = path;
80+ }
0 commit comments