Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gstreamer multifilesink wav files splitting

Tags:

gstreamer

I have problem with recording streams using gstreamer. I have to write audio and video separately and cut in when signal arrived. I have correctly working video, but still have problems with wav files. Even simple pipeline in gst-launch don't work correctly. I have wave file and I am trying to split it using multifilesink:
gst-launch filesrc location=test.wav ! multifilesink location=test2%d.wav next-file=4 max-file-size=512000 But final wav files are corrupted while the same pipeline with ts files is working ok:
gst-launch-1.0 filesrc location=test.ts ! multifilesink location=test2%d.ts next-file=4 max-file-size=2000000

like image 268
user3921796 Avatar asked Dec 04 '25 19:12

user3921796


1 Answers

multifilesink doesn't know anything about the data it splits up, so it won't take care of adding headers to each of the files it writes.

The reason why your .ts files work is because it was designed to be a streaming format where each separate packet will be treated independently. Therefore, one can just 'tune in' to the stream whenever one likes. The decoder will simply look for the next packet header it finds and start decoding there (for Details have a look at MPEG TS' wiki page.

The WAV file format however was designed as pure file (and not as a streaming) format. Therefore, there's only one header at the start of the file. When you split that file up into multiple files, these headers are missing (the file contains only raw PCM data then).

To work around that issue, you can...

  • manually copy the .wav header from the first file to all the other ones
  • use programs that support PCM files and either work directly with them or convert the files (you'll have to set the channel count, sample rate and bitrate manually when opening those files though).
  • use another, stream oriented file format like .mp3 which comes from the same family of codecs as .ts and also uses a separate 4-byte header for each frame (Keep in mind though that MP3 is a lossy file format).
    An example pipeline would be:

    gst-launch filesrc location=test.wav ! wavparse ! lame ! multifilesink location=test%d.mp3 next-file=4 max-file-size=100000
    
like image 154
mreithub Avatar answered Dec 07 '25 15:12

mreithub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!