How to split a video into chunks based on duration using FFmpeg?

I am building a simple streaming service and I have read that to stream a large video in duration I need to use HLS format which allows me to split the video into chunks each of four seconds in duration, I am using FFmpeg for video-related tasks, is there any way I can split a video into smaller chunks using FFmpeg?

Splitting large videos into smaller chunks with FFmpeg is very easy, you just have to use the segment format provided by FFmpeg. With segment format, you can use the -segment_time option provided by FFmpeg to set chunk duration. Consider the following command as an example for your use case.
ffmpeg -i input.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment output%03d.mp4

After splitting if you can also merge videos/audios in FFmpeg.

Why only the first chunk of the chunks created by FFmpeg’s segment format is playable?

Usually, segment format takes care of errors generated in timestamps by splitting the video into chunks but sometimes it generates negative timestamps for some chunks which can create issues with video playback. To avoid this kind of issue you can include -the reset_timestamps 1 option which resets timestamps at the beginning of each segment so that each segment will start with near-zero timestamps.

Does the above command divide a video into equal-length pieces?

You can use the below command to divide into equal-length pieces:
ffmpeg -i ‘input.mp4’ -map 0 -codec copy -f segment -segment_time 15:00 ‘output%03d.mp4’
The options are as follows:
• -i ‘video-name.mp4’ → the input file
• -map 0 → use the first input file for all outputs
• -codec copy → does not recompress the video
• -f segment → the output file will be divided into multiple segments
• -segment_time 10:00 → it will create the segments of this duration (15 minutes in the example)
• output%03d.mp4 → the output files like output001.mp4 etc. (3 is the number of digits in the counter)