FFMPEG integration on iphone/ ipad project

后端 未结 2 1050
耶瑟儿~
耶瑟儿~ 2020-11-28 04:12

Can any One Tell me how do i integrate FFMPEG in my iphone/ ipad project.i m using Xcode 4. i searched a lot but did not find any useful Link .please tell me step by step pr

相关标签:
2条回答
  • 2020-11-28 04:33

    Prerequisites

    MacPorts to install:open terminal and type

    sudo port install pkgconfig

    Launch Terminal and download FFmpeg source

    The location of the directory is up to your personal preference and I chose to save it in a ffmpeg folder under my Home folder for easy access later on.

    git clone git://source.ffmpeg.org/ffmpeg.git ~/ffmpeg

    Before we go further, we need to think ahead and realize that we are likely to do some simulation on Mac itself along with actual testing on iPhone. What we need to do is that we need to build libraries for 3 architectures: armv7 (iPhone 3Gs or later), armv7s (iPhone 5) and i386 (iPhone Simulator).

    Let’s create some folders inside ffmpeg folder to hold 3 different builds so that we can lipo those together into one universal build.

    cd ffmpeg mkdir armv7 mkdir armv7s mkdir i386 mkdir -p universal/lib

    To Install gas-preprocessor

    1. Click on the ZIP icon to download gas-preprocessor.
    2. Copy gas-preprocessor.pl to /usr/bin directory.
    3. Change permission of gas-preprocessor.pl by setting the privilege to Read & Write for all.

    Configure FFmpeg for armv7 build

    Before configuring, You may refer to the detailed options by going in to the ffmpeg folder and type:

    ./configure --help

    list of options for your reference: FFmpeg Configure Options. The “Components options” will be up to you depending on what you want to do with FFmpeg.

    Now run the following configure options:

    ./configure \ --prefix=armv7 \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --enable-avresample \ --enable-cross-compile \ --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk" \ --target-os=darwin \ --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" \ --extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=6.0" \ --extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -miphoneos-version-min=6.0" \ --arch=arm \ --cpu=cortex-a9 \ --enable-pic \

    You may get a warning such as:

    WARNING: Compiler does not indicate floating-point ABI, guessing soft.

    No worries. You should be fine to continue to next steps.

    Build FFmpeg for armv7

    Run the build commands:

    make clean && make && make install

    Now you should be able to see files are populated inside the ffmpeg/armv7 folder. We now move onto building for armv7s for iPhone 5.

    Configure and Install FFmpeg for armv7s architecture (iPhone 5)

    . /configure \ --prefix=armv7s \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --enable-avresample \ --enable-cross-compile \ --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk" \ --target-os=darwin \ --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" \ --extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=6.0" \ --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -miphoneos-version-min=6.0" \ --arch=arm \ --cpu=cortex-a9 \ --enable-pic \

    Then build with:

    make clean && make && make install

    Configure FFmpeg for i386 build

    ./configure \ --prefix=i386 \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --enable-avresample \ --enable-cross-compile \ --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk" \ --target-os=darwin \ --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" \ --extra-cflags="-arch i386" \ --extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk" \ --arch=i386 \ --cpu=i386 \ --enable-pic \ --disable-asm \

    Please note the last --disable-asm tag. If you forget to include this tag, you will likely to receive this error:

    cc1: error in backend: Ran out of registers during register allocation! make: *** [libavcodec/h264_cabac.o] Error 1

    Build FFmpeg for i386

    make clean && make && make install

    Create universal library

    The lipo commands (assuming you are still under the ffmpeg folder): (Please note that Mountain Lion-supplied lipo knows nothing about armv7s as of yet. So we need to use xcrun to find the lipo supplied with the SDK.)

    cd armv7/lib for file in *.a do cd ../.. xcrun -sdk iphoneos lipo -output universal/lib/$file -create \ -arch armv7 armv7/lib/$file \ -arch armv7s armv7s/lib/$file \ -arch i386 i386/lib/$file echo "Universal $file created." cd - done cd ../..

    Look under universal/lib, you will find all FAT libs freshly baked there. We now turn our attention to linking these static libraries to the Xcode project.

    if you are getting error like this Error: No developer directory found at /Developer”? then type

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

    Linking static libraries in Xcode

    Firstly, we pull in the .a files.

    Create a new Empty Application using Xcode. Assign a Product Name and Company Identifier. Then click Next and save the project. Locate the universal libs that we created (the .a files) under ffmpeg/universal/lib. Drag the .a files into the Frameworks folder in the Project Navigator pane. Tick “Copy items into destination group’s folder (if needed)”. And click Finish.

    Now we take care of the include files.

    Locate the include files under ffmpeg/armv7/include. Drag and drop the content of that folder onto the Project Name folder in the Project Navigator pane. Again, tick “Copy items into destination group’s folder (if needed)”. Then click Finish.

    Finally, we need to set the Header Search Paths for the project.

    Click on the Project in the Project Navigator pane. In the Standard Editor in the middle of the screen, click on Build Settings. Search for “Header Search Paths”. Add your project path and set it to Recursive. i.e. $(SRCROOT) Click on Build Phases. Under Link Binary With Libraries, add libbz2.dylib and libz.dylib.

    Test and verify the working of library

    We are not going to be in-depth here. Just to verify that the library is functioning. Go to your AppDelegate.m, and add:

    > #include "avformat.h"

    And in the didFinishLaunchingWithOptions function, add:

    av_register_all();

    if suppose you are getting this errors means

    Undefined symbols for architecture i386: "_iconv", referenced from: _mail_iconv in libmailcore.a(charconv.o) "_iconv_open", referenced from: _charconv in libmailcore.a(charconv.o) _charconv_buffer in libmailcore.a(charconv.o) "_iconv_close", referenced from: _charconv in libmailcore.a(charconv.o) _charconv_buffer in libmailcore.a(charconv.o) ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

    then add libiconv.dylib framework

    you are now ready to dive in to develop using FFmpeg on iOS.

    0 讨论(0)
  • 2020-11-28 04:52

    ./configure script:

    ./configure --extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system --disable-bzlib --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7' --enable-pic
    

    this works fine. since the default FFMPEG configuration script has the default Library path set to /usr/lib/system so it can not find library libcache.dylib, so here I have set it to the latest sdk path.

    0 讨论(0)
提交回复
热议问题