简体   繁体   中英

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:

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. 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

@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.)

Set parm1 to the first of these parameters, with the quotes removed if they are present (the ~ does this) so parm1 becomes in.mpg .

Next we have a loop which

  • "shifts" the parameters' positions : #1 is dropped, #2 becomes #1 and so on.
  • sets parmlast to the resultant #2 parameter.
  • checks to see whether parmlast has a value. 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. parmlast gets the value out.mp4 .

make parm have the same value as parm1 so in.mpg

Now another loop. Remove the first character of parm and of params until parm is empty. This removes in.mpg from params so params becomes "-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 . params becomes "-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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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