30 #include <boost/program_options.hpp>
33 #include <opencv2/core/core.hpp>
49 void init_args(
int argc,
char* argv[], std::string& description,
bool& help,
bool& progress, std::filesystem::path& in_path, std::filesystem::path& out_path);
57 void convert(
const std::filesystem::path& in,
const std::filesystem::path& out,
bool print_progress);
61 main(
int argc,
char* argv[])
63 std::string description =
"";
64 const std::string usage =
"Usage: cvtrec input_file output_file\n"
65 " input_file: Path to input file\n"
66 " output_file: Path to output file";
68 bool progress =
false;
69 std::filesystem::path in_path =
"";
70 std::filesystem::path out_path =
"";
73 ::init_args(argc, argv, description, help, progress, in_path, out_path);
78 std::cout <<
"cvtrec - VisionX utility to convert recordings" << std::endl << std::endl;
79 std::cout << usage << std::endl << std::endl;
80 std::cout <<
"Example: (To convert a PNG image sequence to AVI)" << std::endl;
81 std::cout <<
" `cvtrec /path/to/img/seq/ ./videofile.avi`" << std::endl << std::endl;
82 std::cout << description << std::endl;
87 if (in_path ==
"" or out_path ==
"")
89 std::cerr << usage << std::endl;
94 if (in_path.extension() == out_path.extension())
96 std::cerr <<
"Source and target formats are the same" << std::endl;
106 catch (
const std::exception& e)
110 std::cerr << std::endl;
112 std::cerr <<
"Error while converting: " << e.what() << std::endl;
119 init_args(
int argc,
char* argv[], std::string& description,
bool& help,
bool& progress, std::filesystem::path& in_path, std::filesystem::path& out_path)
121 boost::program_options::options_description desc(
"Arguments and options");
122 boost::program_options::variables_map vm;
126 (
"help,h",
"Show this message")
127 (
"progress,p",
"Print information about the conversion progress")
128 (
"in", boost::program_options::value<std::filesystem::path>(&in_path),
"Path to input file which should be converted")
129 (
"out", boost::program_options::value<std::filesystem::path>(&out_path),
"Path to output file where the converted recording should be written to");
132 boost::program_options::positional_options_description pos;
138 boost::program_options::notify(vm);
141 std::stringstream description_stream;
142 desc.print(description_stream);
143 description = description_stream.str();
146 help = vm.find(
"help") != vm.end();
149 progress = vm.find(
"progress") != vm.end();
154 convert(
const std::filesystem::path& in,
const std::filesystem::path& out,
bool print_progress)
158 if (playback ==
nullptr)
160 throw std::runtime_error(
"Could not read input file format");
163 recording->startRecording();
164 cv::Mat frame_buffer;
165 const unsigned int frame_count = playback->getFrameCount();
168 for (
unsigned int i = 0; i < frame_count; ++i)
170 const bool success = playback->getNextFrame(frame_buffer);
173 throw std::runtime_error(
"Could not read frame");
175 recording->recordFrame(frame_buffer, std::chrono::microseconds{0});
181 std::cerr <<
"Converting... " << (i * 100 / (frame_count - 1)) <<
"%" <<
std::flush;
184 recording->stopRecording();
188 std::cerr << std::endl;