Archive for category Mac OS X
MacOSX: Trimming fat from Mach-O fat files
MacOS X uses fat files.
A fat bundle contains data for different architectures. Here are some examples:
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# file * Terminal: Mach-O fat file with 2 architectures Terminal (for architecture i386): Mach-O executable i386 Terminal (for architecture ppc): Mach-O executable ppc root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]#
or even:
stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ file Accelerate Accelerate: Mach-O fat file with 3 architectures Accelerate (for architecture i386): Mach-O dynamically linked shared library i386 Accelerate (for architecture ppc): Mach-O dynamically linked shared library ppc Accelerate (for architecture ppc64): Mach-O 64-bit dynamically linked shared library ppc64 stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$
In order to operate on fat bundles Apple provides a utility called lipo.
If you are in a situation where you are limited by processor architecture – for example, if you never expect to use internal hard drive of your iBook in firewire target mode to boot up an i386 system – it is possible to remove the extra “fat” from fat binaries, to save some disk space.
Here is an example:
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:09 AM]# mv Terminal Terminal.bak root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls Terminal.bak root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#lipo Terminal.bak -remove i386 -output Terminal root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls -la total 2296 drwxrwxr-x 4 root admin 136 Sep 6 02:10 . drwxrwxr-x 7 root admin 238 Aug 31 00:07 .. -rwxr-xr-x 1 root admin 386472 Sep 6 02:10 Terminal -rwxrwxr-x 1 root admin 783784 May 14 22:22 Terminal.bak root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# file * Terminal: Mach-O fat file with 1 architecture Terminal (for architecture ppc): Mach-O executable ppc Terminal.bak: Mach-O fat file with 2 architectures Terminal.bak (for architecture i386): Mach-O executable i386 Terminal.bak (for architecture ppc): Mach-O executable ppc root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#
A quick test confirms that Terminal.app continues to run as before, however to make sure that everything is kosher I would probably want to correct permissions on the new binary to match what it was on the original.
Disk space saving will not be big, as an average .app consists of many other objects besides the executable itself, so this is probably not a very big issue. If one tries to remove a non-existing architecture from a binary, lipo will complain:
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:18 AM]# \ lipo Terminal.bak -remove ppc64 -output Terminal lipo: -remove ppc64 specified but fat file: Terminal.bak does not contain that architecture root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:19 AM]#
Another interesting option to lipo is -detailed_info:
stany@gilva:~[02:22 AM]$ lipo -detailed_info /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
Fat header in: /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
cputype CPU_TYPE_I386
cpusubtype CPU_SUBTYPE_I386_ALL
offset 4096
size 8488
align 2^12 (4096)
architecture ppc
cputype CPU_TYPE_POWERPC
cpusubtype CPU_SUBTYPE_POWERPC_ALL
offset 16384
size 8564
align 2^12 (4096)
architecture ppc64
cputype CPU_TYPE_POWERPC64
cpusubtype CPU_SUBTYPE_POWERPC_ALL
offset 28672
size 8488
align 2^12 (4096)
stany@gilva:~[02:22 AM]$
writing a script that processes the output of:
find . -type f -perm -55 -exec file {} \; | grep i386 | sed 's/.for arch.*$//g'
while stripping out the arch, AND not screwing up the system is left as an excercise for the reader. :-P
Rendering a manpage
This is more of a general unix hint, that is not really MacOS X specific.
If you have a manpage that you want to look at, that is not in $MANPATH, (Something that got installed by hand into a custom directory, for example something that was built and installed using
./configure –prefix=/opt/packagename && make install ), yet you know where it is (for example because you did run /usr/libexec/locate.updatedb as root at least once since and now can use locate), you can use nroff to render the man page into text:
stany@gilva:~[12:06 AM]$ ls -la /opt/gnu/man/man6/figlet.6
-r--r--r-- 1 root 501 21054 Sep 3 17:41 /opt/gnu/man/man6/figlet.6
stany@gilva:~[12:06 AM]$ nroff -man /opt/gnu/man/man6/figlet.6 | head -20
FIGLET(6) FIGLET(6)
NAME
FIGlet - display large characters made up of ordinary screen characters
SYNOPSIS
figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]
[ -f fontfile ] [ -m layoutmode ]
[ -w outputwidth ] [ -C controlfile ]
[ -I infocode ] [ message ]
DESCRIPTION
FIGlet prints its input using large characters (called ``FIGcharac-
ters'')made up of ordinary screen characters (called ``sub-charac-
ters''). FIGlet output is generally reminiscent of the sort of ``sig-
natures'' many people like to put at the end of e-mail and UseNet mes-
stany@gilva:~[12:06 AM]$
QuickTime (Part 3)
Posted by stany in Mac OS X, Software, Tech. Support on 07/24/2005
Background
I have an iBook G4, that has a 32 meg Radeon 9200 mobile video card, that is below the minimal requirements for CoreImage. Technically CoreImage is supposed to be scalable, and if it can’t do a particular efffect on the video card GPU, it should try doing it on AltiVec unit of the processor, and, in event that the system lacks an AltiVec unit, it should fall back to the CPU.
In reality lack of CoreImage support doesn’t cramp one’s style all that much. I miss some graphical features of the GUI, which is cosmetics. However, occasionally it interferes with productivity, and pisses me off.
Consider the following example:
QuickTime 7 Pro and video adjustments
QuickTime have been coming in “free” and “pro” variety for a long while. The features that 29.95 USD Pro version has are numerous, but amongst the most notorious are:
- ability to save some of the streamed media to hard drive
- ability to export files to different formats
- ability to do some rudimentary merging of video tracks using cut and paste
- ability to adjust brightness, tint, contrast and colors of the video
- ability to correct audio balance, etc.
All of the above features work reasonably well under QuickTime Pro 6.5.2, although color corrections are rather clunky and are represented as a slider on screen. However you can see the adjustments as the movie plays. Here is what it looks like (220K).
Tiger came with QuickTime 7, and once I entered the QT7Pro license key, one of the things that didn’t work on my iBook was color corrections. Apple-K presented me with options to modify the audio settings, but not the video settings.
Technically you can get video adjustments to work by performing the following steps: Export -> Options -> Video Filter and doing a bunch of adjustments there, however there is no fun in waiting for a few minutes in order to see if your guesswork was correct.
This is Broken[TM].
So I did some digging. Inside QuickTime Player.app there are two files: AvControls.nib and AVcontrolsMinimal.nib. One gets used when the system detects CoreImage supported video card, and the other one when it doesn’t.
My hypothesis was that if I were to swap the two around, I’ll get access to video controls:
First I copied QuickTime Player to a different directory, and then dropped to command line:
stany@gilva:~[05:11 PM]$ cd /Applications/extras/QuickTime\ Player.app/Contents/Resources/English.lproj/ stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:11 PM]$ ls -dal AV* drwxrwxr-x 5 root admin 170 Jun 5 08:09 AVControls.nib drwxrwxr-x 5 root admin 170 Jun 5 08:09 AVControlsMinimal.nib stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:11 PM]$ stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]$ sudo /bin/bash Password: root@gilva:/Applications/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]# \ mv AVControls.nib AVControls.nib_ && mv AVControlsMinimal.nib AVControls.nib && mv \ AVControls.nib_ AVControlsMinimal.nib root@gilva:/Applications/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]#
After adjustment, on a non-CoreImage enabled system Apple-K menu looked like this.
Sadly, under Tiger the sliders for video correction still do not work, as they are dependent on CoreImage. However, I wonder if they do work on Panther (10.3). If they do, then likely this is the solution that would work for folks who haven’t upgraded yet. You see, there might be a reason to be a struggler. Comments, please.
Lastly, I wanted to give my modified version of QuickTime Player.app a different version string, so that I could see it when I ctrl-click on the movie, and select “Open with”. In order to do that, I ctrl-clicked on the QuickTime Player.app, and selected “show package contents”. Inside Contents folder, I’ve opened version.plist and Info.plist in Property List Editor. In Info.plist Root, I’ve changed CFBundleGetInfoString so that I know it was changed by me when I get info on the application, CFBundleShortVersionString and CFBundleVersion both to 7.0.1-stany and saved Info.plist. In version.plist I’ve modified CFBundleShortVersionString and CFBundleVersion to match the changes I did in Info.plist, leaving the rest of the properties the same.
Now, If I ctrl-click on a file QT recognizes, and scroll to “Open with”, it looks like this.
Last paragraph is the usual step needed to change a version of any application as recognized by the operating system. I should probably do something like this to all of those pesky Real Players, that I’ve been dealing with.
In closing, inside Info.plist it’s also possible to adjust the filename extensions and the icons that QuickTime is supposed to be able to handle. So you can rename your .mp3 files to, say, .jd, and associate just QT with these files (Barring presence of resource fork, etc, of course).
QuickTime (part 2)
Another braindump.
Somehow I ended up at PBS Nova Science Now page. It had lots of shiny TV goodness that I wanted to watch. Of course there also was a warning on the page saying This program is not available for downloading due to rights reasons.. Rights. Right.
First restriction was trivially bypassed. Netblock I am using is registered in Eugine, Oregon (which has a funny side effect that some web sites insist on hooking me up with “hot girls in Eugine”), which is actually correct, as I lease this /24 from it’s american owner.
So as far as PBS was concerned, I were tax paying merkin, and thus can be permitted to watch their programming (produced by taxpayer money). I can’t verify it right now, however I believe that they out right don’t permit folks connecting from outside US to view videos. *sigh* By the way, BBC does the same thing to some of their on-line content.
So QuickTime video was happily streaming off their web page. Due to pecularities of my network setup, that lead me to believe that they use HTTP protocol for content delivery. I viewed source, and grabbed http://www.pbs.org/wgbh/nova/sciencenow/video/nsn-wrap-new.mov (Feedback please. Does it play in your browser when you click this link?) , which when played in QT quickly sent me to http://www.pbs.org/wgbh/nova/sciencenow/video/rights_restrictions.gif. Right. So it plays from inside the browser, streaming, but not from HD. Joy, PBS.
Eventually I gave up and sniffed traffic ( tcpdump -i en1 -s 0 -w cookie ; strings cookie ). Noticed the following insteresting file: http://www.pbs.org/wgbh/nova/sciencenow/video/3204-new.xml (Sorry, not a hyperlink, as I want you to copy/paste it, thus this post not ending up in referer field – it might raise questions, as it’s not meant to be accessed by a browser).
It refers to a bunch of .mov files, that the program consists of, plus the “captions” for each part of the main movie.
Groovy.
wget --user-agent="QTS (qtver=7.0.1;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/wgbh/nova/sciencenow/video/3204-new.xml wget --user-agent="QTS (qtver=7.0.1;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/wgbh/nova/sciencenow/video/3204-00-ref.mov
This one is another container file. I had to save it and strings on it, to figure out the main file name. It is available in two qualities: 3204-00-300.mov and 3204-00-56.mov
so
wget --user-agent="QTS (qtver=7.0.1;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/video/3204-00-300.mov
worked.
root@gilva:~/pbs[04:27 AM]# grep vidURL 3204-new.xml |sed 's/ref.mov/300\.mov/g ; s/^.*http/wget --user-agent=\"QTS \(qtver=6.5.2;cpu=PPC;os=Mac 10.4.1\)\" http/g ; s/\< .*$//g ; s/\/video//g ; s/wgbh/media\/wgbh/g' wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-00-300.mov wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-01-300.mov wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-02-300.mov wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-03-300.mov wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-04-300.mov wget --user-agent="QTS (qtver=6.5.2;cpu=PPC;os=Mac 10.4.1)" http://www.pbs.org/media/wgbh/nova/sciencenow/3204-05-300.mov root@gilva:~/pbs[04:27 AM]#
Now, these don't play in stand-alone QT and refer you back to the "Rights" image. However VLC will happily play them.
*sigh*
I am going to bed now.
QuickTime (Part I)
Note: This is just a quick braindump, so probably is inconclusive, and makes no sense
Situation
A few days ago LIVE8 concerts were held in major cities around the world. Most interesting (to me, YMMV, of course) was the reunion of Pink Floyd after over 10 years of not being around, with Roger Waters being on stage with the rest of the classic lineup for the first time in 24 years. Wow.
AOL has the license for the internet distribution of the videos, and has a reasonably nice site from which the clips can be streamed using QuckTime.
Clips are really good quality, where quality of the video was not sacrifised in favor of bandwidth. Thank you, AOL, you rock.
If one clicks on the little tab by the song name, a window pops up in which clip plays. One can view source, search for “mov”, and eventually find http URL to the actual file. So I grabbed the 4 Pink Floyd songs.
Problem
When I proceeded to play them in QuickTime, they played great. But every silver lining has a cloud – I wanted to build a playlist, where the songs would be played in sequence.
iTunes kind of helped – I am not a big iTunes user, but I imported .mov files into it, made a playlist, arranged them in sequence, and it kind of worked. There were two snags, however – there were ~2 second gaps between songs, and it was audio only. Grumble. I wanted something that could just play them all.
I could have used VLC.app, I guess. I just verified that it plays these tracks, and it has the concept of playlist down pat. But instead I fired up QT Pro 6.5.2, selected whole video, and wanted to paste it together with the next song, etc, to merge 4 songs into one 20 minute long video.
Of course nothing happened. QT had the copy and paste controls grayed out.
So I attempted to export it. It popped up a window telling me Couldn’t export “‘Breathe’ (LIVE 8)” because this movie doesn’t allow saving. Aaaarrrgggh!
Aimless wandering in the dark, searching for solution
So fater about half an hour of googling I learned that many others run into this problem. Seems like this “feature” of QuickTime got noticed when certain movie trailers (ST: Nemesis is one, apparently) were exported to QT with “do not allow modification” bit set. This had the added benefit of forbidding QT Pro to save the file to HD, and irked some folks to no end.
Hacker’s Guide to QuickTime (Which actually has lots of rather useless pointers, such as “open web page with QT component in browser, and then find the cached file in browser’s cache to save file to HD”, which doesn’t work as most of the time now browser just loads a small file (example) that in turn loads the rest of the content, if it feels like it, or folks actually deploy QuickTime Streaming Server, and browsers generally don’timplement RTSP protocol) mentions that:
So this had a glimmer of hope: If I were to obtain the right software, I could make a small (2 – 3 seconds) source file, import it into video editing package, tell it to save once without disallowing saving, and once with, hexdump both files, and diff them. My stipulation is that it’s just a byte or two in the header, that QuickTime happily follows. If I were to know which ones, I potentially could just hexedit the restriction out, and solve my problem.
At this point for some reason I got diverted, and instead of investigating “Cleaner”, went and grabbed Sorenson Squeeze 4.1. Site e-mailed me confirmation and the above URL to the download package.
Sorensen Squeeze is VISE X packaged blob of data that has 30 day free trial, and that will watermark generated files (until you license it). I didn’t care about watermarking, as as long as it generates both protected and unprotected file identically, it’s not a big deal. I know save restriction doesn’t encrypt the file, as VLC.app happily plays them back.
After playing with Sorensen for a while, I realized that a) It does a rather poor job converting other QT files to requested form at(frame dropping. Gave it an 80K/sec mpeg4 inside QT container file (La Tortura from one of my earlier articles), and told it to generate 750K/sec result. Result had 8 frame/sec output, and was choppy as heck (source was 16 frames/sec). Maybe it’s another restriction of the 30 day demo) and b) I couldn’t find the menu to disable save in Squeeze’s features nor in documentation.
At this point I gave up in disgust, and uninstalled Sorensen Squeeze 4.1.
Another complaint about VISE X. Why the F*&^ does it demand that all other applications must be closed during uninstall of software? It demanded none such thing during install. I am not about to close Safari with 35 windows, nor X11 with 8 xterms. Aaargh, what a piece of crap. MS Media Player for Mac is also packaged with it, and in that case it actually demands admin password just to install an application into /Applications. WHY?
So this is as far I made it.
Questions
- Is there a way to extract files from VISE installers, specifically out of Install.data, without running the installer? I always fear that it will spew files all over my system, and I’ll never find them.
- Any advice about “Cleaner”? Admitedly I am reluctant to put this here, as I’m yet to google it.
- Anyone has any experience dealing with QT restrictions?