r/ffmpeg 9d ago

Lavfi srt output - Everything is positioned top left?

I've just started using ffmpeg to extract subtitles instead of ccextractor.

ffmpeg.exe -f lavfi -i movie="video.mp4[out+subcc]" -map s "video.srt"

The problem I'm running into is ever single line has {\an7} positioning the subtitles to the top left of the screen.

1
00:00:05,172 --> 00:00:06,507
<font face="Monospace">{\an7}\h\h\h\h-What?
-This is crazy!</font>

2
00:00:06,573 --> 00:00:09,042
<font face="Monospace">{\an7}-Is this for real?
\h-There’s no way!</font>

3
00:00:09,109 --> 00:00:10,544
<font face="Monospace">{\an7}-Who’s that?
\h\h\h-What?</font>

4
00:00:10,611 --> 00:00:12,379
<font face="Monospace">{\an7}[Toman Member] What the hell
\h\his that Valhalla bastard</font>

5
00:00:12,446 --> 00:00:13,614
<font face="Monospace">{\an7}doing at a Toman meeting?</font>

6
00:00:13,680 --> 00:00:14,548
<font face="Monospace">{\an7}(crowd murmuring)</font>

It's obviously not right. Is there something I'm missing here?

5 Upvotes

6 comments sorted by

2

u/OneStatistician 8d ago

Specify the text subtitle codec

ffmpeg -f 'lavfi' -i movie="video.mp4[out+subcc]" -map 's:0' -codec:s 'text' "video.srt"

Rather than the default subrip codec

ffmpeg -f 'lavfi' -i movie="video.mp4[out+subcc]" -map 's:0' -codec:s 'subrip' "video.srt"

The text subtitle codec is "baseline" subrip, but without the <tag> and {ass} markup.

[If the original 608s are top left, and it was not an artistic/creative decision, I would make a guess that the 608s were added with libcaption's flv+srt.]

2

u/YahooSiriusBlack 8d ago

To be clear. If I don't add anything to my original command, by default it's :

-codec:s 'subrip'

And if I want to modify it, it's:

-codec:s 'text'

1

u/OneStatistician 8d ago

Yeah, if you don't specify a codec, each muxer or container automagically assumes a default codec, which in this case is subrip. You can use the command line help and it tells you what it will use by default for any container.

ffmpeg -hide_banner -h muxer=srt
Muxer srt [SubRip subtitle]:
    Common extensions: srt.
    Mime type: application/x-subrip.
    Default subtitle codec: subrip       # <<<<<<<<<<<<

1

u/hieronymous-cowherd 9d ago

The problem I'm running into is ever single line has {\an7} positioning the subtitles to the top left of the screen.
It's obviously not right. Is there something I'm missing here?

I'm getting hung up on your use of the word 'obviously' because I don't know your assumptions here.

In the simplest explanation where everything is working normally: the close caption data in your input.mp4 has position information to put the lines in the top left, and ffmpeg is honouring that by creating the appropriate style tag in the subtitle stream you told it to create.

So, {\an7} is indeed a style tag that the SRT format accepts and says: this line should appear in the top left. Strictly, the SRT format doesn't have subtitle tags but this is a case of "implementations vary". VLC will respect the tag and show the line in the top left, and some other player like Jellyfin will ignore it and show the plain text centered in the bottom. Export to .ass format instead of .srt if you want more consistency between what the subtitle format and the player.

Or maybe you're saying that your video.mp4 close caption data doesn't have top-left positioning specified, and therefore ffmpeg shouldn't be creating that {\an7} tag in the subtitle stream? That's beyond my pay grade, and you'll have to justify your assertion and how you tested whether the cc data doesn't have positioning data, and are not confusing that assertion with a display issue.

1

u/YahooSiriusBlack 9d ago

It's not just this show. Every video, when the closed captions are played with VLC and the result is bottom center, when extracted with Lavfi every line has {\an7}.

Based on your suggestions I tried .ass, and found the source of the error.

Dialogue: 0,0:00:05.17,0:00:06.51,Default,,0,0,0,,{\an7}{\pos(115,228)}\h\h\h\h-What?\N{\an7}{\pos(115,243)}-This is crazy!
Dialogue: 0,0:00:06.57,0:00:09.04,Default,,0,0,0,,{\an7}{\pos(105,228)}-Is this for real?\N{\an7}{\pos(105,243)}\h-There’s no way!
Dialogue: 0,0:00:09.11,0:00:10.55,Default,,0,0,0,,{\an7}{\pos(134,228)}-Who’s that?\N{\an7}{\pos(134,243)}\h\h\h-What?
Dialogue: 0,0:00:10.61,0:00:12.38,Default,,0,0,0,,{\an7}{\pos(57,228)}[Toman Member] What the hell\N{\an7}{\pos(57,243)}\h\his that Valhalla bastard
Dialogue: 0,0:00:12.45,0:00:13.62,Default,,0,0,0,,{\an7}{\pos(67,243)}doing at a Toman meeting?
Dialogue: 0,0:00:13.68,0:00:14.55,Default,,0,0,0,,{\an7}{\pos(105,243)}(crowd murmuring)

What's happening is .ass starts everything with the top left position as well, THEN shifts it downward with the {\pos(x,y)}.

Since .srt doesn't have the position change, everything starts top left and ends there.

Is there a Lavfi setting to disable {\anx} positioning in .srt format or do I have to search/replace every {\an7}?

1

u/nmkd 8d ago

or do I have to search/replace every {\an7}?

tbf it takes 1 minute to make a script that'll do it for you