1

I have an application that records raw audio data in LPCM stored in a buffer. I would like to encapsulate the data in a transport stream and send that transport stream through UDP to a stream segmenter (according to HTTP Live Streaming specifications) on another host.

FFmpeg provides a command-line utility to do so but with a file as input ffmpeg -re -i output.aac -acodec copy -f mpegts udp://127.0.0.1:5555.

My first thought was to use FFmpeg API, especially the libavformat library. Does libavformat provide a muxer that I could use to encapsulate my audio in LPCM into a transport stream or do I have to implement it from scratch?

I have found this source code https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/mpegts.c but I am not sure if it actually does what I'm looking for.

Thanks for your help,

Wang Liang
  • 4,244
  • 6
  • 22
  • 45
Pierre P.
  • 1,055
  • 2
  • 14
  • 26
  • 1
    `libavformat/mpegtsenc.c` is the TS muxer but it does not mux LPCM. Patch welcome. – Gyan Apr 16 '18 at 16:35
  • Does it have any kind of documentation or do I have to dive into the code? – Pierre P. Apr 16 '18 at 17:12
  • Individual muxers aren't documented per se. Basic flow is the same: you init, write header (if applicable), write packets, write trailer, deinit. See the relevant functions at the bottom of the file. – Gyan Apr 16 '18 at 17:29
  • Do you have to have LPCM while it is transferred across the network? Being an uncompressed format it is likely why you can't find what you need as not efficient for network transport. You could encode and transport and the decode back to LPCM would be a fairly straight forward process. If you really just want to push the LPCM across the network just send it on a socket and no need for ffmpeg – Andrew Apr 17 '18 at 11:09
  • @Andrew No I don't need to transfer in LPCM. My audio is natively produce in LPCM but I can easily encode it in a more suitable format such as AAC. However, I do need to transfer it in a MPEG Transport Stream because it what the server process is expecting. – Pierre P. Apr 17 '18 at 11:13
  • @Gyan Transport Streams requires Packetized Elementary Stream. Does ffmeg provide any utility to convert segment an elementary stream? – Pierre P. Apr 19 '18 at 15:40

2 Answers2

1

So based on your comment about not needing it to necessarily be LPCM in the TS you will need to:

  1. Decode your audio / read the frames
  2. Encode it as a as something suitable for sending in a Transport Stream e.g. mp3 or AAC I believe this is the list of options: https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/mpegts.h#L45-L64
  3. Package it in a TS suitable for your network conditions e.g. packet sizing etc
  4. Send it via UDP

There is a reasonable example of all this here: https://github.com/rvs/ffmpeg/blob/master/libavformat/output-example.c

As mentioned in the prior answer from szatmary you could also just pipe this to ffmpeg which may be simplest

Andrew
  • 742
  • 8
  • 21
0

You can use the ts muxer directly via libavformat. However you can also pipe the audio to ffmpeg using -i -

szatmary
  • 29,969
  • 8
  • 44
  • 57