3

I'm a software developer who has a video that has been pulled from a livestream event in which attendees commented on the video as it was running. I've got the data on when each comment was made and the text and am wondering if anyone is aware of software that I can 'push' text into the video in an automated manner with?

More precisely I'd like to use some sort of command line tool to be able to pass some text (maybe font and font size as well), a frame/time to display the text, a frame/time to remove the text, and I'm guessing some sort of coordinate rectangle (being able to transition the text to a new location over time would be amazing but not necessary) and have it rendered into the video.

Hope this makes sense, happy to clarify anything further.

4

You could do this by making subtitles from your data streams and then either playing them back on a media player that can display subtitles, or rendering them into the video.

Most subtitle formats are very simple ascii files — to demonstrate, here's an srt subtitle file:

1
00:00:01,046 --> 00:00:02,540
This is my home.

2
00:00:03,560 --> 00:00:05,110
I'm living here.

3
00:00:05,110 --> 00:00:08,640
My name's Nickel
Mundabi Ngadwa Nickel.

It is pretty easy to generate them from any data source, as long as you have start [and finish] times. You can then insert them into a video file as a subtitle stream using ffmpeg:

ffmpeg -i inputvideo.mp4 -i inputsubtitles.srt -c:v copy -c:a copy -c:s mov_text outfile.mp4

Any player that is capable of displaying subtitles will be able to display them. SRT subtitles like these don't have formatting info though, so the format will depend on your player's settings.

Other subtitle formats have more formatting capabilities. Here is an Advanced Substation Alpha subtitle file:

[Script Info]
ScriptType: v4.00+
PlayResX: 1920
PlayResY: 1080

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Univers,56,&Hffffff,&Hffffff,&H0,&H0,0,0,0,1,2,0,2,10,10,16,0,0

[Events]
Format: Layer, Start, End, Style, Text
Dialogue: 0,0:00:01.05,0:00:02.54,Default,This is my home.
Dialogue: 0,0:00:03.56,0:00:05.11,Default,I'm living here.
Dialogue: 0,0:00:05.11,0:00:08.64,Default,My name's Nickel\NMundabi Ngadwa Nickel.

so basically you have the style definitions in the [V4+ Styles] section and the content in the [Events] section, with timing info for each bit of text. You can define multiple styles, and you can add effects and inline formatting.

You can insert them into a video file (you'll need to use the Matroska video container because mp4 doesn't support .ass subtitles),

ffmpeg -i inputvideo.mp4 -i inputsubtitles.ass -c:v copy -c:a copy -c:s mov_text outfile.mkv

or you can "burn them in" by rendering them into the video stream thusly:

ffmpeg -i inputvideofile.mp4 -c:v libx264 -crf 20 -vf ass="inputsubtitlefile.ass" -c:a copy outputvideofile.mp4

So you can see it's not beyond the capabilities of a fairly simple shell script to do it.

  • Awesome. I'd visualised them as subtitles and will certainly see if one of the options above meets the requirements. The one issue I'm anticipating is that there are small periods of time where multiple large comments were submitted. If, say, I display each comment until the next comment was posted they would be way too much text to read in too little time. I was hoping there might be some way to 'stack' comments vertically. It's probably something for me to play with to see how it looks before I look for other answers :) – Red Nightingale Feb 4 '15 at 13:33
  • 1
    I belive there is an "overlap" option in the ASS definition, I'm pretty sure that it can stack overlapping comments, because I've had it do that to me when I didn't want it to. – stib Feb 4 '15 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.