8.4. Video Playback

Contributed by Ross Lippert.

Before configuring video playback, determine the model of the video card and the chip it uses. While Xorg supports a wide variety of video cards, fewer give good playback performance. To obtain a list of extensions supported by the Xorg server using the card, run xdpyinfo(1) while Xorg is running.

It is a good idea to have a short MPEG test file for evaluating various players and options. Since some DVD applications look for DVD media in /dev/dvd by default, or have this device name hardcoded in them, it might be useful to make symbolic links to the proper devices:

# ln -sf /dev/acd0 /dev/dvd # ln -sf /dev/acd0 /dev/rdvd

Due to the nature of devfs(5), manually created links will not persist after a system reboot. In order to create the symbolic links automatically when the system boots, add the following lines to /etc/devfs.conf:

link acd0 dvd link acd0 rdvd

DVD decryption invokes special DVD-ROM functions and requires write permission on the DVD devices.

To enhance the shared memory Xorg interface, it is recommended to increase the values of these sysctl(8) variables:

kern.ipc.shmmax=67108864 kern.ipc.shmall=32768

8.4.1. Determining Video Capabilities

There are several possible ways to display video under Xorg. What works is largely hardware dependent. Each method described below will have varying quality across different hardware.

Common video interfaces include:

  1. Xorg: normal output using shared memory.

  2. XVideo: an extension to the Xorg interface which supports video in any drawable object.

  3. SDL: the Simple Directmedia Layer.

  4. DGA: the Direct Graphics Access.

  5. SVGAlib: low level console graphics layer.

8.4.1.1. XVideo

Xorg has an extension called XVideo, also known as Xvideo, Xv, and xv. It allows video to be directly displayed in drawable objects through a special acceleration. This extension provides good quality playback even on low-end machines.

To check whether the extension is running, use xvinfo:

% xvinfo

XVideo is supported for the card if the result looks like:

X-Video Extension version 2.2 screen #0 Adaptor #0: "Savage Streams Engine" number of ports: 1 port base: 43 operations supported: PutImage supported visuals: depth 16, visualID 0x22 depth 16, visualID 0x23 number of attributes: 5 "XV_COLORKEY" (range 0 to 16777215) client settable attribute client gettable attribute (current value is 2110) "XV_BRIGHTNESS" (range -128 to 127) client settable attribute client gettable attribute (current value is 0) "XV_CONTRAST" (range 0 to 255) client settable attribute client gettable attribute (current value is 128) "XV_SATURATION" (range 0 to 255) client settable attribute client gettable attribute (current value is 128) "XV_HUE" (range -180 to 180) client settable attribute client gettable attribute (current value is 0) maximum XvImage size: 1024 x 1024 Number of image formats: 7 id: 0x32595559 (YUY2) guid: 59555932-0000-0010-8000-00aa00389b71 bits per pixel: 16 number of planes: 1 type: YUV (packed) id: 0x32315659 (YV12) guid: 59563132-0000-0010-8000-00aa00389b71 bits per pixel: 12 number of planes: 3 type: YUV (planar) id: 0x30323449 (I420) guid: 49343230-0000-0010-8000-00aa00389b71 bits per pixel: 12 number of planes: 3 type: YUV (planar) id: 0x36315652 (RV16) guid: 52563135-0000-0000-0000-000000000000 bits per pixel: 16 number of planes: 1 type: RGB (packed) depth: 0 red, green, blue masks: 0x1f, 0x3e0, 0x7c00 id: 0x35315652 (RV15) guid: 52563136-0000-0000-0000-000000000000 bits per pixel: 16 number of planes: 1 type: RGB (packed) depth: 0 red, green, blue masks: 0x1f, 0x7e0, 0xf800 id: 0x31313259 (Y211) guid: 59323131-0000-0010-8000-00aa00389b71 bits per pixel: 6 number of planes: 3 type: YUV (packed) id: 0x0 guid: 00000000-0000-0000-0000-000000000000 bits per pixel: 0 number of planes: 0 type: RGB (packed) depth: 1 red, green, blue masks: 0x0, 0x0, 0x0

The formats listed, such as YUV2 and YUV12, are not present with every implementation of XVideo and their absence may hinder some players.

If the result looks like:

X-Video Extension version 2.2 screen #0 no adaptors present

XVideo is probably not supported for the card. This means that it will be more difficult for the display to meet the computational demands of rendering video. Depending on the video card and processor, one might still be able to have a satisfying experience.

8.4.1.2. Simple Directmedia Layer

The Simple Directmedia Layer, SDL, is a porting layer for many operating systems allowing cross-platform applications to be developed which make efficient use of sound and graphics. The SDL layer provides a low-level abstraction to the hardware which can sometimes be more efficient than the Xorg interface.

SDL can be installed using the devel/sdl12 package or port.

8.4.1.3. Direct Graphics Access

DGA is an Xorg extension which allows a program to bypass the Xorg server and directly alter the framebuffer. Because it relies on a low level memory mapping, programs using it must be run as root.

The DGA extension can be tested and benchmarked using dga(1). When dga is running, it changes the colors of the display whenever a key is pressed. To quit, press q.

8.4.2. Ports and Packages Dealing with Video

This section introduces some of the software available from the FreeBSD Ports Collection which can be used for video playback.

Many of the video applications which run on FreeBSD were developed as Linux® applications. Many of these applications are still beta-quality. Some of the problems commonly encountered with video packages on FreeBSD include:

  1. An application cannot playback a file which another application produced.

  2. An application cannot playback a file which the application itself produced.

  3. The same application on two different machines, rebuilt on each machine for that machine, plays back the same file differently.

  4. A seemingly trivial filter, like rescaling of the image size, results in bad artifacts from a buggy rescaling routine.

  5. An application frequently dumps core.

  6. Documentation is not installed with the port and can be found either on the web or under the port's work directory.

Many applications may also exhibit Linux®-isms. There may be issues resulting from the way some standard libraries are implemented in the Linux® distributions, or some features of the Linux® kernel which have been assumed by the authors of the applications. These issues are not always noticed and worked around by the port maintainers, which can lead to problems like these:

  1. The use of /proc/cpuinfo to detect processor characteristics.

  2. A misuse of threads which causes a program to hang upon completion instead of truly terminating.

  3. Relies on software which is not yet available in the FreeBSD Ports Collection.

8.4.2.1. MPlayer

MPlayer is a command-line video player with an optional graphical interface which aims to provide speed and flexibility. This application, as well as other graphical front-ends, is available from the FreeBSD Ports Collection.

8.4.2.1.1. Building MPlayer

MPlayer is available as a package or port in multimedia/mplayer. Several compile options are available and a variety of hardware checks occur during the build process. For these reasons, some users prefer to build the port rather than install the package. The available options will be displayed in a menu after these commands are input:

# cd /usr/ports/multimedia/mplayer # make

The menu options should be reviewed to determine the type of support to compile into the port. If an option is not selected, MPlayer will not be able to display that type of video format. Use the arrow keys and spacebar to select the required formats. When finished, press Enter to continue the port compile and installation.

By default, this package or port will build the mplayer command line utility and the gmplayer graphical utility. To encode videos, install the multimedia/mencoder port. Due to licensing restrictions, a package is not available for MEncoder.

8.4.2.1.2. Using MPlayer

The first time MPlayer is run, it will create ~/.mplayer in the user's home directory. This subdirectory contains default versions of the user-specific configuration files.

This section describes only a few common uses. Refer to the mplayer manual page for a complete description of its numerous options.

To play the file testfile.avi, specify the video interfaces with -vo:

% mplayer -vo xv testfile.avi
% mplayer -vo sdl testfile.avi
% mplayer -vo x11 testfile.avi
# mplayer -vo dga testfile.avi
# mplayer -vo 'sdl:dga' testfile.avi

It is worth trying all of these options, as their relative performance depends on many factors and will vary significantly with hardware.

To play a DVD, replace the testfile.avi with dvd://N -dvd-device DEVICE, where N is the title number to play and DEVICE is the device node for the DVD-ROM. For example, to play title 3 from /dev/dvd:

# mplayer -vo xv dvd://3 -dvd-device /dev/dvd

Note:

The default DVD device can be defined during the build of the MPlayer port by including the WITH_DVD_DEVICE=/path/to/desired/device option. By default, the device is /dev/acd0. More details can be found in the port's Makefile.options.

To stop, pause, advance, and so on, consult the keybindings, which are displayed by running mplayer -h, or read the manual page.

Additional playback options include -fs -zoom, which engages fullscreen mode, and -framedrop, which helps performance.

Each user can add commonly used options to their ~/.mplayer/config like so:

vo=xv fs=yes zoom=yes

mplayer can be used to rip a DVD title to a .vob. To dump the second title from a DVD:

# mplayer -dumpstream -dumpfile out.vob dvd://2 -dvd-device /dev/dvd

The output file, out.vob, will be MPEG and can be manipulated by the other packages described in this section.

The MPlayer documentation is technically informative and should be consulted by anyone wishing to obtain a high level of expertise with UNIX® video. The MPlayer mailing list is hostile to anyone who has not bothered to read the documentation, so before making a bug report, read the documentation first.

8.4.2.1.3. MEncoder

Before using mencoder, it is a good idea to become familiar with the options described in the HTML documentation. There are innumerable ways to improve quality, lower bitrate, and change formats, and some of these options may make the difference between good or bad performance. Improper combinations of command line options can yield output files that are unplayable even by mplayer.

Here is an example of a simple copy:

% mencoder input.avi -oac copy -ovc copy -o output.avi

To rip to a file, use -dumpfile with mplayer.

To convert input.avi to the MPEG4 codec with MPEG3 audio encoding, first install the audio/lame port. Due to licensing restrictions, a package is not available. Once installed, type:

% mencoder input.avi -oac mp3lame -lameopts br=192 \ -ovc lavc -lavcopts vcodec=mpeg4:vhq -o output.avi

This will produce output playable by applications such as mplayer and xine.

input.avi can be replaced with dvd://1 -dvd-device /dev/dvd and run as root to re-encode a DVD title directly. Since it may take a few tries to get the desired result, it is recommended to dump the title to a file and to work on the file.

8.4.2.2. The xine Video Player

xine is a video player with a reusable base library and a modular executable which can be extended with plugins. It can be installed using the multimedia/xine package or port.

In practice, xine requires either a fast CPU with a fast video card, or support for the XVideo extension. The xine video player performs best on XVideo interfaces.

By default, the xine player starts a graphical user interface. The menus can then be used to open a specific file.

Alternatively, xine may be invoked to play a file immediately without the graphical interface:

% xine

Alternatively, it may be invoked to play a file immediately without the GUI with the command:

% xine -g -p mymovie.avi

The xine HOWTO contains a chapter on performance improvement which is general to all players.

8.4.2.3. The transcode Utilities

transcode provides a suite of tools for re-encoding video and audio files. transcode can be used to merge video files or repair broken files using command line tools with stdin/stdout stream interfaces.

transcode can be installed using the multimedia/transcode package or port. Many users prefer to compile the port as it provides a menu of compile options for specifying the support and codecs to compile in. If an option is not selected, transcode will not be able to encode that format. Use the arrow keys and spacebar to select the required formats. When finished, press Enter to continue the port compile and installation.

This example demonstrates how to convert a DivX file into a PAL MPEG-1 file (PAL VCD):

% transcode -i input.avi -V --export_prof vcd-pal -o output_vcd % mplex -f 1 -o output_vcd.mpg output_vcd.m1v output_vcd.mpa

The resulting MPEG file, output_vcd.mpg, is ready to be played with MPlayer. The file can be burned on a CD-R media to create a Video CD. In this, install and use the multimedia/vcdimager and sysutils/cdrdao programs.

In addition to the manual page for transcode, refer to the transcode wiki for further information and examples.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.