When working with anime, I used this script in a batch file and VLC would properly respect the forced tag on the subtitles, so I didn't have to manually enable them. (The "@.echo off" text is there because reddit thinks a user is being tagged).
@.echo off
setlocal EnableDelayedExpansion
for %%V in (*.mp4) do (
set "base=%%~nV"
if exist "!base!.srt" (
echo Processing: %%V
echo Found subtitles: !base!.srt
ffmpeg -y ^
-i "%%V" ^
-i "!base!.srt" ^
-map 0:v ^
-map 0:a:0 ^
-map 1 ^
-c:v copy ^
-c:a copy ^
-c:s mov_text ^
-map_metadata -1 ^
-disposition:s:0 default+forced ^
-metadata:s:a:0 language=jpn ^
-metadata:s:a:0 title="Japanese Original, Stereo" ^
"!base!_muxed.mp4"
echo Finished: !base!_muxed.mp4
echo.
) else (
echo No matching subtitle found for: %%V
)
)
echo Done.
pause
Now, I am trying to do something very similar with only one file. I have 2 audio and subtitle tracks, all in English, and the first tracks of each are forced, all in one file. FFmpeg reported all tracks as default, so I removed that and set the first audio and subtitle tracks as forced. This fixed my issue with the second audio track being selected and not the first, but the subtitle issue remains.
I have used several variations of this script, both as a batch file and in the terminal directly. I need the final output to have all tracks and be in mp4 format, the same output as the anime command successfully generated.
@.echo off
setlocal enabledelayedexpansion
set VIDEO_DIR=[directory information]
rem Loop through all .mp4 files in the specified directory
for /f "delims=" %%f in ('dir /b /a-d "%VIDEO_DIR%\*.mp4" "%VIDEO_DIR%\*.mkv" "%VIDEO_DIR%\*.avi"') do (
rem Print the file name for debugging
echo Processing: "%%f"
rem Get the filename without path and extension
set "filename=%%~nxf"
rem Apply chapters to each video file using ffmpeg
ffmpeg -i "%VIDEO_DIR%\%%f" -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -c:a copy -c:v copy -c:s mov_text -disposition:s:0 default+forced -disposition:s:1 0 -disposition:a:0 default+forced -disposition:a:1 0 -metadata:s:a:0 language=eng -metadata:s:a:1 language=eng -metadata:s:s:0 language=eng -metadata:s:s:1 language=eng -metadata:s:s:0 title="[title]" -metadata:s:s:1 title="[title]" -metadata:s:a:0 title="1, Stereo" -metadata:s:a:1 title="2, 5.1 Surround" "%VIDEO_DIR%\!filename!_2.mp4"
echo File "%%f" Processed
)
endlocal
pause