extracting frames from movies on iPhone

February 10, 2010

The iPhone SDK provides a high level movie player, but so far there is no way to decode movies or extract frames. In this post I will show you how to do that using FFmpeg.

First, thanks to the FFmpeg project, Martin Böhme for his tutorial on using libavformat and libavcodec and David Conrad for the gas-preprocessor project that allows us to compile FFmpeg for the iPhone.

Before you link the FFmpeg libraries to your project, make sure that you understand FFmpeg’s licensing. My project uses the LGPL version of FFmpeg, which means that I have to make FFmpeg’s source code available (included in the project).

Before you create a commercial project that decodes H264 video, make sure that you get a license from MPEG LA.

The source code is posted on github: git://github.com/lajos/iFrameExtractor.git.

To compile and run the project on your iPhone:

  1. open Terminal
  2. clone the repository: git clone git://github.com/lajos/iFrameExtractor.git
  3. go to the ffmpeg folder in the project: cd iFrameExtractor/ffmpeg
  4. build the ffmpeg libraries: ./build_universal
  5. open the xcode project and run it on your iPhone device

The build_universal shell script creates libraries that work on both armv6 and armv7 processors. If you need libraries for pre-3Gs devices (iPhone 2g, iPhone3G, iPod Touch), use the build_armv6 script. For iPhone 3Gs only libraries, use build_armv7.

iFrameExtractorAppDelegate creates an instance of VideoFrameExtractor (the class that grabs images from the video). When you press the play button, iFrameExtractorAppDelegate sets up a loop and displays all the images from the video until it reaches the end of the movie.

The VideoFrameExtractor class is based on Martin Böhme’s tutorial, upgraded to use swscale. Initialize this class with the full path of the movie:

VideoFrameExtractor *video = [[VideoFrameExtractor alloc]
               initWithVideo:@"/full/path/to/movie.mov"];

By default, the output size will match the movie’s size. You can set outputWidth and outputHeight to change the dimensions:

video.outputWidth = 426;
video.outputHeight = 320;

Use stepFrame to grab the next frame. This method returns false if there are no more frames (reached the end of video):

BOOL result = [video stepFrame];

The processed frame can be accessed as a UIImage on the currentImage property:

UIImage *myImage = video.currentImage;

You can seek to a specific time (in seconds) using the seekTime: method:

[video seekTime:1.0];

The movie’s length can be queried by checking the duration property:

NSLog(@"video duration: %f",video.duration);

This should get you started with extracting frames from iPhone movies ;) If you find any problems, please submit a patch.

Known issues:

  • Images are always decoded as landscape.

55 Responses to “extracting frames from movies on iPhone”

  1. Hi,

    first, this is a very nice example how to use the FFMPEG together with Cocoa, very nice and clean design, thank you for the source code.

    But do you have also a Cocoa example for the opposite way? For example to encode a bunch of UIImages to a video with the FFMPEG?

    Regards,

    GM

  2. Hi,

    another question, is it possible to use the iFrameExtractor with the iPhone Simulator? As far as I can see, the FFmpeg builds only for armv6 and armv7, is a version for the iPhone Simulator possible as well?

    Regards,

    GM

  3. @George: I’m working on a project for video encoding. You can compile ffmpeg for i386 to run on the simulator, I’ll probably take a look at that when the encoding project is done.

  4. Thanks for example, i want to ask if you have a sample code or tutorial for using ffmpeg with stream audio, and if its possible using libmms (for mms;//).

    Regards,
    YD

  5. Hi,
    Can u help me in converting array of frames into video in iPhone using FFmpeg library. I’m greatly suffering from this and its urgent. Any link of code snippet will be very helpful.
    Please its urgent
    Thanks in Advance.

  6. Thanks for this tutorial - I think this ffmpeg stuff is so interesting. I also would love to see your encoding project!

  7. I too would like to see the encoding project.

    Also, how would i make it so that the user can open the camera role a choose the video that they would extract the frame from?

  8. Hi,

    Thanks for this great tutorial.
    Is there any update to build for iPhone simulator? Thanks

  9. Thanks for this tutorial,
    Unfortunately, i have the following error during compilation…
    I have exactly the same compilation error when using instructions from gas-preprocessor site…
    Any idea regarding this error (gcc-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags)???

    Creating config.mak and config.h…
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -DHAVE_AV_CONFIG_H -I. -I”/Users/fvisticot/Documents/Dev_iPhone/iFrameExtractor/ffmpeg” –sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -O2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk -arch armv7 -mcpu=cortex-a8 -std=c99 -fomit-frame-pointer -fPIC -marm -g -Wdeclaration-after-statement -Wall -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wno-pointer-sign -Wcast-qual -Wwrite-strings -Wundef -O3 -fno-math-errno -fno-tree-vectorize -MMD -MF libavdevice/alldevices.d -MT libavdevice/alldevices.o -c -o libavdevice/alldevices.o libavdevice/alldevices.c
    gcc-4.2: -E, -S, -save-temps and -M options are not allowed with multiple -arch flags

  10. @fvisticot: try compiling without -E, -S, -save-temps and -M?

  11. Thanks for this helpfull remark !!!
    Those parameters are not part of the main makefile. I don’t know how to disable those options.
    I do not understand why i need to do something specific to compile…

  12. Hi

    I wonder if Apple would accept an app using this library. Can anyone confirm this?

  13. @Cyttorak: pretty much any app that encodes or decodes video uses ffmpeg, so it doesn’t seem like apple would have any problems with it. However you definitely want to get a license from MPEG LA.

  14. Hi lajos,

    Thanks for the code, it’s really nice.

    I am trying to compile the code for 2 weeks to use on iPhone simulator but not success yet.

    Pls give some suggestion for compiling.

  15. thanks lajos.
    i run it on my iphone 3gs success.
    but i have a quesion,how to convert mov to mp4,use ffmpeg.

  16. Thanks a lot, this was just what I needed.
    I finally got it to work on the simulator (after about 4 hours of messing around) using this configure line:
    ./configure –enable-cross-compile –arch=i386 –cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1 –sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk –extra-cflags=”-mdynamic-no-pic” –target-os=darwin –disable-neon –disable-pic –enable-postproc –disable-debug –disable-stripping –enable-avfilter –enable-avfilter-lavf –enable-gpl –disable-bzlib

    and of course modifying the appropriate lines in the build_universal script:
    lipo -create -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.a

    etc.

    Hope this helps,
    Shahar

  17. Hi,

    When I running the build-universal script I getting the error: “Unrecognized input filetype at /bin/sh line 23″ I see that its from the gas-preprocessor.pl script.

    Pls help me.

    Thanks,
    Eyal.

  18. @Eyal: Make sure that you are running the build script in terminal from the ffmpeg folder.

  19. [...] http://www.codza.com/extracting-frames-from-movies-on-iphone [...]

  20. Hi,Thanks for example,it’s wonderful.

    But there is no sound when play movie.

    How to slove it ?

  21. @eidolon: this project only supports image extraction. You can extract the audio stream using ffmpeg and send the audio data to the iphone hardware, but I have example code for that.

  22. Hi All,

    Hope You All Enjoyed this nice tutorial. Sorry to say but i was not success to run an application. i have gone through all mentioned steps to build ffmpeg libraries in Terminal from ffmpeg folder, but the issue i found is when i build my xcode project it shows reference errors.

    I have posted logs bellow.. kindly have a look and give suggestion.

    Ld build/Debug-iphonesimulator/iFrameExtractor.app/iFrameExtractor normal i386
    cd /Users/ArunThakkar/Desktop/lajos
    setenv MACOSX_DEPLOYMENT_TARGET 10.5
    setenv PATH “/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk -L/Users/ArunThakkar/Desktop/lajos/build/Debug-iphonesimulator -L/Users/ArunThakkar/Desktop/lajos/ffmpeg -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/libavcodec -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/libavdevice -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/libavformat -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/libavutil -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/libswscale -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/universal -L/Users/ArunThakkar/Desktop/lajos/ffmpeg/lib -F/Users/ArunThakkar/Desktop/lajos/build/Debug-iphonesimulator -filelist /Users/ArunThakkar/Desktop/lajos/build/iFrameExtractor.build/Debug-iphonesimulator/iFrameExtractor.build/Objects-normal/i386/iFrameExtractor.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -lz -lavformat -framework CoreGraphics -framework UIKit -lavcodec -lavdevice -lavutil -lswscale -o /Users/ArunThakkar/Desktop/lajos/build/Debug-iphonesimulator/iFrameExtractor.app/iFrameExtractor

    ld: warning: in /Users/ArunThakkar/Desktop/lajos/ffmpeg/universal/libavformat.a, missing required architecture i386 in file
    ld: warning: in /Users/ArunThakkar/Desktop/lajos/ffmpeg/universal/libavcodec.a, missing required architecture i386 in file
    ld: warning: in /Users/ArunThakkar/Desktop/lajos/ffmpeg/universal/libavdevice.a, missing required architecture i386 in file
    ld: warning: in /Users/ArunThakkar/Desktop/lajos/ffmpeg/universal/libavutil.a, missing required architecture i386 in file
    ld: warning: in /Users/ArunThakkar/Desktop/lajos/ffmpeg/universal/libswscale.a, missing required architecture i386 in file
    Undefined symbols:
    “_avcodec_flush_buffers”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    “_avcodec_find_decoder”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_open”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_open_input_file”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_sws_freeContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_av_free_packet”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_sws_getContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_avcodec_decode_video2″, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_av_read_frame”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_avpicture_alloc”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_av_find_stream_info”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_register_all”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_alloc_frame”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_free”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avcodec_close”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_sws_scale”, referenced from:
    -[VideoFrameExtractor convertFrameToRGB] in VideoFrameExtractor.o
    “_av_close_input_file”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avformat_seek_file”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Thanks

    Regards,
    Arun Thakkar.

  23. Hi,iFrameExtractor doesn’t work on iOS4(3.1.3 upgrade)…

  24. @sukiyaki: Thanks for the note. I think this is because 3.1.2 gcc might not be part of sdk 4.0. I’ll take a look.

  25. @lajos: i was able to compile i386 and universal but when i run the project on xcode i’m getting this error:

    “_BZ2_bzDecompressInit”, referenced from: _matroska_decode_buffer in libavformat.a(matroskadec.o)
    “_BZ2_bzDecompress”, referenced from:
    _matroska_decode_buffer in libavformat.a(matroskadec.o)
    “_BZ2_bzDecompressEnd”, referenced from: _matroska_decode_buffer in libavformat.a(matroskadec.o)

    ld: symbol(s) not found

    any ideas how to fix this?

    thanks in advance. :)

  26. @sukiyaki: you need to recompile the builds on top of your new sdk4.0 that worked for me except for the boost-lib errors.

  27. @lajos: i got it working… i edited line 225 of build_i386 from:
    ./configure –disable-mmx –disable-doc –disable-ffmpeg –disable-ffplay –disable-ffserver –cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1 –as=’gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1′ –sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk –extra-cflags=’-fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=30000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2′

    to

    ./configure –disable-bzlib –disable-mmx –disable-doc –disable-ffmpeg –disable-ffplay –disable-ffserver –cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1 –as=’gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1′ –sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk –extra-cflags=’-fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=30000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2′

    basically just added the –disable-bzlib at the beginning of the config line to disable the bzlib… recompiled it again and eurika!!

    i guess you can do the same for the universal builds.

    hope this helps.

  28. @junjet: thanks! I’ll make that fix in the repo.

  29. hello very useful code! thank you.
    but thumbnail is always landscape mode. :(
    is there any solution???

  30. @saito: unfortunatelly the movies are stored landscape and the orientation info is stored in a quicktime atom that ffmpeg doesn’t (yet) understand.

  31. @Arun: get the latest version from git hub, it now builds i386 (simulator) versions of the library.

  32. Hi.Thanks for this great work!

    I have try to build to my iPhone 3g 3.1.3 . But only 3FPS. -.-

    But simulator have >100Fps. CPU %15

    Plz help.. :)

    Maybe SDL is better ? But how use SDL and iPhone SDK UIKit. ?

    Regards!
    -Sue

  33. @lajos

    is there a way you can make a sample code that does the reverse of this? encoding images+audio into the video?

    thanks in advance,

    junjet

  34. Hi lajos,

    Thank you very much for this sample.
    Do you know which ffmpeg version is ok with the latest gas-preprocessor from yuvi ?
    I’m not able to build any version from the svn trunk, or when it succeeds the linker (xcode) complains about missing references.

    Thanx again,
    Guillaume

  35. @Guillaume: It looks like there is a new library in the latest trunk called libavcore. I’ll add it to the build scripts when I find some time… until then you can just add a line to copy libavcore to the built folder in the build scripts, it should be pretty easy.

  36. @junjet: I’ve been meaning to do that for some time but I’ve been super busy. Look at output-example.c in the ffmpeg sources. It’s pretty straight forward and should not be too hard to create an objc class based on it.

  37. @Sulifu: the processor in the iPhone is not as fast as a desktop processor, and we don’t have access to the hardware encoder/decoder. If you can, try to encode your source videos with a different codes. Some decode faster than other. SDL will probably not make it faster, because as soon as the image is a UIImage it’s accelerated by the gfx card.

  38. [...] (http://www.codza.com/extracting-frames-from-movies-on-iphone) [...]

  39. Hi,

    Thanks for this great tutorial.It save my time a lot….Now i am trying for a video editing app and there is any way to Extract audio using this …?can you give me some example code for that..?

  40. Hi, is there any tutorial for editing movies and audio like IMovie app….if there please send me the link….it is urgent

  41. Hi ,
    Thanks for this great tutorial.!

    if i use this build ffmpeg to recv and play RTSP. It was got error like:

    [m4v @ 0x6863000]Estimating duration from bitrate, this may be inaccurate
    [swscaler @ 0xb0b4a00]No accelerated colorspace conversion found.

    [mpeg4 @ 0x6851000]ac-tex damaged at 8 6
    [mpeg4 @ 0x6851000]Error at MB: 80
    [mpeg4 @ 0x6851000]concealing 74 DC, 74 AC, 74 MV errors

    log:
    enter av_read_frame < 0

    and when I run simple in simulator. it was 200FPS. but in driv it was < 10fps.

    Hope your rep!

    Best Regards!

  42. Hi,

    I cannot build for arvm6 and arvm7 but I can build for i386. But, even for the library built by i386, the compiler tells me the error:

    “_posix_memalign”, referenced from:
    _av_malloc in libavutil.a(mem.o)
    _av_strdup in libavutil.a(mem.o)
    _av_mallocz in libavutil.a(mem.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

  43. Hi,
    First, Thanks for your kindness
    however, i followed your steps but i have two errors that

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    so, i ask you to find ways to solve these problems.
    Thanks.

  44. Thanks lajos, i did play it on my 3GS.

    by the way, you did say that you have sample source of extracting sound and send it to iphone-hardware.
    would you show me the sample i study for audio streaming with ffmpeg.
    Thanks for your kindness

    Best Regards!

  45. how to convert array of UIImages into a movie file ….preferably mp4 format by using ffmpeg ….please if there are any tutorial give me the link

  46. Hi, i’m stucked on a compilation problem on XCode 3.2.2.

    I follow the instrunctions and the FFmpeg libraries are build Ok. In fact, i compile the iFrameExtractor project for Simulator and Device with no problems.

    Now i want to use this libraries on my application project. I import the VideoFrameExtractor.m and .h file and also the .a libraries.

    I copy all the search paths configurations from iFrameExtractor project.

    Trying to compile to simulator it compile with no errors and run the program.

    Well, now i try to compile to Device. And i have this errors:

    Ld build/MyProject.build/Debug-iphoneos/MyProject.build/Objects-normal/armv7/MyProject normal armv7
    cd /Projects/MyProject
    setenv IPHONEOS_DEPLOYMENT_TARGET 3.1
    setenv PATH “/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -L/Projects/MyProject/build/Debug-iphoneos -L/Projects/MyProject/../../Work/libs/GHUnit -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/lib -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/libavcodec -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/libavdevice -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/libavformat -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/libavutil -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/libswscale -L/Projects/MyProject/../LIBS/iFrameExtractor/ffmpeg/universal -L/Projects/MyProject/ffmpeg/lib -F/Projects/MyProject/build/Debug-iphoneos -F/Projects/MyProject/../../Work/libs/GHUnit -filelist /Projects/MyProject/build/MyProject.build/Debug-iphoneos/MyProject.build/Objects-normal/armv7/MyProject.LinkFileList -dead_strip -all_load -ObjC -miphoneos-version-min=3.1 -framework Foundation -weak_framework UIKit -framework AudioToolbox -framework CFNetwork -framework SystemConfiguration -framework MobileCoreServices -framework QuartzCore /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20.a -framework CoreData -framework OpenGLES -framework CoreFoundation -framework AVFoundation /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20Core.a /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20Network.a /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20Style.a /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20UI.a /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20UICommon.a /Projects/three20-v2.0/Build/Products/Debug-iphoneos/libThree20UINavigator.a -framework MapKit -lobjc.A -framework Security -lz -framework CoreLocation -framework CoreGraphics -lavcodec -lavdevice -lavformat -lavutil -lswscale -o /Projects/MyProject/build/MyProject.build/Debug-iphoneos/MyProject.build/Objects-normal/armv7/MyProject

    ld: warning: in /Projects/LIBS/iFrameExtractor/ffmpeg/lib/libavcodec.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Projects/LIBS/iFrameExtractor/ffmpeg/lib/libavdevice.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Projects/LIBS/iFrameExtractor/ffmpeg/lib/libavformat.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Projects/LIBS/iFrameExtractor/ffmpeg/lib/libavutil.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Projects/LIBS/iFrameExtractor/ffmpeg/lib/libswscale.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    Undefined symbols:
    “_sws_scale”, referenced from:
    -[VideoFrameExtractor convertFrameToRGB] in VideoFrameExtractor.o
    “_av_register_all”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_alloc_frame”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_find_stream_info”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avpicture_free”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avformat_seek_file”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    “_avcodec_find_decoder”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_decode_video2″, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_avpicture_alloc”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_sws_freeContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avcodec_flush_buffers”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    “_av_open_input_file”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_sws_getContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_av_free”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_av_read_frame”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_avcodec_open”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_close”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_av_free_packet”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_av_close_input_file”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    ** I don’t known what settings is missing. I’m freaking out because the iFrameExtractor project works fine.

  47. Well. Finally i made it. Is working, i reproduce the steps here.

    Basically the problem was the way that i import the files on my project, the XCode wan’t linking to the correct .a files for the correct architecture automatically.

    So first, i create on Finder the folder ffmpeg, all folders of libraries and headers.

    Then i import only the folder ffmpeg to XCode making sure that the Path Type was: Relative to Enclosing Group.

    Then i import all the libraries on the folder ffmpeg/lib also making sure that the Path Type was: Relative to Enclosing Group.

    Now it compiles linking with the correct libraries when i set to Device or Simulator.

    Hope it helps.

  48. [...] some information about FFmpeg. Use FFmpeg on your iOS project is a little tricky, check this post on codza to learn how to install [...]

  49. Anybody get this compiled for OS4 on the new iPhone? I have it compiled and running in the simulator but get the following undefined symbols when trying to link to the armv7 libraries I have built when compiling for the iPhone.

    Undefined symbols:
    “_sws_getContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_avcodec_open”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avformat_seek_file”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    “_avcodec_flush_buffers”, referenced from:
    -[VideoFrameExtractor seekTime:] in VideoFrameExtractor.o
    “_sws_freeContext”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_av_read_frame”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_avcodec_find_decoder”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_free”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avpicture_free”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_avcodec_alloc_frame”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avpicture_alloc”, referenced from:
    -[VideoFrameExtractor setupScaler] in VideoFrameExtractor.o
    “_av_open_input_file”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_avcodec_decode_video2″, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_avcodec_close”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    “_sws_scale”, referenced from:
    -[VideoFrameExtractor convertFrameToRGB] in VideoFrameExtractor.o
    “_av_find_stream_info”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_register_all”, referenced from:
    -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
    “_av_free_packet”, referenced from:
    -[VideoFrameExtractor stepFrame] in VideoFrameExtractor.o
    “_av_close_input_file”, referenced from:
    -[VideoFrameExtractor dealloc] in VideoFrameExtractor.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    I added the armv7 directory to the “Library Search Paths” but no luck.

    Any help would be much appreciated!

    Larry

  50. Actually, I am now stuck on this Unsupported File Format message so I guess the libraries I built are garbage. Any ideas?

    ld: warning: in /Developer/ffmpeg/lib/armv6/libavcodec.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Developer/ffmpeg/lib/armv6/libavformat.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Developer/ffmpeg/lib/armv6/libavutil.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Developer/ffmpeg/lib/armv6/libswscale.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    ld: warning: in /Developer/ffmpeg/lib/armv6/libavdevice.a, file was built for unsupported file format which is not the architecture being linked (armv7)
    Undefined symbols:

  51. Hi lajos,

    I am also having same problem as “ghotetz”, as follows:

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    Can you share its solution with me?

    Thanks in advance.

  52. Hi lajos,

    finally I was able to compile it successfully. it was my silly mistake, without looking into deep I asked you.
    Thanks for your tutorial.

    Keep yourself happy :),
    Sanniv.

  53. Thank you for the nice ‘drop in/starting point sample’ to be able to experiment further with ffmpeg (and on iOS).

    Those trying to build with the (current) iOS 4.1 gm seed (Xcode 3.2.4) SDK may notice that they only have the 4.1 and 3.2 SDK installed (in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/) and not 4.0 as the build scripts reference.
    To work around this replace occurrences of ‘4.0′ with ‘4.1′ in build_armv6, build_armv7 (and in build_i386 too wouldn’t hurt, even though the iPhoneSimulator4.0.sdk is still available).
    To build (the *libraries*, more changes to the Xcode project might be needed) for the iPad, ‘4.0′ should be replaced with ‘3.2′.

    @Ramkumar: You might find “Session 407 - Editing Media with AV Foundation” from WWDC 2010 interesting/useful. It is available for download through iTunes U. http://developer.apple.com/videos/wwdc/2010/

  54. hi,I have the same problem

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    ld: library not found for -lavformat
    Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    Thanks.
    please help

  55. Hi, I done for configuration and compile the App with ffmpeg lib, but some thing happened on putting my iphone device…

    I got this message :

    dyld: Library not loaded: /usr/local/lib/libavcodec.dylib
    Referenced from: /var/mobile/Applications/66E93E8A-AA25-4D9A-B69F-F4F040D84E17/MyAPP.app/MyAPP
    Reason: image not found

    Would you have any idea ?

    Thanks for watching~

Leave a Reply