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 <ffmpeg command here>

instead of the usual

ffmpeg <ffmpeg command here>

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!" (
        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.

  • 1
    this doesn't seem to work --> what happens?
    – Gyan
    Nov 17, 2018 at 16:40
  • @Gyan Just edited the post to contain more info Nov 18, 2018 at 23:49

1 Answer 1


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"


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.