I am trying to convert a sequence of short video files from MP4 to TS using ffmpeg. I get valid TS files, but when playing them in any HLS player, there is a noticeable short gap in the sound between segment to segment.
If I first stitch all the short video files to a single video file, and convert this file to TS while slicing it to segments, it plays perfectly fine.
To the gory details:
My software creates short video clips that should be concateenated to an output video and streamed as HLS.
Each short clip is an H.264 video file and WAV audio file (I can create other formats if needed).
I then convert each such pair of H.264+WAV to a TS file using ffmpeg:
ffmpeg -y -i seg_0.mp4 -i seg_0.wav -c:a libvo_aacenc -c:v copy -bsf:v h264_mp4toannexb seg_0.ts ffmpeg -y -i seg_1.mp4 -i seg_1.wav -c:a libvo_aacenc -c:v copy -bsf:v h264_mp4toannexb -output_ts_offset 2.01 seg_1.ts ffmpeg -y -i seg_2.mp4 -i seg_2.wav -c:a libvo_aacenc -c:v copy -bsf:v h264_mp4toannexb -output_ts_offset 4.02 seg_2.ts
etc.
and I create an appropriate M3U8 file to play all the short clips as a sequence. The result is not satisfying, as I have audio gaps between each segment and segment, as you can hear here: https://rnd3-temp-public.s3.amazonaws.com/HLS_4/out_seg2.m3u8
However, if I concat all the pairs together, and convert the concatenated sequence to TS, while requesting ffmpeg to slice them again to segments, using a command like:
ffmpeg -y -f concat -i mp4_list.txt -f concat -i wav_list.txt -c:a libvo_aacenc -c:v copy -bsf:v h264_mp4toannexb -flags +cgop -g 30 -hls_time 2 out2.m3u8
it plays perfectly OK, as you can hear here:
https://rnd3-temp-public.s3.amazonaws.com/HLS/out2.m3u8
How can I get a clear audio output by still encoding each segment separately? (It's crucial for my workflow)
Thanks!