AVPlayer를 컴파일하는 방법을 밑에서 포스팅했었습니다. 몇분이 질문을 하셔서 체크도 해볼 겸 다시 컴파일해 보니 왠 걸. 몇 달이나 되었다고 이것 저것 바뀌었더군요. 답변 몇줄 적는 걸로 해결되지 않을 것 같아 다시 정리해 보았습니다. 변경된 부분 위주로 빨간색으로 체크해 두었습니다.
준비물
- Snow Leopard 가 설치된 Mac
- Xcode 최신버전 (4.0.1, iPhoneOS4.3 SDK)
- AVPlayer source code
http://eplayworks.com/avplayer/AVPlayer-Objects.zip
위의 사이트에서 source code를 다운받습니다. - gabriel의 ffmpeg ios compile script꼭 필요한 것은 아니지만 참고 필요.
FFmpeg library만들기
- AVPlayer-Objects.zip을 작업할 폴더에 풉니다.
- __MACOSX 폴더는 지우세요.
- AVPlayer 안에 FFMPEG 디렉토리로 이동합니다.
- gas-preprocessor.pl을 /usr/local/bin으로 복사합니다.
- build-armv7으로 armv7용 library만 만드는 것도 가능하지만 combine-libs를 보면 뭔가 이상하죠? 사실 이 스크립드의 원본은 gabriel의 ffmpeg ios compile script입니다. 제대로 armv6, armv7, i386 library를 만들어서 universal library를 만들어 봅시다. (script가 수정되었으니 여기에 첨부된 것을 받으세요)
- 위의 첨부된 파일을 받아 FFMPEG 디렉토리에 풉니다.
- gabriel의 소스에서 svn의 revision을 고정했고 target 마다 별도의 svn source를 다운하지 않도록 변경되었고 configure의 option이 수정되었습니다. --enable-postproc 이 제거되었고 --enable-gpl 을 off 시켰습니다. gpl option을 켜면 LGPL license가 아닌 GPL license가 됩니다. 모든 소스를 공개해야 되죠. 마찬가지의 이유로 LGPL의 경우 libx264나 libxvid를 사용할 수 없게 됩니다.
- svn에서 checkout하는 부분은 git으로 clone하도록 수정되었습니다. 더이상 ffmpeg에서 svn로 source를 공유하지 않습니다. 또한 ffmpeg의 configure option이 변경되었기 때문에 --extra-ldflags="-arch arm7" 뒤에 -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system 이 추가되었습니다. 그리고 document 생성에 문제가 있어 --disable-doc 이 추가되었습니다.
- 바로 build script를 돌리면 지금(2011-04-24)의 ffmpeg은 버그가 있어서 컴파일되지 않습니다.
Undefined symbols for architecture armv7:
"memset", referenced from:
_ff_ac3_bit_alloc_calc_bap_armv6 in libavcodec.a(ac3dsp_armv6.o)
(maybe you meant:__memset_chk, _memset )
"ff_vp8_dct_cat_prob", referenced from:
.Literal_2 in libavcodec.a(vp8_armv6.o)
(maybe you meant: __ff_vp8_dct_cat_prob)
ld: symbol(s) not found for architecture armv7
이런 메시지가 나오면서 link에서 문제가 발생합니다.
ffmpeg-source/libavcodec/ac3dsp_armv6.S 의 82 line에서
b memset 을 b X(memset) 으로
ffmpeg-source/libavcodec/vp8_armv6.S 의 183 line에서
movrel r4, ff_vp8_dct_cat_prob 를 movrel r4, X(ff_vp8_dct_cat_prob) 로
수정하셔야 합니다. - 이제 순서대로 build-armv6, build-armv7, build-i386 스크립트를 실행합니다. ffmpeg 사이트에서 소스를 checkout해 온 후 configure, make를 순서대로 수행하게 됩니다.
- 모든 target의 library가 compile되면 ffmpeg-armv6/dist, ffmpeg-armv7/dist, ffmpeg-i386/dist에 include, lib 디렉토리가 만들어지고 해더와 라이브러리가 생성됩니다.
- combine-libs를 실행해서 모든 target의 library를 합칩니다. ffmpeg-uarch에 최종 헤더와 라이브러리가 만들어집니다. libavcore.a는 더이상 존재하지 않습니다. combine-libs에서도 제거되어야 합니다.
AVPlayer compile하기
- Xcode로 AVPlayer project를 엽니다.
- Targets 에서 AVPlayer,AVPlayerHD의 Build Settings을 선택합니다.
- Search Paths 항목의 Header Search Paths 란의 내용을 수정합니다. $(SRCROOT)/FFMPEG/ffmpeg-uarch/include, $(SRCROOT)/FFMPEG/ffmpeg-armv7/dist/include 이런식으로 수정하고 Recursive를 체크하면 됩니다.
- Search Paths 항목의 Library Search Paths 란의 내용을 수정합니다. $(SRCROOT)/FFMPEG/ffmpeg-uarch/lib, $(SRCROOT)/FFMPEG/ffmpeg-armv7/dist/lib 식으로 수정하고 Recursive를 체크하면 됩니다.
- AVPlayer/LIBS/FFMPEG 밑의 libavcodec.a, libavcore.a, libavdevice.a, libavfilter.a, libavformat.a, libavutil.a, libswscale.a의 Utilities 창을 열고 경로를 수정합니다. AVPlayer/FFMPEG/ffmpeg-uarch/lib 밑에 있는 library를 지정하면 됩니다. libavcore.a는 이제 존재하지 않습니다. library에서 제거하세요.
- 프로젝트의 라이브러리 설정은 모두 수정되었습니다. 이제 build 버튼만 누르면 됩니다. 단, 주의하실 점은 Simulator로는 build가 되지 않습니다. libAVPlayerLib.a에 AVPlayer의 중요한 코드들이 모두 숨어있는데, 이 라이브러리가 i386으로 compile 되어 있지 않습니다. arm용으로만 compile되어 있기 때문에 Device로만 bulid 가능합니다.