[FFmpeg-user] Generate single MPEGTS HLS segment based on fragmented input data

Jan Marlewski jan.marlewski at gmail.com
Fri Dec 11 19:15:01 EET 2020


the problem I want to describe is similar to "Generate individual
HLS-compatible .ts segments on-demand by downloading as little bytes as
possible from a remote input file" described here
http://ffmpeg.org/pipermail/ffmpeg-user/2016-December/034513.html -
unfortunately no answers there.

Initial assumptions are:
- need to provide streaming solution based on HLS-compatible MPEGTS segments
- for now need to stream audio only (maybe audio+video in the future, so
generic solution would be the best for me)
- my data source is a group of WAV file segments, exactly 10 seconds each -
if you take all WAV segments and concatenate them you will get a nice,
seamless audio track (no glitches, gaps etc.)
- the cost of retrieving each WAV segment from my storage is relatively high

My approach:
- create m3u8 index file before any segments are actually available, as I
know how many segments I need to generate and I also know their duration
- when a MPEGTS segment is requested, collect WAV data from storage and
generate MPEGTS file using FFmpeg:

For first segment:
ffmpeg -i input_1.wav -acodec aac -output_ts_offset 0ms output_1.ts

For second segment:
ffmpeg -i input_2.wav -acodec aac -output_ts_offset 10000ms output_2.ts


My problem:
- generated segments are not exactly 10 seconds long
- gaps can be heard between some audio segments (may this be caused by
above issue?)

Any ideas how to generate single MPEGTS segments that will not cause
glitches during playback?

I need to expose the data through web API written in ASP.NET C#. Any idea
on how to solve this problem, even if it may not use FFmpeg at all, would
be appreciated.


More information about the ffmpeg-user mailing list