Sunday, November 28, 2010

[How To] Compiling VLC in XCode for iPad simulator and device

[EDIT Feb 2012]:
It has been a pretty long time since I put this post together and a lot has changed in VLC, FFMPEG and iOS since then. Whilst I hope that there is still useful information here I am not sure that this guide should be considered up to date and correct anymore. Maybe one day I can find time to update it but I am just too busy with other projects for it to be top of my list.
Do keep leaving comments if you have corrections or new info and I will try and add them in.


[NOTE]:
Sorry but I am not able to distribute pre-built binaries for any part of this app so please don't waste time asking me to send you a compiled version, it probably wouldn't work anyways (code signing etc.)

I have been messing with the VLC iOS source recently to see if I could hack it up to work with the new airplay protocols for Apple TV. Sadly any airplay hook up is not going to be straight forward as the VLC player is not using a MPMoviePlayerController instance or subclass to display the movie. It's not clear yet if I can hijack the video stream from the custom view and pipe it over the hard way but I will keep hacking in spare moments.

[UPDATE]:
Now that VLC has been pulled from the AppStore I am expecting that there will be many more people interested in compiling VLC themselves. I will hopefully find some time soon to do some more hacking on VLC myself soon and will update this guide if I find bits of the process change.

Actually getting the source to compile was a bit of a mission and looking at the videolan forums there are a few others out there struggling to compile the sources too so here is how I managed it. There are quite a few steps so I have split it up into the three main tasks.

Build the Aggregate libraries.
  1. Install git if you don't have it already. You will need this to grab the latest source and for the build script to complete.
  2. Open up a terminal window and cd to the directory you want to download and build in.
  3. clone the MobileVLC.git repo.
     git clone git://git.videolan.org/MobileVLC.git  
    
  4. Open up buildMobileVLC.sh in your favourite editor.
  5. I had a problem with the build script failing trying to remove symbolic links that didn't exist. I fixed this by editing line 121 to wrap a remove in a conditional.
    From:
     rm External/MobileVLCKit  
    
    To:
     if [ -e External/MobileVLCKit ]; then  
     rm External/MobileVLCKit  
     fi  
    
  6. If you have XCode setup to use a custom build location (for instance if you use a shared location to leverage project includes in your other projects) then the easiest way to get this working is to go to preferences and set the option back to the default (Place build products in project directory). If you don't do this then you will need to edit the buildMobileVLC.sh lines 117 and 118 so that the products can be found.
  7. In theory the buildMobileVLC.sh script should take a flag to set the SDK you want to use. However in practice I found that it didn't so edited all occurences of 3.2 to be 4.2.
  8. At the time of writing a recent commit causes the AggregateStaticPlugins.sh script phase of MobileVLCKit to fail.  Check that ImportedSources/vlc/projects/macosx/framework/MobileVLCKit/AggregateStaticPlugins.sh does not have plugins+="access/access_mmap ". If it does then just delete this line. ** This has been resolved in the latest revision.
  9. In terminal cd into the MobileVLC directory and execute buildMobileVLC.sh passing the -s flag for simulator, then run it again without the flag to build for device. This is just so that later you can switch between simulator and device in XCode without any problem.
  10. The script will take a little while to run, especially first time out as it needs to bring in 2 repos from git.videolan.org and compile a metric ass ton of dependant libraries. There are a shocking amount of warnings and errors reported by the build of the libraries, no wonder building this thing is so brittle. Once its finished you are looking to see the magic words "Build complete" and you should be OK. 
Configure XCode to get simulator working
  1. Next open up the MobileVLC.xcodeproj. We will get it running from here in the simulator first.
  2. Select the project root and open up the inspector (get info). On the General tab set the "Base SDK for all configurations" to be the SDK you are using (in this case it was 4.2).
  3. Close the inspector and toggle the target select dropdown to debug then back to release so that the "missing base SDK" warning disappears.
  4. Now you can set the target hardware to Simulator and the active executable to iPad (although this guide should work for iPhone too).
  5. You can if you like hit build and run but the VLC app will crash as soon as it launches. This is because there is a bad path to the MediaLibrary data model for core data.
    Expand the External/MediaLibraryKit group and select the MediaLibrary.xcdatamodel (it should be highlighted red showing there is a problem) and open inspector.
  6. Hit choose to find the correct the path. Project relative it is ImportedSources/MediaLibraryKit/MediaLibrary.xcdatamodel.
  7. Finally you should be able to hit build and run and see the VLC app open up in the simulator.
Configure XCode to get it on a device
  1. I am going to assume you already have a developer certificate and an application agnostic Team Provisioning Profile. If not then this next bit is of no use to you anyway.
  2. Select the MobileVLC target and open the inspector. 
  3. On the build tab set the code signing entity to use your developer identity.
  4. Change the target to device in the target select dropdown, plug in your iPad and build and run.
  5. If the build fails at this point with something like:
     file was built for unsupported file format which is not the architecture being linked (armv7)  
     Undefined symbols:  
      "_OBJC_CLASS_$_VLCMediaPlayer", referenced from:  
        objc-class-ref-to-VLCMediaPlayer in MVLCMovieViewController.o  
      "_OBJC_CLASS_$_VLCMedia", referenced from:  
        objc-class-ref-to-VLCMedia in MVLCMovieViewController.o  
      "_OBJC_CLASS_$_VLCTime", referenced from:  
        objc-class-ref-to-VLCTime in MVLCMovieGridViewCell.o  
      "_OBJC_CLASS_$_MLMediaLibrary", referenced from:  
        objc-class-ref-to-MLMediaLibrary in MobileVLCAppDelegate.o  
      "_OBJC_CLASS_$_MLFile", referenced from:  
        objc-class-ref-to-MLFile in MVLCMovieListViewController.o  
        l_OBJC_$_CATEGORY_MLFile_$_HD in MLFile+HD.o  
     ld: symbol(s) not found  
     collect2: ld returned 1 exit status  
    
    Then go back to terminal and run buildMobileVLC.sh again with no flags.
  6. You should now be seeing the VLC app running on the iPad.

12 comments:

Ale Stanga said...

didn't you get an error about dvdnav and dvdread while building mobile vlc?

Rick said...

No but the VLC sources are changing all the time so its possible that there is a new hoop to jump through with the latest revision.

Ale Stanga said...

i solved this adding --enable-dvdnav=no at the end of the build.sh script inside the vlc/extras/packages/ios folder.
now i have a new problem to solve:


The following build commands failed:
MobileVLC:
Ld /Users/ale/Desktop/MobileVLC/build/Release-iphoneos/VLC.app/VLC normal armv6
(1 failure)

i tried both armv6 and 7 in the build.sh script but i can't get rid of this error...
it has something to do with the architectures and the linker... i have to figure where's the problem :)

Arnaud said...

Thanks for your documentation.

But when I type the first command:
git git clone git://git.videolan.org/MobileVLC.git
I get this message:
fatal: The remote end hung up unexpectely

Any idea?

Thanks

Rick said...

I had some issues a while ago with the git server which were resolved with a tweet to @videolan. Give them a shout there see if they can poke the server.

devin said...

Just got this to build for 4.2 (only one error due to posix_memalign, and then only for simulator), however, when trying to run, it crashes instantly... something to do with teh media library... I'll hack around with it, but wondered if anyone else had seen it.

João Paulo Farias said...

Hi! I am trying to compile it but I am getting a lot of ranlib messages and it finally fails with this:


The following build commands failed:
Libtool build/Release-iphonesimulator/libMobileVLCKit.a normal i386


What is the environment required to build mobilevlc?

I tried XCode 3.2.5 and XCode 4 GM, both get the same errors.

Anonymous said...

The following build commands failed:
Libtool build/Release-iphonesimulator/libMobileVLCKit.a normal i386

It seems that the problem with this is that two plugins aren't compiling (or don't even exist -- I didn't check this yet). If you edit the file '${SRCROOT}/MobileVLCKit/AggregateStaticPlugins.sh' and comment out the following two lines:
# plugins+="audio_filter/bandlimited_resampler "
and
#plugins+="misc/xtag "

The code actually goes ahead and compiles (and more importantly links). Now, I have no idea if this actually works out in the end, but you will get past this error and get the sought-after "BUILD SUCCEEDED" :-) Good luck!

Anonymous said...

FYI, if you are using XCode 4, the above instructions can get you up-and-running on the Simulator, but not the Device. This is due to ffmpeg's configuration file which isn't set up correctly for XCode 4 (the -mcpu flag specification trips up)

Until the ffmpeg folks fix this issue the easiest thing will be to make sure you compile with XCode 3.x installed.

Anonymous said...

This may be a noob mistake, but under no circumstances can you have a installation root directory name that contains spaces -- I found that out the hard way :-(

Anonymous said...

how to solve this problem ...
when i run .sh file in terminal .. showing message no directory




"_OBJC_CLASS_$_AVFMFile", referenced from:
l_OBJC_$_CATEGORY_AVFMFile_$_HD in AVFMFile+HD.o
objc-class-ref in ZSMovieListViewController.o
"_OBJC_CLASS_$_VLCTime", referenced from:
objc-class-ref in ZSMovieGridViewCell.o
objc-class-ref in ZSMovieTableViewCell.o
"_OBJC_CLASS_$_AVFMMediaLibrary", referenced from:
objc-class-ref in ZSMovieListViewController.o
objc-class-ref in ZeroStartPlayerAppDelegate.o
"_OBJC_CLASS_$_VLCMediaPlayer",

referenced from:
objc-class-ref in ZSMovieViewController.o
"_OBJC_CLASS_$_VLCMedia", referenced from:
objc-class-ref in ZSMovieViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Rick said...

path errors are usually due to there being spaces in the path to your compile directory.

To be honest its a now a long time since I last tried to compile this and a lot has changed both in VLC, FFMPEG and iOS.

This guide is probably not really correct anymore.