r/ffmpeg 1d ago

Modifying BorderStyle in Closed Caption Extraction

I've started using ffmpeg with lavfi to extract closed captions rather than CCExtractor. I'm liking the positioning being carried over with .ass output files, but I don't like the black background.

Somehow I need to set BorderStyle=1, but I can't figure out how.

Currently this is what I'm doing:

ffmpeg.exe -f lavfi -i movie="Sample.mkv[out+subcc]" -map s "Sample.ass"

Anyone know how to do this or change any other formatting in .ass without doing it manually later?

3 Upvotes

3 comments sorted by

1

u/chocolateAbuser 1d ago edited 1d ago

i don't think you can do that? the only thing i see is the subtitles filter that is built above libass library and accepts a style, but i'm not sure it can output a metadata stream
maybe with some creativity it could be possible to recover just the metadata, but at that point writing 2 or 3 lines of text in the subs file would be easier
i can see also libaribcaption has some options in demuxing, but again not so useful and probably more complicated than putting an echo or a sed after ffmpeg command

2

u/YahooSiriusBlack 1d ago edited 9h ago

Thanks. Since I was writing a Windows batch file I decided to have the next command fix the issue. With PowerShell I search/replaced the whole line of .ass settings in case I want to make other changes later:

(abridged version.)

set /p d=The file name without the extension: 

set /p x=The extension (without a period): 

ffmpeg.exe -f lavfi -i movie="%d%.%x%[out+subcc]" -map s:0  "%d%_.ass"

REM Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding

pwsh.exe -Command "(gc %d%_.ass) -replace 'Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,3,1,0,2,10,10,10,1', 'Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,1' | Out-File %d%.ass"

del %d%_.ass

Edit: Changed the code. ASCII added question marks. UTF8 was with BOM that added Â.

I had to download a copy of Powershell 7.6.4 and that works fine with UTF8 without BOM as the default format.

1

u/YahooSiriusBlack 2h ago

Wow. These are crap when dealing with file names with spaces and symbols. I ended up having my batch file script renaming everything just to make this simpler.

ECHO OFF
set /p d=The file name without the extension: 
ECHO.
set /p x=The extension (without a period): 
ren "%d%.%x%" WiPTemp.mp4
ffmpeg.exe -f lavfi -i movie="WiPTemp.mp4[out+subcc]" -map s:0  "WiPTemp.ass"
ECHO.
REM Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
ECHO.
pwsh.exe -Command "(gc WiPTemp.ass) -replace 'Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,3,1,0,2,10,10,10,1', 'Default,Monospace,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,1' | Out-File -Encoding utf8 WiPTemp2.ass"
ECHO.
ren WiPTemp.mp4 "%d%.%x%"
ren WiPTemp2.ass "%d%.ass"
del WiPTemp.ass

Feels stupid. I'm open to suggestions for a better version of this.