jumpcutter icon indicating copy to clipboard operation
jumpcutter copied to clipboard

Fix for paths that include spaces

Open Ebunix opened this issue 6 years ago • 7 comments

Noticed issues while trying to cut a video file that had a space in its name. Looked at the code and noticed that ffmpeg was being called without taking care of paths that could perhaps contain spaces.

Ebunix avatar Apr 17 '19 19:04 Ebunix

common on Linux to use it this way : "path with spaces"

Kingeng avatar Apr 19 '19 19:04 Kingeng

common on Linux to use it this way : "path with spaces"

Yeah, that's what I tried. Still broke since the string was passed to ffmpeg without those quotations again internally.

Ebunix avatar Apr 19 '19 19:04 Ebunix

i think you use that in iPython ,if you just run the code from terminal there is no problem any way with iPyhton just add +"+ path +"+ to the command line.

Kingeng avatar Apr 19 '19 19:04 Kingeng

If I run python.exe jumpcutter.py --input_file "C:\Some Path\ Some File.mp4" --output_file "some other file.mp4" it will fail because it can't find the input file C:\Some because that's all that gets passed to ffmpeg in the end, because no quotation marks were added to that command. The original code is this: ffmpeg -i "+INPUT_FILE+" -qscale:v "+str(FRAME_QUALITY)+" "+TEMP_FOLDER+"/frame%06d.jpg -hide_banner so if you insert the correctly quoted arguments it turns into this incorrect form: ffmpeg -i C:\Some Path\ Some File.mp4 -qscale:v "+str(FRAME_QUALITY)+" "+TEMP_FOLDER+"/frame%06d.jpg -hide_banner Obviously without correct quotations.

Ebunix avatar Apr 19 '19 20:04 Ebunix

test it on windows, same problem :+1: replace all INPUT_FILE in commands to '"'+INPUT_FILE+'"' same for OUTPUT_FILE

this will correct it

Kingeng avatar Apr 19 '19 22:04 Kingeng

I think it would actually be better to pass the arguments as a list as it will make the code cleaner (in my opinion) and wouldn't break if the filename had a ".

For example:

command = ["ffmpeg", "-i", INPUT_FILE, "-qscale:v", str(FRAME_QUALITY), TEMP_FOLDER+"/frame%06d.jpg", "-hide_banner"]
rc = subprocess.run(command)
if rc.returncode != 0:
    print(rc)
exit(rc.returncode)

Would replace the lines

command = "ffmpeg -i "+INPUT_FILE+" -qscale:v "+str(FRAME_QUALITY)+" "+TEMP_FOLDER+"/frame%06d.jpg -hide_banner"
subprocess.call(command, shell=True)

alvierahman90 avatar Apr 22 '19 15:04 alvierahman90

Nice, I didn't know about that way of calling processes. Learned something new and changed the code to include those changes. It's way cleaner that way for sure.

Ebunix avatar Apr 23 '19 17:04 Ebunix