Hi Henry,
An M4S file is a segment of a video streamed using the MPEG-DASH or HLS video streaming technique. It seems that you are trying to download or store HLS or MPEG-DASH video in an mp4 format. If you have the master playlist URL for the HLS/MPEG-DASH video stream then you can directly convert it into mp4 using FFmpeg, you don’t have to download every segment (m4s) file and then combine it into a single mp4 file.
Option 1: Converting HLS/MPEG-DASH URLs directly to MP4
You can use FFmpeg to immediately convert an HLS or MPEG-DASH video stream into an MP4 format if you know the master playlist URL. This approach saves time and eliminates the need to download and merge separate segment files. This is the command to execute:
ffmpeg -i <HLS/MPEG-DASH URL> -map 0:v -map 0:a -c copy -bsf:a aac_adtstoasc -f mp4 output.mp4
In the above command,
* <HLS/MPEG-DASH URL>
: Replace this with the URL of the master playlist for the video stream.
-map 0:v -map 0:a
: These options specify to include the video and audio streams in the output.-c copy
: This option tells FFmpeg to copy the streams without re-encoding, preserving the original quality.-bsf:a aac_adtstoasc
: This filter is used to convert the audio stream to a format suitable for MP4.-f mp4
: Specifies the output format as MP4.output.mp4
: This is the name you choose for the resulting MP4 file.
Option 2: Install and combine M4S Segment Files
You can take the following actions if you would rather download separate M4S segment files and subsequently merge them into an MP4 file:
-
Download every M4S segment file available from the video stream for a specific resolution.
-
Make a text file (mylist.txt, for example) and put the file locations and/or filenames of the M4S segment files you downloaded in it. Every file ought to be on its line. For instance:
file 'segment1.m4s'
file 'segment2.m4s'
file 'segment3.m4s'
- Execute the following FFmpeg command to merge the M4S files into a single MP4 file:
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
-f concat
: Specifies the format as “concat” for file concatenation.-safe 0
: Allows FFmpeg to read files with relative paths from the text file.-i mylist.txt
: Reads the list of input files from themylist.txt
file.-c copy
: Instructs FFmpeg to copy the audio and video streams without re-encoding.output.mp4
: The name of the output MP4 file.
You can combine the downloaded M4S segment files using these settings to create a single MP4 file, which is very helpful for offline viewing or additional editing. Which option you choose will rely on your unique needs and whether the master playlist URL is available.
You can also:
Convert Mp4 to WebM video
Convert mp4 video into fragmented mp4 files