Automatically insert .mkv filename into .bat file

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
Post Reply
allomere
Posts: 24
Joined: Sat May 30, 2020 3:44 am

Automatically insert .mkv filename into .bat file

Post by allomere »

I'm trying to write a quick 'n dirty .bat file that will detect the filename of an mkv file in a directory and automatically insert that name into the .bat file (am piping the .mkv through ffmpeg). The .bat file will be in my path so that I can use it in any directory. Does anyone know how to do this?
Woodstock
Posts: 8156
Joined: Sun Jul 24, 2011 11:21 pm

Re: Automatically insert .mkv filename into .bat file

Post by Woodstock »

Assuming by "bat file" you mean Windows... This might be a good start.
MakeMKV Frequently Asked Questions
How to aid in finding the answer to your problem: Activating Debug Logging
allomere
Posts: 24
Joined: Sat May 30, 2020 3:44 am

Re: Automatically insert .mkv filename into .bat file

Post by allomere »

Thanks! Looks kinda tricky, but I'll give it a shot!
d00zah
Posts: 852
Joined: Mon Jun 06, 2016 8:23 pm

Re: Automatically insert .mkv filename into .bat file

Post by d00zah »

Here's an example I had archived. Just modify the path to the ffmpeg executable & ffmpeg arg defs ('SET ...') to your preference:

Code: Select all

@ECHO OFF
SET "FFMPEG=C:\Users\username\AppData\Roaming\Emby-Server\system\ffmpeg.exe"
SET "VCODEC=-vcodec copy"
SET "ACODEC=-acodec copy"
REM SET "SCODEC=-scodec copy"

FOR /r %%F IN (*.mkv) DO (

	ECHO "%FFMPEG%" -i "%%F" %VCODEC% %ACODEC% %SCODEC% "%%~dpnF.mp4"
	REM IF NOT ERRORLEVEL 1 IF EXIST "%%~dpnF.mp4" DEL /Q "%%F"

)
Currently, it'll do nothing when executed except...

- Find ANY .mkv below wherever you execute the .bat
- Print the ffmpeg command line to convert the .mkv to.mp4 in the same folder (remove 'ECHO ' to actually execute the conversion)
- The next line will remove the original .mkv IF the conversion is successful (remove 'REM ' if deletion is desired)

& let you experiment w/ some of those strange args the tutorial describes. Hope this helps?
Post Reply