2

I'm trying to get from a .srt subtitle file + a .ts video file => a .ts video file with a dvb_subtitle.

My .srt:

1
00:00:00,000 --> 00:00:05,000
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel hendrerit massa.

2
00:00:05,000 --> 00:00:10,000
Aliquam dolor sapien, molestie ac sagittis eu, tempus nec est.

3
00:00:10,000 --> 00:00:28,000
Morbi id sem eu sapien consectetur imperdiet. Morbi sed purus et sapien interdum placerat vitae quis orci.

My .ts: sample_1920x1080.ts from https://filesamples.com/formats/ts

SubtitleEdit command: .\SubtitleEdit.exe /convert 'test_subtitles.srt' Blu-raysup /resolution:1920x1080 /overwrite. This creates a test_subtitles.sup file as expected.

I then use ffmpeg to include the .sup subtitles, like this: .\ffmpeg.exe -y -i 'sample_1920x1080.ts' -fix_sub_duration -i 'test_subtitles.sup' -map 0:v -map 1:s -vcodec copy -acodec copy -scodec dvbsub -copyts -muxdelay 0 -max_delay 0 'output.ts'. This works, but the results are sometimes not very readable. Here's a screenshot:

Screenshot of VLC showing that the subtitles are hard to read

Do I have any other options here? Or options within subtitleedit/ffmpeg to f.ex. make the subtitles be bigger?

(I've posted this to the SubtitleEdit Github repository as well: https://github.com/SubtitleEdit/subtitleedit/issues/4539.)

UPDATE:

I learned from the author of SubtitleEdit that it's indeed possible to increase the font size if using the graphical user interface of SubtitleEdit (see here. However, I wish to do this using a command line tool.

L42
  • 3,052
  • 4
  • 28
  • 49
  • hi buddy, whats the problem with srt file? you can embed them since into ts file as well as sup? – Abilogos Dec 17 '20 at 14:32
  • 1
    I'm not sure whether I follow you, @Abilogos. I need to add bitmap subtitles to the video, and I need the subtitles to be bigger then what I'm able to create with the commands in my question. Could you elaborate on what you mean? – L42 Dec 17 '20 at 14:35
  • i have updated my answer to include font-size, you can hardcode subtitle into video using this option with desired font size – Abilogos Dec 17 '20 at 15:42
  • do you know any online tools to convert srt to sub? – Abilogos Dec 18 '20 at 08:58
  • Googling "srt to sub" will show you that there are many such tools. "srt to sup" (sup is an image format) however does not yield many results. – L42 Dec 18 '20 at 12:14
  • i couldnt find any online solution, and the programs i have found were for MS Windows which i dont have – Abilogos Dec 18 '20 at 14:50

2 Answers2

0

EDIT 19.12.2020:

The idea from my last comment - a Python script that replaces the font size in Settings.xml of SubtitleEdit, to be called before your scripts:

https://github.com/Twenkid/Python-Various/blob/main/Exercise/SubtitleEdit/sub.py

python sub.py C:\SE3518\Settings.xml 44

etc.

...

Have you tried to scale the dvb track? That thread suggests it is possible: ffmpeg and dvb subtitles scaling

That part by Maknol (I haven't tried it though):

-filter_complex "[0:s:0] scale=-1:2400 [sub],[0:v][sub] overlay=x=150:y=-80"

where:

scale - size of subtitle

overlay x= - vertical

overlay y= - horizontal

EDIT: I managed to scale the .sup subtitles with ffmpeg, but so far it worked in two passes, see below.

My sequence was:

  1. Your command, producing a stream with the subtitles:

ffmpeg -i sample_1920x1080.ts -fix_sub_duration -i test_subtitles.sup -map 0:v -map 1:s -vcodec copy -acodec copy -scodec dvbsub -copyts -muxdelay 0 -max_delay 0 outputA.ts

  1. Scale the subtitles and adjust their position (however it requires reencoding due to the filter_complex)

ffmpeg -i outputA.ts -metadata title="Scale" -filter_complex "[0:s:0] scale=-1:1400 [sub],[0:v][sub] overlay=x=-250:y=-300" -c:v libx264 -b:v 5M -preset fast -aspect 16:9 -c:a copy output_Scaled.ts

Initial size:

enter image description here

My initial subtitles were bigger (font size 25) and the scaling coefficient here is small = 1400/1080

Scaled:

enter image description here

...

If I tried to do it in one pass, my syntax rendered the default size + overlayed the scaled ones (and displays only one item, not all).

That's the attempt for one pass:

#At once overlays them ... ffmpeg -i sample_1920x1080.ts -fix_sub_duration -i test_subtitles.sup -scodec dvbsub -map 0:v -map 1:s -metadata title="Scale" -filter_complex "[1:s] scale=-1:1400 [sub],[0:v][sub] overlay=x=-250:y=-300" -c:v libx264 -crf 20 -preset veryfast -aspect 16:9 -c:a aac -strict experimental -b:a 192k outputSTACK_SUP.ts

It produces something like that:

enter image description here

Twenkid
  • 825
  • 7
  • 15
  • Thank you very much for answering! I tried running your second command (see the result of the command here: https://pastebin.com/dLpiXiM7) but the resulting .ts file does not have a subtitle track. An excerpt from the ffmpeg output is "Error while decoding stream #0:1: Invalid data found when processing input". Are you able to see what I did wrong there? – L42 Dec 17 '20 at 14:34
  • Just commenting to let you know that I intent to offer a new bounty if the current one expires. – L42 Dec 17 '20 at 22:07
  • OK. What about the first command? Did you run it first; does otuputA have subtitles? (I play them with ffplay). Also, I had to mention that I generated the sup file using the GUI of Subtitle editor (the cmd line didn't work on my setup, it didn't produce a file and didn't find out why, no error message). If you wish check my output files and the sup from the GUI: http://twenkid.com/video/stack – Twenkid Dec 17 '20 at 22:17
  • Thanks again for responding. The first command works. That produces a video with one video track and one dvb_subtitle track. What I see from your "output_Scaled.ts" file is that there's not separate dvb_subtitle track. It looks like the subtitles are burned into the video, which is not what I want. – L42 Dec 18 '20 at 07:55
  • OK, I thought about is it possible to scale just the subtitle track, save it separately and then reinclude it. The best so far is: ffmpeg -canvas_size 1920x1080 -i outputA.ts -filter_complex "[0:s:0] scale=-1:1800 [sub],[0:s:0][sub] overlay=x=-500:y=-400" -map 0:s -c:s dvdsub sub2X.mkv The subtitles start from time 0 in the output. Then - injecting the dvb track into the first video, but I don't know the right way for that yet. See: sub2X.mkv in the linked dir + https://stackoverflow.com/questions/41818276/in-ffmpeg-how-do-i-scale-dvdsub-subtitles-to-match-video-size-using-scale2ref – Twenkid Dec 18 '20 at 18:09
  • I found the setting in SubEdit, in Settings.xml Arial 40 When changing here, it changes on the following "clean" opening (not reloading unsaved project), a cmd line call cleans it as well. (However on my machine it doesn't produce a .sup :), just prints: Subtitle Edit 3.5.18 - Batch converter and no errors) So the "0-th" script would be to locate and update these lines (or only the size) with a simple substite parser/regex or xml parser, then call SubtitleEdit etc. in your initial sequence. – Twenkid Dec 18 '20 at 23:50
0

Unfortunately, it had to be done with ffmpeg like this:

ffmpeg -i ./sample_1280x720.ts -i ./sample.srt -map 0 -map 1 -c copy -c:s dvd_subtitle ./out.ts

but ffmpeg wont accept it with this error:

Subtitle encoding currently only possible from text to text or bitmap to bitmap

.srt format is text based and .sup format is image based.

so as long as ffmpeg refuses to encode subtitle into video.

we can using -vf (video filter), Hardcoding (srt) subtitle into video:

ffmpeg -i ./sample_1280x720.ts -vf subtitles=sample.srt:force_style='Fontsize=24' ./out.ts

We Can define font size with Fontsize option.

enter image description here

but if have the sup and want to burn into video, you may use this:

ffmpeg -i ./sample_1280x720.ts -i ./sample.sup  -filter_complex "[0:v][1:s]overlay" ./out.ts
Abilogos
  • 4,777
  • 2
  • 19
  • 39
  • 1
    Thank you for answering, however I do not wish to burn the subtitles into the video. I wish to have them as dvb_subtitles that can be enabled or disabled as the viewer pleases. By burning the subtitles into the video you can't disable them. – L42 Dec 17 '20 at 22:04
  • i have tried to find out a way to encoding srt to sup. unfortunately ffmpeg is not gonna do that. and you have to try your chance on other software like handbrake or subtitleEdit ... . – Abilogos Dec 18 '20 at 08:42
  • 1
    Thanks! I did find that it was possible to do with SubtitleEdit, and I do believe that there are other GUI options out there, but I'll continue my search for a command line tool that can do the job. – L42 Dec 18 '20 at 08:46