4

I had a script that converts all mkvs in a folder to mp4s using ffmpeg. The downside is that it left the .mkv extension and just added .mp4 (eg: file.mkv.mkp4). I know %~n can be used to get a name without the extension, but I can't seem to figure it out.

Here's my original script:

for %%i IN (*.mkv) DO (ffmpeg -y -ss 00:00:00 -threads 6 -i "%%i" -vcodec copy -f mp4 -strict experimental -acodec aac -ab 128k -ac 2 "%%i.mp4")

Here's what I've tried:

for %%i IN (*.mkv) DO (ffmpeg -y -ss 00:00:00 -threads 6 -i "%~ni.mkv" -vcodec copy -f mp4 -strict experimental -acodec aac -ab 128k -ac 2 "%~ni.mp4")

1 Answer 1

6

Percent signs of loop variables must be doubled in batch scripts, so you have to use %%~ni instead of %~ni. See the Examples section in the documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

That link is dead, the proper location is: technet.microsoft.com/en-us/library/bb490869.aspx
@MarcusJ Actually it's technet.microsoft.com/en-us/library/bb490909.aspx, but thanks for the heads-up. Fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.