Making Your Own Simple MPEG-DASH Server (Windows 10)

About: I'm a developer, and I like to tinker with things; in other words take things apart and forget how to put them back together again :P

— 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

Picture of Installing the Software
6 More Images

It is time to install the software we need in order to properly encode and prepare the video for DASH.

  1. 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
  2. Download ffmpeg from here
  3. 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
  4. Install GPAC by running the file. In the Choose Components menu, make sure everything is ticked then click next.
  5. Extract the downloaded ffmpeg zip file to "c:\ffmpeg"
  6. Open up the System information window. (You can use the shortcut WindowsKey+Break/Pause)
  7. Click "Advanced system settings"
  8. Click "Environment Variables..."
  9. Select the "Path" variable under System variables
  10. Click "Edit..."
  11. Click "New"
  12. Type "C:\ffmpeg\bin"
  13. Click OK
  14. Click OK
  15. 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.

  1. Open the Run dialog using the shortcut WindowsKey+R
  2. Type in "cmd" into the textbox and press ENTER
  3. In the command prompt type "ffmpeg" and press ENTER
  4. If you see a bunch of text, like the first image, you have set up ffmpeg properly!
  5. Type "cls" to clear the screen
  6. Type "mp4box" and press ENTER
  7. 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.

  1. Right-Click the Desktop
  2. Hover over New
  3. Click Folder
  4. You can name this folder anything you like.
  5. Double-Click the folder to open it up
  6. Copy the movie file we downloaded earlier into the workspace
  7. 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:

  1. Open up a command prompt by pressing WindowsKey+R to bring up the run dialog
  2. Type "cmd" into the textbox and press ENTER to bring up the command line
  3. Type "cd C:\Users\[your username]\Desktop\[name of your dash workspace]" in the command line
  4. 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:

  1. Copy and paste the command above in the command prompt and press ENTER
  2. 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:

  1. Change the resolution to 320x180
  2. Change the bitrate to 500k
  3. Change the output file to input_video_320x180_500k.mp4
  4. Run the command again
  5. 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.

  1. Open up Programs and Features (either through the control panel or Cortana)
  2. Click Turn Windows features on or off
  3. Find Internet Information Services
  4. Tick the box
  5. Click OK and it will install
  6. Test it by opening Chrome and navigating to your local internet address, "127.0.0.1"
  7. You should see the default IIS page
    1. If you don't see it, try rebooting your computer

Now we need to copy all the generated files to the web server

  1. Select every file ending with _dashinit.mp4 and the bbb.mpd from the workspace
  2. 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:

  1. Open up the web server (WindowsKey+S then type "iis")
  2. Under Connections open up your server
  3. Then open up Sites Click on "Default Web Site" since that is where we put our files
  4. Double Click on HTTP Response Headers
  5. Under Actions click Add...
  6. For name, type in "Access-Control-Allow-Origin"
  7. For value, type "*"
  8. Click OK to add the header
  9. Click add once more
  10. For name, type in "Access-Control-Allow-Headers"
  11. For value, type in "Range"
  12. 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.

  1. Under connections click your server
  2. Double Click MIME Types
  3. Click Add...
  4. For File name extension type ".mpd"
  5. For MIME type type "application/dash+xml"
  6. 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:

  1. Go to www.google.com
  2. Type in "what is my ip"
  3. Copy your public IP Address google gave you in to the browser
  4. 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.

  1. Open up command prompt
  2. Type "ipconfig"
  3. Under Ethernet adapter Ethernet or Wifi adapter find Default Gateway
  4. Copy the default gateway address in to the browser
  5. Login in to you gateway/router (if needed)
  6. 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.
  7. 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.

  1. Navigate to DASH-IF
  2. In the textbox type "http://[your public ip address]/bbb.mpd" "http://127.0.0.1/bbb.mpd"
    (the dash player being in javascript, it runs client-side, therefore it can reach any network your computer is connected to, thus your localhost IP)
  3. Click Load

Your video should commence playing immediately.

Congratulations you are on your way to becoming the next Netflix!