Skip to content

Commit

Permalink
add python usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
MaZderMind committed Aug 7, 2021
1 parent 46752a8 commit 11b0ee9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ inspect-ebur128graph: build
run-tests: builddir
cd builddir && meson test -v

run-example-py: builddir
GST_PLUGIN_PATH=$(realpath builddir) examples/example.py

run-ebur128: build
GST_PLUGIN_PATH=$(realpath builddir) gst-launch-1.0 -m \
filesrc location=example-audio/music.mp3 ! mpegaudioparse ! mpg123audiodec ! \
filesrc location=examples/music.mp3 ! mpegaudioparse ! mpg123audiodec ! \
ebur128 momentary=true shortterm=true global=true window=5000 range=true sample-peak=true true-peak=true interval=100000000 ! \
autoaudiosink

run-ebur128-with-seek: build
GST_PLUGIN_PATH=$(realpath builddir) gst-launch-1.0 -m \
filesrc location=example-audio/music.mp3 ! \
filesrc location=examples/music.mp3 ! \
mpegaudioparse ! mpg123audiodec ! \
ebur128 ! \
navseek ! \
Expand All @@ -44,7 +47,7 @@ run-ebur128-with-seek: build

run-ebur128graph: build
GST_PLUGIN_PATH=$(realpath builddir) gst-launch-1.0 \
filesrc location=example-audio/music.mp3 ! mpegaudioparse ! mpg123audiodec ! tee name=t \
filesrc location=examples/music.mp3 ! mpegaudioparse ! mpg123audiodec ! tee name=t \
t. ! queue ! ebur128graph ! videoconvert ! ximagesink \
t. ! queue ! autoaudiosink

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Configure and build:
apt install build-essential meson libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libebur128-dev libcairo-dev

# For Testing
apt install gstreamer1.0-tools gstreamer1.0-plugins-base
apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good

# Build
make
Expand All @@ -41,4 +41,10 @@ And Test it as with:
make run-ebur128
make run-ebur128graph

## Use in your own App
For an example on how to use the ebur128 Plugin in your own appl see [examples/example.py](example.py). To run it with the correct Plugin-Path, use

make run-example-py


[MIT]: http://www.opensource.org/licenses/mit-license.php or COPYING.MIT
49 changes: 49 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

import gi

gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib

Gst.init(None)

pipeline = Gst.parse_launch("""
filesrc location=examples/music.mp3 ! mpegaudioparse ! mpg123audiodec ! \
ebur128 name=ebur128 momentary=true shortterm=true global=true window=5000 range=true sample-peak=true true-peak=true ! \
autoaudiosink
""")

element = pipeline.get_by_name("ebur128")

def on_message(bus, message):
if message.type == Gst.MessageType.ELEMENT and message.src == element:
structure = message.get_structure()

success, timestamp = structure.get_uint64("timestamp")
success, momentary_loudness = structure.get_double("momentary")
success, shortterm_loudness = structure.get_double("shortterm")
success, global_loudness = structure.get_double("global")
success, window_loudness = structure.get_double("window")
success, loudness_range = structure.get_double("range")
true_peak = structure.get_value("true-peak")
sample_peak = structure.get_value("true-peak")

print({
"timestamp": timestamp,
"momentary_loudness": momentary_loudness,
"shortterm_loudness": shortterm_loudness,
"global_loudness": global_loudness,
"window_loudness": window_loudness,
"loudness_range": loudness_range,
"true_peak": true_peak,
"sample_peak": sample_peak
})

bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", on_message)

pipeline.set_state(Gst.State.PLAYING)

mainloop = GLib.MainLoop()
mainloop.run()
File renamed without changes.

0 comments on commit 11b0ee9

Please sign in to comment.