[FFmpeg-user] Generating HLS chunks on demand
Vincent Deconinck
vdeconinck at gmail.com
Mon Jan 30 23:41:58 EET 2023
Hi Cyril,
I remember that in the first tests I made before answering your first email
> in this thread, I tried to use -ss and -t params with both ts and mp4
> output formats. The ts segments were seemingly random length whereas the
> mp4 seemed strictly of the same length.
Good to know.
In fact, when putting -ss at the start (before -i) and -t at the end (after
the codec details), I think the segment length is correct because both the
number of frames and the durations are the same, according to ffprobe.
> Concomitantly, it seems that HLS is
> now officially compatible with mp4 segments. See
> https://en.wikipedia.org/wiki/HTTP_Live_Streaming#Using_fragmented_MP4 .
> Could that be a way out?
>
Yeah, fragmented MP4 is an option, but as far as I know, it requires an
"initSegment" plus the individual segments while the TS /looked/ simpler
at first.
But maybe creating the initSegment is not that hard in fact. That might be
a workaround indeed...
(Plus, that would be DASH-compatible and natively playable in recent
browsers...)
> Also, care to share the ffprobe command-line or other tool you're using to
> extract a compact string of video frame types (e.g. "IBBBPPBBPBPB") from a
> media?
>
Sure. I asked chatGPT :-) (no kidding).
To extract picture information with ffprobe, I'm running
ffprobe -select_streams v -show_frames -print_format json -i <file.ts> >
streams.json
Then to print the structure in IBBP format, I'm using a small Java program
which loads that JSON into a String and parses it using the Jacskson
library (com.fasterxml.jackson).
Something along the lines of:
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(jsonString);
for (JsonNode frame : root.get("frames")) {
String pictType = frame.get("pict_type").textValue();
if ("I".equals(pictType)) System.out.println();
System.out.print(pictType);
}
I might try a few more things with TS files before switching to MP4. I'll
let you know of course
Thanks for the help,
Vincent
More information about the ffmpeg-user
mailing list