2

Goal
I want to generate a single HLS segment (.ts file) from an .mp4 file, given a segment number n, assuming each segment is 4 seconds long (matching -hls_time 4). The goal is for the segment to play smoothly, just like it does when generated as part of a full HLS playlist.

What works
When generating the full playlist with FFmpeg, playback is great:

ffmpeg -i ./file.mp4 \
  -c copy \
  -map 0 \
  -f hls \
  -hls_time 4 \
  -hls_list_size 0 \
  -hls_segment_type mpegts \
  -hls_flags independent_segments \
  -hls_playlist_type vod \
  -hls_segment_filename ./segment_%04d.ts ./playlist.m3u8

This outputs segments like segment_0000.ts, segment_0001.ts, etc., and they play cleanly one after another.

The problem
When trying to generate just a single segment (e.g., segment_0002.ts) in isolation, using variations with -ss, -t, etc., playback is never as smooth.

Question
What’s the right FFmpeg approach to generate a single .ts segment that will be played smoothly together with other consecutive segments - the same way it would if it came from the full HLS output? No need for perfect binary identicality — just clean playback.

  • I cannot pre-generate the segments.

0 Answers0