I have a few video files in mp4 format which I want to convert into FMP4 (fragmented mp4) format for preparing the ABR stream, is there any tool available for it?
Hi Sahil,
To convert an mp4
video file into a fragmented mp4
file, use the following ffmpeg
command:
ffmpeg -re -i input.mp4 -c copy -f mp4 -movflags frag_keyframe+empty_moov output.mp4
Here,
re
: This flag will instruct FFmpeg to read the input file at its native frame rate.i input.mp4
: Indicates the source file (input.mp4) that has to be converted.-c copy
: The input video and audio streams will be duplicated without being re-encoded in stream copy mode.-f mp4
: Indicates the output format as MP4.-movflags
: This option sets the MOV/MP4 muxer flags.frag_keyframe
: This will instruct the FFmpeg to fragment the output file at keyframes.empty_moov
: It creates a placeholdermoov atom
at the start of the output file, allowing it to be streamed before the entire file is fully written.output.mp4
: Indicates the output file name asoutput.mp4
.
You may also use the following tools to convert MP4 videos into fragmented MP4 files and package them with ABR (HLS/MPEG-DASH) format.
1. Shaka Packager
This media package was developed by Google. The major goal of this is to assist developers in preparing and encrypting media files for streaming using well-liked adaptive streaming formats like MPEG-DASH and HLS.
2. Bento4
Bento4 is a strong and flexible toolkit provided by Incodemedia that gives programmers the resources they need to work with MPEG-4 and ISOBMFF files. It makes it easier to perform activities like packaging, segmenting, and altering media content for streaming and distribution.
Refer this To convert m4s files to mp4 using FFmpeg: How to convert m4s files into mp4 using FFmpeg? - #2 by gurupal_singh
Can you explain the benefits of using fragmented mp4 files over regular mp4 files?
In comparison to standard MP4 files, fragmented MP4 (fMP4) files provide a number of significant advantages, especially when it comes to online video streaming and adaptive bitrate delivery. Let me go into more depth about the main benefits below:
1. Efficient Streaming and Adaptive Bitrate (ABR)
In order to facilitate streaming applications and adjustable bitrate delivery, Fragmented MP4 was specifically created.
The moov
atom, which includes crucial metadata for playing in conventional MP4 files, is typically found near the conclusion of the file. Due to this structure, streaming canât start until the complete moov atom has been downloaded, causing buffering delays.
In contrast, fragmented MP4 breaks the metadata of the moov
atom into smaller, independent pieces called moof
and mdat
boxes. This makes it possible for media players to begin playback and adaptively switch between various quality versions more quickly and effectively, which improves user experiences.
2. Fast Startup and Playback
Since the moov
atom information is present at the beginning of a fragmented MP4 file, the playing of the movie can start practically immediately. Users benefit from quicker startup times and less early buffering as a result, making both short and extended videos more convenient.
3. Enhanced Seekability
By making it easier for users to quickly and correctly skip to specified spots in the video, fragmented MP4 files increase seek ability. Regular MP4 files may require downloading a sizable amount of the file before playback can restart when you search for a certain location. In contrast, the modular design of a fragmented MP4 allows for quicker and more accurate seeking.
4. Optimized Bandwidth Usage
Adaptive bitrate streaming, which allows the streaming server to dynamically change the video quality dependent on the userâs internet connection speed, is supported by fragmented MP4. This optimization makes sure viewers get the highest quality without using up all of their bandwidth, saving data for those with slow connections and enhancing overall video quality for those with faster connections.
5. Seamless Content Delivery Over HTTP(S)
Fragmented MP4 is the perfect format for HTTP-based content distribution because it is compatible with well-liked streaming protocols like HLS (HTTP Live Streaming) and DASH (Dynamic Adaptive Streaming over HTTP). Modern online browsers and mobile devices support these protocols to a large extent, enabling content providers to stream films effectively across a variety of platforms and devices.
6. Device and Platform Compatibility
Most modern multimedia players and gadgets can play fragmented MP4 files, giving users a wide range of accessibility. Major streaming services and content delivery systems are designed to accommodate MP4 files that are fragmented, making it simpler for content producers to connect with their audiences.
The streaming experience is considerably improved by fragmented MP4 files due to faster startup times, decreased buffering, support for adaptive bitrate delivery, and improved error recovery. These benefits allow content providers to efficiently distribute high-quality films and meet the needs of a wide range of viewers across a range of devices and internet connections.
I hope now your query is resolved.
Thanks
@preetpal Is it possible to convert a large batch of mp4 files to fragmented mp4 files simultaneously? If so, whatâs the best approach?
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 thebatch_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 thebatch_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.