Skip to content
Giovanni Bajo edited this page Sep 23, 2023 · 10 revisions

Introduction

Libdragon contains a MPEG-1 player. The player is based on pl_mpeg, but the core algorithms have been replaced by a RSP ucode that makes use of vectorization to speed up decoding.

The player is normally capable of playing back a 320x240 movie at 800 Kbit/s at 20 fps. You can use this as a ballpark for the expected quality.

How to encode a video

Libdragon's MPEG player works with raw MPEG1 video streams. Normally, MPEG1 videos come with the .mpg extension which signals the presence of the mpg container, with interleaved video and audio. Instead, raw MPEG1 streams are normally saved with the .m1v extension. To play a movie with audio, then, both a .m1v and a .wav64 file are required (see the videoplayer example).

Encode a video using ffmpeg

ffmpeg is very popular for video encoding, even though it is a bit inflexible with MPEG-1 (probably the format is too old and less developed). To encode a video that libdragon can playback, use this command line:

ffmpeg -i <INPUTFILE> -vb 800K -vf 'scale=320:240' -r 20 output.m1v

This creates a MPEG-1 file at resolution 320x240, at 20 FPS, with 800 Kbps of bitrate (average). You can play with the various encoding parameters to improve video quality or reduce stuttering. Notice that resolution disproportionately affect decoding speed, so see below for some suggested resolutions to try.

Unfortunately, ffmpeg does not seem to respect the provided bitrate close enough, so there might still be scenes where bitrates go through the roof. The MPEG-1 encoder does not offer many knobs to avoid this (at least that we could find).

Encode a video using TMPGEnc

TMPGEnc is a proprietary video encoder specialized in MPEG-1/2, which distributes a free version that's quite feature packed. The software is pretty old but it still runs correctly on Windows 10/11. It is far slower than ffmpeg at encoding, but it offers many more tuning knobs and a more gradual quality control. It is GUI only.

  • Download and install the TMPGEnc free version.
  • Download and install ffdshow. TMPGEnc is only able to decode video codecs for which a VFW plugin is installed, so ffdshow is probably the best choice to cover most common formats (like H.264).
  • Run TMPGEnc, skip the wizard.
  • Select the input file and output file at the bottom of the screen. Make sure that the option ES (Video Only) is selected.
Screenshot 2023-09-23 alle 23 32 21
  • Click on Settings. Select MPEG-1 Video, the insert the resolution and select the desired framerate. In Rate Control Mode, select Constant Quality (CQ), then click on Setting and move the slider to adjust the quality level. Try levels in the range 80-95, they usually work well enough. In that same screen, edit Maximum Bitrate and insert a value like 1000 that puts an upper cap to the per-frame bitrate.
Screenshot 2023-09-23 alle 23 33 34
Clone this wiki locally