Why am I having to sync between video and audio in the downloaded HLS video?

I wrote a script to download chunks (.ts) from a web page that streams some soccer videos and combines all the chunks in one file. The issue is that the final result is a video “lagging”, it seems that some frames are missing. I have used FFmpeg for combining the .ts chunks.

You are doing it the hard way. The easy way is to let FFmpeg download everything and combine it nicely which does not cause any frame drop or sync issue. Whatever you did in your bash script can be done using a single FFmpeg command.

First, you have to check the stream indices of the streams you want to download using the ffprobe command because the HLS stream contains multiple video and audio streams.

Once you have the stream indices, you can use the following command to download the video.
ffmpeg -i hls_url -map 0:0 map 0:1 -c copy -f mp4 output.mp4

Great! Any suggestions on how to add a request header while downloading an HLS video using FFmpeg?

Same on my side, I want to download an HLS video from a URL that requires cookies and referer headers for accessing it. I
s there any way to add this header to FFmpeg?


FFmpeg provides multiple options for specifying request headers. You can find a list of them at the following link.
For your use case, you have to -cookies and -referer options with your FFmpeg command like following
ffmpeg -cookies “xyz” -referer “https://xyz.com” -i hls_url -map 0:0 map 0:1 -c copy -f mp4 output.mp4
ffmpeg -cookies “xyz” -referer “https://xyz.com” -i hls_url -map 0:0 map 0:1 -c copy -f mp4 output.mp4I hope now this resolve your problem.