[英]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: 问题:
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.mp4
( set
命令中的引号确保行尾空格不包含在分配给变量的值中。)
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 接下来我们有一个循环
parmlast
to the resultant #2 parameter. parmlast
设置为所得的#2参数。 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
使
parm
与parm1
具有相同的值,因此in.mpg
Now another loop. 现在是另一个循环。 Remove the first character of
parm
and of params
until parm
is empty. 删除
parm
和params
的第一个字符,直到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.