<p>I solved it. Silly me.</p>

<p>Turns out you have to use quotation marks around the file path.</p>

<pre><code>"%~dp0\bin\ffmpeg.exe" -i "%%a" -map 0:s:0 -y "Temp.ass"
</code></pre>

<p>not</p>

<pre><code>%~dp0\bin\ffmpeg.exe -i "%%a" -map 0:s:0 -y "Temp.ass"
</code></pre>

CC BY-SA 4.0
2018-11-18T23:54:07.657Z
2018-11-18T23:54:07.657Z
Armand Bernard
<p>So I'm a long time user of ffmpeg, and I know perfectly well how to install it for command line use using the environmental variable editor.</p>

<p><strong>What I want to know is how to run ffmpeg by directly addressing the .exe file.</strong></p>

<p>I want to do this is so that I can pass someone a folder containing ffmpeg and a batch script and just tell them to double click the .bat file to perform a certain action (like converting mkv to mp4) using the copy of ffmpeg that is in that folder. Effectively, I want to make it portable.</p>

<p>The reason for this is that less technical users are not confident/comfortable with changing environmental variables.</p>

<p>I expected that the batch script would work something like this:</p>

<pre><code>%~dp0\bin\ffmpeg.exe &lt;ffmpeg command here&gt;
</code></pre>

<p>instead of the usual</p>

<pre><code>ffmpeg &lt;ffmpeg command here&gt;
</code></pre>

<p>but this doesn't seem to work. The code crashes before the "pause" command (i.e. on hitting the "if" statement)</p>

<pre><code>@echo off
setlocal enabledelayedexpansion
REM cycle through files
for %%a in (*.mkv) do (

    set b=%%a
    echo !b!
    REM only do files without "_mod" in file name.
    REM (This works by seeing if replacing any "_mod.mkv" with ".mkv" results in the same file name as no action)
    if "x!b:_mod.mkv=.mkv!"=="x!b!" (
        pause
        REM Export the subtitles (Note that these must be 'ass' format subtitles)
        %~dp0\bin\ffmpeg.exe -i "%%a" -map 0:s:0 -y "Temp.ass"
        ...
</code></pre>

<p>This doesn't occur with just "ffmpeg ___".</p>

<p>Any suggestions? I'd ideally like to avoid changing the current directory as I'd like to keep the top level folder clean of everything except the batch script and the files to be converted.</p>

CC BY-SA 4.0
2018-11-17T16:40:13.287Z
*this doesn't seem to work* --> what happens?
Gyan
CC BY-SA 4.0
2018-11-18T23:49:02.610Z
@Gyan Just edited the post to contain more info
Armand Bernard
<ffmpeg><script>
Running ffmpeg WITHOUT editing path variable
Armand Bernard
# Running ffmpeg WITHOUT editing path variable

(Asked by: username_0 on 2018-11-17)

So I'm a long time user of ffmpeg, and I know perfectly well how to install it for command line use using the environmental variable editor.
What I want to know is how to run ffmpeg by directly addressing the .exe file.
I want to do this is so that I can pass someone a folder containing ffmpeg and a batch script and just tell them to double click the .bat file to perform a certain action (like converting mkv to mp4) using the copy of ffmpeg that is in that folder. Effectively, I want to make it portable.
The reason for this is that less technical users are not confident/comfortable with changing environmental variables.
I expected that the batch script would work something like this:
%~dp0\bin\ffmpeg.exe 

instead of the usual
ffmpeg 

but this doesn't seem to work. The code crashes before the "pause" command (i.e. on hitting the "if" statement)
@echo off
setlocal enabledelayedexpansion
REM cycle through files
for %%a in (*.mkv) do (

    set b=%%a
    echo !b!
    REM only do files without "_mod" in file name.
    REM (This works by seeing if replacing any "_mod.mkv" with ".mkv" results in the same file name as no action)
    if "x!b:_mod.mkv=.mkv!"=="x!b!" (
        pause
        REM Export the subtitles (Note that these must be 'ass' format subtitles)
        %~dp0\bin\ffmpeg.exe -i "%%a" -map 0:s:0 -y "Temp.ass"
        ...

This doesn't occur with just "ffmpeg ___".
Any suggestions? I'd ideally like to avoid changing the current directory as I'd like to keep the top level folder clean of everything except the batch script and the files to be converted.

**Tags:** ffmpeg, script

> **Comments:**
> **username_1**: *this doesn't seem to work* --> what happens?  
> **username_0**: @username_1 Just edited the post to contain more info  

---

## 1 answers

### Answer by username_0 on 2018-11-18. Score: 0 | Accepted answer

I solved it. Silly me.
Turns out you have to use quotation marks around the file path.
"%~dp0\bin\ffmpeg.exe" -i "%%a" -map 0:s:0 -y "Temp.ass"

not
%~dp0\bin\ffmpeg.exe -i "%%a" -map 0:s:0 -y "Temp.ass"


---

