video_transcoding: Can't (directly) copy commands from detect-crop on Windows

First, a big “thank you” for the time and effort you’ve put into these scripts – they’ve been producing great results for me ever since I found them.

One minor annoyance I’ve come across, though, is that when I’m using Windows to detect crop values, I can’t directly copy and paste the preview commands out of the detect-crop output.

detect-crop produces commands that look like this:

mpv --no-audio --vf 'lavfi=[drawbox=10:0:704:576:invert:1]' Some\ File\ With\ Spaces.mkv

but cmd.exe doesn’t support either single quotes or backslash escaping for filenames. Would it be possible, at least on Windows, to produce commands like this instead:

mpv --no-audio --vf "lavfi=[drawbox=10:0:704:576:invert:1]" "Some File With Spaces.mkv"

? It would save me a bunch of time, especially when I have a big batch of files to process, to not have to manually edit each command.

Thanks again!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 49 (47 by maintainers)

Commits related to this issue

Most upvoted comments

@samhutchins and @forty2 OK, here’s my reworded text:

Please note that path names within the sample commands are not escaped properly when using cmd.exe or PowerShell on Windows. If you have Git for Windows or another Unix-like environment installed, you can use the Bash shell — usually named bash.exe — to work around this issue.

I’m going with that unless I hear otherwise. 😃

I don’t like recommending that people use Cygwin, because it’s completely unnecessary for this application and it’s such a pain to uninstall. But hey, if people already have it and they wanna use it I have no problem with that 😛

I feel that you’re the master of wording Don, but I think @forty2 had a pretty good suggestion

Hi all,

Sorry for not chiming in sooner; I was traveling and away from my computer.

Thanks for jumping in so quickly and taking this so seriously! For my purposes, the workaround of just using bash while working on a big batch of videos is good enough, but thanks for fixing the zsh regression (it did seem like this got more annoying recently, but I couldn’t put my finger on why…)

The only other thing I would add is you might consider explicitly suggesting bash.exe as an alternative in the README comment – trying bash never occurred to me until you suggested trying PowerShell, so it may not occur to other people either. Maybe something like:

Please note that path names within the sample commands will not be escaped properly when using cmd.exe or PowerShell on Windows. If you have Git or Cygwin installed, you can use bash.exe instead to work around this issue.

Whatever you think is best; in any case, this bug is sufficiently fixed to solve my problem. Thanks again!

@donmelton looks good 👍

@donmelton It does indeed return true in Git Bash on Windows. I’d guess the same is true in Cygwin, but I don’t fancy installing it to find out I’m afraid.

@samhutchins BTW, I’ll tackle this and merge that dandy patch of yours, #147, when I get back to my development machine tomorrow.

Yay for different rules on different systems. On Windows you can’t put a double quote, question mark, or colon in the filename, it won’t let you.

https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names,-folder-names,-and-file-names-in-sharepoint

At this point I’d be inclined to re-fix the issues on zsh in a way that doesn’t cause problems on Windows, then accept and document the poor filename escaping on Windows.

In terms of fixing the escaping on Windows, I think the best we can do is simply detect that the program is running on Windows and use some different escaping rules, I just don’t think there’s a way to detect if the program was launched via CMD or PowerShell.

Also maybe worth a quick read: http://stackoverflow.com/questions/30620876/how-to-properly-escape-filenames-in-windows-cmd-exe

I tried a couple of promising looking things, but there’s nothing concrete in there. I’ll keep trying things, see how it goes

I’ve done a little bit of digging, and made a local change to demonstrate the idea:

diff --git a/bin/detect-crop b/bin/detect-crop
index 892ab8b..79a72d4 100755
--- a/bin/detect-crop
+++ b/bin/detect-crop
@@ -90,7 +90,7 @@ HERE
       directory = media.info[:directory]
       hb_crop = media.info[:autocrop]
       hb_crop = Crop.constrain(hb_crop, width, height) if @constrain
-      shell_path = arg.shellescape
+      shell_path = "\"#{arg}\""
 
       print_transcode = ->(crop) do
         puts
@@ -104,7 +104,7 @@ HERE
         puts
 
         if @player == :mpv
-          puts "mpv --no-audio --vf 'lavfi=[drawbox=#{Crop.drawbox_string(crop, width, height)}:invert:1]' #{shell_path}"
+          puts "mpv --no-audio --vf lavfi=[drawbox=#{Crop.drawbox_string(crop, width, height)}:invert:1] #{shell_path}"
           puts "mpv --no-audio --vf crop=#{Crop.player_string(crop, width, height)} #{shell_path}"
         else
           str = Crop.player_string(crop, width, height)

The result of this change:

G:\Video\Unprocessed rips\Review\Howl's_Moving_Castle - done>detect-crop.bat "Howl's Moving Castle t04.mkv"
...

mpv --no-audio --vf lavfi=[drawbox=0:22:1920:1036:invert:1] "Howl's Moving Castle t04.mkv"
mpv --no-audio --vf crop=1920:1036:0:22 "Howl's Moving Castle t04.mkv"

transcode-video --crop 22:22:0:0 "Howl's Moving Castle t04.mkv"

This makes the command directly copy-able on Windows, but effectively reverts 96c490511c5f2fef445791c405acbe3c4333058c in the process. I dunno how to deal with Z shells without breaking Windows. Not to say it can’t be done, just that I’ve never used (or really heard of) Z shells

I also don’t know the effects of just wrapping the arg in " instead of shellescape is on Unix-like systems. I can’t easily test today, the only Mac I have access to is in the office