Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • F ffmpeg-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 402
    • Issues 402
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 34
    • Merge requests 34
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Karl Kroening
  • ffmpeg-python
  • Merge requests
  • !719

Quote filenames to handle paths with spaces in commands created with `.compile()`

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Alex DeLorenzo requested to merge github/fork/alexdelorenzo/master into master Nov 17, 2022
  • Overview 0
  • Commits 3
  • Pipelines 1
  • Changes 1

Problem

ffmpeg-python's .compile() method to generate FFmpeg commands doesn't quote or escape filenames with spaces, so it will generate commands like so:

>>> ' '.join(output.compile())
ffmpeg -fflags +genpts -i /tmp/video with spaces in name.mkv \
 -acodec copy -movflags faststart -scodec copy -threads 12 -vcodec libx264 -vlevel 4.1 \
 /tmp/video with spaces in name [out].mkv -y

(Note that I edited escaped new lines into this example's output for readability, they don't exist in .compile()'s output before or after merging this pull request.)

Running that compiled command fails:

/tmp/video: No such file or directory

Solution

This pull request quotes filenames using shlex.quote() by wrapping filenames parsed by .compile()'s helper functions.

As a result, the following command can run correctly because filenames with spaces were quoted:

>>> ' '.join(output.compile())
ffmpeg -fflags +genpts -i '/tmp/video with spaces in name.mkv' \
  -acodec copy -movflags faststart -scodec copy -threads 12 -vcodec libx264 -vlevel 4.1 \
  '/tmp/video with spaces in name [out].mkv' -y

(Again, escaped new lines were just added to this example for readability, this pull request does not add them to output.)

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/alexdelorenzo/master