Skip to content

Commit

Permalink
Adjust chunking recorder program to API of GStreamer 1.18.4
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jun 20, 2021
1 parent bcf03f5 commit 58f6a13
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions python/examples/flac-timestamp-chunked.py
@@ -1,14 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Saraswati is a robust, multi-channel audio recording, transmission and storage system
# (c) 2018 Andreas Motl <andreas@hiveeyes.org>
# (c) 2018-2021 Andreas Motl <andreas@hiveeyes.org>
import gi
gi.require_version('Gst', '1.0')

import sys
import pytz
import logging
from gi.repository import GObject, Gst
from gi.repository import GLib, Gst
from datetime import datetime
from pkg_resources import parse_version

Expand All @@ -24,7 +24,7 @@ class BasicPipeline:
See also:
- https://gstreamer.freedesktop.org/documentation/tools/gst-launch.html
- https://gstreamer.freedesktop.org/documentation/multifile/splitmuxsink.html
It is derived from these fine blueprints:
Expand All @@ -37,28 +37,27 @@ def __init__(self):
logger.info('Starting audio recorder')

# Create main event loop object
self.mainloop = GObject.MainLoop()
self.mainloop = GLib.MainLoop()

# Where to store the audio fragments
self.output_location = '/var/spool/saraswati/recording_{timestamp}_{fragment:04d}.mka'
# TODO: Make configurable.
self.output_location = './var/spool/recording_{timestamp}_{fragment:04d}.mka'

def setup(self):

logger.info('Configuring the pipeline')

# Configure audio pipeline

# How long should the audio chunks be?
# 10 seconds
chunklength = 10000000000
# How long (ns) should the audio chunks be?
# TODO: Make configurable.
chunklength = 10 * (1000 ** 3) # 10 seconds

# Audio input source
# TODO: Make configurable.
audio_input = 'audiotestsrc'
#audio_input = 'alsasrc device="hw:1"'

if audio_input == 'audiotestsrc':
chunklength *= 12.5

# Pipeline: Use FLAC encoder and Matroska container
pipeline_expression = \
"{audio_input} ! flacenc ! flactag ! flacparse ! " + \
Expand All @@ -84,6 +83,7 @@ def setup(self):
signal_name = "format-location"
signal_callback = self.on_format_location
if parse_version(Gst.version_string()) >= parse_version('GStreamer 1.14.4'):
logger.info("Detected GStreamer>=1.14.4, using 'format-location-full'")
signal_name = "format-location-full"
signal_callback = self.on_format_location_full

Expand Down Expand Up @@ -175,8 +175,7 @@ def on_format_location(self, splitmux, fragment_id, user_data):


def setup_logging(level=logging.INFO):
#log_format = '%(asctime)-15s [%(name)-10s] %(levelname)-7s: %(message)s'
log_format = '%(asctime)-15s [%(name)s] %(levelname)-7s: %(message)s'
log_format = '%(asctime)-15s [%(name)-15s] %(levelname)-7s: %(message)s'
logging.basicConfig(
format=log_format,
stream=sys.stderr,
Expand All @@ -189,7 +188,6 @@ def setup_logging(level=logging.INFO):
setup_logging(level=logging.DEBUG)

# Setup PyGObject and GStreamer
GObject.threads_init()
Gst.init(None)

# Run a basic pipeline test
Expand Down

0 comments on commit 58f6a13

Please sign in to comment.