/** * LoadVideoFileFromDir loads two video files from a directory, given a video * directory, a timestamp, and video number. * * Assigns values to left_video_capture_ and right_video_capture_ or to pgm_left_dir_ * and pgm_right_dir_ depending on stereo_config_.usePGM's value. * * @param timestamp timestamp to extract the date out of * @param video_number video number to load * * @retval frame skip amount, or -1 on failure. * */ int RecordingManager::LoadVideoFileFromDir(long long timestamp, int video_number) { // first, load the log directory std::string cpu_dir, datetime; if (hostname_.length() == 0) { std::cout << "Waiting for hostname..." << std::endl; return -1; } std::tie(cpu_dir, datetime) = GetVideoDirectory(timestamp, video_directory_); std::cout << cpu_dir << std::endl; int skip_amount = MatchVideoFile(video_directory_ + "/" + cpu_dir + "/onboard-vids/" + hostname_, datetime, stereo_config_.usePGM, video_number); // format the video number as a two-decimal value char filenumber[100]; sprintf(filenumber, "%02d", video_number); string video_number_str = filenumber; // now we have the full filename string left_video = video_directory_ + "/" + cpu_dir + "/onboard-vids/" + hostname_ + "/videoL-skip-" + to_string(skip_amount) + "-" + datetime + "." + video_number_str; string right_video = video_directory_ + "/" + cpu_dir + "/onboard-vids/" + hostname_ + "/videoR-skip-" + to_string(skip_amount) + "-" + datetime + "." + video_number_str; if (stereo_config_.usePGM == false) { left_video += ".avi"; right_video += ".avi"; } // attempt to create video capture objects if (LoadVideoFiles(left_video, right_video) == true) { printf("\nLoaded %s and %s with frame-skip: %d\n", left_video.c_str(), right_video.c_str(), skip_amount); return skip_amount; } else { return -1; } }
std::string GetMonoFilename(long timestamp, int video_number) { if (computer_number_char == 'x') { // wait for a computer number std::cout << "Waiting for hostname..." << std::endl; return ""; } char tmbuf[64], buf[64]; // figure out what time the plane thinks it is struct tm *nowtm; time_t tv_sec = timestamp / 1000000.0; nowtm = localtime(&tv_sec); strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d", nowtm); sprintf(buf, "%s", tmbuf); std::string date_str = std::string(buf); std::string dir; if (video_directory != "") { dir = video_directory; } else { dir = log_directory + GetVideoDirectory(date_str); } if (dir == "") { std::cerr << "Warning: unable to find a video file. You might consider using the -v option instead of -d." << std::endl; return ""; } boost::format formatter = boost::format(".%02d.avi") % video_number; std::string path = dir + boost::filesystem::path::preferred_separator + "onboard-vids" + boost::filesystem::path::preferred_separator + + "odroid-cam" + computer_number_char + boost::filesystem::path::preferred_separator + "mono-" + date_str + formatter.str(); return path; }