31 #include <boost/program_options.hpp>
34 #include <opencv2/core/core.hpp>
52 std::string& description,
55 std::filesystem::path& in_path,
56 std::filesystem::path& out_path);
65 convert(
const std::filesystem::path& in,
const std::filesystem::path& out,
bool print_progress);
68 main(
int argc,
char* argv[])
70 std::string description =
"";
71 const std::string usage =
"Usage: cvtrec input_file output_file\n"
72 " input_file: Path to input file\n"
73 " output_file: Path to output file";
75 bool progress =
false;
76 std::filesystem::path in_path =
"";
77 std::filesystem::path out_path =
"";
80 ::init_args(argc, argv, description, help, progress, in_path, out_path);
85 std::cout <<
"cvtrec - VisionX utility to convert recordings" << std::endl << std::endl;
86 std::cout << usage << std::endl << std::endl;
87 std::cout <<
"Example: (To convert a PNG image sequence to AVI)" << std::endl;
88 std::cout <<
" `cvtrec /path/to/img/seq/ ./videofile.avi`" << std::endl << std::endl;
89 std::cout << description << std::endl;
94 if (in_path ==
"" or out_path ==
"")
96 std::cerr << usage << std::endl;
101 if (in_path.extension() == out_path.extension())
103 std::cerr <<
"Source and target formats are the same" << std::endl;
113 catch (
const std::exception& e)
117 std::cerr << std::endl;
119 std::cerr <<
"Error while converting: " << e.what() << std::endl;
127 std::string& description,
130 std::filesystem::path& in_path,
131 std::filesystem::path& out_path)
133 boost::program_options::options_description desc(
"Arguments and options");
134 boost::program_options::variables_map vm;
137 desc.add_options()(
"help,h",
"Show this message")(
138 "progress,p",
"Print information about the conversion progress")(
140 boost::program_options::value<std::filesystem::path>(&in_path),
141 "Path to input file which should be converted")(
143 boost::program_options::value<std::filesystem::path>(&out_path),
144 "Path to output file where the converted recording should be written to");
147 boost::program_options::positional_options_description pos;
153 boost::program_options::command_line_parser(argc, argv).options(desc).positional(pos).run(),
155 boost::program_options::notify(vm);
158 std::stringstream description_stream;
159 desc.print(description_stream);
160 description = description_stream.str();
163 help = vm.find(
"help") != vm.end();
166 progress = vm.find(
"progress") != vm.end();
170 convert(
const std::filesystem::path& in,
const std::filesystem::path& out,
bool print_progress)
174 if (playback ==
nullptr)
176 throw std::runtime_error(
"Could not read input file format");
179 recording->startRecording();
180 cv::Mat frame_buffer;
181 const unsigned int frame_count = playback->getFrameCount();
184 for (
unsigned int i = 0; i < frame_count; ++i)
186 const bool success = playback->getNextFrame(frame_buffer);
189 throw std::runtime_error(
"Could not read frame");
191 recording->recordFrame(frame_buffer, std::chrono::microseconds{0});
197 std::cerr <<
"Converting... " << (i * 100 / (frame_count - 1)) <<
"%" <<
std::flush;
200 recording->stopRecording();
204 std::cerr << std::endl;