John's Corner

Download MPEG-DASH video

This tip covers how to download an MPEG-DASH video stream and save it to a standalone MP4 or other video file.

MPEG-DASH (Dynamic Adaptive Streaming over HTTP) streams are a relatively new way to supply video to users. In simple terms, the video and audio is divided up into short segments (eg. 10 secs) and streamed to the web browser as required. The video and audio can be streamed as a single combined segment or as two separate segments.

This means the user only gets sent data when the video is actually playing which also acts to reduce load on servers. Best of all, it ensures video and audio remain in sync. There is usually provision to increase or decrease the quality on the fly, depending on the speed of the connection to give the user the best quality while minimising dropouts. Downloading to an offline file allows the best quality to be saved and then played back locally without dropouts. Information about the available resolutions and segments is contained in an initial master file, typically in JSON, XML, MPD or M3U8 format.

The video is not downloadable as a single file, so the video and audio data segments must be individually downloaded and then assembled into a standalone file. The process described below uses the Windows Command Prompt console and requires Youtube DL to download the segments and FFmpeg to create the standalone file. You will need to play the video in your browser and use the DevTools or Debug console in your browser to get information about the video and audio streams. Sometimes the browser will not play the video when the debug console is active. In this case, you will need to use a network traffic monitoring extension. The Traffic Analyser extension for Google Chrome is recommended.

The instructions below should work for a wide variety of files and websites but read carefully. Some of the commands will need modification to suit the particular situation.

  1. Initial Setup
    This step sets up the folders and tools you will need.

  2. Get download URLs
    This step gets information about the video and audio streams and where to download them from. Note: These URLs may be time limited so best to download immediately.

  3. Prepare the download commands
    This step sets up the commands needed to download all the video and audio data segments. An example of a completed video command is shown below:
    for /L %A in (0,1,288) do (youtube-dl -o video\%(title^)s "https://200vod-adaptive.akamaized.net/exp=1585613778~acl=%2F01cf90c8-e4ad-4e58-b547-2dd8a8728aa7%2F%2A~hmac=fffda9518507e194075586e847af3bdea325d1dacdac11d3fbb0bcbabd28a333/01cf90c8-e4ad-4e58-b547-2dd8a8728aa7/sep/video/96dec4e9/chop/segment-%A.m4s")
    These video and audio commands will be used to download all the associated segments in a single step. Note that the -o video\%(title^)s following youtube-dl instructs Youtube downloader to store the downloaded file in the video subfolder - similarly for the audio subfolder. The ^ character is an "escape" character which essentially tells the windows command interpreter to ignore the following ) character and pass it on to the youtube-dl command. Without it, the overall command will fail.

  4. Download video and audio segments
    This step downloads all the segments for each stream into their respective subfolders. Note: segment-0 has the header information to create the playable video or audio file.

  5. Join segments
    This step joins the segments to create the video and audio data files. This excludes the first header segment.

  6. Create playable video and audio files
    You have four key files ready, the video and audio header files and the video and audio data files. You now need to join the headers to their respective data files to create the playable video and audio stream files using ffmpeg as follows:
    ffmpeg -i "concat:video-header.m4s|video.m4s" -c copy video.mp4
    ffmpeg -i "concat:audio-header.m4s|audio.m4s" -c copy audio.aac
    Note: if audio.aac causes an error, try audio.mp3

  7. Create the final mp4 file
    Use the following command to combine the video and audio stream files into the final container. This could be mp4 or mkv
    ffmpeg -i video.mp4 -i audio.aac -c copy movie.mp4
    Test movie.mp4 in your favourite player (or drop onto a web browser page) to ensure it is playable in the desired resolution with audio.

  8. Cleanup
    This step removes all intermediate files to reclaim space and prepare for next use.

Please Note:  Where possible, try to use aac for the audio stream. You can use Xmedia Recode to transcode the audio file before you create the final mp4 file. This will produce an mp4 file that is playable on the widest range of devices. Some Apple devices do not support mp3 audio in an mp4 video file.


Return to Tips and Tricks


John's Corner