How to convert mp4 video files to fragmented mp4 files?

Yes, it is possible to simultaneously convert a large number of MP4 files to fragmented MP4 files. Batch conversions can help you save time and effort, particularly when working with lots of video files. The tools or software you use for the converting process will determine the optimal strategy.

You can use FFmpeg and MP4Box, two well-known command-line programs.

1. Using FFmpeg

Install FFmepg

Use this guide to download FFmpeg on your system.

Create a Batch List

Put every MP4 file you intend to convert into a single folder. Make a plain text file inside the folder with the name “batch_list.txt” and list the paths or filenames of the MP4 files, one per line.

Open Command Prompt/Terminal

Open the Command Prompt on Windows, and the Terminal on macOS or Linux. Use the ‘cd’ command to move to the folder containing the batch_list.txt file.

Execute ffmpeg Command

Use ffmpeg and a “for” loop to transform each MP4 file into a fragmented MP4 file. The following is the fundamental command syntax:

for /f "tokens=*" %i in (batch_list.txt) do ffmpeg -i "%i" -movflags frag_keyframe+empty_moov "fragmented_%~ni.mp4"

In the command above,

  • %i represents each line (file path) in the batch_list.txt file.
  • %~ni extracts the filename (without extension) from the original MP4 file.
  • The output files will be named fragmented_filename.mp4.

Start Batch Conversion

To carry out the command, press Enter. Each MP4 file will be individually processed by ffmpeg, which will result in a fragmented MP4.

2. Using MP4Box

Install GPAC

The GPAC (Multimedia Framework) project includes MP4Box. If you don’t already have GPAC installed, download it from the official page and install it.

Create a Batch List

As with the prior technique, group all of the MP4 files you wish to convert into a single folder. Make a text file inside the folder with the name “batch_list.txt” and list the paths or filenames of the MP4 files, one per line.

Open Command Prompt/Terminal

Similar to the last approach, use the Command Prompt (Windows) or Terminal (macOS/Linux), and then use the ‘cd’ command to go to the folder holding the batch_list.txt file.

Execute MP4Box Command

To create a fragmented MP4 file from each MP4 file, use MP4Box and a “for” loop. The syntax for the command is as follows:

for /f "tokens=*" %i in (batch_list.txt) do MP4Box -dash 1000 -frag 1000 -rap -segment-name "segment_" "%i"

In this command,

  • %i represents each line (file path) in the batch_list.txt file.
  • The ‘-dash’ option specifies the duration of each segment in milliseconds (here set to 1000 ms).
  • The ‘-frag’ option sets the duration of each fragment in milliseconds (also set to 1000 ms).
  • The ‘-rap’ flag ensures that each fragment starts with a Random Access Point, ensuring better seekability.

Start Batch Conversion

To carry out the command, press Enter. Each MP4 file will be processed by MP4Box, which will split each one into many segments and convert it to fragmented MP4.