Phil's blog

Apr 2014
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

GStreamer and on-disk videos buffering

A really nice feature every video player using GStreamer and playbin2 should have is media on-disk buffering. Even though it is supported only for Quicktime and Flash videos currently it remains one good improvement of the user experience if you are an avid consumer of Apple trailers and flv :)

Under the hood the magic is in queue2 and uridecodebin but you mostly interface with playbin2. Here is the action plan:

  1. Add the "download" flag to the playbin2 flags property
  2. Upon reception of GST_MESSAGE_BUFFERING messages on the bus, add an idle source to the main loop (for instance)
  3. In that source create a gst_query_new_buffering() query with GST_PERCENT_FORMAT format perform the query to playbin2
  4. Use gst_query_parse_buffering_range() to get the stop value and compute the fill_status value
  5. Notify your UI of the fill level

Additionally you can allow the user to save the buffered media for later off-line consumption :) The media is buffered by queue2 in the tmp folder, the exact file location, temp-location queue2 property, can be retrieved by connecting to the "deep-notify::temp-location" signal of playbin2. You also need to make sure that the temporary file is removed when the user exits from your application, GStreamer doesn't automatically take care of that, as far as I could see.

This is what Totem does, as far as I could understand its code. This is also how I implemented (yet to merge) it in WebKitGTK+:


And to provide a simple example I added this feature to the gst-python example, available in a gist after the break!

by Philippe Normand on Fri Jan 22 09:51:42 2010 (Viewed: 9059 / 4 comments )
  |   RSS  |   RSS2  |   Atom  |   Source  |   Edit

#.   philn on Fri Jan 22 12:30:03 2010

One thing to note, GStreamer should remove the temp file if you reset the pipeline to GST_STATE_NULL or play another uri.

Thanks to Bastien Nocera for the tip!

#.   avb on Fri Jan 22 22:56:09 2010

man, you the best :) Everybody is waiting for a full screen :)

#.   Gabriel on Sat Jan 23 06:42:33 2010

Great summary, thanks a lot! Hopefully we'll get this into Banshee soon.

#.   rnr on Fri Jan 29 00:39:34 2010

Nicely explained!

Comments not allowed anymore on this post