FFmpeg kindly provides a straightforward way can create master HLS playlist. You can simply do it by adding master_pl_name as a part of ffmpeg encoding options. Make sure to require a closed GOP when encoding and to set the GOP size to fit your segment time constraint. For more information, please refer at https://ffmpeg.org/ffmpeg-formats.html#hls
Following example shows how to create a master HLS playlist.m3u8 by combination of
If you are considering fragmented MP4, the option you need to add is just adding -hls_segment_type fmp4.