0

1. Context

I have a very simple pipeline:

filesrc location=foo.wav ! decodebin ! ENCODER ! MUXER ! filesink location=bar.whatever

with ENCODER being any gstreamer encoder and MUXER, whatever suitable muxer. The pipeline is working. For the sake of simplicity, assume there is only one audio stream coming from decodebin.

2. Problem

Now,

  • How can I query the total audio stream size in bytes, right after decodebin (i.e. the raw PCM size)?
  • How can I query the total audio stream size in bytes, right after ENCODER (i.e. the raw compressed size)?

3. What I tried

I am using Python with GI. I've tried with the appsink element, to no avail, with the following pipeline:

filesrc location=foo.wav ! decodebin ! ENCODER ! tee name=tee \
      tee. ! queue ! MUXER ! filesink location=bar.whatever \
      tee. ! queue ! appsink

The relevant part with appsink is the following:

counter = 0
appsink = Gst.ElementFactory.make('appsink', None)
appsink.set_property('emit-signals', True)
appsink.set_property('sync', False)
appsink.connect('new-sample', on_new_buffer)
appsink.connect('new-preroll', on_new_preroll)

def on_new_buffer(sample):
    counter += sample.emit('pull-sample').get_buffer().get_size() 

def on_new_preroll(sample):
    counter += sample.emit('pull-preroll').get_buffer().get_size()

However this is really really slow (20x slower than just using filesink).

Community
  • 1
  • 1
JohnW
  • 505
  • 3
  • 14
  • 20x slower is a lot, did you try tracking what exactly is consuming all that extra time? Perhaps it can be improved. – thiagoss Jan 02 '16 at 19:48

1 Answers1

1

You can try using pad probes.

http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html#gst-pad-add-probe

Add a pad probe for buffers and buffer lists on the pads where you want to count the number of bytes.

thiagoss
  • 2,034
  • 13
  • 8
  • I'd also suggest considering using `identity` elements. I find them to be a bit easier to hook onto than pads, especially dynamically created pads off a decodebin. – mpr Jan 04 '16 at 16:52