Put in remaining pages and wiki contents.
[ikiwiki.git] / docs / handbook / handbook-video-playback.mdwn
1 \r
2 \r
3 ## 16.4 Video Playback \r
4 \r
5 ***Contributed by Ross Lippert. ***\r
6 \r
7 Video playback is a very new and rapidly developing application area. Be patient. Not everything is going to work as smoothly as it did with sound.\r
8 \r
9 Before you begin, you should know the model of the video card you have and the chip it uses. While  **XFree86™**  and  **X.org**  support a wide variety of video cards, fewer give good playback performance. To obtain a list of extensions supported by the X server using your card use the command [xdpyinfo(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#xdpyinfo&section1&manpath=XFree86+4.3.0) while X11 is running.\r
10 \r
11 It is a good idea to have a short MPEG file which can be treated as a test file for evaluating various players and options. Since some DVD players will look for DVD media in `/dev/dvd` by default, or have this device name hardcoded in them, you might find it useful to make symbolic links to the proper devices:\r
12 \r
13     \r
14     # ln -sf /dev/acd0c /dev/dvd\r
15     # ln -sf /dev/racd0c /dev/rdvd\r
16 \r
17 \r
18 Additionally, DVD decryption, which requires invoking special DVD-ROM functions, requires write permission on the DVD devices.\r
19 \r
20 Some of the packages discussed rely on the following kernel options to build correctly. Before attempting to build, add these options to the kernel configuration file, build a new kernel, and reboot:\r
21 \r
22     \r
23     option CPU_ENABLE_SSE\r
24     option USER_LDT\r
25 \r
26 \r
27 To enhance the shared memory X11 interface, it is recommended that the values of some [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#sysctl&section8) variables should be increased:\r
28 \r
29     \r
30     kern.ipc.shmmax=67108864\r
31     kern.ipc.shmall=32768\r
32 \r
33 \r
34 ### 16.4.1 Determining Video Capabilities \r
35 \r
36 There are several possible ways to display video under X11. What will really work is largely hardware dependent. Each method described below will have varying quality across different hardware. Secondly, the rendering of video in X11 is a topic receiving a lot of attention lately, and with each version of  **X.org**  or  **XFree86**  there may be significant improvement.\r
37 \r
38 A list of common video interfaces:\r
39 \r
40   1. X11: normal X11 output using shared memory.\r
41   1. XVideo: an extension to the X11 interface which supports video in any X11 drawable.\r
42   1. SDL: the Simple Directmedia Layer.\r
43   1. DGA: the Direct Graphics Access.\r
44   1. SVGAlib: low level console graphics layer.\r
45 \r
46 #### 16.4.1.1 XVideo \r
47 \r
48 Both  **XFree86 4.X**  and  **X.org**  have an extension called ***XVideo*** (aka Xvideo, aka Xv, aka xv) which allows video to be directly displayed in drawable objects through a special acceleration. This extension provides very good quality playback even on low-end machines (for example my PIII 400 Mhz laptop). Unfortunately, the list of cards in which this feature is supported ***out of the box*** is currently:\r
49 \r
50   1. 3DFX Voodoo 3\r
51   1. Intel® i810 and i815\r
52   1. some S3 chips (such as Savage/IX and Savage/MX)\r
53 \r
54 If your card is not one of these, do not be disappointed yet.  **XFree86 4.X**  adds new xv capabilities with each release [(1)](#FTN.AEN17552). To check whether the extension is running, use `xvinfo`:\r
55 \r
56     \r
57     % xvinfo\r
58 \r
59 \r
60 XVideo is supported for your card if the result looks like:\r
61 \r
62     \r
63     X-Video Extension version 2.2\r
64     screen #0\r
65       Adaptor #0: "Savage Streams Engine"\r
66         number of ports: 1\r
67         port base: 43\r
68         operations supported: PutImage\r
69         supported visuals:\r
70           depth 16, visualID 0x22\r
71           depth 16, visualID 0x23\r
72         number of attributes: 5\r
73           "XV_COLORKEY" (range 0 to 16777215)\r
74                   client settable attribute\r
75                   client gettable attribute (current value is 2110)\r
76           "XV_BRIGHTNESS" (range -128 to 127)\r
77                   client settable attribute\r
78                   client gettable attribute (current value is 0)\r
79           "XV_CONTRAST" (range 0 to 255)\r
80                   client settable attribute\r
81                   client gettable attribute (current value is 128)\r
82           "XV_SATURATION" (range 0 to 255)\r
83                   client settable attribute\r
84                   client gettable attribute (current value is 128)\r
85           "XV_HUE" (range -180 to 180)\r
86                   client settable attribute\r
87                   client gettable attribute (current value is 0)\r
88         maximum XvImage size: 1024 x 1024\r
89         Number of image formats: 7\r
90           id: 0x32595559 (YUY2)\r
91             guid: 59555932-0000-0010-8000-00aa00389b71\r
92             bits per pixel: 16\r
93             number of planes: 1\r
94             type: YUV (packed)\r
95           id: 0x32315659 (YV12)\r
96             guid: 59563132-0000-0010-8000-00aa00389b71\r
97             bits per pixel: 12\r
98             number of planes: 3\r
99             type: YUV (planar)\r
100           id: 0x30323449 (I420)\r
101             guid: 49343230-0000-0010-8000-00aa00389b71\r
102             bits per pixel: 12\r
103             number of planes: 3\r
104             type: YUV (planar)\r
105           id: 0x36315652 (RV16)\r
106             guid: 52563135-0000-0000-0000-000000000000\r
107             bits per pixel: 16\r
108             number of planes: 1\r
109             type: RGB (packed)\r
110             depth: 0\r
111             red, green, blue masks: 0x1f, 0x3e0, 0x7c00\r
112           id: 0x35315652 (RV15)\r
113             guid: 52563136-0000-0000-0000-000000000000\r
114             bits per pixel: 16\r
115             number of planes: 1\r
116             type: RGB (packed)\r
117             depth: 0\r
118             red, green, blue masks: 0x1f, 0x7e0, 0xf800\r
119           id: 0x31313259 (Y211)\r
120             guid: 59323131-0000-0010-8000-00aa00389b71\r
121             bits per pixel: 6\r
122             number of planes: 3\r
123             type: YUV (packed)\r
124           id: 0x0\r
125             guid: 00000000-0000-0000-0000-000000000000\r
126             bits per pixel: 0\r
127             number of planes: 0\r
128             type: RGB (packed)\r
129             depth: 1\r
130             red, green, blue masks: 0x0, 0x0, 0x0\r
131 \r
132 \r
133 Also note that the formats listed (YUV2, YUV12, etc) are not present with every implementation of XVideo and their absence may hinder some players.\r
134 \r
135 If the result looks like:\r
136 \r
137     \r
138     X-Video Extension version 2.2\r
139     screen #0\r
140     no adaptors present\r
141 \r
142 \r
143 Then XVideo is probably not supported for your card.\r
144 \r
145 If XVideo is not supported for your card, this only means that it will be more difficult for your display to meet the computational demands of rendering video. Depending on your video card and processor, though, you might still be able to have a satisfying experience. You should probably read about ways of improving performance in the advanced reading [video-playback.html#VIDEO-FURTHER-READING Section 16.4.3].\r
146 \r
147 #### 16.4.1.2 Simple Directmedia Layer \r
148 \r
149 The Simple Directmedia Layer, SDL, was intended to be a porting layer between Microsoft® Windows®, BeOS, and UNIX®, allowing cross-platform applications to be developed which made 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 X11 interface.\r
150 \r
151 The SDL can be found at [`devel/SDL`](http://pkgsrc.se/devel/SDL).\r
152 \r
153 #### 16.4.1.3 Direct Graphics Access \r
154 \r
155 Direct Graphics Access is an X11 extension which allows a program to bypass the X server and directly alter the framebuffer. Because it relies on a low level memory mapping to effect this sharing, programs using it must be run as `root`.\r
156 \r
157 The DGA extension can be tested and benchmarked by [dga(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#dga&section1&manpath=XFree86+4.3.0). When `dga` is running, it changes the colors of the display whenever a key is pressed. To quit, use  **q** .\r
158 \r
159 ### 16.4.2 Ports and Packages Dealing with Video \r
160 \r
161 This section discusses the software available from the pkgsrc® tree which can be used for video playback. Video playback is a very active area of software development, and the capabilities of various applications are bound to diverge somewhat from the descriptions given here.\r
162 \r
163 Firstly, it is important to know that many of the video applications which run on DragonFly were developed as Linux applications. Many of these applications are still beta-quality. Some of the problems that you may encounter with video packages on DragonFly include:\r
164 \r
165   1. An application cannot playback a file which another application produced.\r
166   1. An application cannot playback a file which the application itself produced.\r
167   1. The same application on two different machines, rebuilt on each machine for that machine, plays back the same file differently.\r
168   1. A seemingly trivial filter like rescaling of the image size results in very bad artifacts from a buggy rescaling routine.\r
169   1. An application frequently dumps core.\r
170   1. Documentation is not installed with the port and can be found either on the web or under the port's `work` directory.\r
171 \r
172 Many of these applications may also exhibit ***Linux-isms***. That is, 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:\r
173 \r
174   1. The use of `/proc/cpuinfo` to detect processor characteristics.\r
175   1. A misuse of threads which causes a program to hang upon completion instead of truly terminating.\r
176   1. Software not yet in the pkgsrc tree which is commonly used in conjunction with the application.\r
177 \r
178 So far, these application developers have been cooperative with port maintainers to minimize the work-arounds needed for port-ing.\r
179 \r
180 #### 16.4.2.1 MPlayer \r
181 \r
182  **MPlayer**  is a recently developed and rapidly developing video player. The goals of the  **MPlayer**  team are speed and flexibility on Linux and other Unices. The project was started when the team founder got fed up with bad playback performance on then available players. Some would say that the graphical interface has been sacrificed for a streamlined design. However, once you get used to the command line options and the key-stroke controls, it works very well.\r
183 \r
184 ##### 16.4.2.1.1 Building MPlayer \r
185 \r
186  **MPlayer**  resides in [`multimedia/mplayer`](http://pkgsrc.se/multimedia/mplayer).  **MPlayer**  performs a variety of hardware checks during the build process, resulting in a binary which will not be portable from one system to another. Therefore, it is important to build it from ports and not to use a binary package. Additionally, a number of options can be specified in the `bmake` command line, as described in the `bmake show-options`.\r
187 \r
188     \r
189     # cd /usr/pkgsrc/multimedia/mplayer\r
190     # bmake show-options\r
191     Any of the following general options may be selected:\r
192             aalib    Enable aalib support.\r
193             arts     Use the aRts audio daemon.\r
194             dts      Enable DTS Coherent Acoustics support.\r
195             dv       Enable usage of the libdv library.\r
196             dvdread  Enable reproduction of DVDs.\r
197             esound   Enable support for the Enlightment Sound Daemon.\r
198             ggi      Enable GGI support.\r
199             gif      Enable GIF support.\r
200             jpeg     Enable JPEG support.\r
201             mad      Enable usage of the mad library to play MP3 files.\r
202             mplayer-menu     Enable support for user-defined menus.\r
203             mplayer-real     Enable usage of Real codecs.\r
204             mplayer-runtime-cpudetection    Enable CPU detection at run time.\r
205             mplayer-win32    Enable usage of Win32 DLLs (codecs).\r
206             nas      Enable usage of the Network Audio System.\r
207             oss      Enable support for the Open Sound System audio library.\r
208             png      Enable PNG support.\r
209             sdl      Use SDL as display library.\r
210             theora   Use the theora codecs.\r
211             vorbis   Enable Ogg Vorbis support.\r
212             xvid     Enable usage of XVid codecs.\r
213     At most one of the following faadgroup options may be selected:\r
214             faad     Enable AAC decoding support using faad2.\r
215             mplayer-internal-faad\r
216     \r
217     These options are enabled by default:\r
218             aalib arts dv dvdread esound faad gif jpeg\r
219             mad mplayer-menu mplayer-real mplayer-runtime-cpudetection\r
220             mplayer-win32 nas oss png sdl theora vorbis\r
221             xvid\r
222     \r
223     These options are currently enabled:\r
224             aalib arts dv dvdread esound faad gif jpeg\r
225             mad mplayer-menu mplayer-real mplayer-runtime-cpudetection\r
226             mplayer-win32 nas oss png sdl theora vorbis\r
227             xvid\r
228     \r
229     You can select which build options to use by setting PKG_DEFAULT_OPTIONS\r
230     or PKG_OPTIONS.mplayer.\r
231 \r
232 \r
233 If you have [`x11/gtk`](http://pkgsrc.se/x11/gtk) installed, then you might as well enable the GUI. Otherwise, it is not worth the effort. If it is illegal to play (possibly CSS encoded) DVD's with  **MPlayer**  on your country you must disable the DVD support option[(2)](#FTN.AEN17649). Otherwise the defaults are ok:\r
234 \r
235     \r
236     # bmake\r
237 \r
238 \r
239 As of this writing, the  **MPlayer**  port will build its HTML documentation and one executable, `mplayer`. By default it builds an encoder, `mencoder`, which is a tool for re-encoding video. A modification to the `Makefile` can disable it.\r
240 \r
241 The HTML documentation for  **MPlayer**  is very informative. If the reader finds the information on video hardware and interfaces in this chapter lacking, the  **MPlayer**  documentation is a very thorough supplement. You should definitely take the time to read the  **MPlayer**  documentation if you are looking for information about video support in UNIX.\r
242 \r
243 ##### 16.4.2.1.2 Using MPlayer \r
244 \r
245 The command options for `mplayer` are listed in the manual page. For even more detail there is HTML documentation. In this section, we will describe only a few common uses.\r
246 \r
247 To play a file, such as ' **testfile.avi** ', through one of the various video interfaces set the `-vo` option:\r
248 \r
249     \r
250     % mplayer -vo xv testfile.avi\r
251 \r
252 \r
253     \r
254     % mplayer -vo sdl testfile.avi\r
255 \r
256 \r
257     \r
258     % mplayer -vo x11 testfile.avi\r
259 \r
260 \r
261     \r
262     # mplayer -vo dga testfile.avi\r
263 \r
264 \r
265     \r
266     # mplayer -vo 'sdl:dga' testfile.avi\r
267 \r
268 \r
269 It is worth trying all of these options, as their relative performance depends on many factors and will vary significantly with hardware.\r
270 \r
271 To play from a DVD, replace the `testfile.avi` with `-dvd `***N***` `***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`:\r
272 \r
273     \r
274     # mplayer -vo dga -dvd 3 /dev/dvd\r
275 \r
276 \r
277 To stop, pause, advance and so on, consult the keybindings, which are output by running `mplayer -h` or read the manual page.\r
278 \r
279 Additional important options for playback are: `-fs -zoom` which engages the fullscreen mode and `-framedrop` which helps performance.\r
280 \r
281 In order for the mplayer command line to not become too large, the user can create a file `.mplayer/config` and set default options there:\r
282 \r
283     \r
284     vo=xv\r
285     fs=yes\r
286     zoom=yes\r
287 \r
288 \r
289 Finally, `mplayer` can be used to rip a DVD title into a `.vob` file. To dump out the second title from a DVD, type this:\r
290 \r
291     \r
292     # mplayer -dumpstream -dumpfile out.vob -dvd 2 /dev/dvd\r
293 \r
294 \r
295 The output file, `out.vob`, will be MPEG and can be manipulated by the other packages described in this section.\r
296 \r
297 ##### 16.4.2.1.3 mencoder \r
298 \r
299 If you installed `mencoder` when you build  **MPlayer** , be forewarned that it is still an experimental component. Before using `mencoder` it is a good idea to familiarize yourself with the options from the HTML documentation. There is a manual page, but it is not very useful without the HTML documentation. There are innumerable ways to improve quality, lower bitrate, and change formats, and some of these tricks may make the difference between good or bad performance. Here are a couple of examples to get you going. First a simple copy:\r
300 \r
301     \r
302     % mencoder input.avi -oac copy -ovc copy -o output.avi\r
303 \r
304 \r
305 Improper combinations of command line options can yield output files that are unplayable even by `mplayer`. Thus, if you just want to rip to a file, stick to the `-dumpfile` in `mplayer`.\r
306 \r
307 To convert `input.avi` to the MPEG4 codec with MPEG3 audio encoding ([`audio/lame`](http://pkgsrc.se/audio/lame) is required):\r
308 \r
309     \r
310     % mencoder input.avi -oac mp3lame -lameopts br=192 \\r
311          -ovc lavc -lavcopts vcodec=mpeg4:vhq -o output.avi\r
312 \r
313 \r
314 This has produced output playable by `mplayer` and `xine`.\r
315 \r
316 `input.avi` can be replaced with `-dvd 1 /dev/dvd` and run as `root` to re-encode a DVD title directly. Since you are likely to be dissatisfied with your results the first time around, it is recommended you dump the title to a file and work on the file.\r
317 \r
318 #### 16.4.2.2 The xine Video Player \r
319 \r
320 The  **xine**  video player is a project of wide scope aiming not only at being an all in one video solution, but also in producing a reusable base library and a modular executable which can be extended with plugins. It comes both as a package and as a port, [`multimedia/xine-ui`](http://pkgsrc.se/multimedia/xine-ui).\r
321 \r
322 The  **xine**  player is still very rough around the edges, but it is clearly off to a good start. In practice,  **xine**  requires either a fast CPU with a fast video card, or support for the XVideo extension. The GUI is usable, but a bit clumsy.\r
323 \r
324 As of this writing, there is no input module shipped with  **xine**  which will play CSS encoded DVD's. There are third party builds which do have modules for this built in them, but none of these are in the pkgsrc tree.\r
325 \r
326 Compared to  **MPlayer** ,  **xine**  does more for the user, but at the same time, takes some of the more fine-grained control away from the user. The  **xine**  video player performs best on XVideo interfaces.\r
327 \r
328 By default,  **xine**  player will start up in a graphical user interface. The menus can then be used to open a specific file:\r
329 \r
330     \r
331     % xine\r
332 \r
333 \r
334 Alternatively, it may be invoked to play a file immediately without the GUI with the command:\r
335 \r
336     \r
337     % xine -g -p mymovie.avi\r
338 \r
339 \r
340 #### 16.4.2.3 The transcode Utilities \r
341 \r
342 The software  **transcode**  is not a player, but a suite of tools for re-encoding `.avi` and `.mpg` files. With  **transcode** , one has the ability to merge video files, repair broken files, using command line tools with `stdin/stdout` stream interfaces.\r
343 \r
344 Like  **MPlayer** ,  **transcode**  is very experimental software which must be build from pkgsrc at [`multimedia/transcode`](http://pkgsrc.se/multimedia/transcode). You can see all the available options with the `bmake show-options` command. I recommend the default ones.\r
345 \r
346     \r
347     # bmake\r
348 \r
349 \r
350 Here are two examples of using `transcode` for video conversion which produce rescaled output. The first encodes the output to an openDIVX AVI file, while the second encodes to the much more portable MPEG format.\r
351 \r
352     \r
353     % transcode -i input.vob -x vob -V -Z 320x240 \\r
354     -y opendivx -N 0x55 -o output.avi\r
355 \r
356 \r
357     \r
358     % transcode -i input.vob -x vob -V -Z 320x240 \\r
359     -y mpeg -N 0x55 -o output.tmp\r
360     % tcmplex -o output.mpg -i output.tmp.m1v -p output.tmp.mpa -m 1\r
361 \r
362 \r
363 There is a manual page for `transcode`, but there is little documentation for the various `tc*` utilities (such as `tcmplex`) which are also installed. However, the `-h` command line option can always be given to get curt usage instructions for a command.\r
364 \r
365 In comparison, `transcode` runs significantly slower than `mencoder`, but it has a better chance of producing a more widely playable file. MPEGs created by `transcode` have been known to play on  **Windows Media® Player**  and Apple's  **Quicktime®** , for example.\r
366 \r
367 ### 16.4.3 Further Reading \r
368 \r
369 The various video software packages for DragonFly are developing rapidly. It is quite possible that in the near future many of the problems discussed here will have been resolved. In the mean time, those who want to get the very most out of DragonFly's A/V capabilities will have to cobble together knowledge from several FAQs and tutorials and use a few different applications. This section exists to give the reader pointers to such additional information.\r
370 \r
371 The [MPlayer documentation](http://www.mplayerhq.hu/DOCS/) is very technically informative. These documents should probably 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 if you plan on making bug reports to them, RTFM.\r
372 \r
373 The [xine HOWTO](http://dvd.sourceforge.net/xine-howto/en_GB/html/howto.html) contains a chapter on performance improvement which is general to all players.\r
374 \r
375 Finally, there are some other promising applications which the reader may try:\r
376 \r
377
378 * [Avifile](http://avifile.sourceforge.net/) which is not yet in the official pkgsrc tree, but you can find it on [pkgsrc-wip](http://pkgsrc-wip.sourceforge.net/).\r
379
380 * [Ogle](http://www.dtek.chalmers.se/groups/dvd/) which is also a port [`multimedia/ogle`](http://pkgsrc.se/multimedia/ogle).\r
381
382 * [Xtheater](http://xtheater.sourceforge.net/)\r
383
384 * [`multimedia/dvdauthor`](http://pkgsrc.se/multimedia/dvdauthor), an open source package for authoring DVD content.\r
385 \r
386 #### Notes \r
387 \r
388 [[!table  data="""
389 |<tablestyle="width:100%"> [video-playback.html#AEN17552 (1)] | A popular familiar graphics card with generally very good  **XFree86**  performance, nVidia, has yet to release the specifications on their XVideo support to the  **XFree86**  team. It may be some time before  **XFree86**  fully support XVideo for these cards. 
390  [video-playback.html#AEN17649 (2)] | Unauthorized DVD playback is a serious criminal act in some countries. Check local laws before enabling this option. |\r
391 """]]\r
392 \r
393 \r
394 CategoryHandbook\r
395 CategoryHandbook-multimedia\r