Optimisation of mp4 videos

This question really relates to content, but this looked like the best place for it.

I have the latest Kolibri (0.15.1) installed on RPi 4B using the RPi image provided, and I have loaded various channels from the online Studio resources, including Khan Academy (US)

The KA channel in particular contains some fairly large videos where the files are 100 - 200MB in size.
Good examples are in the section:
Khan Academy (English - US curriculum) / College, careers, and more / Entrepreneurship /
Interviews with entrepreneurs / Sal chats with entrepreneurs

I noticed that these videos took a long time to load into the browser - sometimes minutes.

The video files are .mp4 type. This type of file needs to be optimised for Web usage so that the browser can start playing the file without waiting for the whole file to be downloaded.
The key optimisation involves placing the metadata block (known as the “moov” block) to the beginning of the file rather the end. Once the browser has received the “moov” block it can commence playing the video. An explanation is provided here:
3 Solutions to MP4 Fast Start - How to Optimize Video for Web Fast Streaming?

I tested all of the large “entrepreneurs” video files from the KA channel and found that if I optimised them the slow loading issue was resolved.

So I suspect that at least some the video files in the online channel repositories are not optimised for Web usage by default.

Can anyone confirm whether videos files in the online Studio channel repositories are routinely optimised or not please? (Or did I just find some bad examples perhaps.)

Apart from the delay for users in starting the video playing, loading non-optimised files creates a major workload for the Kolibri server and the network. Transferring a 100MB video file will fully consume a 100Mbps Ethernet network for more than 10 seconds (at best), so if even a few users try to launch videos the overall effect can be a very significant loss of performance, and the appearance that the system has “hung”.

When the video files are optimised, only a small chunk of the video is sent to the browser to get started. As the video plays, further small chunks are sent as required. This allows many users to be active on the system without loss of performance. You can see this “chunking” effect happening in the progress bar at the bottom of the screen which will advance in steps as a large video plays.

Any feedback on this would be appreciated


For anyone interested in trying out the optimisation, I used ffmeg on Ubuntu command line to optimise individual video files as follows:
$ ffmpeg -i <input.mp4> -movflags faststart -c copy <output.mp4>

I then optimised all the .mp4 content on my Kolibri system storage card by running a simple script (as below) to the content stored on the system uSD card, where the content is stored at: /KOLIBRI_DATA/content/storage

The script looks recursively through sub-directories for any file whose name includes “.mp4” and applies the optimisation to each file in turn. The (temporary) output file has “.fix” appended to the original filename.
When each file optimisation is complete, the original file is replaced by the “.fix” file.
The script ran for a couple of hours to process the 80GB of content I had downloaded onto the Kolibri system.

---------------------------------
#!/bin/bash

# Find the pathname for all mp4 files in all subdirectories, then optimise each one in the loop
for vidfile in $(tree -if --noreport . | grep ".mp4"); do

   # Apply Faststart optimisation
   ffmpeg  -i $vidfile   -movflags faststart   -c copy   $vidfile.fix

   # Replace the original file
   mv   $vidfile.fix   $vidfile

done
--------------------------
2 Likes

@tgillett Thank you very much for sharing these comprehensive observations and recommendations about improving videos for streaming! :star_struck:

We do perform optimization steps with videos prior to publishing them as a Kolibri channel, but we’ll certainly include some steps that you mention to further improve. We’ll additionally include these recommendations into the user documentation for Kolibri, Studio and the Ricecooker, so the whole community can benefit from them. Thank you again for sharing! :clap:t4: