Skip to content

Commit

Permalink
fix handling videos with spaces in filename
Browse files Browse the repository at this point in the history
Video conversion failed at multiple points due to filenames being split
at whitespace. This commit fixes all the failure points I was able to
identify.

resolves #116
  • Loading branch information
gangelop authored and Psycojoker committed Oct 12, 2020
1 parent 9cbcc3f commit 82d43f6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions prosopopee/prosopopee.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def ffmpeg(self, source, target, options):
warning("Generation", source)

if options.get("resize"):
command = "{binary} {loglevel} -i {source} {resize} -vframes 1 -y {target}".format(**ffmpeg_switches)
command = "{binary} {loglevel} -i '{source}' {resize} -vframes 1 -y '{target}'".format(**ffmpeg_switches)
else:
command = "{binary} {loglevel} -i {source} {video} {vbitrate} {other} {audio} {abitrate} {resolution} {format} -y {target}".format(**ffmpeg_switches)
command = "{binary} {loglevel} -i '{source}' {video} {vbitrate} {other} {audio} {abitrate} {resolution} {format} -y '{target}'".format(**ffmpeg_switches)
print(command)
error(os.system(command) == 0, "%s command failed" % ffmpeg_switches["binary"])

Expand Down Expand Up @@ -155,8 +155,13 @@ def ratio(self):
binary = "ffprobe"
else:
binary = "avprobe"
command = binary + " -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 " + self.base_dir.joinpath(self.name)
out = subprocess.check_output(command.split())
target = self.base_dir.joinpath(self.name)
command = binary + " -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0"
command_list = command.split()
# target is Type path.Path, encodes to bytes, decodes to str, which we can append to the list
# disgusting, I know. But it works
command_list.append(target.encode().decode())
out = subprocess.check_output(command_list)
width, height = out.decode("utf-8").split(',')
return float(width) / int(height)

Expand Down Expand Up @@ -198,7 +203,7 @@ def ffmpeg(self, source, target, options):

warning("Generation", source)

command = "{binary} {loglevel} -i {source} {audio} -y {target}".format(**ffmpeg_switches)
command = "{binary} {loglevel} -i '{source}' {audio} -y '{target}'".format(**ffmpeg_switches)
print(command)
error(os.system(command) == 0, "%s command failed" % ffmpeg_switches["binary"])

Expand Down

0 comments on commit 82d43f6

Please sign in to comment.