Windows环境下使用cygwin ndk_r9c编译FFmpeg

 一、废话

最近学习,第一步就是编译.我们需要编译FFmpag,x264,fdk_aac,一步步来.先来讲一下FFmpeg,网上说的很多都是几百年前的,我亲测完美可用

联系我可以直接评论,也可以加我QQ:11635423 

 二、干货 

 我能力有限,但是我希望我写的东西能够让更多的人能够接受.我也是刚刚接触.做一个记录,也希望能够对其他人有好处.

几个概念理解一下:不理解也没关系.用了之后再说慢慢就理解了.主要是因为我们是windows

        先是cygwin下的一些概念:
        unix style path: /cygdrive/盘符/目录名/文件名(其实是:/path/to/ mount/point/path/to/ file
        mixed style path: 盘符:/目录名/文件名
        windows style path: 盘符:\目录名\文件名
 
        用cygpath可以在这些路径形式之间转换
        cygpath -m  " path "
        cygpath -u  " path "
        cygpath - w  " path "

 

  准备:1.FFmpeg的源码

2.cygwin下载,安装,这个网上基本都有.我不讲太多.git cygdrive bash make 这几个都需要下载 

3.ndk我现在的版本r9c.最新的现在应该到r9d了.需要的去更新问题不大的.而且注意设置环境变量

我的设置如下: 因为下面的命令要用到,所以没设的就跟我设一样的就好,避免出现不必要的问题

ANDROID_NDK_ROOT  E:\android-ndk-r9c\

名字一样就好,路径还是你自己的.

4.编译脚本.这个脚本自己去理解吧.我也是一知半解--脚本名称:Config.sh

echo  " FFMPEG_SOURCE_DIR=$FFMPEG_SOURCE_DIR "
EXTRA_OPTIONS=()

case $OS  in
Android)
    GNU_BUILD_OS=linux

     case $ARCH  in
    armeabi-v7a*)
        TARGET_ARCH=arm
        GNU_BUILD_ARCH=armv7-a

        CROSSCOMPILE_PREFIX=arm-linux-androideabi-

        EXTRA_OPTIONS+=(
            --cpu=cortex-a9
            --extra-cflags=-mfpu=vfpv3-d16
            --extra-cflags=-DANDROID
            --extra-cflags=-gdwarf- 2
            --disable-fast-unaligned
            --extra-cflags=-mno-unaligned-access
        )
        ;;
     esac


     case $ARCH  in
    armeabi-v7a-hard)
        APP_PLATFORM=android- 19

        EXTRA_OPTIONS+=(
            --extra-cflags=-mhard- float
            --extra-cflags=-D_NDK_MATH_NO_SOFTFP= 1
            --extra-libs=-lm_hard
            --extra-ldflags=-Wl,--no-warn-mismatch
        )
        ;;
    armeabi-v7a)
        APP_PLATFORM=android- 8
        ;;
     esac

    SYSROOT= " ${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-${TARGET_ARCH} "
    ;;
Windows)
     case $ARCH  in
    x86_64)
        CROSSCOMPILE_PREFIX=x86_64-w64-mingw32-
        EXTRA_OPTIONS+=(
            --extra-cflags=-m64
        )
        ;;
     esac

    GNU_BUILD_OS=mingw32
    GNU_BUILD_ARCH=$ARCH
    ;;
Linux)
    GNU_BUILD_OS=linux
    GNU_BUILD_ARCH=$ARCH
    ;;
esac

INSTALL_SUBDIR=${OS}/${ARCH}

echo FDK_AAC_INSTALL_DIR=$FDK_AAC_INSTALL_DIR
echo X264_INSTALL_DIR=$X264_INSTALL_DIR


$FFMPEG_SOURCE_DIR/configure \
    --prefix=/ \
    --sysroot=${SYSROOT} \
    --cross-prefix=${CROSSCOMPILE_PREFIX} \
    --arch=$GNU_BUILD_ARCH \
    --target-os=$GNU_BUILD_OS \
     " ${EXTRA_OPTIONS[@]} " \
    --extra-cflags= " -I${FDK_AAC_INSTALL_DIR}/include " \
    --extra-cflags= " -I${X264_INSTALL_DIR}/include " \
    --extra-ldflags= " -L${FDK_AAC_INSTALL_DIR}/lib " \
    --extra-ldflags= " -L${X264_INSTALL_DIR}/lib " \
    \
    --enable-gpl \
    --enable-version3 \
    --enable-nonfree \
    \
    --enable-pic \
    \
    --disable-swscale-alpha \
    --disable-doc \
    --disable-network \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-avdevice \
    --disable-postproc \
    \
    --disable-everything \
    \
    --enable-demuxer=mov \
    --enable-demuxer=mpegts \
    --enable-demuxer=mp3 \
    --enable-demuxer=pcm_s16le \
    --enable-demuxer=rawvideo \
    \
    --enable-muxer=mp4 \
    --enable-muxer=mpegts \
    --enable-muxer=pcm_s16le \
    --enable-muxer=rawvideo \
    \
    --enable-decoder=amrnb \
    --enable-decoder=amrwb \
    --enable-decoder=h264 \
    --enable-decoder=mpeg4 \
    --enable-decoder=h263 \
    --enable-decoder=h263p \
    --enable-decoder=mp3 \
    --enable-decoder=pcm_s16le \
    --enable-decoder=aac \
    --enable-decoder=rawvideo \
    \
    --enable-encoder=libfdk_aac \
    --enable-encoder=libx264 \
    --enable-encoder=pcm_s16le \
    --enable-encoder=rawvideo \
    \
    \
    --enable-bsf=aac_adtstoasc \
    --enable-bsf=h264_mp4toannexb \
    \
    --enable-filter=scale \
    --enable-filter=aresample \
    --enable-filter=resample \
    --enable-filter=transpose \
    --enable-filter=vflip \
    --enable-filter=hflip \
    --enable-filter=crop \
    --enable-filter=amix \
    --enable-filter=pan \
    \
    --enable-protocol= file \
    \
    --enable-parser=mpegaudio \
    --enable-parser=mpeg4video \
    --enable-parser=h264 \
    --enable-parser=h263 \
    --enable-parser=aac \
    --enable-parser=aac_latm \

 三、编译

 FFmpeg

1.定位到编译目录
2.执行以下命令
TMP=$(cygpath -m  " $TMP ") \
ARCH=armeabi-v7a \
OS=Android \
ANDROID_NDK_ROOT=$(cygpath -m  " $ANDROID_NDK_ROOT ") \
FFMPEG_SOURCE_DIR=/cygdrive/e/soft/source/FFmpeg \
/cygdrive/e/qupai_code_eclipse/code/ThirdParty/Build/FFmpeg/Config. sh
3.修改config.h config.mk Makefile 路径问题 

config之后还需要修改build目录下config.mak中的SRC_PATH和Makefile(不是SRC_DIR下的)中的路径, 将其改为mixed style

 

4.执行make命令 --注意,这里使用NDK的make.
"$ANDROID_NDK_ROOT/prebuilt/windows/bin/make" -j8
5.执行install  --注意,这里使用NDK的make.
"$ANDROID_NDK_ROOT/prebuilt/windows-x86_64/bin/make" install DESTDIR="指定的安装目录,mixed style"

 

你可能感兴趣的:(windows)