====== Video Encoding ======
In general, video needs to be encoded as MP4 (or M4V) files, with video encoded using the H.264 codec and audio (if any) using the AAC codec. While there are many programs you can use to encode video, we recommend the free ffmpeg program, which provides very good and consistent result on all platforms. Here's an example of an ffmpeg command encoding video in the recommended format:
ffmpeg -i in.mov -pix_fmt yuv420p -c:v libx264 -crf 22 -movflags +faststart out.mp4
The command above uses the constant quality option //-crf 22// rather than a specific bit-rate. We've found this to give the best possible quality while using an adaptive data rate depending on the needs of the source content.
In some cases, you may also be able to use the less common WebM format. This supports video with transparent areas (more on that below).
Blocks streams video over the network. For best streaming performance, an video file should have a reasonable data-rate for its resolution, and be optimized for "fast start". Such a "fast start" video file has the following properties:
* The internal "file dictionary" is positioned at the beginning of the file, making this available right away as the file begins to stream.
* The file's data tracks (audio and video) are properly interleaved in the file, arriving for playback as needed.
Some video encoders provide options to optimize the file for "streaming" and/or "fast start". If so, you can use those options. Ffmpeg provides the //-movflags +faststart// option to accomplish this, as mentioned above. If your video encoder of choice doesn't have such an option, you can apply this optimization to an already encoded video file using the following command line, again using the ffmpeg program. This example optimizes the file in that respect without re-encoding it, so there's no loss in quality:
ffmpeg -i "SourceFile.mov" -movflags +faststart -c:v copy -c:a copy "DestFile.mp4"
This assumes that the file already holds H.264-encoded video, and any audio is AAC encoded.
The MOV and MP4 container file formats are very similar. Thus, if you have a MOV file that you know contains H.264 video and AAC audio, you can often use it as is, possibly after "optimizing" it as described above, where the source file is a MOV and the output file is set to MP4.
===== Using WebM Video Files =====
Another file format that can offer additional capabilities is WebM from Google. One interesting capability of this format is that it supports true transparency (sometimes referred to as an "alpha channel"). To use such a file with Blocks, use a browser that supports this format (such as Google Chrome) to bring the file into Blocks.
Example ffmpeg command line to encode a video in webm format:
ffmpeg -i SourceVideoWithAlpha.mov -c:v libvpx-vp9 -crf 22 out.webm
More on using transparency in video for the web in [[https://rotato.app/blog/transparent-videos-for-the-web|this article]].
:!: **IMPORTANT:** While WebM works on PIXILAB Player and most other Chrome-based browsers (including Android-based devices), it does //not// work on iOS or iPadOS. Thus, do not use the WebM format if your content may need to play back on visitor's mobile phones or other devices over which you have no control of which browser is being used.