ekisu / mpv-webm

Simple WebM maker for mpv, with no external dependencies.
MIT License
586 stars 33 forks source link

Subprocess call failed when `--vf-add` contains space in Windows #134

Open qip opened 3 years ago

qip commented 3 years ago

mpv version and platform

On Windows 11 21H2 22000.282

mpv 0.33.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Sun Dec  6 10:03:04 +08 2020
FFmpeg library versions:
   libavutil       56.62.100
   libavcodec      58.114.100
   libavformat     58.64.100
   libswscale      5.8.100
   libavfilter     7.92.100
   libswresample   3.8.100
FFmpeg version: git-2020-12-05-89e3f5ab

Description

The generated command line for encoding contains varies parameters, where a bunch of --vf-add were added via get_video_encode_flags() function (in src/encode.moon). While filters for contrast/saturation/brightness/etc. always work, apply_current_filters() can meet edge cases. And in my case, it's something like:

--vf-add=vapoursynth:file=%51%C:\Users\End User\Documents\src\vs\preprocessing.py

Note the space in path, which ultimately break the workflow in Windows. The log:

[   9.765][v][webm] Command failed! Reason:  nil  Killed by us?  no 

And if I ran the command manually, mpv threw error messages like this:

Invalid length 51 for 'file'
Error parsing option vf-add (option parameter could not be parsed)
Setting commandline option --vf-add=vapoursynth:file=%51%C:\Users\End failed.
Exiting... (Fatal error)

Apparently, special chars like space break mpv argument parsing in Windows. A little bit of digging and I found its manual page about arguments handling, so I manually ran it as

"--vf-add=vapoursynth:file=%51%C:\Users\End User\Documents\src\vs\preprocessing.py"

And

--vf-add="vapoursynth:file=%51%C:\Users\End User\Documents\src\vs\preprocessing.py"

Both way works. I then add following to here

        if string.find(v, " ") then
          v = "\"" .. v .. "\""
        end

And encoding... well, let's say just didn't break. However, when checking logs, vapoursynth's just silently skipped:

[   7.875][v][webm] [vapoursynth] Script evaluation failed:
[   7.875][v][webm] [vapoursynth] File reading exception:
[   7.875][v][webm] [vapoursynth] [Errno 22] Invalid argument: '"C:\\Users\\End User\\Documents\\src\\vs\\preprocessing.py"'
[   7.875][v][webm] [vapoursynth] could not init VS
[   7.875][v][webm] Disabling filter vapoursynth.00 because it has failed.

Now it converts to another problem. /facepalm

Anyway, here's how to reproduce the original issue, in case interested:

Reproduction

  1. Prepare a Windows environment, a working mpv compiled with vapoursynth support (with webm.lua and logging set up in mpv.conf), and a video file for playback.
  2. Create C:\a test.py with following content:
    video_in.set_output()
  3. run mpv "--vf-add=vapoursynth:file=%12%C:\a test.py" "C:\sample_video.mp4"
  4. encode with webm.lua
  5. encode fails in OSD and log from mpv contains [webm] Command failed! Reason: nil Killed by us? no