batch file – Ffmpeg it’s not setting the correct variable names and hence throwing Unable to choose format

I set up a directory with some dummy files matching the problem name format and simply echoed the resultant ffmpeg line. The result was of the form

set filename="1 der 1" _and_ ffmpeg -i "1 der 1.mp4" -vf 
subtitles=subtitledir\"1 der 1".srt -f mp4 donesubsdir\"1 der 1"_srt.mp4

(OK – I’ve broken the line for ease of viewing and substituted subtitledir and donesubsdir for the directorynames.)

Observing that the quoted filename appears within a string and theorising that ffmpeg may have difficulty with that structure, I suggest

SET "vpath=U:\Users\titos\Resilio_Sync\4K_Video_Downloader\videoprocess"
FOR /f "delims=" %%e IN ('dir /b /a-d "%vpath%\*.mp4" 2^>nul') DO ECHO ffmpeg -i "%vpath%\%%~ne" -vf subtitles="subtitledir\%%~ne.srt" -f mp4 "donesubsdir\%%~ne_srt.mp4"

Where you need to follow the bouncing ball for subtitledir and donesubsdir.

My results were:

ffmpeg -i "U:\Users\titos\Resilio_Sync\4K_Video_Downloader\videoprocess\1 der 1" -vf 
subtitles="subtitledir\1 der 1.srt" -f mp4 "donesubsdir\1 der 1_srt.mp4"

(OK – I’ve broken the line for ease of viewing and substituted subtitledir and donesubsdir for the directorynames.)

Theory:

The command dir /b /a-d "%vpath%\*.mp4" 2^>nul is executed and produces lines of the filename only (/b) with no directorynames (/a-d) which are applied to %%e.”delims=” tells for that no tokenising is required, so the entire name appears in %%e, The 2^>nul suppresses error messages – the ^ tells cmd that the > is part of the dir command, not the for.

(there are hundreds, if not thousands, of similar applications posted on SO)

See for /? or thousands of examples on SO for the use of metavariable-modifiers.

Then %%~ne is the name-part only of the filename in %%e.

Read more here: Source link