— Edited by Clément Taverne for the NET4520 course
Dynamic adaptive streaming over HTTP is a way to stream video over the internet. How is this different than progressive streaming or just downloading the video? It is different because DASH uses multiple video files, and optionally audio files, of different bitrates and resolutions to conserve bandwidth and provided the best viewing quality possible with minimal buffering time. To do this DASH starts out with the lowest quality video file the server can provide and steady works its way up in quality until your device can't pull the video any faster. That is why Netflix videos look terrible and progressively look better for the first 15 seconds or so.
If you wish to read the specifications for DASH you can go to here (http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=65274) and purchase the document. Be prepared to shell out about $200 to look at the document.
Step 1: Installing the Software
It is time to install the software we need in order to properly encode and prepare the video for DASH.
Download the test movie file named "big_buck_bunny_720p_stereo.avi" from here
The server having a really low bandwidth, it is more advised to download the MP4 1920x1080 surround version from the .torrent link from this page
- Download ffmpeg from here
- Download the latest installer of GPAC from here
Note: the filename will most likely not match what is in the picture; this is fine. Just pick the .exe file
- Install GPAC by running the file. In the Choose Components menu, make sure everything is ticked then click next.
- Extract the downloaded ffmpeg zip file to "c:\ffmpeg"
- Open up the System information window. (You can use the shortcut WindowsKey+Break/Pause)
- Click "Advanced system settings"
- Click "Environment Variables..."
- Select the "Path" variable under System variables
- Click "Edit..."
- Click "New"
- Type "C:\ffmpeg\bin"
- Click OK
- Click OK
- Click OK
Step 2: Testing the Programs
It is time to test your system to make sure the software you installed in the last step is installed properly.
Testing is a crucial step. Even if you did everything correctly it is always a good idea to make sure everything is working properly because the system or the software could have bugs and have messed up somewhere.
- Open the Run dialog using the shortcut WindowsKey+R
- Type in "cmd" into the textbox and press ENTER
- In the command prompt type "ffmpeg" and press ENTER
- If you see a bunch of text, like the first image, you have set up ffmpeg properly!
- Type "cls" to clear the screen
- Type "mp4box" and press ENTER
- If you see a bunch of text, like the second image, you have set up mp4box successfully!
If you see something like "ffmpeg" is not recognized as an internal or external command... then something is not setup correctly. You need to go back to step 1 and reinstall the programs.
Step 3: Creating Your Workspace
Creating a workspace is essential to keeping everything organized and together.
- Right-Click the Desktop
- Hover over New
- Click Folder
- You can name this folder anything you like.
- Double-Click the folder to open it up
- Copy the movie file we downloaded earlier into the workspace
- Rename this move to "input.avi", this will make typing easier later
Step 4: Opening the Command Line
In order to run the command necessary in the next steps, we need to prepare the command line.
To do that:
- Open up a command prompt by pressing WindowsKey+R to bring up the run dialog
- Type "cmd" into the textbox and press ENTER to bring up the command line
- Type "cd C:\Users\[your username]\Desktop\[name of your dash workspace]" in the command line
- Press ENTER to change the current directory
Step 5: Encoding the Video
This is where the fun begins. Here you are going to write the commands to transform the input video into multiple bitrates and resolutions, so a DASH video player can switch between bitrates depending on the current download speed of the playback device. This switching is what makes DASH so important to content streaming companies like Netflix, YouTube, and others because it saves bandwidth and thus money!
Now we are going to use the following command to encode the video:
ffmpeg -i input.avi -s 160x90 -c:v libx264 -b:v 250k -g 90 -an input_video_160x90_250k.mp4
Here are what the arguments mean:
- -i input.avi - tells ffmpeg where the input file is
- -s 160x90 - is the resolution we want to encode our input file to
- -c:v libx264 - specifies the video codec to use, in this case we want H.264
- -b:v 250k - is the bitrate we want to encode the video to
- -g 90 - tells ffmpeg we want a keyframe interval (GOP length) of 90
- -an - do not encode audio
- input_video_160x90_250k.mp4 - the output file
To encode the file:
- Copy and paste the command above in the command prompt and press ENTER
- You will need to wait about 10 seconds to 5 minutes depending on the speed of your processor and the options used
Having one file is fine, but that defeats the purpose of DASH. In order to use DASH effectively, you need to have multiple files at different bitrates and resolutions. Run the command again but with some of the parameters changed:
- Change the resolution to 320x180
- Change the bitrate to 500k
- Change the output file to input_video_320x180_500k.mp4
- Run the command again
- Optional: Repeat this again for a wide range of bitrates and resolutions (you don't need to do this, I provided all the commands you need in the next step)
Step 6: Encode the Audio
Notice there is no audio in any of the videos. That is because in DASH you want to stream audio separate from video. To do that we use the following command:
ffmpeg -i input.avi -c:a aac -ac 2 -b:a 128k -vn input_audio_128k.mp4
Here are what the arguments mean:
- -i input.avi - the input file
- -c:a - the audio codec
- -ac - the number of channels
- -b:a - the bitrate of the audio
- -vn - do not encode video
- input_audio_128k.mp4 - the output file
To encode the file Copy and paste the command above in the command prompt and press ENTER. You will need to wait about 10 seconds to 1 minute depending on the speed of your processor
You have successfully created an encoded audio file and encoded video files, now you need to run the following commands in order to create all the necessary files for the rest of the Instructable. Notice how the arguments change. (will take about 8 - 20 minutes):
- ffmpeg -i input.avi -s 160x90 -c:v libx264 -b:v 250k -g 90 -an input_video_160x90_250k.mp4
- ffmpeg -i input.avi -s 320x180 -c:v libx264 -b:v 500k -g 90 -an input_video_320x180_500k.mp4
- ffmpeg -i input.avi -s 640x360 -c:v libx264 -b:v 750k -g 90 -an input_video_640x360_750k.mp4
- ffmpeg -i input.avi -s 640x360 -c:v libx264 -b:v 1000k -g 90 -an input_video_640x360_1000k.mp4
- ffmpeg -i input.avi -s 1280x720 -c:v libx264 -b:v 1500k -g 90 -an input_video_1280x720_1500k.mp4
- ffmpeg -i input.avi -c:a aac -ac 2 -b:a 128k -vn input_audio_128k.mp4
Step 7: Dashifying the Encoded Files
Now that you have all you encoded files, you can turn them into DASH compatible files. This process will generate MPEG-4 initialization files that the DASH player reads at load time and a manifest file that tells the player where all the necessary files are and how to read them.
To prepare your files for streaming you need to use the following command:
mp4box -dash 5000 -rap -profile dashavc264:onDemand -mpd-title BBB -out manifest.mpd -frag 2000 input_audio_128k.mp4 input_video_160x90_250k.mp4 input_video_320x180_500k.mp4 input_video_640x360_750k.mp4 input_video_640x360_1000k.mp4 input_video_1280x720_1500k.mp4
- -dash 5000 - cuts the input files into 5 second segments
- -rap - forces the segments to start with random access points. In other words the allows for seeking of the video
- -profile dashavc264:onDemand - use the onDemand profile (you can look in the dash specifications to find out more information about the different kinds of profiles)
- -mpd-title - sets the title of the manifest to "BBB"
- -out - the output file name
- -frag - sets the fragment length to 2 seconds. This must be less than the value specified with -dash
Just make sure the created .mpd file is named "bbb.mpd".
Congratulations you have just created a video capable of streaming using DASH.
Step 8: Setting Up the Web Server
Now it is time to stream the files from our computer. To do that you need a web server. Microsoft provides one for you called Internet Information Services (IIS); all you have to do is install it.
- Open up Programs and Features (either through the control panel or Cortana)
- Click Turn Windows features on or off
- Find Internet Information Services
- Tick the box
- Click OK and it will install
- Test it by opening Chrome and navigating to your local internet address, "127.0.0.1"
- You should see the default IIS page
- If you don't see it, try rebooting your computer
Now we need to copy all the generated files to the web server
- Select every file ending with _dashinit.mp4 and the bbb.mpd from the workspace
- Copy the files to "C:\inetpub\wwwroot\"
Step 9: Enabling CORS
To test the streams you need to allow other websites to access the files on your web server. However, due to security concerns all modern browsers disallow this by default. To allow this, you need to explicitly tell the browser you are okaying a website to read data from your server. This is called Cross-origin resource sharing (CORS). To enable CORS:
- Open up the web server (WindowsKey+S then type "iis")
- Under Connections open up your server
- Then open up Sites Click on "Default Web Site" since that is where we put our files
- Double Click on HTTP Response Headers
- Under Actions click Add...
- For name, type in "Access-Control-Allow-Origin"
- For value, type "*"
- Click OK to add the header
- Click add once more
- For name, type in "Access-Control-Allow-Headers"
- For value, type in "Range"
- Click OK to add the header
Step 10: Adding the DASH MIME Type
DASH requires the use of a manifest to see how to parse the video and audio files. This manifest file ends with the extension of .mpd and Windows does not know about this extension. So to get IIS to properly send the file to the player you need to add this extension into IIS.
- Under connections click your server
- Double Click MIME Types
- Click Add...
- For File name extension type ".mpd"
- For MIME type type "application/dash+xml"
- Click OK
Now your server will be able to send the manifest to the DASH player.
Step 11: Setting Up Your Network This is absolutely not needed and should not be done This step is not required for some people. To see if you need to complete this step: Go to www.google.com Type in "what is my ip" Copy your public IP Address google gave you in to the browser Wait for the page to load; if you can see the same page as when we set up the server you can skip this step otherwise keep going If you get here then your web server is hidden from the world and you need to change that so we can see the streams. Open up command prompt Type "ipconfig" Under Ethernet adapter Ethernet or Wifi adapter find Default Gateway Copy the default gateway address in to the browser Login in to you gateway/router (if needed) From here this Instructable can't direct you on what to do, as every gateway/router is different. You need to search the model of your gateway/router and find a way to add a firewall port exception for port 80. Once you add the exception you will be able to see your website using your public IP address.
Step 12: Streaming the Video
Now that you have encoded the files, modified them for use with DASH, and setup the web server, it is finally time to see the fruit of your labor. You are going to use an external site made by the organization that created DASH to test you stream.
- Navigate to DASH-IF
- In the textbox type
"http://[your public ip address]/bbb.mpd""http://127.0.0.1/bbb.mpd"
- Click Load
Your video should commence playing immediately.
Congratulations you are on your way to becoming the next Netflix!