Dynamic (Alternate) Text Overlay

Tim-Philipp Müller t.i.m at zen.co.uk
Fri Feb 24 12:18:15 PST 2012


On Fri, 2012-02-24 at 11:40 -0800, kususe wrote:
> I coded a function to perform dynamic text overlay, displaying lines from a
> file.
> 
> def show_line(self):
> 		next_line = self.curr_line + 1
> 		self.line = self.lines[self.curr_line]
> 		y = self.line.split(' ')
> 		z = self.lines[next_line].split(' ')
> 		d1 = datetime.datetime.fromtimestamp(float(y[0]))
> 		d2 = datetime.datetime.fromtimestamp(float(z[0]))
> 		d3 = d2-d1	
> 		d3s = str(d3)
> 		sleep_time = int(float(d3s[6::]))*1000
> 		self.player.get_by_name("textoverlay").set_property("text", self.line)
> 		glib.timeout_add(sleep_time, self.show_line)
> 		self.curr_line += 1
> 		return False
> 
> where "line" is an array which contains the lines of the file (I used
> readlines() ). 
> In each of these lines, there is the timestamp, used to display the strings
> on screen in according with the difference between two of them (d3). 
> This function is called by another one. 
> 
> The problem is that is displayed the 1st line, 3rd one, 5th one and so on
> and not respecting the timestamp

If you use the "text" or "markup" property, textoverlay will show the
text as you set it on the property, immediately when you set it, for as
long as you don't set the property to something else.

If you want to show timed text, you can either

a) handle the timing yourself, or

b) use the GstController interface on the "text" property, to make it
automatically show certain strings at a certain time in the stream, or

c) push timed text/markup on textoverlay's text_sink sink pad. The
buffers should contain UTF-8 text or pango markup, and the buffers
should have timestamp and duration set on them. You could use an appsrc
element to feed timed-text buffers to textoverlay, for example (or read
them from file, like  filesrc location=foo ! subparse ! ...)

Cheers
 -Tim



More information about the gstreamer-devel mailing list