Archive

Archive for the ‘Streaming’ Category

Fragmented MP4 File Format

As I have already mentioned in one of  my previous posts about MP4 file format with MOOV box and media data box. Each terminology is represented by “box” in MP4 file format. As microsoft used fragmented MP4 in their smooth streaming technique where fragments are internally organized in a simple contiguous MP4 file.  Each fragment section consists of two parts: Movie Fragment (moof) and media data (mdat). Moof section carry more accurate fragment level metadata and media is contained in the mdat section.

We have used MP4split to generate the fmp4 file.  There is another opensource tool MP4 explorer from cmstream that is used to analyze the header information of a MP4 file. Below you can see a snapshot that shows the fragments information of my encoded mp4 file. Chunks information are delivered to the client through client manifest file (*.ismc).

mp4explorer

If you are really interested to see what is in the client manifest file you can look into the following link :

https://mithunme.wordpress.com/2009/11/04/information-in-the-ismc-and-ism-file/

Information in the *.ismc and *.ism file

November 4, 2009 4 comments

Here is the information in the *.ism server manifest file after using the mp4split:

<?xml version=”1.0″ encoding=”utf-8″?>
<!–Created with mod_smooth_streaming(version=1.0.2)–>
<smil xmlns=”http://www.w3.org/2001/SMIL20/Language”&gt;
<head>
<meta name=”clientManifestRelativePath” content=”manifest” />
</head>
<body>
<switch>
<video src=”video.ismv” systemBitrate=”490000″>
<param name=”trackID” value=”1″ valueType=”data” />
</video>
<audio src=”video.ismv” systemBitrate=”76000″>
<param name=”trackID” value=”2″ valueType=”data” />
</audio>
</switch>
</body>
</smil>

Here is the information in the *.ismc client manifest file after using the mp4split to generate the file:

<?xml version=”1.0″ encoding=”utf-8″?>
<!–Created with mod_smooth_streaming(version=1.0.2)–>
<SmoothStreamingMedia MajorVersion=”1″ MinorVersion=”0″ Duration=”3208550000″>
<StreamIndex Type=”video” Subtype=”H264″ Chunks=”55″ Url=”QualityLevels({bitrate})/Fragments(video={start time})”>
<QualityLevel Bitrate=”490000″ FourCC=”H264″ Width=”208″ Height=”132″ CodecPrivateData=”0000000167640014AC34E60D13F9F01100000300C80000176A8F14291A0000000168EEB2C8B0″ />
<c n=”0″ d=”58058058″ />
<c n=”1″ d=”21354688″ />
<c n=”2″ d=”35368702″ />
<c n=”3″ d=”93426760″ />
<c n=”4″ d=”47380714″ />
<c n=”5″ d=”40707374″ />
<c n=”6″ d=”24024024″ />
<c n=”7″ d=”72739406″ />
<c n=”8″ d=”52052052″ />
<c n=”9″ d=”38038038″ />
<c n=”10″ d=”52052052″ />
<c n=”11″ d=”32699366″ />
<c n=”12″ d=”82082082″ />
<c n=”13″ d=”41374708″ />
<c n=”14″ d=”38038038″ />
<c n=”15″ d=”69402736″ />
<c n=”16″ d=”49382716″ />
<c n=”17″ d=”36703370″ />
<c n=”18″ d=”24691358″ />
<c n=”19″ d=”40040040″ />
<c n=”20″ d=”46046046″ />
<c n=”21″ d=”42042043″ />
<c n=”22″ d=”39372706″ />
<c n=”23″ d=”18685352″ />
<c n=”24″ d=”38705372″ />
<c n=”25″ d=”50050050″ />
<c n=”26″ d=”65398732″ />
<c n=”27″ d=”40707374″ />
<c n=”28″ d=”45378712″ />
<c n=”29″ d=”67400734″ />
<c n=”30″ d=”106106106″ />
<c n=”31″ d=”16683350″ />
<c n=”32″ d=”32032032″ />
<c n=”33″ d=”31364698″ />
<c n=”34″ d=”166833500″ />
<c n=”35″ d=”87420754″ />
<c n=”36″ d=”32699366″ />
<c n=”37″ d=”82082082″ />
<c n=”38″ d=”57390725″ />
<c n=”39″ d=”28695362″ />
<c n=”40″ d=”26693360″ />
<c n=”41″ d=”33366700″ />
<c n=”42″ d=”32699366″ />
<c n=”43″ d=”70070070″ />
<c n=”44″ d=”124791458″ />
<c n=”45″ d=”27360694″ />
<c n=”46″ d=”59392726″ />
<c n=”47″ d=”64064064″ />
<c n=”48″ d=”27360694″ />
<c n=”49″ d=”166833500″ />
<c n=”50″ d=”22022022″ />
<c n=”51″ d=”166833500″ />
<c n=”52″ d=”166833501″ />
<c n=”53″ d=”71404738″ />
<c n=”54″ d=”104104104″ />
</StreamIndex>
<StreamIndex Type=”audio” Subtype=”mp4a” Chunks=”55″ Url=”QualityLevels({bitrate})/Fragments(audio={start time})”>
<QualityLevel Bitrate=”76000″ FourCC=”mp4a” WaveFormatEx=”FF00010044AC0000E02E00000100100002001208″ />
<c n=”0″ d=”58282086″ />
<c n=”1″ d=”21362358″ />
<c n=”2″ d=”35294331″ />
<c n=”3″ d=”93344218″ />
<c n=”4″ d=”47368707″ />
<c n=”5″ d=”40867120″ />
<c n=”6″ d=”23916554″ />
<c n=”7″ d=”72678458″ />
<c n=”8″ d=”52012698″ />
<c n=”9″ d=”38080726″ />
<c n=”10″ d=”52012698″ />
<c n=”11″ d=”32740136″ />
<c n=”12″ d=”82198640″ />
<c n=”13″ d=”41331519″ />
<c n=”14″ d=”38080726″ />
<c n=”15″ d=”69427664″ />
<c n=”16″ d=”49226304″ />
<c n=”17″ d=”36687528″ />
<c n=”18″ d=”24845352″ />
<c n=”19″ d=”39938322″ />
<c n=”20″ d=”45975510″ />
<c n=”21″ d=”42260317″ />
<c n=”22″ d=”39241724″ />
<c n=”23″ d=”18808163″ />
<c n=”24″ d=”38545125″ />
<c n=”25″ d=”50155102″ />
<c n=”26″ d=”65248072″ />
<c n=”27″ d=”40867120″ />
<c n=”28″ d=”45278912″ />
<c n=”29″ d=”67337868″ />
<c n=”30″ d=”106115193″ />
<c n=”31″ d=”16718368″ />
<c n=”32″ d=”32043537″ />
<c n=”33″ d=”31346939″ />
<c n=”34″ d=”166951474″ />
<c n=”35″ d=”87307029″ />
<c n=”36″ d=”32740136″ />
<c n=”37″ d=”82198640″ />
<c n=”38″ d=”57353288″ />
<c n=”39″ d=”28560544″ />
<c n=”40″ d=”26702948″ />
<c n=”41″ d=”33436734″ />
<c n=”42″ d=”32740136″ />
<c n=”43″ d=”70124263″ />
<c n=”44″ d=”124691157″ />
<c n=”45″ d=”27399546″ />
<c n=”46″ d=”59443084″ />
<c n=”47″ d=”64087075″ />
<c n=”48″ d=”27167347″ />
<c n=”49″ d=”166951474″ />
<c n=”50″ d=”22058957″ />
<c n=”51″ d=”166719274″ />
<c n=”52″ d=”166951474″ />
<c n=”53″ d=”71285261″ />
<c n=”54″ d=”102864399″ />
</StreamIndex>
</SmoothStreamingMedia>

How to create a fragmented MP4 file for streaming

November 4, 2009 9 comments

Microsoft smooth streaming used the fragmented MP4 file for streaming.In fragmented mp4 file, each file is internally fragmented into several chunks. Each chunk is known as an MPEG-4 movie fragment. Each fragment is stored within a contiguous MP4 file. File chunks are created virtually upon a client request. However, the actual video is stored on disk as a full length MP4 file. For each bit rate, one MP4 file is created.

The following file format is used by Microsoft in their smooth streaming approach:

smooth streaming media asset consists of the following files:

  • MP4 files In order to differentiate from the traditional MP4 files , IIS streaming uses two new file extensions “*.isma” and “*.ismv”. A file with the first extension contains only audio; while a file with the other extension contains either video and audio or only video.
  • Server manifest file (*.ism) This file describes the relationship between the media tracks, bitrates, and files on disk.
  • Client Manifest file (*.ismc) This file describes the availability of streams to the client.It also describes what CODECs are used, encoded bit rates, video resolution, and other information.

I have used an opensource tool  “MP4Split” developed by code-shop.com to create this manifest files and fragmented mp4 in *.ismv format.

Installing mp4split in ubuntu :

wget http://smoothstreaming.code-shop.com/download/mp4split-1.0.2.tar.gz
tar -zxvf mp4split-1.0.2.tar.gz

cd ~/mp4split-1.0.2
./configure –with-expat
make
sudo make install

Generating a server manifest file :

mp4split – i input.mp4 -o output.ism

Generating a client manifest file :

mp4split – i input.mp4 -o output.ismc

Generating a fragmented output :

mp4split – i input.mp4 -o output.ismv

Encoding a video in H264 format and use MP4 as container

November 4, 2009 1 comment

I have used ffmpeg to encode the input video into H264 format and finally used MP4 as container. The following command line I have used for encoding.

#!/bin/bash
outfile=”video.mp4″
options=”-vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \
-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
-qmax 51 -qdiff 4″

ffmpeg -y -i “$1” -an -pass 1 -threads 2 $options “$outfile”

ffmpeg -y -i “$1” -acodec libfaac -ar 44100 -ab 96k -pass 2 -threads 2 $options “$outfile”

Categories: Streaming Tags: , , ,

Streaming MP4 via HTTP

November 4, 2009 6 comments

Microsoft introduced “Smooth Streaming”  that provides seamless bit rate switching of video by dynamically detecting the network conditions. In order to deliver the media, they have used MP4 container. Normally, a MP4 file format contains a header and media data where the header contains the metadata information. In order to use it for streaming the header information should be placed in the beginning. But, the traditional MP4 file has the header information at the last. The diagram below shows the traditional file MP4 file format.

MP4_trad

To move the header file in the beginning we have used qt-faststart that can be found in : /ffmpeg/tools/qt-faststart

qt-faststart input.mp4 output.mp4

The format of output.mp4 will be as following:

MP4