Skip to content

Commit

Permalink
Add provision to customize how extracted images are named
Browse files Browse the repository at this point in the history
Summary:
Expose new option to customize image names during image extraction, so customization is possible while preserving the current/default behavior.
meta:
The visionlib part of vrstool can now set VRStoolCommands' extractedImagesImageNamer to customize file naming in a new command line option.

Reviewed By: davidhahnfb, kiminoue7

Differential Revision: D51444581

fbshipit-source-id: 4732a98e643e7dcbdc3baf8dfd75754bd994e545
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Nov 28, 2023
1 parent fdf4399 commit da0a9b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions vrs/utils/cli/DataExtraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ using namespace std;

namespace vrs::utils {

void extractImages(const string& path, FilteredFileReader& filteredReader, bool extractImagesRaw) {
void extractImages(
const string& path,
FilteredFileReader& filteredReader,
bool extractImagesRaw,
ImageNamer* imageNamer) {
if (path.length() > 0) {
os::makeDirectories(path);
}
ImageNamer defaultImageNamer;
if (imageNamer == nullptr) {
imageNamer = &defaultImageNamer;
}
imageNamer->init(filteredReader.reader);
uint32_t imageCounter = 0;
deque<unique_ptr<StreamPlayer>> extractors;
for (auto id : filteredReader.filter.streams) {
if (filteredReader.reader.mightContainImages(id)) {
extractors.emplace_back(make_unique<ImageExtractor>(path, imageCounter, extractImagesRaw));
extractors.emplace_back(
make_unique<ImageExtractor>(*imageNamer, path, imageCounter, extractImagesRaw));
filteredReader.reader.setStreamPlayer(id, extractors.back().get());
}
}
Expand Down
6 changes: 5 additions & 1 deletion vrs/utils/cli/DataExtraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@

namespace vrs::utils {

class ImageNamer;

/// Helper for cli tool to extract images from a VRS file into image files.
/// Streams containing no images will be ignored.
/// @param folderPath: path to a folder where to extract the files
/// @param filteredReader: filtered reader for the file to read from.
/// @param extractImagesRaw: if true, raw images will be saved as ".raw" files with no processing,
/// otherwise, raw images will be saved as png files, even if that means that a pixel format
/// conversion is performed.
/// @param imageNamer: an optional helper to customize how extracted images are named.
/// @return A status code, 0 meaning success.
void extractImages(
const std::string& path,
FilteredFileReader& filteredReader,
bool extractImagesRaw = false);
bool extractImagesRaw = false,
ImageNamer* imageNamer = nullptr);

/// Helper for cli tool to extract raw audio streams from a VRS file into WAV files.
/// Streams containing no audio will be ignored.
Expand Down

0 comments on commit da0a9b5

Please sign in to comment.