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

Use fspath to consistently support PathLike objects as input/output filenames. #700

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brianhou
Copy link

@brianhou brianhou commented Aug 21, 2022

Path-like objects were already supported by input and by output when the filename was explicitly specified as a keyword argument. (subprocess.Popen accepts path-like objects in addition to strings.) However, implicitly specifying the output filename as the last element of a list of output streams/filename did not permit a path-like object; instead, this raises a ValueError with a somewhat misleading error message.

>>> import ffmpeg
>>> from pathlib import Path
>>> ffmpeg.input("input.mp4").output("output.mp4")
output(filename='output.mp4')[None] <1fa880dddf3d>
>>> ffmpeg.input("input.mp4").output(filename="output.mp4")
output(filename='output.mp4')[None] <1fa880dddf3d>
>>> ffmpeg.input(Path("input.mp4")).output(filename="output.mp4")
output(filename='output.mp4')[None] <3105870c5a1e>
>>> ffmpeg.input(Path("input.mp4")).output(filename=Path("output.mp4"))
output(filename=PosixPath('output.mp4'))[None] <3cf3744481bb>
>>> ffmpeg.input(Path("input.mp4")).output(Path("output.mp4"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../ffmpeg/_ffmpeg.py", line 85, in output
    raise ValueError('A filename must be provided')
ValueError: A filename must be provided

This PR uses a patched version of os.fspath to explicitly convert all path-like objects to strings (or raise an error). Once support is dropped for versions before 3.6, this should be updated to use os.fspath directly.

PathLike objects were already implicitly supported by `input` and by
`output` when the filename was explicitly specified as a keyword
argument. However, implicitly setting the output filename from a list of
output streams/filename did not permit a PathLike object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant