Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] oiiotool to be able to create output directories that don't yet exist #4598

Open
tanant opened this issue Jan 16, 2025 · 2 comments
Labels
difficulty/easy Hours-to-days for veterans, days for newcomers to the project feature request oiiotool oiiotool

Comments

@tanant
Copy link

tanant commented Jan 16, 2025

Is your feature request related to a problem? Please describe.
When running oiiotool to do some reformatting work I noticed that if I specify an output path, where the directory does not exist oiiotool will perform the operation and consume the time but then fail on the output step after the work is done.

As a trivial example:

B:\> oiiotool.exe -v -i .\inputfile.exr -o subdirectory\outputfile.exr 
oiiotool ERROR: -o : Could not open "subdirectory\outputfile.e204dc78.temp.exr" (No such file or directory)
Full command line was:
> oiiotool.exe -v -i ./inputfile.exr -o subdirectory\\outputfile.exr 

When combined with multiple operations the impact is a bit worse as I can potentially get partial completion as the stack is evaluated in order and terminates at the first error, in this case (which is slightly contrived, I admit) I'd take the source image, resize to 500px, output to a subdir, then output the jpg version of that alongside the full resolution, and finally make a jpg version from the full res.

oiiotool.exe -i .\inputfile.exr --label "source" -o outputfile.exr --resize 500x0 -o reformatted\outputfile.exr  -o outputfile.jpg -i source -o another_version.jpg

I'll get outputfile.exr, it'll then consume the time to calculate the resize and then fail on the output for the missing subdirectory and terminate at that point.

Describe the solution you'd like
I'd ideally like to pass a --make-paths flag in the same way i can pass --no-clobber so that the output stage would attempt to make the full path provided. If that failed, then behaviour as current where the remainder of the command for that frame doesn't get executed.

In the same vein it'd be nice to have a way to fast-fail if it knew the output directory wasn't there and --make-paths wasn't supplied to save on computation time and IO but due to expressions that could depend on a characteristic of the image I'm not sure this is feasible (but would be nice). Wouldn't be that much of a saving overall, but I would prefer to have an all-or-nothing for the command as partial completion is harder to detect (and since it's a behaviour change from defaults it'd probably need to go behind a flag incase people are relying on current partial behaviour)

Describe alternatives you've considered
Another option would be to pre-create directories or do a saning of the input command but I don't think this feels correct in the spirit of oiiotool. and due to the expression capability, is also I suspect fraught.

Additional context
Checked against oiiotool shipped with oiio 3.0.1 and 2.5.16, built using vcpkg and triplet x64-windows-static-release
buildinfo for completeness:

OIIO 3.0.1.0 | unknown arch?
    Build compiler: MSVS 1941 | C++17/199711
    HW features enabled at build: sse2
    No CUDA support (disabled / unavailable at build time)
Dependencies: BZip2 1.0.8, FFmpeg 7.1, fmt 11.0.2, Freetype 2.13.3, GIF 5.2.2, Imath 3.1.12, JPEG 62, JXL NONE,
    Libheif 1.19.5, libjpeg-turbo 3.1.0, LibRaw 0.21.3, libuhdr NONE, OpenColorIO 2.2.1, OpenCV 4.10.0, OpenEXR
    3.3.2, OpenGL, OpenJPEG 2.5.2, PNG 1.6.45, pybind11 2.13.6, Python3 3.11.10, Qt6 6.8.1, Robinmap, TIFF 4.7.0,
    WebP 1.5.0, ZLIB 1.3.1

and

OIIO 2.5.16.0 | unknown arch?
    Build compiler: MSVS 1941 | C++14/199711
    HW features enabled at build: sse2
Dependencies: Boost 1.86.0, BZip2 1.0.8, FFmpeg 7.1, fmt 11.0.2, Freetype 2.13.3, GIF 5.2.2, JPEG 62, Libheif
    1.19.5, libjpeg-turbo 3.1.0, LibRaw 0.21.3, OpenColorIO 2.2.1, OpenCV 4.10.0, OpenEXR 3.3.2, OpenGL, OpenJPEG
    2.5.2, PNG 1.6.45, pybind11 2.13.6, Python 3.11.10, Qt6 6.8.1, Robinmap, TIFF 4.7.0, WebP 1.5.0, ZLIB 1.3.1
@lgritz
Copy link
Collaborator

lgritz commented Jan 18, 2025

Repeating what I think you're requesting for confirmation of your intent:

  1. A new flag for oiiotool that, if set, means "output should create necessary directories specified in the output path, akin to the -p argument to mkdir"
  2. A new flag for oiiotool that, if set, prior to doing any real work, will do a pre-scan of the command line arguments looking for output names (arguments after -o that appear to be filenames), and error/exit at that point if any outputs appear to be requested in directories that don't exist or aren't writable (and perhaps, also if an output names a file that does exist but is not writable?).

@lgritz lgritz added feature request oiiotool oiiotool difficulty/easy Hours-to-days for veterans, days for newcomers to the project labels Jan 18, 2025
@tanant
Copy link
Author

tanant commented Jan 18, 2025

A new flag for oiiotool that, if set, means "output should create necessary directories specified in the output path, akin to the -p argument to mkdir"

Yep, pretty much identical to -p for mkdir

A new flag for oiiotool that, if set, prior to doing any real work, will do a pre-scan of the command line arguments looking for output names (arguments after -o that appear to be filenames), and error/exit at that point if any outputs appear to be requested in directories that don't exist or aren't writable (and perhaps, also if an output names a file that does exist but is not writable?).

Yep in general theme, but I was thinking about it on the metro just now and I'd see it as a best-efforts approach due to the weird-as-heck permutations you could get. (i.e. this one could just fall off the radar and i'd 100% understand)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/easy Hours-to-days for veterans, days for newcomers to the project feature request oiiotool oiiotool
Projects
None yet
Development

No branches or pull requests

2 participants