简体   繁体   English

CMD传递等号双引号,外部双引号作为参数

[英]CMD Pass double quotes with equal signs with outer double quotes as a parameter

Thanks for concern. 感谢您的关注。 The case is like: 情况如下:

[ffm.bat]
rem %0 in "options" out
set opt=%2
set opt=%opt:~1,-1%&rem de-quotes
set ffcmdstr=ffmpeg -i "%~1" %2 "%~3"

if I want the ffcmdstr variable to be set to the following: 如果我想将ffcmdstr变量设置为以下内容:

ffmpeg -i in.mpg -vf "hqdn3d=0:0:4:0" -c:v h264 out.mp4

ideally I'd enter: 理想情况下,我输入:

ffm.bat in.mpg "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4

problem: 问题:

  1. space is a delimiter, so I use "..." 空格是定界符,因此我使用“ ...”
  2. = is a delimiter, too; =也是定界符; fine within "..." but 在“ ...”之内可以,但是
  3. " is also needed within "..." then cause space breaks the parameter again. “ ...”内也需要使用“”,然后导致空格再次中断参数。

Tried several ESCAPE ways but failed. 尝试了几种ESCAPE方法,但失败了。 Please give me any useful thoughts. 请给我任何有用的想法。

Now I use: 现在我使用:

"-vf 'hqdn3d=0:0:4:0' -c:v h264"

and add a substitution: 并添加替换:

set opt=%opt:'="%
@ECHO OFF
SETLOCAL
CALL :gffmpeg "in.mpg -vf "hqdn3d=0:0:4:0" -c:v h264 out.mp4"
CALL :gffmpeg2 in.mpg "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4
GOTO :eof

:gffmpeg
SET "params=%*"
ECHO ffmpeg -i %params:~1,-1%
GOTO :EOF

:gffmpeg2
SET "params=%*"
SET parm1=%~1
:parml
SHIFT
SET "parmlast=%~2"
IF DEFINED parmlast GOTO parml
SET "parmlast=%~1"

SET "parm=%parm1%"
:parm1L
IF DEFINED parm SET "parm=%parm:~1%"&SET "params=%params:~1%"&GOTO parm1L

SET "parm=%parmlast%"
:parmLL
IF DEFINED parm SET "parm=%parm:~1%"&SET "params=%params:~0,-1%"&GOTO parmLL

ECHO ffmpeg -i %parm1% %params:~2,-2% %parmlast%
GOTO :EOF

Here's two ways - the first requires a reformatting of your parameter-supplied; 这有两种方式-第一种需要重新格式化您提供的参数; the second as you've currently got it. 第二,因为您目前已经掌握了它。


So, taking the second method step-by-step: 因此,逐步采取第二种方法:

Driving the batch with thisbatch in.mpg "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4 thisbatch in.mpg驱动批处理。 - vf“ hqdn3d = 0:0:4:0” -c:v h264“ out.mp4

@ECHO OFF
SETLOCAL

SET "params=%*"
SET parm1=%~1
:parml
SHIFT
SET "parmlast=%~2"
IF DEFINED parmlast GOTO parml
SET "parmlast=%~1"

SET "parm=%parm1%"
:parm1L
IF DEFINED parm SET "parm=%parm:~1%"&SET "params=%params:~1%"&GOTO parm1L

SET "parm=%parmlast%"
:parmLL
IF DEFINED parm SET "parm=%parm:~1%"&SET "params=%params:~0,-1%"&GOTO parmLL

ECHO ffmpeg -i %parm1% %params:~2,-2% %parmlast%
GOTO :EOF

First, set params to the entire command-tail in.mpg "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4 (the quotes in the set command ensure that trailing spaces on the line are not included in the value assigned to the variable.) 首先,将params设置为整个命令尾部in.mpg "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4set命令中的引号确保行尾空格包含在分配给变量的值中。)

Set parm1 to the first of these parameters, with the quotes removed if they are present (the ~ does this) so parm1 becomes in.mpg . parm1设置为这些参数中的第一个,如果存在引号,则将其删除( ~这样做),因此parm1变为in.mpg

Next we have a loop which 接下来我们有一个循环

  • "shifts" the parameters' positions : #1 is dropped, #2 becomes #1 and so on. “移动”参数的位置:#1掉下,#2变成#1,依此类推。
  • sets parmlast to the resultant #2 parameter. parmlast设置为所得的#2参数。
  • checks to see whether parmlast has a value. 检查parmlast是否具有值。 If it has, keep shifting until it hasn't. 如果有的话,继续转移直到没有。

%1 must now have the last parameter, so assign it to parmlast and remove any quotes. %1现在必须具有最后一个参数,因此将其分配给parmlast并删除所有引号。 parmlast gets the value out.mp4 . parmlast获取值out.mp4

make parm have the same value as parm1 so in.mpg 使parmparm1具有相同的值,因此in.mpg

Now another loop. 现在是另一个循环。 Remove the first character of parm and of params until parm is empty. 删除parmparams的第一个字符,直到parm为空。 This removes in.mpg from params so params becomes "-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4 这将从params删除in.mpg ,因此params变为"-vf "hqdn3d=0:0:4:0" -c:v h264" out.mp4

Next, pull a similar trick, this time using paramlast to remove out.mp4 from the end of params . 接下来,使用拉类似的技巧,这一次paramlast删除out.mp4年底 params params becomes "-vf "hqdn3d=0:0:4:0" -c:v h264" params变为"-vf "hqdn3d=0:0:4:0" -c:v h264"

Final step - echo the required ffmpeg line with the -i switch, the value of parm1 , the string from params minus the first 2 and last 2 characters ( Space " and " Space respectively) and apply the last parameter from parmlast . 最后一步-回波所需ffmpeg与线-i开关,的值parm1 ,从字符串params减去第一2和最后2个字符( 空间 空间分别地)和从应用的最后一个参数parmlast

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM