0

I'm using gstreamer (gst-launch-1.0 actually) to receive audio and encode it using flacenc. At this point, for testing, the command line looks like this:

gst-launch-1.0 -q autoaudiosrc ! flacenc ! fdsink

This is actually launched by a separate program that gets the FLAC native format data via the child process's stdout.

Now, what I want to be able to do, for archiving purposes, is segment this audio stream into multiple files of limited duration, e.g. one file per minute. I have written code that does the minimal work necessary to parse the stream, segment audio frames, buffer them, and output fully-formed FLAC files. However, in the long term, I'm concerned about the CPU load once I'm archiving hundreds of streams.

The main problem is the frame number. It has a variable length encoding, and even worse, this requires two CRCs to be recomputed for every frame. Wouldn't it be nice if I could either:

  1. Have gstreamer reset the frame number every so often, or even better
  2. Have gstreamer start a whole new file mid-stream?

The latter case would be ideal. If I just dumped this to a file, it wouldn't be a valid FLAC file. After the first segment, the reader would find a file header where it expects a frame header and puke. But I can handle that in my receiving code.

I'm working on trying to figure out how to use various mux and split filters, but most combinations I have tried have resulted in errors of this ilk:

WARNING: erroneous pipeline: could not link flacenc0 to splitmuxsink0

I am also aware that I can use the gstreamer library and probably do stuff like this in my own code where I keep the audio source going and keep bringing the FLAC encoder up and down. A few months ago, I tried to figure out in general how to write programs that link to the gstreamer API and just got thoroughly lost. I was probably not looking at the right docs.

I've also so far found clever ways to always do what I wanted to do with the gstreamer command line. For instance, I managed to get metadata inserted into an tsmpeg stream from a fifo. So maybe I can manage to solve this problem the same way, with some help from kind stackoverflow users. :)

CLARIFICATION: I don't want gstreamer to write multiple files. I want it to generate multiple files but have them concatenated going through stdout and have a completely separate program split them into files.

1 Answer 1

0

The default muxer selected by splitmuxsink is mp4mux, which does not support flac. Setting muxer=matroskamux as an example would help you using splitmuxsink. Though you'll get FLAC contained into matroska, which may or may not be what you want.

While this is likely not working yet, you could try and make flacparse usable as a muxer in splitmuxsink in order to avoid the container.

Meanwhile, you can always use a container for the split, and then remove the container using the sink property. The following is an example pipeline the generates 5 seconds flac files.

gst-launch-1.0 audiotestsrc ! flacenc ! flacparse ! sm.audio_0 \
    splitmuxsink name=sm muxer=matroskamux \
                         location=audio%05d.flac \
                         max-size-time=5000000000 \
                         sink="matroskademux ! filesink"
2
  • Thank you for the suggestion. I'm not sure where it's going wrong, but this only produces one file. audio00000.flac is produced and is the requested duration. audio00001.flac is created but is always zero. This is even it I set the duration to one second. May 12, 2017 at 20:55
  • Hi there. I'm currently implementing a tool to create on the fly subtitles using Google Speech to Text, however, I've to use a solution very similar to yours because I cannot split my files directly on ram. I'm splitmuxing flacs into a RAM directory and then pushing them to Google, however, I'd like to do it directly with pipes and appsrc / appsinks. How does splitmuxsink measure the time, so I can implement some short of queue that allows me to do the trick? Also, I need the last second of audio of EVERY file to be concatenated at the begining of the next, to avoid missing words due to cutoff
    – DGoiko
    Nov 15, 2018 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.