`MULTIMEDIA
`HACKSM
`
`Kyle Rankin
`
`Beijing - Cambridge - Farnham - Kijin - Paris - Sebastopoi - Taipei
`- Tokyo
`Akamai 1012
`iii
`Akamai 1012
`111
`
`T
`
`O’RE|LLY°°
`
`
`
`Linux Multimedia Hacks”
`
`by Kyle Rankin
`
`Copyright © 2006 O’Reilly Media,_lnc. All rights reserved.
`Printed in the United States of America.
`
`Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
`
`O’Reilly books may be purchased for educational, business, or sales promotional use. Online
`editions are also available for most titles (safari.oreilly.com). For more information, Contact
`our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.c0m.
`
`Editor:
`
`David Brickner
`
`Production Editor:
`
`Jarnie Peppard
`
`581168 Editor:
`
`Rael Dornfest
`
`COVE!‘ Designer:
`
`Marcia Friedman
`
`Executive Editor:
`
`Dale Dougherty
`
`Interior Designer:
`
`David Futato
`
`Printing History:
`
`November 2005:
`
`First Edition.
`
`Nutshell Handbook, the Nutshell-Handbook logo, and the O’Reilly logo are registered
`trademarks of O’Reilly Media, Inc. The Hacks series designations, Linux Multimedia Hacks,
`the image of a stereoscope, and related trade dress are trademarks of O'Reilly Media, Inc.
`
`Many of the designations used by manufacturers and sellers to distinguish their products are
`claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc.
`was aware of a trademark claim, the designations have been printed in caps or initial caps.
`
`While every precaution has been taken in the preparation of this book, the publisher and
`author assume no responsibility for errors or omissions, or for damages resulting from the use
`of the information contained herein.
`
`Small print: The technologies discussed in this publication, the limitations on these
`technologies that technology and content owners seek to impose, and the laws actually
`limiting the use of these technologies are constantly changing. Thus, some of the hacks
`described in this publication may not work, may Cause unintended harm to systems on which
`they are used, or may not be consistent with applicable user agreements. Your use of these
`hacks is at your own risk, and O'Reilly Media, Inc. disclaims responsibility for any damage or
`expense resulting from their use. ln any event, you should take care that your use of these
`hacks does not violate any applicable laws, including copyright laws.
`
`ENG»?
`
`3.ot7<;»
`
`
`
`"‘-§:';»
`
`fin This book uses RepKover",' a durable and flexible lay—flat binding.
`
`ISBN: 0-596-10076-0
`
`[M]
`
`iv
`
`iv
`
`
`
`contents
`
`Credits .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`ix
`
`. .. xiii
`
`Preface .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`_
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`1
`
`Chapter 1. Images .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`1. Take a Screenshot
`
`2. Convert from One Image Format to Another
`
`3. Make Image Thumbnails
`
`4. Animate Images
`
`5. Leave a Watermark
`
`6. Pull Images from a Digital Camera
`
`7. Manage Photos with f—spot
`
`8. Edit Images
`
`9. Remove Red Eye from Photos
`
`10. Create a Slideshow
`
`II. Automatically Synchronize Your Camera and Computer
`
`12. Make a Screen-Capture Movie
`
`.
`
`2
`
`3
`
`5
`
`6
`
`7
`
`9
`
`11
`
`16
`
`18
`
`20
`
`22
`
`27
`
`Chapter 2. Audio .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`. 33
`
`13. Mix Your Audio for Perfect Sound
`
`14. Surround Yourself with Sound
`
`15. Play Multiple Sounds at the Same Time
`
`16. Get MP3 Libraries for Red I-Iat—Based Distributions
`
`I7. Configure Network Sound
`
`18. Manage Your Audio with XMMS
`
`19. Shuffle Your Music the Smart Way
`
`34
`
`37
`
`42
`
`45
`
`47
`
`48
`
`51
`
`
`
`20. Try Rhythmbox
`
`21. Let amaroK Rock Your Music Collection
`22. Store amaroK Data in MySQL
`
`23. Enable Your Multimedia Keyboard
`
`24. Rip CDs from the Command Line
`
`25. Rip CD5 Straight from Konqueror
`
`.
`
`26. Get a Grip on CD Ripping
`
`27. Edit ID3v2 Tags from the Command Line
`
`28. Add Album Art to ID3 Tags
`
`29. Automate Music File Tagging
`
`30. Correct Music Metadata with MusicBrainz
`
`31. Clean Music Metadata at the Command Line
`
`32. Clean Music Metadata with a GUI
`33. Pass the Mic and Record Audio
`
`34. Edit Audio with Audacity
`
`35. Convert from One Audio Format to Another
`
`-
`
`36. Normalize the Volume of Your Audio Files
`
`37. Make Your Computer Talk to You
`
`38. Search Audio for Hidden Messages
`
`39. Burn Audio CD5 from the Command Line
`
`40. Automate Audio CD Burning with K3b
`
`41. Turn Your Computer into a Turntable
`
`42. Use an iPod with Linux
`
`43. Sync Your iRiver with Linux
`
`44. Use Other Portable Audio Players
`
`45. Use a Bluetooth Headset with Linux
`
`46. Find All Your Media Files
`
`54
`
`56
`62
`
`63
`
`66
`
`70
`
`71
`
`76
`
`78
`
`80
`
`.87
`
`89
`
`93
`96
`
`97
`
`99
`
`103
`
`105
`
`107
`
`108
`
`110
`
`112
`
`118
`
`125
`
`127
`
`1.30
`
`133
`
`.
`
`.
`
`.
`
`.
`
`.
`
`. 136
`
`I
`
`Chapter 3. Video .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`47. Master Video Output Options
`
`A
`
`48. Use MPlayer
`
`49. Advanced MPlayer Tweaks
`
`50. Create Family—Friendly Edits of Movies
`
`S1. Crop Video During Playback
`
`52. Add Custom Subtitles to Video
`
`137
`
`140
`
`144
`
`146
`
`148
`
`150
`
`
`
`vi
`
`I
`
`contents
`
`
`
`53. Play Restricted Media Formats
`
`54. Watch Videos in ASCII Art
`
`_
`
`55. Try xine-Based Video Players
`
`56. View VLC, the Cross-Platform Video Player
`
`57. Probe Video Settings
`
`58. Rip a VCD
`
`59. Rip a DVD
`
`60. Encode a DVD to MPEG4 from the Command Line
`
`61. Rip and Encode DVDs with a mencoder Frontend
`
`62. Rip and Encode DVDS with K3b
`
`63. Convert from One Video Format to Another
`
`64. Create Archos—Compatible Video
`65. Convert Dual—Layer DVD to Single~Layer DVD
`
`66. Use a Digital Video Camcorder with Linux
`
`67. Edit Video
`
`68. Resize a Video
`
`69. Create 21 VCD
`
`70. Create a DVD
`
`71. Customize a DVD Menu
`
`72. Create Self-Booting Movies
`
`153
`
`156
`
`158
`
`161
`
`163
`
`164
`
`165
`
`167
`
`169
`
`172
`
`174
`
`179
`181
`
`185
`
`189
`
`191
`
`194
`
`199
`
`203
`
`206
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`. 213
`
`Chapter 4. Broadcast Media .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`73. Install a TV Tuner
`
`74. Watch TV on Your Computer
`
`75. Output to a TV with NVIDIA Cards
`
`76. Cut Commercials
`
`77. Create a DVR with MythTV
`
`78. MythTV as a Digital Hub
`
`79. Take (Remote) Control
`
`80. Browse Streaming Radio Stations
`
`81. Rip Streaming Audio
`
`82. Rip Streaming Video
`
`83. Command-Line Streaming MP3 Player
`
`84. Build a Linux Jukebox with jinzora
`
`85. Stream Video with VLC
`
`213
`
`215
`
`218
`
`221
`
`223
`
`241
`
`244
`
`246
`
`249
`
`252
`
`253
`
`254
`
`257
`
`Contents 7!
`
`vii
`
`
`
`86. Grab Podcasts from the Command Line
`
`87. Get Podcasts with a GUI
`
`88. Broadcast Sound to AM with a Monitor
`
`258
`
`260
`
`263
`
`Chapter 5. Web .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`_
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`_
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`. 266
`
`89. Install the Macromedia Plug-in in a Flash
`90. Use the Real RealPlayer
`
`I
`
`91. Watch Videos Within Firefox
`
`92. Kaffeinate Konqueror
`
`93. Install the Acrobat Reader Plug-in
`
`94. Control Your Media Player with Firefox
`
`—
`
`95. Grab Color Profiles from Other Web Sites
`
`266
`267
`
`268
`
`270
`
`271
`
`272
`
`273
`
`275
`
`96. Browse Graphical Sites from an xterm
`
`' 97. Star in Your Own Reality TV Show
`
`98. Make Internet Phone Calls with Skype
`
`99. Turn Your Linux Box into a PBX
`
`100. Host a Photo Gallery
`
`277
`
`281
`
`283
`
`286
`
`Index .
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`.
`
`. 291
`
`viii
`
`I
`
`contents
`
`
`
`This material may be protected by Copyright law (Title 17 U.S. Code)
`
`
`
`Encode a DVD to MPEG4 from the Command Line
`
`open up the DVD in your favorite video player application and check the dif-
`ferent chapters to see. In the following examples, I will encode all of chapter
`one from a DVD I have ripped into ~/example/VIDEO_TS, so change the
`chapter and file paths to suit your DVD.
`
`Full Quality Encoding with MP3 Audio
`
`The simplest method for 2—pass encoding encodes the DVD at the full bitrate
`(or how many bits you can use to store a second of video). This method will
`create a larger resulting file, but it won’t require a preliminary step of calculat-
`ing a bitrate to create an output file of a specific size. This requires two differ-
`ent mencoder commands, one for each pass:
`
`$ cat "'/example/VIDEO_TS/VTS_01*.VOB | mencoder -oac Inp31ame -ovc lavc - \
`lavcopts vcodec=mpeg4:vpass=1 -o examp1e.av:i -
`3; cat “'/example/VIDEO_TS/I/TS_a1*.VOB I mencoder -oac mp31ame -ovc lavc - \
`lavcopts vcodec=mpeg4:vpass=2 -o examp1e.av.i
`-
`
`These commands concatenate all the VOB files for chapter one as input for
`mencoder. mencoder sets the output audio codec (-oac) to MP3, and sets the
`output video codec to MPEG4 (vcodec=mpeg4). At the end of the second pass
`example.avi will be finished and ready to play. On my 1.2 CH2 Pentium-M
`processor, 2~pass encoding usually takes twice as long as the length of the
`movie, so a two~hour movie takes four hours to encode.
`
`‘A
`
`_
`
`You can encode into formats other than MPEG4 with this
`method; just view the MPlayer manpage for information on
`the different values you can pass the vcodec parameter.
`
`Encode with Specified Bitrates
`
`If space is a concern, you will likely want to specify a particular bitrate for
`mencoder to use so you can create a smaller output file. Although you could fig-
`ure out which bitrate to use by picking different bitrates at random and seeing
`how big the resulting file is, or possibly through calculation, mencoder can cal-
`culate some acceptable bitrates for you. This calculation will add some extra
`time (on a 1.2 CH2 Pentium—M, it adds 15 to 20 minutes for an average movie)
`to the process, but after you use it a few times you will probably notice a range
`of bitrates that fit with the file size you want. The first step is to remove any pre-
`vious temporary files created by the calculation process and then launch the
`special mencoder calculation command:
`
`$ rm frameno. avi
`
`$cat '‘'/examp1e/VIDEO_TS/VTS__o1*.VOB { mencoder -oac mp31ame -ovc frameno -o \
`f:rameno.av:i —
`
`168
`
`I Chapter 3, Video
`
`
`
`Rip and Encode DVDs with a mencoder Frontend
`
`Recommended video bitrate for 650MB CD: 710
`Recommended video bitrate for 700MB CD: 785
`Recommended video bitrate for 800MB CD: 934
`Recommended video bitrate for 2 x 650MB CD: 1679
`Recommended video bitrate for 2 x 700MB CD: 1828
`Recommended video bitrate for 2 x 800MB CD: 2126
`
`Text will scroll by as mencoder processes through the video. The last lines of
`the output will give you rough estimates for bitrates to use for 600, 700, and
`800 MB files (suitable for CD5). After you have chosen which bitrate to use,
`run the same 2-pass encoding commands as before, but with the addition of
`the vbitrate option (in this example 780):
`
`1: cat "/example/VIDEO_TS/I/TS_01*.VOB | mencoder -oac mp31ame -ovc lavc -\
`Iavcopts vcodec=mpeg4:vpass=1:vbitIate=78o -o examp1e.avi -
`$ cat "'/example/VIDEO_TS/VTS_o1*.VOB I mencoder -oac mp31ame -ovc lavc -\
`-lavcopts vcodec=mpeg4:vpass=2:vbitrate=780 -o examp1e.av1'
`-
`
`mencoder will process through the video as in the previous example, only
`this time with an output file that meets your space requirements.
`
`Reducing the bitrate for encoding will cause the output file to
`lose Video quality. If you aren’t pleased with the quality of a
`particular bitrate you might want to experiment with higher
`bitrates until you find one that has acceptable quality loss.
`
`
`
`i.
`
`E.
`
`if #61 Hip and Encode DVDs with a mencoder Frontend
`
`
`The acidrip utility gives you access to many of the common mencoder
`functions that rip and encode a DVD in a GUI.
`
`In “Encode a DVD to MPl{i(}4 from the Cjoinmand Linc“ [Hack #60], I discuss
`how to use mencoder’s 2—pass encoding to turn VOB files you have extracted
`from a DVD into an MPEG4 .avi file. This method works great; however,
`some people are turned off by the thought of doing encoding entirely from
`the command line. If you want to use mencoder to encode a DVD, but
`would rather have a GUI, the acidrip utility provides you with most of the
`major mencoder options you might want in a GUI interface.
`
`First, install acidrip. If you search Google a bit, you can find third—party
`acidrip packages for most distributions. For example, Debian packages are
`available in Marillat’s third—party repository that also houses packages such
`as mplayer and mencoder. If you can't find a pre—built package, then down-
`load the acidrip and accompanying lsdvd packages from the official site at
`http://untrepid.com/acidrip and follow the installation instructions.
`
`With acidrip installed, type acidrip to start the program. The default screen
`that greets you (see Figure 3-3) can be a bit intimidating at first since it has
`so many options. For basic ripping there are only a few options you need to
`
`Chapter 3, Video
`
`I
`
`169