Topic: Build Avidemux 2.4SVN from source on MacOsX

Build Avidemux 2.4SVN from source on MacOsX

Document Version: 0.08
Version date: 2-Dec-2007
Avidemux Version(s): 2.4
Avidemux SubVersion(s): 3715+
Operating System: MacOsX 10.4.x Tiger with Xcode 2.41 and MacOsx 10.5.x Leopard with Xcode 3.1.x
Note: It will be noted where Tiger and Leopard require different steps.


1.    Introduction:
Compiling Avidemux on MacOsx is different from what "default" Mac-users are used to. It requires a lot of terminal work. The Mac way of installing programs is to have a “Bundle”, the .App, which is actually a special directory containing the program(s) and necessary “other stuff” like libraries, scripts and so on. Everything you need is packed into this .App, or is default available on a standard MacOSX system.
This HowTo is based on MacPorts (previously DarwinPorts).  MacPorts keeps itself “separated” from the rest of MacOSX. Avidemux has quite some dependencies which are also kept “separated”  from MacOSX. This HowTo will focus on building and using Avidemux on your own system and not on creating a portable App to share with your friends. If you want to make a really portable bundle, read section 6 at the end of this Howto first. Not ready yet
Even though this howto is based on MacPorts you should be able to follow it if you are using Fink as that works comparable.

1.1    Disclaimer
I wrote this "howto" based on my own experiences on MacOsx on an Intel based MacBook, so it works for me. Feel free to add suggestions or ask me for assistance to help make this howto better, but don't blame me if it doesn't work for you.

2.    Prerequisites:
To be able to build Avidemux you need the following:

    1. XCode: Developers environment on MacOsx containing full gcc environment. Get it here
    2. X11(XWindows): You absolutely need this if you want the Gtk version.
    3. MacPorts: The ported "linux/freebsd environment" (my definition). Get it here
    4. QT4 for Mac: You absolutely need this if you want the QT4 version.
    5. CMake: You can download a universal binary package from www.cmake.org
    6. both MacPorts and Non-MacPorts libraries.
    7. At least a basic knowledge of use of the Terminal and of Unix filesystems.

3.    Installation of Prerequisites.
I will not explain here how to install XCode and MacPorts as the XCode install is straightforward and the MacPorts install is well documented in the MacPorts WIKI (and very compact too). Same is valid for X11 on the second Mac CD.
Note1: Do not install XCode from your MAC-CD's that came with your Mac. That version is most definitely outdated and will cause several problems when compiling (Trust me: I've been there).
You will need a developer-id to be able to download XCode. It’s free and it’s simple and Apple doesn’t bother you with all kinds of mailing (if you uncheck that little box in the end).

Steps:
- Install XCode.
- Install X11(XWindows). Preferably the one from your Mac CD’s and not the MacPorts one. (A lot of graphical MacPorts rely on X11(XWindows))
- Install CMake: The downloaded dmg will open automatically and the install will also start automatically.
- Install MacPorts. If you already have macports (formerly darwinports) installed, make sure you have the latest version (macports base):

$ sudo port selfupdate

Make sure you have synced the latest port files:

$ sudo port -d sync

To update (all) your ports (programs):

$ sudo port upgrade outdated

Don’t do this last step if you have a lot of libraries and dependencies in other programs and you want to keep it that way. You might need to recompile your already installed McPorts ports or otherwise ported programs (As mentioned, it will not touch your "normal" Mac applications.)

Note2: lines starting with $ are commands executed in the terminal window.
Note3: the sudo command advancing the port command is necessary as you need superuser access to install this software; sudo isssues the command with super user rights. It will ask for a password. This is your own password.

So we will use “sudo port” to install the necessary libraries and commands before compiling (the SVN version of) Avidemux:

$ sudo port install automake subversion yasm gettext autoconf

$ sudo port install pkgconfig fontconfig gettext freetype libsamplerate libxml2 gtk2 lame libvorbis faad2 faac libdts

Note4: Every port being downloaded is actually a source code package. It means that  it will be downloaded, configured, compiled and then installed in the correct directory. This can take anywhere from 30 seconds to 30 minutes for the big packages (e.g. qt4-mac and gtk2). So get away from your pc and go play with your children, hug your wife/husband/partner or give your dog a walk. Don't wait for errors, they will always show up automatically smile.
Note5: automake, libxml2 and freetype are also part of MacOsx, but macports will install them anyway as some of the needed ports (packages) claim them as dependencies within MacPorts and MacPorts doesn’t touch your MAC installed base. I install and mention them here specifically so you know that these libs/tools are redundant on your system).
Note6: Next to the above mentioned packages, you will most likely see a lot of other packages being installed as they are needed (the so called dependencies) by the specified packages.
Note7: You might get errors like (last two ERROR lines):

---;  Fetching libvorbis
--->  Verifying checksum(s) for libvorbis
--->  Extracting libvorbis
--->  Configuring libvorbis
--->  Building libvorbis with target all
--->  Staging libvorbis into destroot
--->  Installing libvorbis 1.1.2_0
Error: Target org.macports.install returned: Registry error: libvorbis @1.1.2_0 already registered as installed.  Please uninstall it first.
Error: Status 1 encountered during processing.

The package system is not 100% stable yet. In 90% of the cases the tool wil say: "Skipping org.macports.activate (<package name> ) since this port is already active", which is the correct behaviour. Sometimes however, the system will give you the above mentioned error message. Just remove the package from the command line (including the already installed packages before it) and issue the command again.

- Install QT4
QT4 is an absolute necessity if you want a QT4 build. QT4 can be used from the MacPorts repository or downloaded from TrollTech. The trollTech version has a source code version and a binary version. The last one only for 10.4 (Tiger) and 10.5 (Leopard). The easiest and fastest one (when it comes to installing), is the binary one, which can be found at the bottom of the page. Both source versions (MacPorts and TrollTech) will also produce a usable QT4 environment for Avidemux.
(Did I already mention how long it takes to build QT4? No?
Well, let me tell you that it takes ages to build QT4, especially the TrollTech one!

- The TrollTech binary.
Simply download the .dmg and run the installer which will start immediatley after the download has finished (with Safari that is).
Note8: The binaries will be installed as Framework(s).

- The MacPorts source
type:

$ sudo port install qt4-mac

Wait for it to download, build and install: That's all.

- The TrollTech source
Only use this one when you have a good reason to do so.
Download the latest stable version from TrollTech. In finder double click the qt-mac-opensource-src-4.x.y.tar to untar it. Open a terminal and move to the directory containing the QT source code and type:

$ ./configure -prefix-install -no-framework

Note9: The "-prefix-install" will install in /opt/local. The "-no-framework" will build dynamic libraries. This second option is not necessary, but you better specify this second option if you ever want to build a portable avidemux. Otherwise the FrameWorks version will be build which is just as suitable (and the Osx default way of installing), but it's much bigger in size when you want to create a bundle for distribution.
Note10: QT will ask "Do you accept the terms of the license?". You'd better say "yes" if you want to continue.
After the configure step type:

$ gmake
$ sudo gmake install

This will make and install QT4 and it will take a very long time.

4.    Installing extra codecs.

4.1    Installing Xvid:
Xvid is definitely something you want and need in your Avidemux. Xvid can be installed two ways: The “easy” MacPorts way or the “more advanced” CVS way.
The MacPorts Xvid will give you a fully functional XVid which can be fully used by Avidemux. However, the MacPorts version is compiled without Assembly which will make your xvid about 4 times as slow as an “Assembly enabled” xvid. The CVS has another "bonus": multi-threading. Avidemux supports this and it will increase your xvid performance by another 20-30% on a multicore intel cpu.
Note: For Leopard assembly doesn't work yet. Use the "MacPorts way".

4.1.1    The MacPorts way
type:

$ sudo port install xvid

Wait for it to download, build and install: That's all.

4.1.2    The CVS way
Leopard: This doesn't work on Leopard.
You can download the latest CVS version from www.xvid.org
Once downloaded move to the directory where you have downloaded xvid and untar the files (Finder will do that for you if you double-click the file). Run these command lines from within a terminal:

$ cd xvidcore/build/generic
$ ./bootstrap.sh

The second step is the configure step. To stay "compatible" with MacPorts you need to add --prefix=/opt/local to the configure command like:

$ ./configure --prefix=/opt/local

Note11: The prefix is not necessary for Avidemux. If yo don't use it (like $ ./configure) xvid will be installed in /usr/local instead of /opt/local.

After the configure step you have to edit the file platform.inc in build/generic:
- Find "SPECIFIC_CFLAGS=-fPIC -fno-common -no-cpp-precomp -DHAVE_PTHREAD"
- Change to "SPECIFIC_CFLAGS=-fPIC -fno-common -no-cpp-precomp -DHAVE_PTHREAD -undefined suppress"

- Find "AS=nasm"
- Change to "AS=yasm"

- Find "AFLAGS=-I$(<D)/ "
- Change to "AFLAGS=-I$(<D)/ -f macho -DPREFIX"

- Find "SPECIFIC_LDFLAGS=-dynamiclib -flat_namespace -compatibility_version $(API_MAJOR) -current_version $(API_MAJOR).$(API_MINOR) -install_name $(libdir)/$(SHARED_LIB) -lpthread"
- Change to "SPECIFIC_LDFLAGS=-dynamiclib -flat_namespace -compatibility_version $(API_MAJOR) -current_version $(API_MAJOR).$(API_MINOR) -install_name $(libdir)/$(SHARED_LIB) -lpthread -read_only_relocs suppress"

Save the file.

From the xvidcore/build/generic directory, type in the terminal:

$ make
$ sudo make install

4.2    Installing x264:
x264 is definitely something you also want and need in your Avidemux. x264 can be installed two ways: The MacPorts way or the SVN way.
The MacPorts x264 version is fully functional and can be used by Avidemux but is a little outdated. The svn version contains bugfixes, is more optimized and so on.

4.2.1    The MacPorts way
type:

$ sudo port install x264

Wait for it to download, build and install: That's all.

4.2.2    The SVN way
You can download the latest SVN version from www.videolan.org/developers/x264.html
Run the following command from within a terminal to download the source code in subdirectory x264 (make sure you are in a directory where you want to have the sourcode tree):

$ svn co svn://svn.videolan.org/x264/trunk x264

Once downloaded issue the following commands to cd into the directory and configure, make and install x264:

$ cd x264
$ ./configure --prefix=/opt/local  --enable-pthread --enable-pic
$ make
$ sudo make install

That should do it.

4.3  Installing (lib)aften
Aften is currently at version 0.0.8. Avidemux supports aften version 0.0.7 and 0.0.8. Download the 0.0.8 version from http://aften.sourceforge.net/.
After downloading unzip/untar the source into a suitable directory. cd into the directory where you downloaded aften, e.g. aften-0.0.8, and create a build directory from where you issue the necessary compilation and build steps.

$ cd aften-0.0.8
$ mkdir build
$ cd build
$ cmake -DSHARED=1 ..
$ make
$ sudo make install

That should do it. It will install aften in /usr/local (as I like to separate it from macports and older versions of avidemux could not find it in /opt/local). If you want to install it in /opt/local, you need to issue the command "cmake -DCMAKE_INSTALL_PREFIX=/opt/local -DSHARED=1 .." instead of "cmake -DSHARED=1 ..".

4.4       Installing amr-nb
Download the amrnb source from http://www.penguin.cz/~utx/amr.
After downloading unzip/untar the source and cd into the amrnb directory (currently amrnb-7.0.0.0). Issue the following commands.

$ ./configure
$ make
$ sudo make install

That should do it. It will install amrnb in /usr/local (as I like to separate it from macports). If you want to install it in /opt/local, you need to issue the command "./configure --prefix=/opt/local" instead of only "./configure".


5.    Compiling Avidemux SVN

We need to download the avidemux 2.4 branch from SVN. In a terminal move to a suitable directory where you want the source code to be downloaded.
In the terminal type:

$ svn co svn://svn.berlios.de/avidemux/branches/avidemux_2.4_branch/

This command will download the entire source code into a directory called " avidemux_2.4_branch".
Still from the terminal go into this subdirectory "avidemux_2.4_branch" by typing:

$ cd avidemux_2.4_branch
$ mkdir build  
$ cd build

This will create a directory build and you will move into it. Cmake has the nice option to build everything outside the source tree, thereby keeping the source tree clean.
Leopard: Leopard needs an extra LDFLAGS setting otherwise the gtk version will not compile&build. In the terminal window issue the following command before the cmake step.

export LDFLAGS="-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"

Avidemux will install in /usr/local by default. If we want to maintain the MacPorts default way (/opt/local) we have to specify that.
So when you are inside the build directory, type:

$ cmake -DCMAKE_INSTALL_PREFIX=/opt/local ..

If you want the default installation in /usr/local type "cmake .."
Once the cmake step has finished you have a couple of options now to make Avidemux. You can type:
- $make            This will build avidemux2_cli, avidemux2_gtk and avidemux2_qt4
- $make avidemux2_cli    This will only build avidemux2_cli
- $make avidemux2_gtk    This will only build avidemux2_gtk
- $make avidemux2_qt4    This will only build avidemux2_qt4 (I suppose you already got the picture smile)

So from inside the build directory type:

make <your option or nothing>

Normally, you will not specify a specific build (Hey, it's free, so we want everything).
This compilation is quite a lengthy process. So again: get away from your pc and go play with your children, hug your wife/husband/partner or give your dog a walk. Don't wait for errors, they will always show up automatically smile.

When the compile & link step has (hopefully succesfully) finshed, you can install the created program(s) in the directories where you want them to be:

$ sudo make install

This will install the cli, gtk and qt4 version and it's accompanying files in the correct directories depending on the prefix you did or did not specify.

By default avidemux2_qt4 on Osx is also linked against XV. This is not necessary, but it has no influence on the functioning of your application. If you want to make your install as "clean" as possible, you need to recompile QT4. You do this by running cmake again with other parameters like:

cmake -DCMAKE_INSTALL_PREFIX=/opt/local -DNO_XV=1 -DNO_NLS=1 ../avidemux_2.4_branch

Run the make command again from the build directory but only for avidemux2_qt4, so:

$ make avidemux2_qt4

When finished, do not run the "make install", but instead copy the file to the correct directory, so:

$ sudo cp avidemux/avidemux2_qt4 /opt/local/bin
or
$ sudo cp avidemux/avidemux2_qt4 /usr/local/bin

6.    Executing your avidemux applications
You can use finder to go to either /opt/local/bin or /usr/local/bin and start the avidemux2_qt4 by just double-clicking it.  You need to start avidemux2_cli from a terminal. For avidemux2_gtk you need to start X11 first and than from an xterminal go to /opt/local/bin or /usr/local/bin and start avidemux2_gtk.
On my website you'll find a .dmg containing two small "script applications" in "Application_shells". You can place these applications in your dock or your Applications folder. Please note that these "script applications"  don't contain avidemux!! They only work with the applications you created yourself. If you want a complete (avidemux2_qt4) bundle, download it from my website

7.    Creating a bundle
To be added.
Making a bundle should be as automatic as running cmake ..; make; sudo make install. At this moment it is still a lot of manual labour as a good script to do this is not available (yet).


8.    ToDo
- The Bundle section (obviously)

Last edited by surfer (2009-03-08 09:49:29)

Re: Build Avidemux 2.4SVN from source on MacOsX

Updated.
- Added compilation/build instructions for aften and amrnb
- Added tiger/leopard specific steps and comments.

Re: Build Avidemux 2.4SVN from source on MacOsX

Hi,

After the same reuqest from Kekster I added command line functionality to the QT version. I doesn't work yet for the Gtk-Quartz and it will never work for the Gtk-X11.

Check:
http://avidemux.org/admForum/viewtopic.php?id=4822

last few posts http://www.avidemux.org/admForum/viewto … 87&p=6

last few posts in http://www.avidemux.org/admForum/viewtopic.php?id=3157

Re: Build Avidemux 2.4SVN from source on MacOsX

The problem here is that a MacOSX bundle is made to allow for "bundled"graphical applications. A command line bundle is almost a "contradictio in terminis."

I once made for myself a "package" which is actually a directory structure with everything inside that directory and which could be used on every Mac as long as users left the directory structure intact. I did this more as an experiment than that I really needed it.

We never had questions from OSX users regarding command-line versions, but you are now the second in a very short time. I'll see whether I can find my command line script back and make a command line tool.

Last edited by surfer (2008-07-01 07:02:54)

Re: Build Avidemux 2.4SVN from source on MacOsX

As I still had everything available, it wasn't too hard to build a avidemux_cli package (not a bundle). Check my website.

Re: Build Avidemux 2.4SVN from source on MacOsX

If you do compile avidemux according the instructions in this thread, you have a avidemux2_cli command line application available. The instructions in my "howto"  actually describe the "Linux way" of compiling/building an application. So, in the end you have a avidemux2_qt4, an avidemux2_gtk and an avidemux2_cli  application in /opt/local/bin or /usr/local/bin. Exactly the same as on Linux.
However, these applications are off course "my system only" one-architecture builds as they are not portable and not universal.
My bundles are portable and universal (and take more effort to build).

I'm currently working on a completely separate way of building libraries and binaries completely stand-alone from Macports and Fink. They should enable almost anyone (without terminal fear) to create universal binaries and libraries and, in the end, an avidemux bundle. Basically, it comes down to downloading a lot of source packages and running a lot of scripts in the correct order. If you can download and read, you should be successful.
When that's done (and if I succeed) I will write a new Howto. I'm currently stuck however on libpango for quite some time already.

With regard to a statically linked binary: Yes, in theory that's possible but on OSX extremely difficult. It requires you to remove all dynamic libraries from your path's as OSX will ALWAYS use the dynamic library if available. It also means that you have to modify most Macports build scripts (the Portfiles) as svn and more tools are also build dynamically. Some scripts even disable the building of static libs. As long as you have your "basic" macports in place, you also have your "basic"  dynamic libs available. Some of these basic libs are then again also used by avidemux as you can't disable that.
Note that with my completely separate build tree (when ready), you can overcome this. All dependencies are then "internal" and you can switch between a dynamic build or a static build. (I'm also the OSX bundle maintainer of Hugin. I sometimes use it there).

Note (again) that specifying the --disable-shared --enable-static option does not work on OSX if an underlying dependency dynamic lib is available. That's how Mac modified gcc (and there were real flame wars going on on developer.apple.com some years ago about this. Some developers completely rebuilt gcc on their systems).

Last edited by surfer (2008-07-01 13:33:43)

Re: Build Avidemux 2.4SVN from source on MacOsX

Is it possible to build the 2.5 source with this documention?

Re: Build Avidemux 2.4SVN from source on MacOsX

I would guess not, because with AVIdemux 2.5 you need to build plugins separately.