0
votes

as title, i want to encode hardsub some mkv videos which contain subtitles. These subs is maybe ASS, SRT or picture-based. I have read FFmpeg Document and stuffs, but only found the way to burn sub if the type of sub is known.

I try to get subtitle info using mediainfo:

mediainfo "--Output=Text;%Format%\r\n" input.mkv

The output is "ASS" with ass , "Text" or "Subrip" or "UTF-8" with SRT.... But i find it hard to keep going because of many kind of output i can get, which is still so hard to create a batch file to tell ffmpeg to auto dectected kind of subs so auto choose correct filter.

Is there any ways to do this? Thanks !

1

1 Answers

1
votes

I'm not familiar with ffmpeg, so here's my guess.

for /f %%G in ('mediainfo "--Output=Text;%Format%\r\n" input.mkv') do (
    set type=%%G
)

rem rename Text, Subrip and UTF-8 to SRT
if "%type%"=="Text"   set type=SRT
if "%type%"=="Subrip" set type=SRT
if "%type%"=="UTF-8"  set type=SRT

rem ffmpeg burn as %type%

Explanation:

  • Gets result of mediainfo and set it into variable type
  • If type is equal to "Text"/"Subrip"/"UTF-8", set it to "SRT"
  • Burn the file(I don't know the command)

Note: if you want to loop through a list of files, you will need a double loop like so:

setlocal enableDelayedExpansion

for /f %%A in (*.mkv) do (
    for /f %%G in ('mediainfo "--Output=Text;%Format%\r\n" %%A') do (
        set type=%%G
    )

    if "!type!"=="Text"   set type=SRT
    if "!type!"=="Subrip" set type=SRT
    if "!type!"=="UTF-8"  set type=SRT

    rem ffmpeg burn as %type%
)
  • Loops through all .mkv files and;
    • Gets result of mediainfo and set it into variable type
    • If type is equal to "Text"/"Subrip"/"UTF-8", set it to "SRT"
    • Burn the file(I don't know the command)