"-tmp" parameter of MP4Box needs 2 backslashes

0

I'm on Windows 7 Ultimate SP1 x64, running MP4Box - GPAC version 0.7.2-DEV-rev357-g7115eeb8-master.

I've created a BAT file like this :

mp4box -add %1#trackID=1:name= -add %2#trackID=1:name= -tmp "%~dp1\" -new "%~n1_new.mp4"

which works fine, but before adding \ to %~dp1\ it gave the error :

Error - 2 input names specified, please check usage

Why does it need 2 backslashes to work ?

If it's important I just drag&drop the video and audio on the BAT file.

BTW, is %1#trackID=1:name= OK or I should change it to this "%~1#trackID=1:name=" ?

Derp

Posted 2018-07-05T14:05:08.977

Reputation: 11

Answers

0

To fix this you can use batch variable substrings to replace the single back slash characters \ in the string value of the first argument with two backslash characters \\ in that string value instead. You can set another variable to have the new value and use it accordingly.


Batch Script

@ECHO OFF
SET a=%~1
SET a=%a:\=\\%
SET dp=%~dp1
SET dp=%dp:\=\\%

mp4box -add %a%#trackID=1:name= -add %2#trackID=1:name= -tmp "%dp%" -new "%~n1_new.mp4"
::::mp4box -add %1#trackID=1:name= -add %2#trackID=1:name= -tmp "%dp%" -new "%~n1_new.mp4"

Note: The issue is likely the mp4box app expects full paths to use either double backslashes \\ or single forward slashes / due to the backslash character being an escape character it uses otherwise internally and thus using a single backslash it does not see the backslash literally.

You may be able to use to test if it also uses forward slashes as well as double backslashes.

SET a=%~1
SET a=%a:\=/%
SET dp=%~dp1
SET dp=%dp:\=/%

Further Resources

Pimp Juice IT

Posted 2018-07-05T14:05:08.977

Reputation: 29 425

Thank you so much for the explanation and the links, they were educational. I just wanted to know why it needed 2 backslashes at the end, so now if I understand this correctly the last backslash is being escaped (") so I need to add another backslash. What about the second question ? Do you know which one is better ? – Derp – 2018-07-05T16:46:20.870

@Derp I would suggest always using %~1 and then ensuring to enclose the variable as needed with double quotes so it will handle spaces in the file names or folder path correctly. So if file name test 123.txt you will use "%~1" so it is returned as "test 123.txt"... you obviously need to understand the app parameters you are using and how this is interpreted and thus the "%~1#trackID=1:name=" example you showed would be best in my opinion. Using the tilde and enclosing in double quotes has never caused problems for me whereas not using and having spaces in the value has. – Pimp Juice IT – 2018-07-05T17:14:14.303